Dependency Manager - Bundle Adapter

Bundle adapters are similar to AdapterService, but instead of adapting a service, they adapt a bundle with a certain set of states (STARTED|INSTALLED|…​), and provide a service on top of it.

The bundle adapter will be applied to any bundle that matches the specified bundle state mask and filter conditions, which may match some of the bundle OSGi manifest headers. For each matching bundle an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and with service properties found from the original bundle OSGi manifest headers plus any extra properties you supply here. If you declare the original bundle as a member it will be injected.

To define a bundle adapter component, you need to create a BundleComponent component using the DependencyActivatorBase.createBundleComponent() or the DependencyManager.createBundleComponent() method.

This interface extends the Component interface in order to add extra setters methods needed to define a bundle adapter service component.

Example usage

In the following example, a "VideoPlayer" Service is registered into the OSGi registry each time an active bundle containing a "Video-Path" manifest header is detected:

 public class Activator extends DependencyManagerActivator {
     public void init(BundleContext ctx, DependencyManager dm) throws Exception {
         Component c = dm.createBundleComponent()
             .setBundleFilter(Bundle.ACTIVE, "(Video-Path=*)")
             .setInterface(VideoPlayer.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
             .setImplementation(VideoPlayerImpl.class);
         dm.add(c);
     }
 }