Java Code Examples for org.osgi.framework.ServiceRegistration#getReference()

The following examples show how to use org.osgi.framework.ServiceRegistration#getReference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelPackageBundleListener.java    From sling-org-apache-sling-models-impl with Apache License 2.0 6 votes vote down vote up
@Override
public void removedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] object) {
    for (ServiceRegistration reg : object) {
        ServiceReference ref = reg.getReference();
        String[] adapterTypeNames = PropertiesUtil.toStringArray(ref.getProperty(AdapterFactory.ADAPTER_CLASSES));
        if (adapterTypeNames != null) {
            String implTypeName = PropertiesUtil.toString(ref.getProperty(PROP_IMPLEMENTATION_CLASS), null);
            for (String adapterTypeName : adapterTypeNames) {
                adapterImplementations.remove(adapterTypeName, implTypeName);
            }
        }
        reg.unregister();
    }
    adapterImplementations.removeResourceTypeBindings(bundle);

}
 
Example 2
Source File: Utils.java    From aries-jax-rs-whiteboard with Apache License 2.0 6 votes vote down vote up
public static void updateProperty(
    ServiceRegistration<?> serviceRegistration, String key, Object value) {

    CachingServiceReference<?> serviceReference =
        new CachingServiceReference<>(serviceRegistration.getReference());

    Dictionary<String, Object> properties = new Hashtable<>();

    for (String propertyKey : serviceReference.getPropertyKeys()) {
        properties.put(
            propertyKey, serviceReference.getProperty(propertyKey));
    }

    properties.put(key, value);

    serviceRegistration.setProperties(properties);
}
 
Example 3
Source File: FactoryImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ServiceReference<Repository> createFromString(String xml) throws Exception {
  System.out.println(xml);
  if(xml != null && !"".equals(xml) && !repositoryRegistrations.containsKey(xml)) {
    ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
    ParseResult pr = RepositoryXmlParser.parse(is);
    if(!pr.resources.isEmpty()) {
      RepositoryImpl repo = new RepositoryImpl(bc, pr.resources);
      Hashtable<String, Object> h = new Hashtable<String, Object>();
      h.put(Constants.SERVICE_PID, "org.knopflerfish.repository.xml.STRING." + System.currentTimeMillis());
      h.put(Constants.SERVICE_DESCRIPTION, pr.name);
 
      ServiceRegistration<Repository> sr = bc.registerService(Repository.class, repo, h);

      repositoryRegistrations.put(xml, sr);
      return sr.getReference();
    }
  }
  return null;
}
 
Example 4
Source File: XMLParserActivator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new XML Parser Factory object.
 * 
 * <p>
 * A unique XML Parser Factory object is returned for each call to this
 * method.
 * 
 * <p>
 * The returned XML Parser Factory object will be configured for validating
 * and namespace aware support as specified in the service properties of the
 * specified ServiceRegistration object.
 * 
 * This method can be overridden to configure additional features in the
 * returned XML Parser Factory object.
 * 
 * @param bundle The bundle using the service.
 * @param registration The <code>ServiceRegistration</code> object for the
 *        service.
 * @return A new, configured XML Parser Factory object or null if a
 *         configuration error was encountered
 */
public Object getService(Bundle bundle, ServiceRegistration registration) {
	ServiceReference sref = registration.getReference();
	String parserFactoryClassName = (String) sref
			.getProperty(FACTORYNAMEKEY);
	// need to set factory properties
	Object factory = getFactory(parserFactoryClassName);
	if (factory instanceof SAXParserFactory) {
		((SAXParserFactory) factory).setValidating(((Boolean) sref
				.getProperty(PARSER_VALIDATING)).booleanValue());
		((SAXParserFactory) factory).setNamespaceAware(((Boolean) sref
				.getProperty(PARSER_NAMESPACEAWARE)).booleanValue());
	}
	else {
		if (factory instanceof DocumentBuilderFactory) {
			((DocumentBuilderFactory) factory)
					.setValidating(((Boolean) sref
							.getProperty(PARSER_VALIDATING)).booleanValue());
			((DocumentBuilderFactory) factory)
					.setNamespaceAware(((Boolean) sref
							.getProperty(PARSER_NAMESPACEAWARE))
							.booleanValue());
		}
	}
	return factory;
}
 
