public interface BundleComponent extends Component<BundleComponent>
AdapterComponent
, are used to "extend"
existing bundles, and can publish an adapter services based on the existing bundle.
An example would be implementing a video player which adapters a resource bundle having
some specific headers.
When you create a bundle adapter component, it will be applied to any bundle that matches the specified bundle state mask as well as the specified ldap filter used to match the bundle manifest headers. The bundle adapter will be registered with the specified bundle manifest headers as service properties, plus any extra properties you suppl. If you declare a bundle field in your bundle adapter class, it will be injected it will be injected with the original bundle.
public class Activator extends DependencyActivatorBase { &Override public void init(BundleContext context, DependencyManager dm) throws Exception { Component bundleComponent = createBundleComponent() .setFilter(Bundle.ACTIVE, "(Video-Path=*)") .setInterface(VideoPlayer.class.getName(), null) .setImplementation(VideoPlayerImpl.class); dm.add(bundleComponent); } } public interface VideoPlayer { void play(); } public class VideoPlayerImpl implements VideoPlayer { volatile Bundle bundle; // injected String path; void start() { path = bundle.getHeaders().get("Video-Path"); } void play() { ... } }
When you use callbacks to get injected with the bundle, the "add", "change", "remove" callbacks support the following method signatures:
(Bundle)
(Object)
(COmponent, Bundle)
Component.ServiceScope
Modifier and Type | Method and Description |
---|---|
BundleComponent |
setBundleCallbackInstance(java.lang.Object callbackInstance)
Sets the instance to invoke the callbacks on (null by default, meaning the callbacks have to be invoked on the adapter itself)
|
BundleComponent |
setBundleCallbacks(java.lang.String add,
java.lang.String change,
java.lang.String remove)
Sets the callbacks to invoke when injecting the bundle into the adapter component.
|
BundleComponent |
setBundleFilter(int bundleStateMask,
java.lang.String bundleFilter)
Sets the bundle state mask and bundle manifest headers filter.
|
BundleComponent |
setPropagate(boolean propagate)
Sets if the bundle manifest headers should be propagated to the bundle component adapter service consumer (true by default).
|
add, add, getServiceRegistration, remove, remove, setAutoConfig, setAutoConfig, setCallbacks, setCallbacks, setComposition, setComposition, setDebug, setFactory, setFactory, setImplementation, setInterface, setInterface, setInterface, setInterface, setScope, setServiceProperties
getComponentDeclaration, getDependencyManager, getInstance, getInstances, getServiceProperties
BundleComponent setBundleFilter(int bundleStateMask, java.lang.String bundleFilter)
bundleStateMask
- the bundle state mask to applybundleFilter
- the filter to apply to the bundle manifestBundleComponent setBundleCallbacks(java.lang.String add, java.lang.String change, java.lang.String remove)
add
- name of the callback method to invoke on addchange
- name of the callback method to invoke on changeremove
- name of the callback method to invoke on removeBundleComponent setBundleCallbackInstance(java.lang.Object callbackInstance)
callbackInstance
- the instance to invoke the callbacks on (null by default, meaning the callbacks have to be invoked on the adapter itself)BundleComponent setPropagate(boolean propagate)
propagate
- true if the bundle manifest headers should be propagated to the adapter service consumers