diff --git a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java index 3dabdc802..44ccaf73f 100644 --- a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java +++ b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java @@ -8,6 +8,7 @@ import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.util.*; + import org.jitsi.service.configuration.*; import org.osgi.framework.*; @@ -15,7 +16,7 @@ * Implements BundleActivator for the browserlauncher bundle. * * @author Yana Stamcheva - * @author Lubomir Marinov + * @author Lyubomir Marinov * @author Pawel Domas */ public class BrowserLauncherActivator @@ -73,11 +74,10 @@ public static ConfigurationService getConfigurationService() { if (configService == null && bundleContext != null) { - ServiceReference serviceReference = bundleContext - .getServiceReference(ConfigurationService.class.getName()); - - configService = (ConfigurationService)bundleContext - .getService(serviceReference); + configService + = ServiceUtils.getService( + bundleContext, + ConfigurationService.class); } return configService; diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java index c4859bc6d..d18cb44b6 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryActivator.java @@ -68,11 +68,8 @@ public void start(BundleContext bc) throws Exception try{ 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 call history service. callHistoryService = @@ -150,27 +147,28 @@ public static ResourceManagementService getResources() public static Map getProtocolProviderFactories() { - ServiceReference[] serRefs = null; + Collection> serRefs; try { // get all registered provider factories - serRefs = - bundleContext.getServiceReferences( - ProtocolProviderFactory.class.getName(), null); + serRefs + = bundleContext.getServiceReferences( + ProtocolProviderFactory.class, + null); } catch (InvalidSyntaxException e) { + serRefs = null; logger.error("LoginManager : " + e); } if (serRefs != null) { - for (ServiceReference serRef : serRefs) + for (ServiceReference serRef : serRefs) { ProtocolProviderFactory providerFactory - = (ProtocolProviderFactory) - bundleContext.getService(serRef); + = bundleContext.getService(serRef); providerFactoriesMap.put( serRef.getProperty(ProtocolProviderFactory.PROTOCOL), diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java index aa007299c..d83c6ad69 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java @@ -618,39 +618,35 @@ public void start(BundleContext bc) // start listening for newly register or removed protocol providers bc.addServiceListener(this); - ServiceReference[] protocolProviderRefs = null; + Collection> ppsRefs; try { - protocolProviderRefs - = bc.getServiceReferences( - ProtocolProviderService.class.getName(), - null); + 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); } // in case we found any - if (protocolProviderRefs != null) + if (ppsRefs != null) { if (logger.isDebugEnabled()) { logger.debug( - "Found " - + protocolProviderRefs.length + "Found " + ppsRefs.size() + " already installed providers."); } - for (ServiceReference protocolProviderRef : protocolProviderRefs) + for (ServiceReference ppsRef : ppsRefs) { - ProtocolProviderService provider - = (ProtocolProviderService) - bc.getService(protocolProviderRef); + ProtocolProviderService pps = bc.getService(ppsRef); - this.handleProviderAdded(provider); + this.handleProviderAdded(pps); } } } @@ -664,32 +660,29 @@ public void stop(BundleContext bc) { bc.removeServiceListener(this); - ServiceReference[] protocolProviderRefs = null; + Collection> ppsRefs; try { - protocolProviderRefs - = bc.getServiceReferences( - ProtocolProviderService.class.getName(), - null); + 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); } // in case we found any - if (protocolProviderRefs != null) + if (ppsRefs != null) { - for (ServiceReference protocolProviderRef : protocolProviderRefs) + for (ServiceReference ppsRef : ppsRefs) { - ProtocolProviderService provider - = (ProtocolProviderService) - bc.getService(protocolProviderRef); + ProtocolProviderService pps = bc.getService(ppsRef); - this.handleProviderRemoved(provider); + this.handleProviderRemoved(pps); } } } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/IceTransportManagerSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/IceTransportManagerSipImpl.java index e300a6edb..eeaebaa7b 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/IceTransportManagerSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/IceTransportManagerSipImpl.java @@ -91,10 +91,10 @@ public void startCandidateHarvest(SessionDescription ourOffer, iceAgent.setControlling(true); //add the candidate attributes and set default candidates - for(MediaDescription mLine : SdpUtils.extractMediaDescriptions(ourOffer)) + for(MediaDescription mLine + : SdpUtils.extractMediaDescriptions(ourOffer)) { - IceMediaStream iceStream = createIceStream( - SdpUtils.getMediaType(mLine).toString(), iceAgent); + createIceStream(SdpUtils.getMediaType(mLine).toString(), iceAgent); } //now that our iceAgent is ready, reflect it on our offer. @@ -134,7 +134,7 @@ public void startCandidateHarvest( SessionDescription theirOffer, * @return the content list that we received earlier (possibly cloned into * a new instance) and that we have updated with transport lists. */ - public List wrapupCandidateHarvest() + public List> wrapupCandidateHarvest() { return null; } diff --git a/src/net/java/sip/communicator/service/protocol/AccountManager.java b/src/net/java/sip/communicator/service/protocol/AccountManager.java index 6cf7c5b7f..c85ed7aeb 100644 --- a/src/net/java/sip/communicator/service/protocol/AccountManager.java +++ b/src/net/java/sip/communicator/service/protocol/AccountManager.java @@ -11,7 +11,7 @@ import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.util.*; -import net.java.sip.communicator.util.Base64; // disambiguation +import net.java.sip.communicator.util.Base64; import org.jitsi.service.configuration.*; import org.osgi.framework.*; @@ -20,7 +20,7 @@ * Represents an implementation of AccountManager which loads the * accounts in a separate thread. * - * @author Lubomir Marinov + * @author Lyubomir Marinov * @author Yana Stamcheva */ public class AccountManager @@ -286,35 +286,37 @@ public boolean hasStoredAccount(String protocolName, boolean includeHidden, String userID) { - ServiceReference[] factoryRefs = null; + Collection> factoryRefs; boolean hasStoredAccounts = false; try { factoryRefs = bundleContext.getServiceReferences( - ProtocolProviderFactory.class.getName(), null); + ProtocolProviderFactory.class, + null); } catch (InvalidSyntaxException ex) { + factoryRefs = null; logger.error( "Failed to retrieve the registered ProtocolProviderFactories", ex); } - if ((factoryRefs != null) && (factoryRefs.length > 0)) + if ((factoryRefs != null) && !factoryRefs.isEmpty()) { ConfigurationService configService = ProtocolProviderActivator.getConfigurationService(); - for (ServiceReference factoryRef : factoryRefs) + for (ServiceReference factoryRef + : factoryRefs) { ProtocolProviderFactory factory - = (ProtocolProviderFactory) - bundleContext.getService(factoryRef); + = bundleContext.getService(factoryRef); if ((protocolName != null) - && !protocolName.equals(factory.getProtocolName())) + && !protocolName.equals(factory.getProtocolName())) { continue; } @@ -397,31 +399,33 @@ else if(userID == null) */ public AccountID findAccountID(String uid) { - ServiceReference[] factoryRefs = null; + Collection> factoryRefs; try { factoryRefs = bundleContext.getServiceReferences( - ProtocolProviderFactory.class.getName(), null); + ProtocolProviderFactory.class, + null); } catch (InvalidSyntaxException ex) { + factoryRefs = null; logger.error( "Failed to retrieve the registered ProtocolProviderFactories", ex); } - if ((factoryRefs != null) && (factoryRefs.length > 0)) + if ((factoryRefs != null) && !factoryRefs.isEmpty()) { ConfigurationService configService = ProtocolProviderActivator.getConfigurationService(); - for (ServiceReference factoryRef : factoryRefs) + for (ServiceReference factoryRef + : factoryRefs) { ProtocolProviderFactory factory - = (ProtocolProviderFactory) - bundleContext.getService(factoryRef); + = bundleContext.getService(factoryRef); String factoryPackage = getFactoryImplPackageName(factory); List storedAccountsProps @@ -508,8 +512,8 @@ public void run() } }; loadStoredAccountsThread.setDaemon(true); - loadStoredAccountsThread - .setName("AccountManager.loadStoredAccounts"); + loadStoredAccountsThread.setName( + "AccountManager.loadStoredAccounts"); loadStoredAccountsThread.start(); } } @@ -1022,15 +1026,15 @@ public void unloadAccount(AccountID accountID) accountID.getProtocolName()); // Obtain the protocol provider. - ServiceReference serRef + ServiceReference serRef = providerFactory.getProviderForAccount(accountID); // If there's no such provider we have nothing to do here. if (serRef == null) return; - ProtocolProviderService protocolProvider = - (ProtocolProviderService) bundleContext.getService(serRef); + ProtocolProviderService protocolProvider + = bundleContext.getService(serRef); // Set the account icon path for unloaded accounts. String iconPathProperty = accountID.getAccountPropertyString( diff --git a/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java b/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java index bd9299ceb..d10a05fbf 100644 --- a/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java +++ b/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java @@ -6,6 +6,8 @@ */ package net.java.sip.communicator.service.protocol; +import java.util.*; + import net.java.sip.communicator.service.protocol.event.*; import org.osgi.framework.*; @@ -13,17 +15,15 @@ /** * Provides utilities to aid the manipulation of {@link AccountManager}. * - * @author Lubomir Marinov + * @author Lyubomir Marinov */ public final class AccountManagerUtils { private static AccountManager getAccountManager(BundleContext bundleContext) { return - (AccountManager) - bundleContext.getService( - bundleContext.getServiceReference( - AccountManager.class.getName())); + bundleContext.getService( + bundleContext.getServiceReference(AccountManager.class)); } /** @@ -92,14 +92,13 @@ public void handleAccountManagerEvent(AccountManagerEvent event) if (bundleContext == null) return; - ServiceReference[] factoryRefs; + Collection> factoryRefs; try { factoryRefs - = bundleContext - .getServiceReferences( - ProtocolProviderFactory.class.getName(), + = bundleContext.getServiceReferences( + ProtocolProviderFactory.class, "(" + ProtocolProviderFactory.PROTOCOL + "=" @@ -119,13 +118,15 @@ public void handleAccountManagerEvent(AccountManagerEvent event) { boolean factoryIsRegistered = false; - for (ServiceReference factoryRef : factoryRefs) + for (ServiceReference factoryRef + : factoryRefs) + { if (factory == bundleContext.getService(factoryRef)) { factoryIsRegistered = true; break; } - + } if (!factoryIsRegistered) return; }