OSGi and blueprint APIs

OSGi and blueprint also have APIs. Two components of these APIs are used extensively throughout InfoSphere MDM.

Throughout this document you’ll see this snippet:
<property name="bpContainer" ref="blueprintContainer"/> 
<property name="bundle" ref="blueprintBundle"/> 
In InfoSphere MDM, we are injecting the blueprint API and the OSGi bundle API into our code so we can use it. The blueprintContainer is a special reference to the blueprint API. The blueprintBundle is a special reference to the OSGi bundle API. Beans having these properties in a blueprint definition, also have these imports in their corresponding bean class:
import org.osgi.framework.Bundle; 
import org.osgi.service.blueprint.container.BlueprintContainer; 
They also have these member variables:
private Bundle bundle; 
private BlueprintContainer bpContainer; 

These two interfaces are used to get the class loader for a bundle, to load classes from within a bundle, to query the blueprint components within a bundle, and so forth.

Another approach to getting the bundle API is to use the static method org.osgi.framework.FrameworkUtil.getBundle(<a class>). It will return the bundle API for the bundle containing a class.

Note that the two approaches (that is, injecting the bundle API and using the getBundle method) are not necessarily equivalent: the method to inject the bundle API into a bean injects the bundle where the blueprint bean is defined. This is not necessarily the same place as where the bean class is defined. This technique is used for blueprint locator patterns. It enables you to define a single service bean in one bundle and have it locate artifacts in any bundle, provided there is a service using the bean class registered within those bundles.

For more information on OSGi APIs, see http://www.osgi.org/javadoc/