/** * Initializes and creates an account corresponding to the specified accountProperties and * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter. * * @param accountProperties a set of protocol (or implementation) specific properties defining the * new account. * @return the AccountID of the newly created account */ protected AccountID loadAccount(Map accountProperties) { BundleContext context = SipActivator.getBundleContext(); if (context == null) throw new NullPointerException("The specified BundleContext was null"); String userIDStr = (String) accountProperties.get(USER_ID); if (userIDStr == null) throw new NullPointerException("The account properties contained no user id."); if (accountProperties == null) throw new NullPointerException("The specified property map was null"); String serverAddress = (String) accountProperties.get(SERVER_ADDRESS); if (serverAddress == null) throw new NullPointerException(serverAddress + " is not a valid ServerAddress"); if (!accountProperties.containsKey(PROTOCOL)) accountProperties.put(PROTOCOL, ProtocolNames.SIP); SipAccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress); // get a reference to the configuration service and register whatever // properties we have in it. Hashtable properties = new Hashtable(); properties.put(PROTOCOL, ProtocolNames.SIP); properties.put(USER_ID, userIDStr); ProtocolProviderServiceSipImpl sipProtocolProvider = new ProtocolProviderServiceSipImpl(); try { sipProtocolProvider.initialize(userIDStr, accountID); // We store again the account in order to store all properties added // during the protocol provider initialization. this.storeAccount(SipActivator.getBundleContext(), accountID); } catch (OperationFailedException ex) { logger.error("Failed to initialize account", ex); throw new IllegalArgumentException("Failed to initialize account" + ex.getMessage()); } ServiceRegistration registration = context.registerService( ProtocolProviderService.class.getName(), sipProtocolProvider, properties); registeredAccounts.put(accountID, registration); return accountID; }
/** Prepares the factory for bundle shutdown. */ public void stop() { logger.trace("Preparing to stop all SIP protocol providers."); Enumeration registrations = this.registeredAccounts.elements(); while (registrations.hasMoreElements()) { ServiceRegistration reg = ((ServiceRegistration) registrations.nextElement()); ProtocolProviderServiceSipImpl provider = (ProtocolProviderServiceSipImpl) SipActivator.getBundleContext().getService(reg.getReference()); // do an attempt to kill the provider provider.shutdown(); reg.unregister(); } registeredAccounts.clear(); }