/** * Starts the Metacafe replacement source bundle * * @param context the <tt>BundleContext</tt> as provided from the OSGi framework * @throws Exception if anything goes wrong */ public void start(BundleContext context) throws Exception { Hashtable<String, String> hashtable = new Hashtable<String, String>(); hashtable.put( ReplacementService.SOURCE_NAME, ReplacementServiceMetacafeImpl.METACAFE_CONFIG_LABEL); metacafeSource = new ReplacementServiceMetacafeImpl(); metacafeServReg = context.registerService(ReplacementService.class.getName(), metacafeSource, hashtable); logger.info("Metacafe source implementation [STARTED]."); }
/** * Implements CallListener.callEnded. Stops sounds that are playing at the moment if there're any. * Removes the call panel and disables the hangup button. */ public void callEnded(CallEvent event) { Call sourceCall = event.getSourceCall(); NotificationManager.stopSound(NotificationManager.BUSY_CALL); NotificationManager.stopSound(NotificationManager.INCOMING_CALL); NotificationManager.stopSound(NotificationManager.OUTGOING_CALL); if (activeCalls.get(sourceCall) != null) { CallPanel callPanel = (CallPanel) activeCalls.get(sourceCall); this.removeCallPanelWait(callPanel); } }
static { iconsTable.put( ProtocolIcon.ICON_SIZE_16x16, getImageInBytes("service.protocol.yahoo.YAHOO_16x16")); iconsTable.put( ProtocolIcon.ICON_SIZE_32x32, getImageInBytes("service.protocol.yahoo.YAHOO_32x32")); iconsTable.put( ProtocolIcon.ICON_SIZE_48x48, getImageInBytes("service.protocol.yahoo.YAHOO_48x48")); iconsTable.put( ProtocolIcon.ICON_SIZE_64x64, getImageInBytes("service.protocol.yahoo.YAHOO_64x64")); }
/** * The dependent service is available and the bundle will start. * * @param dependentService the UIService this activator is waiting. */ @Override public void start(Object dependentService) { if (logger.isDebugEnabled()) logger.debug("Update checker [STARTED]"); ConfigurationService cfg = getConfiguration(); if (OSUtils.IS_WINDOWS) { updateService = new Update(); bundleContext.registerService(UpdateService.class.getName(), updateService, null); // Register the "Check for Updates" menu item if // the "Check for Updates" property isn't disabled. if (!cfg.getBoolean(CHECK_FOR_UPDATES_MENU_DISABLED_PROP, false)) { // Register the "Check for Updates" menu item. CheckForUpdatesMenuItemComponent checkForUpdatesMenuItemComponent = new CheckForUpdatesMenuItemComponent(Container.CONTAINER_HELP_MENU); Hashtable<String, String> toolsMenuFilter = new Hashtable<String, String>(); toolsMenuFilter.put(Container.CONTAINER_ID, Container.CONTAINER_HELP_MENU.getID()); bundleContext.registerService( PluginComponent.class.getName(), checkForUpdatesMenuItemComponent, toolsMenuFilter); } // Check for software update upon startup if enabled. if (cfg.getBoolean(UPDATE_ENABLED, true)) updateService.checkForUpdates(false); } if (cfg.getBoolean(CHECK_FOR_UPDATES_DAILY_ENABLED_PROP, false)) { logger.info("Scheduled update checking enabled"); // Schedule a "check for updates" task that will run once a day int hoursToWait = calcHoursToWait(); Runnable updateRunnable = new Runnable() { public void run() { logger.debug("Performing scheduled update check"); getUpdateService().checkForUpdates(false); } }; mUpdateExecutor = Executors.newSingleThreadScheduledExecutor(); mUpdateExecutor.scheduleAtFixedRate( updateRunnable, hoursToWait, 24 * 60 * 60, TimeUnit.SECONDS); } if (logger.isDebugEnabled()) logger.debug("Update checker [REGISTERED]"); }
/** * 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; }
/** * Implements CallListener.incomingCallReceived. When a call is received creates a call panel and * adds it to the main tabbed pane and plays the ring phone sound to the user. */ public void incomingCallReceived(CallEvent event) { Call sourceCall = event.getSourceCall(); CallPanel callPanel = new CallPanel(this, sourceCall, GuiCallParticipantRecord.INCOMING_CALL); mainFrame.addCallPanel(callPanel); if (mainFrame.getState() == JFrame.ICONIFIED) mainFrame.setState(JFrame.NORMAL); if (!mainFrame.isVisible()) mainFrame.setVisible(true); mainFrame.toFront(); this.callButton.setEnabled(true); this.hangupButton.setEnabled(true); NotificationManager.fireNotification( NotificationManager.INCOMING_CALL, null, "Incoming call recived from: " + sourceCall.getCallParticipants().next()); activeCalls.put(sourceCall, callPanel); this.setCallPanelVisible(true); }
/** Prepares the factory for bundle shutdown. */ public void stop() { if (logger.isTraceEnabled()) logger.trace("Preparing to stop all protocol providers of" + this); synchronized (registeredAccounts) { for (Enumeration<ServiceRegistration> registrations = registeredAccounts.elements(); registrations.hasMoreElements(); ) { ServiceRegistration reg = registrations.nextElement(); stop(reg); reg.unregister(); } registeredAccounts.clear(); } }
/** * Returns the set of data that user has entered through this wizard. * * @return Iterator */ public Iterator<Map.Entry<String, String>> getSummary() { Hashtable<String, String> summaryTable = new Hashtable<String, String>(); /* * Hashtable arranges the entries alphabetically so the order * of appearance is * - Computer Name / IP * - Port * - User ID */ summaryTable.put("Account ID", registration.getAccountID()); summaryTable.put("Known Hosts", registration.getKnownHostsFile()); summaryTable.put("Identity", registration.getIdentityFile()); return summaryTable.entrySet().iterator(); }
/** * Removes the specified account from the list of accounts that this provider factory is handling. * If the specified accountID is unknown to the ProtocolProviderFactory, the call has no effect * and false is returned. This method is persistent in nature and once called the account * corresponding to the specified ID will not be loaded during future runs of the project. * * @param accountID the ID of the account to remove. * @return true if an account with the specified ID existed and was removed and false otherwise. */ public boolean uninstallAccount(AccountID accountID) { // unregister the protocol provider ServiceReference serRef = getProviderForAccount(accountID); if (serRef == null) return false; ProtocolProviderService protocolProvider = (ProtocolProviderService) SipActivator.getBundleContext().getService(serRef); try { protocolProvider.unregister(); } catch (OperationFailedException e) { logger.error( "Failed to unregister protocol provider for account : " + accountID + " caused by : " + e); } ServiceRegistration registration = (ServiceRegistration) registeredAccounts.remove(accountID); if (registration == null) return false; // kill the service registration.unregister(); return removeStoredAccount(SipActivator.getBundleContext(), accountID); }
static { iconPathsTable.put( ProtocolIcon.ICON_SIZE_16x16, getResources().getImagePath("service.protocol.yahoo.YAHOO_16x16")); iconPathsTable.put( ProtocolIcon.ICON_SIZE_32x32, getResources().getImagePath("service.protocol.yahoo.YAHOO_32x32")); iconPathsTable.put( ProtocolIcon.ICON_SIZE_48x48, getResources().getImagePath("service.protocol.yahoo.YAHOO_48x48")); iconPathsTable.put( ProtocolIcon.ICON_SIZE_64x64, getResources().getImagePath("service.protocol.yahoo.YAHOO_64x64")); }
/** * Removes the given call panel tab. * * @param callPanel the CallPanel to remove */ private void removeCallPanel(CallPanel callPanel) { if (callPanel.getCall() != null && activeCalls.contains(callPanel.getCall())) { this.activeCalls.remove(callPanel.getCall()); } mainFrame.removeCallPanel(callPanel); updateButtonsStateAccordingToSelectedPanel(); }
static { iconPathsTable.put( ProtocolIcon.ICON_SIZE_16x16, getResources().getImagePath("service.protocol.gibberish.GIBBERISH_16x16")); iconPathsTable.put( ProtocolIcon.ICON_SIZE_32x32, getResources().getImagePath("service.protocol.gibberish.GIBBERISH_32x32")); iconPathsTable.put( ProtocolIcon.ICON_SIZE_48x48, getResources().getImagePath("service.protocol.gibberish.GIBBERISH_48x48")); iconPathsTable.put( ProtocolIcon.ICON_SIZE_64x64, getResources().getImagePath("service.protocol.gibberish.GIBBERISH_64x64")); }
/** * Returns the ServiceReference for the protocol provider corresponding to the specified accountID * or null if the accountID is unknown. * * @param accountID the accountID of the protocol provider we'd like to get * @return a ServiceReference object to the protocol provider with the specified account id and * null if the account id is unknown to the provider factory. */ public ServiceReference getProviderForAccount(AccountID accountID) { ServiceRegistration registration; synchronized (registeredAccounts) { registration = registeredAccounts.get(accountID); } return (registration == null) ? null : registration.getReference(); }
static { iconsTable.put( ProtocolIcon.ICON_SIZE_16x16, getImageInBytes("service.protocol.gibberish.GIBBERISH_16x16")); iconsTable.put( ProtocolIcon.ICON_SIZE_32x32, getImageInBytes("service.protocol.gibberish.GIBBERISH_32x32")); iconsTable.put( ProtocolIcon.ICON_SIZE_48x48, getImageInBytes("service.protocol.gibberish.GIBBERISH_48x48")); iconsTable.put( ProtocolIcon.ICON_SIZE_64x64, getImageInBytes("service.protocol.gibberish.GIBBERISH_64x64")); }
/** implements BundleActivator.start() */ public void start(BundleContext bc) throws Exception { logger.info("starting popup message test "); bundleContext = bc; setName("PopupMessageHandlerSLick"); Hashtable<String, String> properties = new Hashtable<String, String>(); properties.put("service.pid", getName()); // we maybe are running on machine without WM and systray // (test server machine), skip tests if (ServiceUtils.getService(bc, SystrayService.class) != null) { addTest(TestPopupMessageHandler.suite()); } bundleContext.registerService(getClass().getName(), this, properties); }
/** * Creates an account for the given user and password. * * @param providerFactory the ProtocolProviderFactory which will create the account * @param user the user identifier * @return the <tt>ProtocolProviderService</tt> for the new account. */ public ProtocolProviderService installAccount( ProtocolProviderFactory providerFactory, String user) throws OperationFailedException { Hashtable<String, String> accountProperties = new Hashtable<String, String>(); accountProperties.put( ProtocolProviderFactory.ACCOUNT_ICON_PATH, "resources/images/protocol/gibberish/gibberish32x32.png"); if (registration.isRememberPassword()) { accountProperties.put(ProtocolProviderFactory.PASSWORD, registration.getPassword()); } if (isModification()) { providerFactory.uninstallAccount(protocolProvider.getAccountID()); this.protocolProvider = null; setModification(false); } try { AccountID accountID = providerFactory.installAccount(user, accountProperties); ServiceReference serRef = providerFactory.getProviderForAccount(accountID); protocolProvider = (ProtocolProviderService) GibberishAccRegWizzActivator.bundleContext.getService(serRef); } catch (IllegalStateException exc) { logger.warn(exc.getMessage()); throw new OperationFailedException( "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT); } catch (Exception exc) { logger.warn(exc.getMessage()); throw new OperationFailedException( "Failed to add account", OperationFailedException.GENERAL_ERROR); } return protocolProvider; }
/** * Creates an account for the given Account ID, Identity File and Known Hosts File * * @param providerFactory the ProtocolProviderFactory which will create the account * @param user the user identifier * @return the <tt>ProtocolProviderService</tt> for the new account. */ public ProtocolProviderService installAccount( ProtocolProviderFactory providerFactory, String user) throws OperationFailedException { Hashtable<String, String> accountProperties = new Hashtable<String, String>(); accountProperties.put( ProtocolProviderFactory.ACCOUNT_ICON_PATH, "resources/images/protocol/ssh/ssh32x32.png"); accountProperties.put( ProtocolProviderFactory.NO_PASSWORD_REQUIRED, new Boolean(true).toString()); accountProperties.put( ProtocolProviderFactorySSHImpl.IDENTITY_FILE, registration.getIdentityFile()); accountProperties.put( ProtocolProviderFactorySSHImpl.KNOWN_HOSTS_FILE, String.valueOf(registration.getKnownHostsFile())); try { AccountID accountID = providerFactory.installAccount(user, accountProperties); ServiceReference serRef = providerFactory.getProviderForAccount(accountID); protocolProvider = (ProtocolProviderService) SSHAccRegWizzActivator.bundleContext.getService(serRef); } catch (IllegalStateException exc) { logger.warn(exc.getMessage()); throw new OperationFailedException( "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT); } catch (Exception exc) { logger.warn(exc.getMessage()); throw new OperationFailedException( "Failed to add account", OperationFailedException.GENERAL_ERROR); } return protocolProvider; }
/** * Implements ChangeListener.stateChanged. Enables the hangup button if ones selects a tab in the * main tabbed pane that contains a call panel. */ public void stateChanged(ChangeEvent e) { this.updateButtonsStateAccordingToSelectedPanel(); Component selectedPanel = mainFrame.getSelectedTab(); if (selectedPanel == null || !(selectedPanel instanceof CallPanel)) { Iterator callPanels = activeCalls.values().iterator(); while (callPanels.hasNext()) { CallPanel callPanel = (CallPanel) callPanels.next(); callPanel.removeDialogs(); } } }
/** 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(); }
/** * Initializes and creates an account corresponding to the specified accountProperties and * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter. * * @param userIDStr the user identifier uniquely representing the newly created account within the * protocol namespace. * @param accountProperties a set of protocol (or implementation) specific properties defining the * new account. * @return the AccountID of the newly created account. * @throws IllegalArgumentException if userID does not correspond to an identifier in the context * of the underlying protocol or if accountProperties does not contain a complete set of * account installation properties. * @throws IllegalStateException if the account has already been installed. * @throws NullPointerException if any of the arguments is null. */ public AccountID installAccount(String userIDStr, Map accountProperties) { BundleContext context = SipActivator.getBundleContext(); if (context == null) throw new NullPointerException("The specified BundleContext was null"); if (userIDStr == null) throw new NullPointerException("The specified AccountID was null"); accountProperties.put(USER_ID, userIDStr); 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("null is not a valid ServerAddress"); if (!accountProperties.containsKey(PROTOCOL)) accountProperties.put(PROTOCOL, ProtocolNames.SIP); AccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress); // make sure we haven't seen this account id before. if (registeredAccounts.containsKey(accountID)) throw new IllegalStateException("An account for id " + userIDStr + " was already installed!"); // first store the account and only then load it as the load generates // an osgi event, the osgi event triggers (trhgough the UI) a call to // the register() method and it needs to acces the configuration service // and check for a password. this.storeAccount(SipActivator.getBundleContext(), accountID); try { accountID = loadAccount(accountProperties); } catch (RuntimeException exc) { // it might happen that load-ing the account fails because of a bad // initialization. if this is the case, make sure we remove it. this.removeStoredAccount(SipActivator.getBundleContext(), accountID); throw exc; } return accountID; }
/** * Removes the specified account from the list of accounts that this provider factory is handling. * If the specified accountID is unknown to the ProtocolProviderFactory, the call has no effect * and false is returned. This method is persistent in nature and once called the account * corresponding to the specified ID will not be loaded during future runs of the project. * * @param accountID the ID of the account to remove. * @return true if an account with the specified ID existed and was removed and false otherwise. */ public boolean uninstallAccount(AccountID accountID) { // Unregister the protocol provider. ServiceReference serRef = getProviderForAccount(accountID); boolean wasAccountExisting = false; // If the protocol provider service is registered, first unregister the // service. if (serRef != null) { BundleContext bundleContext = getBundleContext(); ProtocolProviderService protocolProvider = (ProtocolProviderService) bundleContext.getService(serRef); try { protocolProvider.unregister(); } catch (OperationFailedException ex) { logger.error( "Failed to unregister protocol provider for account: " + accountID + " caused by: " + ex); } } ServiceRegistration registration; synchronized (registeredAccounts) { registration = registeredAccounts.remove(accountID); } // first remove the stored account so when PP is unregistered we can // distinguish between deleted or just disabled account wasAccountExisting = removeStoredAccount(accountID); if (registration != null) { // Kill the service. registration.unregister(); } return wasAccountExisting; }
/** * Creates a protocol provider for the given <tt>accountID</tt> and registers it in the bundle * context. This method has a persistent effect. Once created the resulting account will remain * installed until removed through the uninstallAccount method. * * @param accountID the account identifier * @return <tt>true</tt> if the account with the given <tt>accountID</tt> is successfully loaded, * otherwise returns <tt>false</tt> */ public boolean loadAccount(AccountID accountID) { // Need to obtain the original user id property, instead of calling // accountID.getUserID(), because this method could return a modified // version of the user id property. String userID = accountID.getAccountPropertyString(ProtocolProviderFactory.USER_ID); ProtocolProviderService service = createService(userID, accountID); Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put(PROTOCOL, protocolName); properties.put(USER_ID, userID); ServiceRegistration serviceRegistration = bundleContext.registerService(ProtocolProviderService.class.getName(), service, properties); if (serviceRegistration == null) return false; else { synchronized (registeredAccounts) { registeredAccounts.put(accountID, serviceRegistration); } return true; } }
/** * Unloads the account corresponding to the given <tt>accountID</tt>. Unregisters the * corresponding protocol provider, but keeps the account in contrast to the uninstallAccount * method. * * @param accountID the account identifier * @return true if an account with the specified ID existed and was unloaded and false otherwise. */ public boolean unloadAccount(AccountID accountID) { // Unregister the protocol provider. ServiceReference serRef = getProviderForAccount(accountID); if (serRef == null) { return false; } BundleContext bundleContext = getBundleContext(); ProtocolProviderService protocolProvider = (ProtocolProviderService) bundleContext.getService(serRef); try { protocolProvider.unregister(); } catch (OperationFailedException ex) { logger.error( "Failed to unregister protocol provider for account : " + accountID + " caused by: " + ex); } ServiceRegistration registration; synchronized (registeredAccounts) { registration = registeredAccounts.remove(accountID); } if (registration == null) { return false; } // Kill the service. registration.unregister(); return true; }
/** * Returns a copy of the list containing the <tt>AccountID</tt>s of all accounts currently * registered in this protocol provider. * * @return a copy of the list containing the <tt>AccountID</tt>s of all accounts currently * registered in this protocol provider. */ public ArrayList<AccountID> getRegisteredAccounts() { synchronized (registeredAccounts) { return new ArrayList<AccountID>(registeredAccounts.keySet()); } }
/** * Returns the ServiceReference for the protocol provider corresponding to the specified accountID * or null if the accountID is unknown. * * @param accountID the accountID of the protocol provider we'd like to get * @return a ServiceReference object to the protocol provider with the specified account id and * null if the account id is unknwon to the provider factory. */ public ServiceReference getProviderForAccount(AccountID accountID) { ServiceRegistration registration = (ServiceRegistration) registeredAccounts.get(accountID); return (registration == null) ? null : registration.getReference(); }
/** * Returns the icon image in the given size. * * @param iconSize the icon size; one of ICON_SIZE_XXX constants */ public byte[] getIcon(String iconSize) { return iconsTable.get(iconSize); }
/** Returne TRUE if a icon with the given size is supported, FALSE-otherwise. */ public boolean isSizeSupported(String iconSize) { return iconsTable.containsKey(iconSize); }
/** * Implements the <tt>ProtocolIcon.getSupportedSizes()</tt> method. Returns an iterator to a set * containing the supported icon sizes. * * @return an iterator to a set containing the supported icon sizes */ public Iterator<String> getSupportedSizes() { return iconsTable.keySet().iterator(); }
/** * Returns a copy of the list containing all accounts currently registered in this protocol * provider. * * @return a copy of the llist containing all accounts currently installed in the protocol * provider. */ public ArrayList getRegisteredAccounts() { return new ArrayList(registeredAccounts.keySet()); }
/** * Returns a path to the icon with the given size. * * @param iconSize the size of the icon we're looking for * @return the path to the icon with the given size */ public String getIconPath(String iconSize) { return iconPathsTable.get(iconSize); }