diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2014-09-29 01:12:42 +0300 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2014-09-29 01:12:42 +0300 |
commit | 15f40128402690804efd9e948234f12a4e7d5050 (patch) | |
tree | c2248255f618ce7267de10b17280dd9b1858fcaa /src/net/java/sip/communicator/plugin | |
parent | a613195ef42ca5a88e663b17d6419ab4a6db1891 (diff) | |
download | jitsi-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/java/sip/communicator/plugin')
3 files changed, 95 insertions, 118 deletions
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); } } |