/** Handles service change events. */ public void serviceChanged(ServiceEvent event) { ServiceReference serviceRef = event.getServiceReference(); // if the event is caused by a bundle being stopped, we don't want to // know if (serviceRef.getBundle().getState() == Bundle.STOPPING) { return; } Object service = MUCActivator.bundleContext.getService(serviceRef); // we don't care if the source service is not a protocol provider if (!(service instanceof ProtocolProviderService)) { return; } switch (event.getType()) { case ServiceEvent.REGISTERED: addQueryToProviderPresenceListeners((ProtocolProviderService) service); break; case ServiceEvent.UNREGISTERING: removeQueryFromProviderPresenceListeners((ProtocolProviderService) service); break; } }
private static ServiceReferenceDTO getServiceReferenceDTO(ServiceReference<?> ref) { if (ref == null) { return null; } Bundle b = ref.getBundle(); if (b == null) { // service has been unregistered return null; } ServiceReferenceDTO dto = new ServiceReferenceDTO(); dto.bundle = b.getBundleId(); String[] keys = ref.getPropertyKeys(); Map<String, Object> properties = newMap(keys.length); for (String k : keys) { Object v = ref.getProperty(k); if (Constants.SERVICE_ID.equals(k)) { dto.id = ((Long) v).longValue(); } properties.put(k, mapValue(v)); } dto.properties = properties; Bundle[] using = ref.getUsingBundles(); final int length = (using == null) ? 0 : using.length; long[] usingBundles = new long[length]; for (int i = 0; i < length; i++) { usingBundles[i] = using[i].getBundleId(); } dto.usingBundles = usingBundles; return dto; }
private MetaTypeProviderWrapper[] getMetaTypeProviders() { Map<ServiceReference<Object>, Object> services = _tracker.getTracked(); if (services.isEmpty()) return new MetaTypeProviderWrapper[0]; Set<ServiceReference<Object>> serviceReferences = services.keySet(); Set<MetaTypeProviderWrapper> result = new HashSet<MetaTypeProviderWrapper>(); for (ServiceReference<Object> serviceReference : serviceReferences) { if (serviceReference.getBundle() == _bundle) { Object service = services.get(serviceReference); // If the service is not a MetaTypeProvider, we're not interested in it. if (service instanceof MetaTypeProvider) { // Include the METATYPE_PID, if present, to return as part of getPids(). Also, include the // METATYPE_FACTORY_PID, if present, to return as part of getFactoryPids(). // The filter ensures at least one of these properties was set for a standalone // MetaTypeProvider. addMetaTypeProviderWrappers( MetaTypeProvider.METATYPE_PID, serviceReference, (MetaTypeProvider) service, false, result); addMetaTypeProviderWrappers( MetaTypeProvider.METATYPE_FACTORY_PID, serviceReference, (MetaTypeProvider) service, true, result); // If the service is a ManagedService, include the SERVICE_PID to return as part of // getPids(). // The filter ensures the SERVICE_PID property was set. if (service instanceof ManagedService) { addMetaTypeProviderWrappers( Constants.SERVICE_PID, serviceReference, (MetaTypeProvider) service, false, result); } // If the service is a ManagedServiceFactory, include the SERVICE_PID to return as part of // getFactoryPids(). // The filter ensures the SERVICE_PID property was set. else if (service instanceof ManagedServiceFactory) { addMetaTypeProviderWrappers( Constants.SERVICE_PID, serviceReference, (MetaTypeProvider) service, true, result); } } } } return result.toArray(new MetaTypeProviderWrapper[result.size()]); }
private void addMetaTypeProviderWrappers( String servicePropertyName, ServiceReference<Object> serviceReference, MetaTypeProvider service, boolean factory, Set<MetaTypeProviderWrapper> wrappers) { String[] pids = getStringProperty(servicePropertyName, serviceReference.getProperty(servicePropertyName)); for (String pid : pids) { wrappers.add(new MetaTypeProviderWrapper(service, pid, factory)); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public IAuthenticationService addingService( ServiceReference<IAuthenticationService> reference) { if ("true".equals(reference.getProperty(PROP_CONFIGURED))) // $NON-NLS-1$ return null; IAuthenticationService authService = super.addingService(reference); // TODO need to read auth properties from InstanceScope preferences authService.configure(new Properties()); Dictionary dictionary = new Properties(); dictionary.put(PROP_CONFIGURED, "true"); // $NON-NLS-1$ if (getService() != null) { getService().setRegistered(false); } authService.setRegistered(true); context.registerService(IAuthenticationService.class.getName(), authService, dictionary); return authService; }