BundleContextWrapper

public class BundleContextWrapper implements BundleContextAware

This is a wrapper class for the OSGi org.osgi.framework.BundleContext class. It provides convenience methods for processing Blueprint contexts of modules. This class implements org.eclipse.gemini.blueprint.context.BundleContextAware, so if it’s published as a Spring bean, the bundle context object should get injected by Spring.

Fields

CONTEXT_SERVICE_NAME

public static final String CONTEXT_SERVICE_NAME

The service property set by Blueprint for application contexts published at services. The value for this property will be equal to the symbolic name of the bundle from which the context comes from. It allows to retrieve a published context for a given bundle from the bundle context.

Constructors

BundleContextWrapper

public BundleContextWrapper()

The default constructor, expects the bundle context to be injected by Spring.

BundleContextWrapper

public BundleContextWrapper(BundleContext context)

Constructs this wrapper for a given bundle context.

Parameters:
  • context – the bundle context to wrap around

Methods

getBundleApplicationContext

public ApplicationContext getBundleApplicationContext()

Returns the Spring org.springframework.context.ApplicationContext created by Blueprint for the bundle the underlying bundle context comes from. The context is retrieved from the bundle context, since Blueprint publishes application contexts as OSGi services.

Returns:the context created by Blueprint for the bundle the underlying context comes from, or null if there is no context

getBundleContext

public BundleContext getBundleContext()
Returns:the underlying org.osgi.framework.BundleContext object

getCurrentBundleSymbolicName

public String getCurrentBundleSymbolicName()
Returns:the symbolic name of the bundle from which the underlying context comes from

getService

public <T> T getService(Class<T> clazz)

Retrieves an OSGi service using the underlying bundle context. Note that this will return the service from the first reference, so multiple services for one class are not supported by this method (you will get a random instance).

Parameters:
  • clazz – the class of the service to retrieve
  • <T> – the class of the service to retrieve
Returns:

an OSGi service for the class, or null if there is no such service available

setBundleContext

public void setBundleContext(BundleContext bundleContext)