aboutsummaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2014-09-29 01:12:42 +0300
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2014-09-29 01:12:42 +0300
commit15f40128402690804efd9e948234f12a4e7d5050 (patch)
treec2248255f618ce7267de10b17280dd9b1858fcaa /src/net
parenta613195ef42ca5a88e663b17d6419ab4a6db1891 (diff)
downloadjitsi-15f40128402690804efd9e948234f12a4e7d5050.zip
jitsi-15f40128402690804efd9e948234f12a4e7d5050.tar.gz
jitsi-15f40128402690804efd9e948234f12a4e7d5050.tar.bz2
Fixes warnings, bugs. Reduces source code duplication. Simplifies, clarifies source code.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/java/sip/communicator/impl/argdelegation/ArgDelegationPeerImpl.java45
-rw-r--r--src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java21
-rw-r--r--src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java45
-rw-r--r--src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java33
-rw-r--r--src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java47
-rw-r--r--src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageActivator.java45
-rw-r--r--src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageServiceImpl.java5
-rw-r--r--src/net/java/sip/communicator/impl/filehistory/FileHistoryActivator.java18
-rw-r--r--src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java69
-rw-r--r--src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java23
-rw-r--r--src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutActivator.java74
-rw-r--r--src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java38
-rw-r--r--src/net/java/sip/communicator/impl/gui/GuiActivator.java134
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/MainFrame.java53
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/account/AccountRegWizardContainerImpl.java54
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/account/AccountRightButtonMenu.java44
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java38
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java25
-rw-r--r--src/net/java/sip/communicator/impl/muc/MUCActivator.java29
-rw-r--r--src/net/java/sip/communicator/plugin/otr/OtrActivator.java80
-rw-r--r--src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigActivator.java49
-rw-r--r--src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigurationPanel.java84
-rw-r--r--src/net/java/sip/communicator/service/protocol/AccountManager.java44
-rw-r--r--src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java3
-rw-r--r--src/net/java/sip/communicator/service/systray/AbstractSystrayService.java45
-rw-r--r--src/net/java/sip/communicator/util/ServiceObserver.java91
-rw-r--r--src/net/java/sip/communicator/util/ServiceUtils.java70
27 files changed, 566 insertions, 740 deletions
diff --git a/src/net/java/sip/communicator/impl/argdelegation/ArgDelegationPeerImpl.java b/src/net/java/sip/communicator/impl/argdelegation/ArgDelegationPeerImpl.java
index 273000f..568eb65 100644
--- a/src/net/java/sip/communicator/impl/argdelegation/ArgDelegationPeerImpl.java
+++ b/src/net/java/sip/communicator/impl/argdelegation/ArgDelegationPeerImpl.java
@@ -48,40 +48,23 @@ public class ArgDelegationPeerImpl
*/
public ArgDelegationPeerImpl(BundleContext bundleContext)
{
- Collection<ServiceReference<UriHandler>> uriHandlerRefs;
+ Collection<ServiceReference<UriHandler>> uriHandlerRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ UriHandler.class);
- try
- {
- uriHandlerRefs
- = bundleContext.getServiceReferences(UriHandler.class, null);
- }
- catch (InvalidSyntaxException ex)
- {
- // This shouldn't happen because we aren't using a filter but let's
- // log just the same.
- if (logger.isInfoEnabled())
- {
- logger.info(
- "An error occurred while retrieving UriHandlers",
- ex);
- }
- return;
- }
-
- if((uriHandlerRefs == null) || uriHandlerRefs.isEmpty())
- {
- // No URI handlers are registered at this point. Some might come
- // later.
- return;
- }
-
- synchronized (uriHandlers)
+ if (!uriHandlerRefs.isEmpty())
{
- for (ServiceReference<UriHandler> uriHandlerRef : uriHandlerRefs)
+ synchronized (uriHandlers)
{
- UriHandler uriHandler = bundleContext.getService(uriHandlerRef);
-
- uriHandlers.put(uriHandler.getProtocol(), uriHandler);
+ for (ServiceReference<UriHandler> uriHandlerRef
+ : uriHandlerRefs)
+ {
+ UriHandler uriHandler
+ = bundleContext.getService(uriHandlerRef);
+
+ uriHandlers.put(uriHandler.getProtocol(), uriHandler);
+ }
}
}
}
diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java
index d18cb44..6e3d5fa 100644
--- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java
+++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java
@@ -147,23 +147,12 @@ public class CallHistoryActivator
public static Map<Object, ProtocolProviderFactory>
getProtocolProviderFactories()
{
- Collection<ServiceReference<ProtocolProviderFactory>> serRefs;
- try
- {
- // get all registered provider factories
- serRefs
- = bundleContext.getServiceReferences(
- ProtocolProviderFactory.class,
- null);
-
- }
- catch (InvalidSyntaxException e)
- {
- serRefs = null;
- logger.error("LoginManager : " + e);
- }
+ Collection<ServiceReference<ProtocolProviderFactory>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
- if (serRefs != null)
+ if (!serRefs.isEmpty())
{
for (ServiceReference<ProtocolProviderFactory> serRef : serRefs)
{
diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java
index d83c6ad..117fb34 100644
--- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java
@@ -618,23 +618,13 @@ public class CallHistoryServiceImpl
// start listening for newly register or removed protocol providers
bc.addServiceListener(this);
- Collection<ServiceReference<ProtocolProviderService>> ppsRefs;
-
- try
- {
- ppsRefs
- = bc.getServiceReferences(ProtocolProviderService.class, null);
- }
- catch (InvalidSyntaxException ex)
- {
- ppsRefs = null;
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error("Error while retrieving service refs", ex);
- }
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
+ = ServiceUtils.getServiceReferences(
+ bc,
+ ProtocolProviderService.class);
// in case we found any
- if (ppsRefs != null)
+ if (!ppsRefs.isEmpty())
{
if (logger.isDebugEnabled())
{
@@ -646,7 +636,7 @@ public class CallHistoryServiceImpl
{
ProtocolProviderService pps = bc.getService(ppsRef);
- this.handleProviderAdded(pps);
+ handleProviderAdded(pps);
}
}
}
@@ -660,34 +650,23 @@ public class CallHistoryServiceImpl
{
bc.removeServiceListener(this);
- Collection<ServiceReference<ProtocolProviderService>> ppsRefs;
-
- try
- {
- ppsRefs
- = bc.getServiceReferences(ProtocolProviderService.class, null);
- }
- catch (InvalidSyntaxException ex)
- {
- ppsRefs = null;
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error("Error while retrieving service refs", ex);
- }
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
+ = ServiceUtils.getServiceReferences(
+ bc,
+ ProtocolProviderService.class);
// in case we found any
- if (ppsRefs != null)
+ if (!ppsRefs.isEmpty())
{
for (ServiceReference<ProtocolProviderService> ppsRef : ppsRefs)
{
ProtocolProviderService pps = bc.getService(ppsRef);
- this.handleProviderRemoved(pps);
+ handleProviderRemoved(pps);
}
}
}
-
/**
* Writes the given record to the history service
* @param callRecord CallRecord
diff --git a/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java b/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java
index 0183ae3..01721ef 100644
--- a/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java
+++ b/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java
@@ -286,21 +286,14 @@ public class MclStorageManager
bundleContext = bc;
// retrieve a reference to the file access service.
- ServiceReference faServiceReference =
- bundleContext
- .getServiceReference(FileAccessService.class.getName());
-
- faService =
- (FileAccessService) bundleContext.getService(faServiceReference);
+ faService
+ = ServiceUtils.getService(bundleContext, FileAccessService.class);
// retrieve a reference to the file access service.
- ServiceReference confServiceRefs =
- bundleContext.getServiceReference(ConfigurationService.class
- .getName());
-
- ConfigurationService configurationService =
- (ConfigurationService) bundleContext.getService(confServiceRefs);
-
+ ConfigurationService configurationService
+ = ServiceUtils.getService(
+ bundleContext,
+ ConfigurationService.class);
String fileName = configurationService.getString(FILE_NAME_PROPERTY);
if (fileName == null)
@@ -312,12 +305,16 @@ public class MclStorageManager
// get a reference to the contact list file.
try
{
- contactlistFile = faService.getPrivatePersistentFile(fileName,
- FileCategory.PROFILE);
-
+ contactlistFile
+ = faService.getPrivatePersistentFile(
+ fileName,
+ FileCategory.PROFILE);
if (!contactlistFile.exists() && !contactlistFile.createNewFile())
- throw new IOException("Failed to create file"
- + contactlistFile.getAbsolutePath());
+ {
+ throw new IOException(
+ "Failed to create file"
+ + contactlistFile.getAbsolutePath());
+ }
}
catch (Exception ex)
{
diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java
index a17d3fc..b4481a8 100644
--- a/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java
@@ -159,9 +159,9 @@ public class MetaContactListServiceImpl
{
storageManager.start(bundleContext, this);
}
- catch (Exception exc)
+ catch (Exception ex)
{
- logger.error("Failed loading the stored contact list.", exc);
+ logger.error("Failed loading the stored contact list.", ex);
}
// start listening for newly register or removed protocol providers
@@ -169,36 +169,26 @@ public class MetaContactListServiceImpl
// first discover the icq service
// then find the protocol provider service
- ServiceReference[] protocolProviderRefs = null;
- try
- {
- protocolProviderRefs = bc.getServiceReferences(
- ProtocolProviderService.class.getName(),
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
- return;
- }
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
+ = ServiceUtils.getServiceReferences(
+ bc,
+ ProtocolProviderService.class);
// in case we found any, retrieve the root groups for all protocol
// providers and create the meta contact list
- if (protocolProviderRefs != null)
+ if (!ppsRefs.isEmpty())
{
if (logger.isDebugEnabled())
- logger.debug("Found "
- + protocolProviderRefs.length
- + " already installed providers.");
- for (ServiceReference providerRef : protocolProviderRefs)
{
- ProtocolProviderService provider
- = (ProtocolProviderService) bc.getService(providerRef);
+ logger.debug(
+ "Found " + ppsRefs.size()
+ + " already installed providers.");
+ }
+ for (ServiceReference<ProtocolProviderService> ppsRef : ppsRefs)
+ {
+ ProtocolProviderService pps = bc.getService(ppsRef);
- this.handleProviderAdded(provider);
+ handleProviderAdded(pps);
}
}
}
@@ -2353,11 +2343,10 @@ public class MetaContactListServiceImpl
// before that however, we'd need to get a reference to the service.
ProtocolProviderFactory sourceFactory = null;
- ServiceReference[] allBundleServices
- = event.getServiceReference().getBundle()
- .getRegisteredServices();
+ ServiceReference<?>[] allBundleServices
+ = event.getServiceReference().getBundle().getRegisteredServices();
- for (ServiceReference bundleServiceRef : allBundleServices)
+ for (ServiceReference<?> bundleServiceRef : allBundleServices)
{
Object service = bundleContext.getService(bundleServiceRef);
if(service instanceof ProtocolProviderFactory)
diff --git a/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageActivator.java b/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageActivator.java
index 632c599..ba581ac 100644
--- a/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageActivator.java
+++ b/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageActivator.java
@@ -20,6 +20,11 @@ public class CredentialsStorageActivator
implements BundleActivator
{
/**
+ * The {@link BundleContext}.
+ */
+ private static BundleContext bundleContext;
+
+ /**
* The <tt>Logger</tt> used by the <tt>CredentialsStorageActivator</tt>
* class and its instances.
*/
@@ -27,14 +32,21 @@ public class CredentialsStorageActivator
= Logger.getLogger(CredentialsStorageActivator.class);
/**
- * The {@link CredentialsStorageService} implementation.
+ * Returns service to show master password input dialog.
+ * @return return master password service to display input dialog.
*/
- private CredentialsStorageServiceImpl impl;
+ public static MasterPasswordInputService getMasterPasswordInputService()
+ {
+ return
+ ServiceUtils.getService(
+ bundleContext,
+ MasterPasswordInputService.class);
+ }
/**
- * The {@link BundleContext}.
+ * The {@link CredentialsStorageService} implementation.
*/
- private static BundleContext bundleContext;
+ private CredentialsStorageServiceImpl impl;
/**
* Starts the credentials storage service
@@ -76,28 +88,7 @@ public class CredentialsStorageActivator
{
logger.logEntry();
impl.stop();
- logger
- .info("The CredentialsStorageService stop method has been called.");
- }
-
- /**
- * Returns the service corresponding to the <tt>ServiceReference</tt>.
- *
- * @param serviceReference service reference
- * @return service
- */
- public static Object getService(ServiceReference serviceReference)
- {
- return bundleContext.getService(serviceReference);
- }
-
- /**
- * Returns service to show master password input dialog.
- * @return return master password service to display input dialog.
- */
- public static MasterPasswordInputService getMasterPasswordInputService()
- {
- return ServiceUtils.getService(
- bundleContext, MasterPasswordInputService.class);
+ logger.info(
+ "The CredentialsStorageService stop method has been called.");
}
}
diff --git a/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageServiceImpl.java b/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageServiceImpl.java
index 87bbfc2..672a0a9 100644
--- a/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/credentialsstorage/CredentialsStorageServiceImpl.java
@@ -75,7 +75,7 @@ public class CredentialsStorageServiceImpl
void start(BundleContext bc)
{
configurationService
- = ServiceUtils.getService(bc, ConfigurationService.class);
+ = ServiceUtils.getService(bc, ConfigurationService.class);
/*
* If a master password is set, the migration of the unencrypted
@@ -471,7 +471,8 @@ public class CredentialsStorageServiceImpl
if(masterPasswordInputService == null)
{
- logger.error("Missing MasterPasswordInputService to show input dialog");
+ logger.error(
+ "Missing MasterPasswordInputService to show input dialog");
return null;
}
diff --git a/src/net/java/sip/communicator/impl/filehistory/FileHistoryActivator.java b/src/net/java/sip/communicator/impl/filehistory/FileHistoryActivator.java
index adcdf0f..6f0abad 100644
--- a/src/net/java/sip/communicator/impl/filehistory/FileHistoryActivator.java
+++ b/src/net/java/sip/communicator/impl/filehistory/FileHistoryActivator.java
@@ -23,8 +23,8 @@ public class FileHistoryActivator
* The <tt>Logger</tt> instance used by the
* <tt>FileHistoryActivator</tt> class and its instances for logging output.
*/
- private static Logger logger =
- Logger.getLogger(FileHistoryActivator.class);
+ private static Logger logger
+ = Logger.getLogger(FileHistoryActivator.class);
/**
* A <tt>FileHistoryService</tt> service reference.
@@ -43,22 +43,20 @@ public class FileHistoryActivator
logger.logEntry();
- ServiceReference refHistory = bundleContext.getServiceReference(
- HistoryService.class.getName());
-
- HistoryService historyService = (HistoryService)
- bundleContext.getService(refHistory);
+ HistoryService historyService
+ = ServiceUtils.getService(bundleContext, HistoryService.class);
//Create and start the file history service.
- fileHistoryService =
- new FileHistoryServiceImpl();
+ fileHistoryService = new FileHistoryServiceImpl();
// set the history service
fileHistoryService.setHistoryService(historyService);
fileHistoryService.start(bundleContext);
bundleContext.registerService(
- FileHistoryService.class.getName(), fileHistoryService, null);
+ FileHistoryService.class.getName(),
+ fileHistoryService,
+ null);
if (logger.isInfoEnabled())
logger.info("File History Service ...[REGISTERED]");
diff --git a/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java
index c10eac1..83fe513 100644
--- a/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java
@@ -6,8 +6,7 @@
*/
package net.java.sip.communicator.impl.filehistory;
-import static
- net.java.sip.communicator.service.history.HistoryService.DATE_FORMAT;
+import static net.java.sip.communicator.service.history.HistoryService.*;
import java.io.*;
import java.text.*;
@@ -77,35 +76,25 @@ public class FileHistoryServiceImpl
// start listening for newly register or removed protocol providers
bc.addServiceListener(this);
- ServiceReference[] protocolProviderRefs = null;
- try
- {
- protocolProviderRefs = bc.getServiceReferences(
- ProtocolProviderService.class.getName(),
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
- return;
- }
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
+ = ServiceUtils.getServiceReferences(
+ bc,
+ ProtocolProviderService.class);
// in case we found any
- if (protocolProviderRefs != null)
+ if (!ppsRefs.isEmpty())
{
if (logger.isDebugEnabled())
- logger.debug("Found "
- + protocolProviderRefs.length
- + " already installed providers.");
- for (int i = 0; i < protocolProviderRefs.length; i++)
{
- ProtocolProviderService provider = (ProtocolProviderService) bc
- .getService(protocolProviderRefs[i]);
+ logger.debug(
+ "Found " + ppsRefs.size()
+ + " already installed providers.");
+ }
+ for (ServiceReference<ProtocolProviderService> ppsRef : ppsRefs)
+ {
+ ProtocolProviderService pps = bc.getService(ppsRef);
- this.handleProviderAdded(provider);
+ handleProviderAdded(pps);
}
}
}
@@ -119,30 +108,19 @@ public class FileHistoryServiceImpl
{
bc.removeServiceListener(this);
- ServiceReference[] protocolProviderRefs = null;
- try
- {
- protocolProviderRefs = bc.getServiceReferences(
- ProtocolProviderService.class.getName(),
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error("Error while retrieving service refs", ex);
- return;
- }
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
+ = ServiceUtils.getServiceReferences(
+ bc,
+ ProtocolProviderService.class);
// in case we found any
- if (protocolProviderRefs != null)
+ if (!ppsRefs.isEmpty())
{
- for (int i = 0; i < protocolProviderRefs.length; i++)
+ for (ServiceReference<ProtocolProviderService> ppsRef : ppsRefs)
{
- ProtocolProviderService provider = (ProtocolProviderService) bc
- .getService(protocolProviderRefs[i]);
+ ProtocolProviderService pps = bc.getService(ppsRef);
- this.handleProviderRemoved(provider);
+ handleProviderRemoved(pps);
}
}
}
@@ -207,7 +185,8 @@ public class FileHistoryServiceImpl
*/
private Map<Contact, HistoryReader> getHistoryReaders(MetaContact contact)
{
- Map<Contact, HistoryReader> readers = new Hashtable<Contact, HistoryReader>();
+ Map<Contact, HistoryReader> readers
+ = new Hashtable<Contact, HistoryReader>();
Iterator<Contact> iter = contact.getContacts();
while (iter.hasNext())
{
diff --git a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java
index bc43262..4aa3cb4 100644
--- a/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java
+++ b/src/net/java/sip/communicator/impl/globaldisplaydetails/GlobalDisplayDetailsActivator.java
@@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.impl.globaldisplaydetails;
+import java.util.*;
+
import net.java.sip.communicator.service.globaldisplaydetails.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
@@ -90,20 +92,19 @@ public class GlobalDisplayDetailsActivator
*/
private void handleAlreadyRegisteredProviders()
{
- ServiceReference[] providerRefs
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
= ServiceUtils.getServiceReferences(
- bundleContext, ProtocolProviderService.class);
+ bundleContext,
+ ProtocolProviderService.class);
- if(providerRefs == null)
+ if(ppsRefs.isEmpty())
return;
- for (ServiceReference protocolProviderRef : providerRefs)
+ for (ServiceReference<ProtocolProviderService> ppsRef : ppsRefs)
{
- ProtocolProviderService provider
- = (ProtocolProviderService)
- bundleContext.getService(protocolProviderRef);
+ ProtocolProviderService pps = bundleContext.getService(ppsRef);
- this.handleProviderAdded(provider);
+ handleProviderAdded(pps);
}
}
@@ -212,7 +213,7 @@ public class GlobalDisplayDetailsActivator
*/
public void serviceChanged(ServiceEvent event)
{
- ServiceReference serviceRef = event.getServiceReference();
+ ServiceReference<?> serviceRef = event.getServiceReference();
// if the event is caused by a bundle being stopped, we don't want to
// know
@@ -221,8 +222,7 @@ public class GlobalDisplayDetailsActivator
return;
}
- Object service
- = UtilActivator.bundleContext.getService(serviceRef);
+ Object service = UtilActivator.bundleContext.getService(serviceRef);
// we don't care if the source service is not a protocol provider
if (!(service instanceof ProtocolProviderService))
@@ -243,5 +243,4 @@ public class GlobalDisplayDetailsActivator
break;
}
}
-
}
diff --git a/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutActivator.java b/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutActivator.java
index 0a71974..aa3c61c 100644
--- a/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutActivator.java
+++ b/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutActivator.java
@@ -6,6 +6,8 @@
*/
package net.java.sip.communicator.impl.globalshortcut;
+import java.util.*;
+
import net.java.sip.communicator.service.globalshortcut.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.keybindings.*;
@@ -26,13 +28,8 @@ public class GlobalShortcutActivator
* The <tt>Logger</tt> used by the <tt>GlobalShortcutActivator</tt> class
* and its instances for logging output.
*/
- private static final Logger logger =
- Logger.getLogger(GlobalShortcutActivator.class);
-
- /**
- * The OSGi <tt>ServiceRegistration</tt> of <tt>GlobalShortcut</tt>.
- */
- private ServiceRegistration serviceRegistration;
+ private static final Logger logger
+ = Logger.getLogger(GlobalShortcutActivator.class);
/**
* The <tt>GlobalShortcutServiceImpl</tt>.
@@ -100,11 +97,13 @@ public class GlobalShortcutActivator
throws Exception
{
GlobalShortcutActivator.bundleContext = bundleContext;
- serviceRegistration = null;
+
globalShortcutService = new GlobalShortcutServiceImpl();
globalShortcutService.start();
- bundleContext.registerService(GlobalShortcutService.class.getName(),
- globalShortcutService, null);
+ bundleContext.registerService(
+ GlobalShortcutService.class,
+ globalShortcutService,
+ null);
globalShortcutService.reloadGlobalShortcuts();
@@ -132,15 +131,7 @@ public class GlobalShortcutActivator
public void stop(BundleContext bundleContext)
throws Exception
{
- if (serviceRegistration != null)
- {
- globalShortcutService.stop();
- serviceRegistration.unregister();
- serviceRegistration = null;
-
- if (logger.isDebugEnabled())
- logger.debug("GlobalShortcut Service ... [UNREGISTERED]");
- }
+ globalShortcutService.stop();
GlobalShortcutActivator.bundleContext = null;
}
@@ -154,7 +145,7 @@ public class GlobalShortcutActivator
*/
private void serviceChanged(ServiceEvent event)
{
- ServiceReference serviceRef = event.getServiceReference();
+ ServiceReference<?> serviceRef = event.getServiceReference();
// if the event is caused by a bundle being stopped, we don't want to
// know
@@ -187,34 +178,25 @@ public class GlobalShortcutActivator
*/
public void registerListenerWithProtocolProviderService()
{
- ServiceReference[] ppsRefs = null;
-
- try
- {
- ppsRefs
- = bundleContext.getServiceReferences(
- ProtocolProviderService.class.getName(),
- null);
- }
- catch(InvalidSyntaxException ise)
- {
- logger.error(
- "Failed to get ProtocolProviderService ServiceReferences",
- ise);
- }
+ Collection<ServiceReference<ProtocolProviderService>> ppsRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderService.class);
- if(ppsRefs == null)
- return;
-
- for(ServiceReference ppsRef : ppsRefs)
+ if(!ppsRefs.isEmpty())
{
- ProtocolProviderService pps
- = (ProtocolProviderService) bundleContext.getService(ppsRef);
- OperationSetBasicTelephony<?> opSet
- = pps.getOperationSet(OperationSetBasicTelephony.class);
-
- if(opSet != null)
- opSet.addCallListener(globalShortcutService.getCallShortcut());
+ for(ServiceReference<ProtocolProviderService> ppsRef : ppsRefs)
+ {
+ ProtocolProviderService pps = bundleContext.getService(ppsRef);
+ OperationSetBasicTelephony<?> opSet
+ = pps.getOperationSet(OperationSetBasicTelephony.class);
+
+ if(opSet != null)
+ {
+ opSet.addCallListener(
+ globalShortcutService.getCallShortcut());
+ }
+ }
}
}
diff --git a/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java b/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java
index bff5f73..82e61c1 100644
--- a/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java
@@ -174,15 +174,18 @@ public class GlobalShortcutServiceImpl
for(AWTKeyStroke l : keystrokes)
{
- if(l.getKeyCode() == keycode &&
- l.getModifiers() == modifiers)
+ if(l.getKeyCode() == keycode
+ && l.getModifiers() == modifiers)
+ {
ks = l;
+ }
}
if(modifiers != SPECIAL_KEY_MODIFIERS)
{
- keyboardHook.unregisterShortcut(keyStroke.getKeyCode(),
- getModifiers(keyStroke));
+ keyboardHook.unregisterShortcut(
+ keyStroke.getKeyCode(),
+ getModifiers(keyStroke));
}
else
{
@@ -202,7 +205,9 @@ public class GlobalShortcutServiceImpl
}
else
{
- mapActions.put(listener, keystrokes);
+ // We do not have to put keystrokes back into mapActions
+ // because keystrokes is a reference to a modifiable
+ // List.
}
}
}
@@ -229,15 +234,20 @@ public class GlobalShortcutServiceImpl
{
isRunning = false;
- for(Map.Entry<GlobalShortcutListener, List<AWTKeyStroke>> entry :
- mapActions.entrySet())
- {
- GlobalShortcutListener l = entry.getKey();
- for(AWTKeyStroke e : entry.getValue())
- {
- unregisterShortcut(l, e);
- }
- }
+ // FIXME Lyubomir Marinov: The method unregisterShortcut will cause a
+ // ConcurrentModificationException because of either mapActions or a
+ // List<AWTKeyStroke> value. The method stop was never invoked before
+ // though because of a bug in the methods start and stop of the class
+ // GlobalShortcutActivator.
+// for(Map.Entry<GlobalShortcutListener, List<AWTKeyStroke>> entry
+// : mapActions.entrySet())
+// {
+// GlobalShortcutListener l = entry.getKey();
+// for(AWTKeyStroke e : entry.getValue())
+// {
+// unregisterShortcut(l, e);
+// }
+// }
if(keyboardHook != null)
{
diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java
index 40bdf63..26d93ac 100644
--- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java
+++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java
@@ -18,7 +18,6 @@ import net.java.sip.communicator.service.callhistory.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.credentialsstorage.*;
-import net.java.sip.communicator.service.customcontactactions.*;
import net.java.sip.communicator.service.desktop.*;
import net.java.sip.communicator.service.globaldisplaydetails.*;
import net.java.sip.communicator.service.gui.*;
@@ -99,8 +98,6 @@ public class GuiActivator implements BundleActivator
private static List<ContactSourceService> contactSources;
- private static List<CustomContactActionsService<?>> contactActionsServices;
-
private static SecurityAuthority securityAuthority;
private static DemuxContactSourceService demuxContactSourceService;
@@ -247,27 +244,17 @@ public class GuiActivator implements BundleActivator
public static Map<Object, ProtocolProviderFactory>
getProtocolProviderFactories()
{
- ServiceReference[] serRefs = null;
- try
- {
- // get all registered provider factories
- serRefs
- = bundleContext.getServiceReferences(
- ProtocolProviderFactory.class.getName(),
- null);
- }
- catch (InvalidSyntaxException e)
- {
- logger.error("LoginManager : " + e);
- }
+ Collection<ServiceReference<ProtocolProviderFactory>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
- if (serRefs != null)
+ if (!serRefs.isEmpty())
{
- for (ServiceReference serRef : serRefs)
+ for (ServiceReference<ProtocolProviderFactory> serRef : serRefs)
{
ProtocolProviderFactory providerFactory
- = (ProtocolProviderFactory)
- bundleContext.getService(serRef);
+ = bundleContext.getService(serRef);
providerFactoriesMap.put(
serRef.getProperty(ProtocolProviderFactory.PROTOCOL),
@@ -580,25 +567,17 @@ public class GuiActivator implements BundleActivator
{
contactSources = new Vector<ContactSourceService>();
- ServiceReference[] serRefs = null;
- try
- {
- // get all registered provider factories
- serRefs =
- bundleContext.getServiceReferences(
- ContactSourceService.class.getName(), null);
- }
- catch (InvalidSyntaxException e)
- {
- logger.error("GuiActivator : " + e);
- }
+ Collection<ServiceReference<ContactSourceService>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ContactSourceService.class);
- if (serRefs != null)
+ if (!serRefs.isEmpty())
{
- for (ServiceReference serRef : serRefs)
+ for (ServiceReference<ContactSourceService> serRef : serRefs)
{
ContactSourceService contactSource
- = (ContactSourceService) bundleContext.getService(serRef);
+ = bundleContext.getService(serRef);
contactSources.add(contactSource);
}
@@ -615,30 +594,22 @@ public class GuiActivator implements BundleActivator
*/
public static Map<String, ReplacementService> getReplacementSources()
{
- ServiceReference[] serRefs = null;
- try
- {
- // get all registered sources
- serRefs
- = bundleContext.getServiceReferences(ReplacementService.class
- .getName(), null);
-
- }
- catch (InvalidSyntaxException e)
- {
- logger.error("Error : " + e);
- }
+ Collection<ServiceReference<ReplacementService>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ReplacementService.class);
- if (serRefs != null)
+ if (!serRefs.isEmpty())
{
- for (int i = 0; i < serRefs.length; i++)
+ for (ServiceReference<ReplacementService> serRef : serRefs)
{
- ReplacementService replacementSources =
- (ReplacementService) bundleContext.getService(serRefs[i]);
+ ReplacementService replacementSources
+ = bundleContext.getService(serRef);
- replacementSourcesMap.put((String)serRefs[i]
- .getProperty(ReplacementService.SOURCE_NAME),
- replacementSources);
+ replacementSourcesMap.put(
+ (String)
+ serRef.getProperty(ReplacementService.SOURCE_NAME),
+ replacementSources);
}
}
return replacementSourcesMap;
@@ -725,21 +696,24 @@ public class GuiActivator implements BundleActivator
*/
public static SecurityAuthority getSecurityAuthority(String protocolName)
{
- String osgiFilter = "("
- + ProtocolProviderFactory.PROTOCOL
- + "=" + protocolName + ")";
-
+ String osgiFilter
+ = "(" + ProtocolProviderFactory.PROTOCOL + "=" + protocolName + ")";
SecurityAuthority securityAuthority = null;
+
try
{
- ServiceReference[] serRefs
+ Collection<ServiceReference<SecurityAuthority>> serRefs
= bundleContext.getServiceReferences(
- SecurityAuthority.class.getName(), osgiFilter);
+ SecurityAuthority.class,
+ osgiFilter);
+
+ if (!serRefs.isEmpty())
+ {
+ ServiceReference<SecurityAuthority> serRef
+ = serRefs.iterator().next();
- if (serRefs != null && serRefs.length > 0)
- securityAuthority
- = (SecurityAuthority) bundleContext
- .getService(serRefs[0]);
+ securityAuthority = bundleContext.getService(serRef);
+ }
}
catch (InvalidSyntaxException ex)
{
@@ -799,22 +773,10 @@ public class GuiActivator implements BundleActivator
if(prefWName == null || prefWName.length() <= 0)
return null;
- Collection<ServiceReference<AccountRegistrationWizard>> accountWizardRefs;
- try
- {
- accountWizardRefs
- = GuiActivator.bundleContext.getServiceReferences(
- AccountRegistrationWizard.class,
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
- return null;
- }
+ Collection<ServiceReference<AccountRegistrationWizard>> accountWizardRefs
+ = ServiceUtils.getServiceReferences(
+ GuiActivator.bundleContext,
+ AccountRegistrationWizard.class);
// in case we found any, add them in this container.
if (accountWizardRefs != null)
@@ -873,16 +835,14 @@ public class GuiActivator implements BundleActivator
{
if (credentialsService == null)
{
- ServiceReference credentialsReference
- = bundleContext.getServiceReference(
- CredentialsStorageService.class.getName());
credentialsService
- = (CredentialsStorageService) bundleContext
- .getService(credentialsReference);
+ = ServiceUtils.getService(
+ bundleContext,
+ CredentialsStorageService.class);
}
return credentialsService;
}
-
+
/**
* Returns a reference to a MUCService implementation
* currently registered in the bundle context or null if no such
diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java
index ab7853e..c50262d 100644
--- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java
+++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java
@@ -1420,26 +1420,28 @@ public class MainFrame
private ContactEventHandler getContactHandlerForProvider(
ProtocolProviderService protocolProvider)
{
- ServiceReference[] serRefs = null;
-
- String osgiFilter = "("
- + ProtocolProviderFactory.PROTOCOL
- + "=" + protocolProvider.getProtocolName()+")";
+ Collection<ServiceReference<ContactEventHandler>> serRefs;
+ String osgiFilter
+ = "(" + ProtocolProviderFactory.PROTOCOL + "="
+ + protocolProvider.getProtocolName() + ")";
try
{
- serRefs = GuiActivator.bundleContext.getServiceReferences(
- ContactEventHandler.class.getName(), osgiFilter);
+ serRefs
+ = GuiActivator.bundleContext.getServiceReferences(
+ ContactEventHandler.class,
+ osgiFilter);
}
- catch (InvalidSyntaxException ex){
+ catch (InvalidSyntaxException ex)
+ {
+ serRefs = null;
logger.error("GuiActivator : " + ex);
}
- if(serRefs == null)
+ if ((serRefs == null) || serRefs.isEmpty())
return null;
- return (ContactEventHandler) GuiActivator.bundleContext
- .getService(serRefs[0]);
+ return GuiActivator.bundleContext.getService(serRefs.iterator().next());
}
/**
@@ -1464,37 +1466,30 @@ public class MainFrame
// Search for plugin components registered through the OSGI bundle
// context.
- ServiceReference[] serRefs = null;
+ Collection<ServiceReference<PluginComponentFactory>> serRefs;
try
{
serRefs
- = GuiActivator
- .bundleContext
- .getServiceReferences(
- PluginComponentFactory.class.getName(),
- "(|("
- + Container.CONTAINER_ID
- + "="
- + Container.CONTAINER_MAIN_WINDOW.getID()
- + ")("
- + Container.CONTAINER_ID
- + "="
- + Container.CONTAINER_STATUS_BAR.getID()
- + "))");
+ = GuiActivator.bundleContext.getServiceReferences(
+ PluginComponentFactory.class,
+ "(|(" + Container.CONTAINER_ID + "="
+ + Container.CONTAINER_MAIN_WINDOW.getID() + ")("
+ + Container.CONTAINER_ID + "="
+ + Container.CONTAINER_STATUS_BAR.getID() + "))");
}
catch (InvalidSyntaxException exc)
{
+ serRefs = null;
logger.error("Could not obtain plugin reference.", exc);
}
- if (serRefs != null)
+ if ((serRefs != null) && !serRefs.isEmpty())
{
- for (ServiceReference serRef : serRefs)
+ for (ServiceReference<PluginComponentFactory> serRef : serRefs)
{
PluginComponentFactory factory
- = (PluginComponentFactory)
- GuiActivator.bundleContext.getService(serRef);
+ = GuiActivator.bundleContext.getService(serRef);
if (factory.isNativeComponent())
nativePluginsTable.add(factory);
diff --git a/src/net/java/sip/communicator/impl/gui/main/account/AccountRegWizardContainerImpl.java b/src/net/java/sip/communicator/impl/gui/main/account/AccountRegWizardContainerImpl.java
index e7baed8..2f78596 100644
--- a/src/net/java/sip/communicator/impl/gui/main/account/AccountRegWizardContainerImpl.java
+++ b/src/net/java/sip/communicator/impl/gui/main/account/AccountRegWizardContainerImpl.java
@@ -59,38 +59,41 @@ public class AccountRegWizardContainerImpl
this.registerWizardPage(summaryPage.getIdentifier(), summaryPage);
- ServiceReference[] accountWizardRefs = null;
+ Collection<ServiceReference<AccountRegistrationWizard>> accountWizardRefs;
try
{
- accountWizardRefs = GuiActivator.bundleContext
- .getServiceReferences(
- AccountRegistrationWizard.class.getName(),
- null);
+ accountWizardRefs
+ = GuiActivator.bundleContext.getServiceReferences(
+ AccountRegistrationWizard.class,
+ null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
+ logger.error("Error while retrieving service refs", ex);
return;
}
// in case we found any, add them in this container.
- if (accountWizardRefs != null)
+ if ((accountWizardRefs != null) && !accountWizardRefs.isEmpty())
{
if (logger.isDebugEnabled())
- logger.debug("Found "
- + accountWizardRefs.length
- + " already installed providers.");
- for (ServiceReference serRef : accountWizardRefs)
{
- String protocolName = (String)
- serRef.getProperty(ProtocolProviderFactory.PROTOCOL);
- AccountRegistrationWizard wizard = (AccountRegistrationWizard)
- GuiActivator.bundleContext.getService(serRef);
+ logger.debug(
+ "Found " + accountWizardRefs.size()
+ + " already installed providers.");
+ }
+ for (ServiceReference<AccountRegistrationWizard> serRef
+ : accountWizardRefs)
+ {
+ String protocolName
+ = (String)
+ serRef.getProperty(ProtocolProviderFactory.PROTOCOL);
+ AccountRegistrationWizard wizard
+ = GuiActivator.bundleContext.getService(serRef);
- this.addAccountRegistrationWizard(protocolName, wizard);
+ addAccountRegistrationWizard(protocolName, wizard);
}
}
@@ -331,7 +334,7 @@ public class AccountRegWizardContainerImpl
if(!GuiActivator.isStarted)
return;
- ServiceReference serRef = event.getServiceReference();
+ ServiceReference<?> serRef = event.getServiceReference();
Object sService = GuiActivator.bundleContext.getService(serRef);
// we don't care if the source service is not a plugin component
@@ -340,18 +343,17 @@ public class AccountRegWizardContainerImpl
String protocolName
= (String) serRef.getProperty(ProtocolProviderFactory.PROTOCOL);
- AccountRegistrationWizard wizard
- = (AccountRegistrationWizard) sService;
+ AccountRegistrationWizard wizard = (AccountRegistrationWizard) sService;
- switch (event.getType()) {
+ switch (event.getType())
+ {
case ServiceEvent.REGISTERED:
- logger
- .info("Handling registration of a new Account Wizard.");
-
- this.addAccountRegistrationWizard(protocolName, wizard);
+ logger.info("Handling registration of a new Account Wizard.");
+ addAccountRegistrationWizard(protocolName, wizard);
break;
+
case ServiceEvent.UNREGISTERING:
- this.removeAccountRegistrationWizard(protocolName, wizard);
+ removeAccountRegistrationWizard(protocolName, wizard);
break;
}
}
diff --git a/src/net/java/sip/communicator/impl/gui/main/account/AccountRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/account/AccountRightButtonMenu.java
index f74ffb9..6037ef2 100644
--- a/src/net/java/sip/communicator/impl/gui/main/account/AccountRightButtonMenu.java
+++ b/src/net/java/sip/communicator/impl/gui/main/account/AccountRightButtonMenu.java
@@ -118,44 +118,44 @@ public class AccountRightButtonMenu
{
// Search for plugin components registered through the OSGI bundle
// context.
- ServiceReference[] serRefs = null;
-
- String osgiFilter = "("
- + Container.CONTAINER_ID
- + "="+Container.CONTAINER_ACCOUNT_RIGHT_BUTTON_MENU.getID()+")";
+ Collection<ServiceReference<PluginComponentFactory>> serRefs;
+ String osgiFilter
+ = "(" + Container.CONTAINER_ID + "="
+ + Container.CONTAINER_ACCOUNT_RIGHT_BUTTON_MENU.getID() + ")";
try
{
- serRefs = GuiActivator.bundleContext.getServiceReferences(
- PluginComponentFactory.class.getName(),
- osgiFilter);
+ serRefs
+ = GuiActivator.bundleContext.getServiceReferences(
+ PluginComponentFactory.class,
+ osgiFilter);
}
- catch (InvalidSyntaxException exc)
+ catch (InvalidSyntaxException ex)
{
- logger.error("Could not obtain plugin reference.", exc);
+ serRefs = null;
+ logger.error("Could not obtain plugin reference.", ex);
}
- if (serRefs != null)
+ if ((serRefs != null) && !serRefs.isEmpty())
{
- for (int i = 0; i < serRefs.length; i ++)
+ for (ServiceReference<PluginComponentFactory> serRef : serRefs)
{
- PluginComponentFactory factory =
- (PluginComponentFactory) GuiActivator
- .bundleContext.getService(serRefs[i]);
-
- PluginComponent component =
- factory.getPluginComponentInstance(this);
+ PluginComponentFactory factory
+ = GuiActivator.bundleContext.getService(serRef);
+ PluginComponent component
+ = factory.getPluginComponentInstance(this);
if (component.getComponent() == null)
continue;
pluginComponents.add(component);
- if (factory.getPositionIndex() != -1)
- this.add((Component)component.getComponent(),
- factory.getPositionIndex());
+ int positionIndex = factory.getPositionIndex();
+
+ if (positionIndex != -1)
+ add((Component)component.getComponent(), positionIndex);
else
- this.add((Component)component.getComponent());
+ add((Component)component.getComponent());
}
}
GuiActivator.getUIService().addPluginComponentListener(this);
diff --git a/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java b/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java
index 2bbdd1d..5cc84a9 100644
--- a/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java
+++ b/src/net/java/sip/communicator/impl/gui/main/account/NewAccountDialog.java
@@ -175,49 +175,51 @@ public class NewAccountDialog
String preferredWizardName
= (prefWName != null && prefWName.length() > 0) ? prefWName : null;
- ServiceReference[] accountWizardRefs = null;
+ Collection<ServiceReference<AccountRegistrationWizard>> accountWizardRefs;
try
{
- accountWizardRefs = GuiActivator.bundleContext
- .getServiceReferences(
- AccountRegistrationWizard.class.getName(),
- null);
+ accountWizardRefs
+ = GuiActivator.bundleContext.getServiceReferences(
+ AccountRegistrationWizard.class,
+ null);
}
catch (InvalidSyntaxException ex)
{
// this shouldn't happen since we're providing no parameter string
// but let's log just in case.
- logger.error(
- "Error while retrieving service refs", ex);
+ logger.error("Error while retrieving service refs", ex);
return;
}
// in case we found any, add them in this container.
- if (accountWizardRefs != null)
+ if ((accountWizardRefs != null) && !accountWizardRefs.isEmpty())
{
if (logger.isDebugEnabled())
- logger.debug("Found "
- + accountWizardRefs.length
- + " already installed providers.");
+ {
+ logger.debug(
+ "Found " + accountWizardRefs.size()
+ + " already installed providers.");
+ }
// Create a list to sort the wizards
- ArrayList<AccountRegistrationWizard> networksList =
- new ArrayList<AccountRegistrationWizard>();
- networksList.ensureCapacity(accountWizardRefs.length);
+ ArrayList<AccountRegistrationWizard> networksList
+ = new ArrayList<AccountRegistrationWizard>(
+ accountWizardRefs.size());
AccountRegistrationWizard prefWiz = null;
- for (int i = 0; i < accountWizardRefs.length; i++)
+ for (ServiceReference<AccountRegistrationWizard> serRef
+ : accountWizardRefs)
{
AccountRegistrationWizard wizard
- = (AccountRegistrationWizard) GuiActivator.bundleContext
- .getService(accountWizardRefs[i]);
+ = GuiActivator.bundleContext.getService(serRef);
networksList.add(wizard);
// is it the preferred protocol ?
if(preferredWizardName != null
- && wizard.getClass().getName().equals(preferredWizardName))
+ && wizard.getClass().getName().equals(
+ preferredWizardName))
{
prefWiz = wizard;
}
diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java
index 51fc669..2971a1c 100644
--- a/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java
+++ b/src/net/java/sip/communicator/impl/gui/main/call/CallPanel.java
@@ -1441,42 +1441,39 @@ public class CallPanel
{
// Search for plug-in components registered through the OSGI
// BundleContext.
-
+ Collection<ServiceReference<PluginComponentFactory>> serRefs;
String osgiFilter
- = "("
- + net.java.sip.communicator.service.gui.Container.CONTAINER_ID
+ = "(" + net.java.sip.communicator.service.gui.Container.CONTAINER_ID
+ "="
+ net.java.sip.communicator.service.gui.Container
.CONTAINER_CALL_DIALOG.getID()
+ ")";
- ServiceReference[] serRefs = null;
try
{
serRefs
= GuiActivator.bundleContext.getServiceReferences(
- PluginComponentFactory.class.getName(),
+ PluginComponentFactory.class,
osgiFilter);
}
catch (InvalidSyntaxException ise)
{
+ serRefs = null;
logger.error("Could not obtain plugin reference.", ise);
}
- if (serRefs != null)
+ if ((serRefs != null) && !serRefs.isEmpty())
{
- for (ServiceReference serRef : serRefs)
+ for (ServiceReference<PluginComponentFactory> serRef : serRefs)
{
PluginComponentFactory factory
- = (PluginComponentFactory)
- GuiActivator.bundleContext.getService(serRef);
-
- PluginComponent component =
- factory.getPluginComponentInstance(CallPanel.this);
+ = GuiActivator.bundleContext.getService(serRef);
+ PluginComponent component
+ = factory.getPluginComponentInstance(CallPanel.this);
component.setCurrentContact(
- CallManager.getPeerMetaContact(
- callConference.getCallPeers().get(0)));
+ CallManager.getPeerMetaContact(
+ callConference.getCallPeers().get(0)));
settingsPanel.add((Component) component.getComponent());
}
diff --git a/src/net/java/sip/communicator/impl/muc/MUCActivator.java b/src/net/java/sip/communicator/impl/muc/MUCActivator.java
index 0cdf76f..aadfef8 100644
--- a/src/net/java/sip/communicator/impl/muc/MUCActivator.java
+++ b/src/net/java/sip/communicator/impl/muc/MUCActivator.java
@@ -31,13 +31,6 @@ public class MUCActivator
implements BundleActivator
{
/**
- * The <tt>Logger</tt> used by the
- * <tt>MUCActivator</tt> class for logging output.
- */
- private static final Logger logger
- = Logger.getLogger(MUCActivator.class);
-
- /**
* The configuration property to disable
*/
private static final String DISABLED_PROPERTY
@@ -282,22 +275,12 @@ public class MUCActivator
protocolProviderRegListener = new ProtocolProviderRegListener();
bundleContext.addServiceListener(protocolProviderRegListener);
- Collection<ServiceReference<ProtocolProviderFactory>> serRefs;
- try
- {
- // get all registered provider factories
- serRefs
- = bundleContext.getServiceReferences(
- ProtocolProviderFactory.class,
- null);
- }
- catch (InvalidSyntaxException e)
- {
- serRefs = null;
- logger.error("LoginManager : " + e);
- }
+ Collection<ServiceReference<ProtocolProviderFactory>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
- if (serRefs != null)
+ if (!serRefs.isEmpty())
{
for (ServiceReference<ProtocolProviderFactory> ppfSerRef : serRefs)
{
@@ -330,7 +313,7 @@ public class MUCActivator
*/
public void serviceChanged(ServiceEvent event)
{
- ServiceReference serviceRef = event.getServiceReference();
+ ServiceReference<?> serviceRef = event.getServiceReference();
// if the event is caused by a bundle being stopped, we don't want to
// know
diff --git a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
index 6908778..4a58650 100644
--- a/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
+++ b/src/net/java/sip/communicator/plugin/otr/OtrActivator.java
@@ -166,33 +166,23 @@ public class OtrActivator
private static Map<Object, ProtocolProviderFactory>
getProtocolProviderFactories()
{
- ServiceReference[] serRefs;
- try
- {
- // get all registered provider factories
- serRefs =
- bundleContext.getServiceReferences(
- ProtocolProviderFactory.class.getName(), null);
-
- }
- catch (InvalidSyntaxException ex)
- {
- logger.error("Error while retrieving service refs", ex);
- return null;
- }
+ Collection<ServiceReference<ProtocolProviderFactory>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
+ Map<Object, ProtocolProviderFactory> providerFactoriesMap
+ = new Hashtable<Object, ProtocolProviderFactory>();
- Map<Object, ProtocolProviderFactory> providerFactoriesMap =
- new Hashtable<Object, ProtocolProviderFactory>();
- if (serRefs != null)
+ if (!serRefs.isEmpty())
{
- for (ServiceReference serRef : serRefs)
+ for (ServiceReference<ProtocolProviderFactory> serRef : serRefs)
{
- ProtocolProviderFactory providerFactory =
- (ProtocolProviderFactory) bundleContext.getService(serRef);
+ ProtocolProviderFactory providerFactory
+ = bundleContext.getService(serRef);
- providerFactoriesMap.put(serRef
- .getProperty(ProtocolProviderFactory.PROTOCOL),
- providerFactory);
+ providerFactoriesMap.put(
+ serRef.getProperty(ProtocolProviderFactory.PROTOCOL),
+ providerFactory);
}
}
return providerFactoriesMap;
@@ -317,26 +307,26 @@ public class OtrActivator
bundleContext.addServiceListener(scOtrEngine);
bundleContext.addServiceListener(otrContactManager);
- ServiceReference[] protocolProviderRefs
+ Collection<ServiceReference<ProtocolProviderService>> protocolProviderRefs
= ServiceUtils.getServiceReferences(
bundleContext,
ProtocolProviderService.class);
- if (protocolProviderRefs != null && protocolProviderRefs.length > 0)
+ if (!protocolProviderRefs.isEmpty())
{
if (logger.isDebugEnabled())
{
logger.debug(
- "Found " + protocolProviderRefs.length
+ "Found " + protocolProviderRefs.size()
+ " already installed providers.");
}
- for (ServiceReference protocolProviderRef : protocolProviderRefs)
+ for (ServiceReference<ProtocolProviderService> protocolProviderRef
+ : protocolProviderRefs)
{
ProtocolProviderService provider
- = (ProtocolProviderService)
- bundleContext.getService(protocolProviderRef);
+ = bundleContext.getService(protocolProviderRef);
- this.handleProviderAdded(provider);
+ handleProviderAdded(provider);
}
}
@@ -435,31 +425,21 @@ public class OtrActivator
if(otrContactManager != null)
bundleContext.removeServiceListener(otrContactManager);
- ServiceReference[] protocolProviderRefs;
- try
- {
- protocolProviderRefs =
- bundleContext.getServiceReferences(
- ProtocolProviderService.class.getName(), null);
- }
- catch (InvalidSyntaxException ex)
- {
- // this shouldn't happen since we're providing no parameter string
- // but let's log just in case.
- logger.error("Error while retrieving service refs", ex);
- return;
- }
+ Collection<ServiceReference<ProtocolProviderService>> protocolProviderRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderService.class);
- if (protocolProviderRefs != null && protocolProviderRefs.length > 0)
+ if (!protocolProviderRefs.isEmpty())
{
// in case we found any
- for (ServiceReference protocolProviderRef : protocolProviderRefs)
+ for (ServiceReference<ProtocolProviderService> protocolProviderRef
+ : protocolProviderRefs)
{
- ProtocolProviderService provider =
- (ProtocolProviderService) bundleContext
- .getService(protocolProviderRef);
+ ProtocolProviderService provider
+ = bundleContext.getService(protocolProviderRef);
- this.handleProviderRemoved(provider);
+ handleProviderRemoved(provider);
}
}
}
diff --git a/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigActivator.java b/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigActivator.java
index e85dced..0a3748b 100644
--- a/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigActivator.java
+++ b/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigActivator.java
@@ -25,12 +25,6 @@ public class SecurityConfigActivator
implements BundleActivator
{
/**
- * The logger.
- */
- private static Logger logger
- = Logger.getLogger(SecurityConfigActivator.class);
-
- /**
* The {@link BundleContext} of the {@link SecurityConfigActivator}.
*/
public static BundleContext bundleContext;
@@ -85,8 +79,10 @@ public class SecurityConfigActivator
{
bundleContext = bc;
+ ConfigurationService cfg = getConfigurationService();
+
// If the security configuration form is disabled don't continue.
- if (getConfigurationService().getBoolean(DISABLED_PROP, false))
+ if (cfg.getBoolean(DISABLED_PROP, false))
return;
// Register the configuration form.
@@ -106,8 +102,7 @@ public class SecurityConfigActivator
properties);
// If the master password config form is disabled don't register it.
- if(!getConfigurationService()
- .getBoolean(MASTER_PASSWORD_DISABLED_PROP, false))
+ if(!cfg.getBoolean(MASTER_PASSWORD_DISABLED_PROP, false))
{
properties = new Hashtable<String, String>();
properties.put( ConfigurationForm.FORM_TYPE,
@@ -233,33 +228,23 @@ public class SecurityConfigActivator
private static Map<Object, ProtocolProviderFactory>
getProtocolProviderFactories()
{
- ServiceReference[] serRefs = null;
- try
- {
- // get all registered provider factories
- serRefs =
- bundleContext.getServiceReferences(
- ProtocolProviderFactory.class.getName(), null);
-
- }
- catch (InvalidSyntaxException ex)
- {
- logger.error("Error while retrieving service refs", ex);
- return null;
- }
+ Collection<ServiceReference<ProtocolProviderFactory>> serRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
+ Map<Object, ProtocolProviderFactory> providerFactoriesMap
+ = new Hashtable<Object, ProtocolProviderFactory>();
- Map<Object, ProtocolProviderFactory> providerFactoriesMap =
- new Hashtable<Object, ProtocolProviderFactory>();
- if (serRefs != null)
+ if ((serRefs != null) && !serRefs.isEmpty())
{
- for (ServiceReference serRef : serRefs)
+ for (ServiceReference<ProtocolProviderFactory> serRef : serRefs)
{
- ProtocolProviderFactory providerFactory =
- (ProtocolProviderFactory) bundleContext.getService(serRef);
+ ProtocolProviderFactory providerFactory
+ = bundleContext.getService(serRef);
- providerFactoriesMap.put(serRef
- .getProperty(ProtocolProviderFactory.PROTOCOL),
- providerFactory);
+ providerFactoriesMap.put(
+ serRef.getProperty(ProtocolProviderFactory.PROTOCOL),
+ providerFactory);
}
}
return providerFactoriesMap;
diff --git a/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigurationPanel.java b/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigurationPanel.java
index e5ecd67..ab4621a 100644
--- a/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigurationPanel.java
+++ b/src/net/java/sip/communicator/plugin/securityconfig/SecurityConfigurationPanel.java
@@ -6,9 +6,10 @@
package net.java.sip.communicator.plugin.securityconfig;
import java.awt.*;
+import java.util.*;
-import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.plugin.desktoputil.*;
+import net.java.sip.communicator.service.gui.*;
import org.osgi.framework.*;
@@ -40,29 +41,31 @@ public class SecurityConfigurationPanel
*/
private void init()
{
- String osgiFilter = "("
- + ConfigurationForm.FORM_TYPE
- + "="+ConfigurationForm.SECURITY_TYPE+")";
+ Collection<ServiceReference<ConfigurationForm>> confFormsRefs;
+ String osgiFilter
+ = "(" + ConfigurationForm.FORM_TYPE + "="
+ + ConfigurationForm.SECURITY_TYPE + ")";
- ServiceReference[] confFormsRefs = null;
try
{
- confFormsRefs = SecurityConfigActivator.bundleContext
- .getServiceReferences( ConfigurationForm.class.getName(),
- osgiFilter);
+ confFormsRefs
+ = SecurityConfigActivator.bundleContext.getServiceReferences(
+ ConfigurationForm.class,
+ osgiFilter);
}
catch (InvalidSyntaxException ex)
- {}
+ {
+ confFormsRefs = null;
+ }
- if(confFormsRefs != null)
+ if ((confFormsRefs != null) && !confFormsRefs.isEmpty())
{
- for (int i = 0; i < confFormsRefs.length; i++)
+ for (ServiceReference<ConfigurationForm> sr : confFormsRefs)
{
ConfigurationForm form
- = (ConfigurationForm) SecurityConfigActivator.bundleContext
- .getService(confFormsRefs[i]);
-
+ = SecurityConfigActivator.bundleContext.getService(sr);
Object formComponent = form.getForm();
+
if (formComponent instanceof Component)
addConfigForm(form);
}
@@ -71,40 +74,53 @@ public class SecurityConfigurationPanel
/**
* Handles registration of a new configuration form.
+ *
* @param event the <tt>ServiceEvent</tt> that notified us
*/
public void serviceChanged(ServiceEvent event)
{
- ServiceReference serviceRef = event.getServiceReference();
+ ServiceReference<?> ref = event.getServiceReference();
+ Object property = ref.getProperty(ConfigurationForm.FORM_TYPE);
- Object property = serviceRef.getProperty(ConfigurationForm.FORM_TYPE);
- if (property != ConfigurationForm.SECURITY_TYPE)
+ if (!ConfigurationForm.SECURITY_TYPE.equals(property))
return;
- Object sService
- = SecurityConfigActivator.bundleContext
- .getService(serviceRef);
+ // SecurityConfigActivator registers a ConfigurationForm with FORM_TYPE
+ // SECURITY_TYPE so when, SecurityConfigActivator.stop is invoked, an
+ // IllegalStateException will be thrown here.
+ Object service;
+
+ try
+ {
+ service = SecurityConfigActivator.bundleContext.getService(ref);
+ }
+ catch (IllegalStateException ex)
+ {
+ // SecurityConfigActivator.bundleContext is no longer valid.
+ return;
+ }
// we don't care if the source service is not a configuration form
- if (!(sService instanceof ConfigurationForm))
+ if (!(service instanceof ConfigurationForm))
return;
- ConfigurationForm configForm = (ConfigurationForm) sService;
+ ConfigurationForm cfgForm = (ConfigurationForm) service;
- if (!configForm.isAdvanced())
+ if (!cfgForm.isAdvanced())
return;
Object formComponent;
+
switch (event.getType())
{
case ServiceEvent.REGISTERED:
- formComponent = configForm.getForm();
+ formComponent = cfgForm.getForm();
if (formComponent instanceof Component)
- addConfigForm(configForm);
+ addConfigForm(cfgForm);
break;
case ServiceEvent.UNREGISTERING:
- formComponent = configForm.getForm();
+ formComponent = cfgForm.getForm();
if (formComponent instanceof Component)
remove((Component) formComponent);
break;
@@ -118,17 +134,13 @@ public class SecurityConfigurationPanel
*/
private void addConfigForm(ConfigurationForm form)
{
- int cIndex = form.getIndex();
- String formTitle = form.getTitle();
- Component formComponent = (Component) form.getForm();
+ int index = form.getIndex();
+ String title = form.getTitle();
+ Component component = (Component) form.getForm();
- if (cIndex >= getTabCount())
- addTab(formTitle, formComponent);
+ if (index >= getTabCount())
+ addTab(title, component);
else
- insertTab( formTitle,
- null,
- formComponent,
- formTitle,
- cIndex);
+ insertTab(title, null, component, title, index);
}
}
diff --git a/src/net/java/sip/communicator/service/protocol/AccountManager.java b/src/net/java/sip/communicator/service/protocol/AccountManager.java
index c85ed7a..6889f5c 100644
--- a/src/net/java/sip/communicator/service/protocol/AccountManager.java
+++ b/src/net/java/sip/communicator/service/protocol/AccountManager.java
@@ -286,25 +286,13 @@ public class AccountManager
boolean includeHidden,
String userID)
{
- Collection<ServiceReference<ProtocolProviderFactory>> factoryRefs;
+ Collection<ServiceReference<ProtocolProviderFactory>> factoryRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
boolean hasStoredAccounts = false;
- try
- {
- factoryRefs
- = bundleContext.getServiceReferences(
- ProtocolProviderFactory.class,
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- factoryRefs = null;
- logger.error(
- "Failed to retrieve the registered ProtocolProviderFactories",
- ex);
- }
-
- if ((factoryRefs != null) && !factoryRefs.isEmpty())
+ if (!factoryRefs.isEmpty())
{
ConfigurationService configService
= ProtocolProviderActivator.getConfigurationService();
@@ -399,24 +387,12 @@ public class AccountManager
*/
public AccountID findAccountID(String uid)
{
- Collection<ServiceReference<ProtocolProviderFactory>> factoryRefs;
-
- try
- {
- factoryRefs
- = bundleContext.getServiceReferences(
- ProtocolProviderFactory.class,
- null);
- }
- catch (InvalidSyntaxException ex)
- {
- factoryRefs = null;
- logger.error(
- "Failed to retrieve the registered ProtocolProviderFactories",
- ex);
- }
+ Collection<ServiceReference<ProtocolProviderFactory>> factoryRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ ProtocolProviderFactory.class);
- if ((factoryRefs != null) && !factoryRefs.isEmpty())
+ if (!factoryRefs.isEmpty())
{
ConfigurationService configService
= ProtocolProviderActivator.getConfigurationService();
diff --git a/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java b/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java
index d10a05f..ff94e66 100644
--- a/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java
+++ b/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java
@@ -113,8 +113,7 @@ public final class AccountManagerUtils
*/
factoryRefs = null;
}
-
- if (factoryRefs != null)
+ if ((factoryRefs != null) && !factoryRefs.isEmpty())
{
boolean factoryIsRegistered = false;
diff --git a/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java b/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java
index 24bc676..0f26651 100644
--- a/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java
+++ b/src/net/java/sip/communicator/service/systray/AbstractSystrayService.java
@@ -227,36 +227,34 @@ public abstract class AbstractSystrayService
{
bundleContext.addServiceListener(
new ServiceListenerImpl(),
- "(objectclass="
- + PopupMessageHandler.class.getName()
- + ")");
+ "(objectclass=" + PopupMessageHandler.class.getName()
+ + ")");
}
catch (Exception e)
{
logger.warn(e);
}
+
// now we look if some handler has been registered before we start
// to listen
- ServiceReference[] handlerRefs
- = ServiceUtils.getServiceReferences(
- bundleContext,
- PopupMessageHandler.class);
+ Collection<ServiceReference<PopupMessageHandler>> handlerRefs
+ = ServiceUtils.getServiceReferences(
+ bundleContext,
+ PopupMessageHandler.class);
- if (handlerRefs != null)
+ if (!handlerRefs.isEmpty())
{
ConfigurationService config
- = ServiceUtils.getService(
- bundleContext,
- ConfigurationService.class);
-
+ = ServiceUtils.getService(
+ bundleContext,
+ ConfigurationService.class);
String configuredHandler
- = (String) config.getProperty("systray.POPUP_HANDLER");
+ = config.getString("systray.POPUP_HANDLER");
- for (ServiceReference handlerRef : handlerRefs)
+ for (ServiceReference<PopupMessageHandler> handlerRef : handlerRefs)
{
PopupMessageHandler handler
- = (PopupMessageHandler) bundleContext
- .getService(handlerRef);
+ = bundleContext.getService(handlerRef);
String handlerName = handler.getClass().getName();
if (!containsHandler(handlerName))
@@ -270,7 +268,7 @@ public abstract class AbstractSystrayService
}
if ((configuredHandler != null)
&& configuredHandler.equals(
- handler.getClass().getName()))
+ handler.getClass().getName()))
{
setActivePopupMessageHandler(handler);
}
@@ -284,7 +282,7 @@ public abstract class AbstractSystrayService
/** An implementation of <tt>ServiceListener</tt> we will use */
private class ServiceListenerImpl
- implements ServiceListener
+ implements ServiceListener
{
/**
@@ -296,15 +294,16 @@ public abstract class AbstractSystrayService
try
{
Object service
- = bundleContext.getService(
- serviceEvent.getServiceReference());
+ = bundleContext.getService(
+ serviceEvent.getServiceReference());
// Event filters don't work on Android
if(!(service instanceof PopupMessageHandler))
return;
PopupMessageHandler handler
- = (PopupMessageHandler) bundleContext
- .getService(serviceEvent.getServiceReference());
+ = (PopupMessageHandler)
+ bundleContext.getService(
+ serviceEvent.getServiceReference());
if (serviceEvent.getType() == ServiceEvent.REGISTERED)
{
@@ -324,7 +323,7 @@ public abstract class AbstractSystrayService
= ServiceUtils.getService( bundleContext,
ConfigurationService.class);
String configuredHandler
- = (String) cfg.getProperty("systray.POPUP_HANDLER");
+ = cfg.getString("systray.POPUP_HANDLER");
if ((configuredHandler == null)
&& ((getActivePopupHandler() == null)
diff --git a/src/net/java/sip/communicator/util/ServiceObserver.java b/src/net/java/sip/communicator/util/ServiceObserver.java
index d668608..ef19c81 100644
--- a/src/net/java/sip/communicator/util/ServiceObserver.java
+++ b/src/net/java/sip/communicator/util/ServiceObserver.java
@@ -18,62 +18,43 @@ import java.util.*;
* @author Pawel Domas
*/
public class ServiceObserver<T>
- implements ServiceListener
+ implements ServiceListener
{
/**
- * Service instances list.
- */
- private final List<T> services;
- /**
* Service class name.
*/
- private final Class<T> className;
+ private final Class<T> clazz;
+
/**
* The OSGi context.
*/
private BundleContext context;
/**
+ * Service instances list.
+ */
+ private final List<T> services = new ArrayList<T>();
+
+ /**
* Creates new instance of <tt>ServiceObserver</tt> that will observe
* services of given <tt>className</tt>.
*
- * @param className class name of the service to observe.
+ * @param clazz the <tt>Class</tt> of the service to observe.
*/
- public ServiceObserver(Class<T> className)
+ public ServiceObserver(Class<T> clazz)
{
- services = new ArrayList<T>();
- this.className = className;
+ this.clazz = clazz;
}
/**
- * This method must be called when OSGi i s starting to initialize the
- * observer.
- * @param ctx the OSGi bundle context.
- */
- @SuppressWarnings("unchecked")
- public void start(BundleContext ctx)
- {
- this.context = ctx;
-
- ctx.addServiceListener(this);
-
- ServiceReference[] refs
- = ServiceUtils.getServiceReferences(ctx, className);
- for(ServiceReference ref : refs)
- services.add((T) ctx.getService(ref));
- }
-
- /**
- * This method should be called on bundle shutdown to properly release
- * the resources.
- *
- * @param ctx OSGi context
+ * Returns list of services compatible with service class observed by
+ * this instance.
+ * @return list of services compatible with service class observed by
+ * this instance.
*/
- public void stop(BundleContext ctx)
+ public List<T> getServices()
{
- ctx.removeServiceListener(this);
- services.clear();
- this.context = null;
+ return Collections.unmodifiableList(services);
}
/**
@@ -83,15 +64,15 @@ public class ServiceObserver<T>
@Override
public void serviceChanged(ServiceEvent serviceEvent)
{
- Object service
- = context.getService(serviceEvent.getServiceReference());
+ Object service = context.getService(serviceEvent.getServiceReference());
- if(!className.isInstance(service))
+ if(!clazz.isInstance(service))
{
return;
}
int eventType = serviceEvent.getType();
+
if(eventType == ServiceEvent.REGISTERED)
{
services.add((T) service);
@@ -103,13 +84,33 @@ public class ServiceObserver<T>
}
/**
- * Returns list of services compatible with service class observed by
- * this instance.
- * @return list of services compatible with service class observed by
- * this instance.
+ * This method must be called when OSGi i s starting to initialize the
+ * observer.
+ * @param ctx the OSGi bundle context.
*/
- public List<T> getServices()
+ public void start(BundleContext ctx)
{
- return Collections.unmodifiableList(services);
+ this.context = ctx;
+
+ ctx.addServiceListener(this);
+
+ Collection<ServiceReference<T>> refs
+ = ServiceUtils.getServiceReferences(ctx, clazz);
+
+ for(ServiceReference<T> ref : refs)
+ services.add(ctx.getService(ref));
+ }
+
+ /**
+ * This method should be called on bundle shutdown to properly release
+ * the resources.
+ *
+ * @param ctx OSGi context
+ */
+ public void stop(BundleContext ctx)
+ {
+ ctx.removeServiceListener(this);
+ services.clear();
+ this.context = null;
}
}
diff --git a/src/net/java/sip/communicator/util/ServiceUtils.java b/src/net/java/sip/communicator/util/ServiceUtils.java
index 3509891..31d90ca 100644
--- a/src/net/java/sip/communicator/util/ServiceUtils.java
+++ b/src/net/java/sip/communicator/util/ServiceUtils.java
@@ -6,13 +6,15 @@
*/
package net.java.sip.communicator.util;
+import java.util.*;
+
import org.osgi.framework.*;
/**
* Gathers utility functions related to OSGi services such as getting a service
* registered in a BundleContext.
*
- * @author Lubomir Marinov
+ * @author Lyubomir Marinov
* @author Pawel Domas
*/
public class ServiceUtils
@@ -30,48 +32,84 @@ public class ServiceUtils
* specified <tt>serviceClass</tt> if such a service exists there;
* otherwise, <tt>null</tt>
*/
- @SuppressWarnings("unchecked")
public static <T> T getService(
BundleContext bundleContext,
Class<T> serviceClass)
{
- ServiceReference serviceReference
- = bundleContext.getServiceReference(serviceClass.getName());
+ ServiceReference<T> serviceReference
+ = bundleContext.getServiceReference(serviceClass);
return
(serviceReference == null)
? null
- : (T) bundleContext.getService(serviceReference);
+ : bundleContext.getService(serviceReference);
}
/**
* Gets an OSGi service references registered in a specific
- * <tt>BundleContext</tt> by its <tt>Class</tt>
+ * <tt>BundleContext</tt> by its <tt>Class</tt>.
*
* @param bundleContext the <tt>BundleContext</tt> in which the services to
* get have been registered
- * @param serviceClass the <tt>Class</tt> of the OSGi service references to get
+ * @param serviceClass the <tt>Class</tt> of the OSGi service references to
+ * get
* @return the OSGi service references registered in <tt>bundleContext</tt>
* with the specified <tt>serviceClass</tt> if such a services exists there;
- * otherwise, <tt>null</tt>
+ * otherwise, an empty <tt>Collection</tt>
*/
- public static ServiceReference[] getServiceReferences(
+ public static <T> Collection<ServiceReference<T>> getServiceReferences(
BundleContext bundleContext,
- Class<?> serviceClass)
+ Class<T> serviceClass)
{
- ServiceReference[] handlerRefs = null;
+ Collection<ServiceReference<T>> serviceReferences;
+
try
{
- handlerRefs = bundleContext.getServiceReferences(
- serviceClass.getName(),
- null);
+ serviceReferences
+ = bundleContext.getServiceReferences(
+ serviceClass,
+ null);
}
catch (InvalidSyntaxException ex)
{
- throw new RuntimeException(ex);
+ serviceReferences = null;
}
+ if (serviceReferences == null)
+ serviceReferences = Collections.emptyList();
+ return serviceReferences;
+ }
- return handlerRefs;
+ /**
+ * Gets an OSGi service references registered in a specific
+ * <tt>BundleContext</tt> by its <tt>Class</tt> name.
+ *
+ * @param bundleContext the <tt>BundleContext</tt> in which the services to
+ * get have been registered
+ * @param serviceClassName the name of the <tt>Class</tt> of the OSGi
+ * service references to get
+ * @return the OSGi service references registered in <tt>bundleContext</tt>
+ * with the specified <tt>serviceClassName</tt> if such a services exists
+ * there; otherwise, <tt>null</tt>
+ */
+ @SuppressWarnings("unused")
+ private static ServiceReference<?>[] getServiceReferences(
+ BundleContext bundleContext,
+ String serviceClassName)
+ {
+ ServiceReference<?>[] serviceReferences;
+
+ try
+ {
+ serviceReferences
+ = bundleContext.getServiceReferences(
+ serviceClassName,
+ null);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ serviceReferences = null;
+ }
+ return serviceReferences;
}
/** Prevents the creation of <tt>ServiceUtils</tt> instances. */