Example 5
Source File: FactoryImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ServiceReference<Repository> create(String url, Dictionary<String, ?> properties, Object handle) throws Exception {
  if(url != null && !"".equals(url) && !repositoryRegistrations.containsKey(url)) {
    ParseResult pr =  RepositoryXmlParser.parse(url);
    if(!pr.resources.isEmpty()) {
      RepositoryImpl repo = new RepositoryImpl(bc, pr.resources);
      Hashtable<String, Object> h = new Hashtable<String, Object>();
      h.put(Constants.SERVICE_PID, "org.knopflerfish.repository.xml.PROP." + System.currentTimeMillis());
      h.put(Constants.SERVICE_DESCRIPTION, pr.name);
      h.put(Repository.URL, url);
      if (properties != null) {
        for (Enumeration<String> e = properties.keys(); e.hasMoreElements(); ) {
          String key = e.nextElement();
          h.put(key, properties.get(key));
        }
      }
      ServiceRegistration<Repository> sr = bc.registerService(Repository.class, repo, h);

      repositoryRegistrations.put(url, sr);
      if(handle != null) {
        // User provided non-url custom handle
        repositoryRegistrations.put(handle, sr);
      }
      return sr.getReference();
    }
  }
  return null;
}
 
Example 6
Source File: Activator.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 */
@Override
public void start(BundleContext context) throws Exception {
	
	bc = context;
	
	this.factory = new RepositoryModelFactory();
	ServiceRegistration registration = bc.registerService(ModelFactory.class.getName(),
	        this.factory, new Hashtable<String ,Object>());
	this.reference = registration.getReference();
}
 
Example 7
Source File: Activator.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 */
@Override
public void start(BundleContext context) throws Exception {
	
	bc = context;
	
	this.factory = new RepositoryModelFactory();
	ServiceRegistration registration = bc.registerService(ModelFactory.class.getName(),
	        this.factory, new Hashtable<String ,Object>());
	this.reference = registration.getReference();
}
 
Example 8
Source File: XMLParserActivator.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new XML Parser Factory object.
 * 
 * <p>
 * A unique XML Parser Factory object is returned for each call to this
 * method.
 * 
 * <p>
 * The returned XML Parser Factory object will be configured for validating
 * and namespace aware support as specified in the service properties of the
 * specified ServiceRegistration object.
 * 
 * This method can be overridden to configure additional features in the
 * returned XML Parser Factory object.
 * 
 * @param bundle The bundle using the service.
 * @param registration The {@code ServiceRegistration} object for the
 *        service.
 * @return A new, configured XML Parser Factory object or null if a
 *         configuration error was encountered
 */
public Object getService(Bundle bundle, ServiceRegistration registration) {
	ServiceReference sref = registration.getReference();
	String parserFactoryClassName = (String) sref.getProperty(FACTORYNAMEKEY);
	// need to set factory properties
	Object factory = getFactory(parserFactoryClassName);
	if (factory instanceof SAXParserFactory) {
		((SAXParserFactory) factory).setValidating(((Boolean) sref.getProperty(PARSER_VALIDATING)).booleanValue());
		((SAXParserFactory) factory).setNamespaceAware(((Boolean) sref.getProperty(PARSER_NAMESPACEAWARE)).booleanValue());
	} else {
		if (factory instanceof DocumentBuilderFactory) {
			((DocumentBuilderFactory) factory).setValidating(((Boolean) sref.getProperty(PARSER_VALIDATING)).booleanValue());
			((DocumentBuilderFactory) factory).setNamespaceAware(((Boolean) sref.getProperty(PARSER_NAMESPACEAWARE)).booleanValue());
		}
	}
	return factory;
}
 
Example 9
Source File: XMLParserActivator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a new XML Parser Factory object.
 * 
 * <p>
 * A unique XML Parser Factory object is returned for each call to this
 * method.
 * 
 * <p>
 * The returned XML Parser Factory object will be configured for validating
 * and namespace aware support as specified in the service properties of the
 * specified ServiceRegistration object.
 * 
 * This method can be overridden to configure additional features in the
 * returned XML Parser Factory object.
 * 
 * @param bundle The bundle using the service.
 * @param registration The {@code ServiceRegistration} object for the
 *        service.
 * @return A new, configured XML Parser Factory object or null if a
 *         configuration error was encountered
 */
public Object getService(Bundle bundle, ServiceRegistration registration) {
	ServiceReference sref = registration.getReference();
	String parserFactoryClassName = (String) sref.getProperty(FACTORYNAMEKEY);
	// need to set factory properties
	Object factory = getFactory(parserFactoryClassName);
	if (factory instanceof SAXParserFactory) {
		((SAXParserFactory) factory).setValidating(((Boolean) sref.getProperty(PARSER_VALIDATING)).booleanValue());
		((SAXParserFactory) factory).setNamespaceAware(((Boolean) sref.getProperty(PARSER_NAMESPACEAWARE)).booleanValue());
	} else {
		if (factory instanceof DocumentBuilderFactory) {
			((DocumentBuilderFactory) factory).setValidating(((Boolean) sref.getProperty(PARSER_VALIDATING)).booleanValue());
			((DocumentBuilderFactory) factory).setNamespaceAware(((Boolean) sref.getProperty(PARSER_NAMESPACEAWARE)).booleanValue());
		}
	}
	return factory;
}