public interface BundleAdapterBuilder extends ComponentBuilder<BundleAdapterBuilder>
The adapter created by this builder will be applied to any bundle that matches the specified bundle state mask and filter condition. For each matching bundle an adapter service will be created based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original bundle plus any extra properties you supply here. The bundle is injected by reflection in adapter class fields having a Bundle type, or using a callback method that you can specify. You can specify reflection based (using method names), or java8 method references for callbacks.
Example which creates a BundleAdapter service for each started bundle (the bundle is added by reflection on a class field that has a "Bundle" type):
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
bundleAdapter(adapt -> adapt
.impl(BundleAdapterImpl.class)
.provides(BundleAdapter.class)
.mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE));
}
}
Example that creates a BundleAdapter service for each started bundle (the bundle is added using a method reference):
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
bundleAdapter(adapt -> adapt
.impl(BundleAdapterImpl.class)
.provides(BundleAdapter.class)
.mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE)
.add(BundleAdapterImpl::setBundle));
}
}
Example that creates a BundleAdapter service for each started bundle (the bundle is added using a method name):
public class Activator extends DependencyManagerActivator {
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
bundleAdapter(adapt -> adapt
.impl(BundleAdapterImpl.class)
.provides(BundleAdapter.class)
.mask(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE)
.add("setBundle"));
}
}
Modifier and Type | Method and Description |
---|---|
<T> BundleAdapterBuilder |
add(CbBundle<T> add)
Sets a reference to a callback method invoked on one of the component implementation classes.
|
<T> BundleAdapterBuilder |
add(CbBundleComponent<T> add)
Sets a reference to a callback method invoked on one of the component implementation classes.
|
BundleAdapterBuilder |
add(InstanceCbBundle add)
Sets a reference to a callback method invoked on a given Object instance.
|
BundleAdapterBuilder |
add(InstanceCbBundleComponent add)
Sets a reference to a callback method invoked on a given Object instance.
|
BundleAdapterBuilder |
add(java.lang.String callback)
Sets a "add" callback name invoked on the component implementation instance(s).
|
BundleAdapterBuilder |
callbackInstance(java.lang.Object callbackInstance)
Sets a callback instance to use when invoking reflection based callbacks.
|
<T> BundleAdapterBuilder |
change(CbBundle<T> change)
Sets a reference to a callback method invoked on one of the component implementation classes.
|
<T> BundleAdapterBuilder |
change(CbBundleComponent<T> change)
Sets a reference to a callback method invoked on one of the component implementation classes.
|
BundleAdapterBuilder |
change(InstanceCbBundle change)
Sets a reference to a callback method invoked on a given Object instance.
|
BundleAdapterBuilder |
change(InstanceCbBundleComponent change)
Sets a reference to a callback method invoked on a given Object instance.
|
BundleAdapterBuilder |
change(java.lang.String callback)
Sets a "change" callback name invoked on the component implementation instance(s).
|
BundleAdapterBuilder |
filter(java.lang.String filter)
Sets the filter condition to depend on.
|
BundleAdapterBuilder |
mask(int mask)
Sets the bundle state mask to depend on.
|
BundleAdapterBuilder |
propagate()
Enables property propagation.
|
BundleAdapterBuilder |
propagate(boolean propagate)
Sets property propagation.
|
<T> BundleAdapterBuilder |
remove(CbBundle<T> remove)
Sets a reference to a callback method invoked on one of the component implementation classes.
|
<T> BundleAdapterBuilder |
remove(CbBundleComponent<T> remove)
Sets a reference to a callback method invoked on one of the component implementation classes.
|
BundleAdapterBuilder |
remove(InstanceCbBundle remove)
Sets a reference to a callback method invoked on a given Object instance.
|
BundleAdapterBuilder |
remove(InstanceCbBundleComponent remove)
Sets a reference to a callback method invoked on a given Object instance.
|
BundleAdapterBuilder |
remove(java.lang.String callback)
Sets a "remove" callback name invoked on the component implementation instance(s).
|
autoAdd, autoConfig, autoConfig, build, composition, composition, composition, debug, destroy, destroy, destroy, destroy, factory, factory, factory, factory, factory, impl, init, init, init, init, listener, properties, properties, properties, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, provides, scope, start, start, start, start, stop, stop, stop, stop, withBundle, withCnf, withCnf, withCnf, withDep, withFuture, withSvc, withSvc, withSvc, withSvc, withSvc, withSvc
BundleAdapterBuilder mask(int mask)
mask
- the mask to useBundleAdapterBuilder filter(java.lang.String filter)
filter
- the filter conditionBundleAdapterBuilder propagate(boolean propagate)
true
any bundle manifest properties will be added
to the service properties of the component that has this dependency (if it registers as a service).propagate
- true
to propagate the bundle manifest propertiesBundleAdapterBuilder propagate()
BundleAdapterBuilder add(java.lang.String callback)
callback
- the method to call when a bundle was added
The following method signature are supported:
callback(Bundle b)
callback(Component c, Bundle b)
callback
- the callback nameBundleAdapterBuilder change(java.lang.String callback)
callback
- the method to call when a bundle was changed
The following method signature are supported:
callback(Bundle b)
callback(Component c, Bundle b)
callback
- the callback nameBundleAdapterBuilder remove(java.lang.String callback)
callback
- the method to call when a bundle was removed
The following method signature are supported:
callback(Bundle b)
callback(Component c, Bundle b)
callback
- the callback nameBundleAdapterBuilder callbackInstance(java.lang.Object callbackInstance)
callbackInstance
- the instance to call the reflection based callbacks onadd(String)
,
change(String)
,
remove(String)
<T> BundleAdapterBuilder add(CbBundle<T> add)
T
- the type of the component implementation class on which the callback is invoked.add
- the method reference invoked when a bundle is added.<T> BundleAdapterBuilder change(CbBundle<T> change)
T
- the type of the component implementation class on which the callback is invoked.change
- the method reference invoked when a bundle has changed.<T> BundleAdapterBuilder remove(CbBundle<T> remove)
T
- the type of the component implementation class on which the callback is invoked.remove
- the method reference invoked when a bundle is removed.<T> BundleAdapterBuilder add(CbBundleComponent<T> add)
T
- the type of the component implementation class on which the callback is invoked.add
- the method reference invoked when a bundle is added.<T> BundleAdapterBuilder change(CbBundleComponent<T> change)
T
- the type of the component implementation class on which the callback is invoked.change
- the method reference invoked when a bundle has changed.<T> BundleAdapterBuilder remove(CbBundleComponent<T> remove)
T
- the type of the component implementation class on which the callback is invoked.remove
- the method reference invoked when a bundle is removed.BundleAdapterBuilder add(InstanceCbBundle add)
add
- the method reference invoked when a bundle is added.BundleAdapterBuilder change(InstanceCbBundle change)
change
- the method reference invoked when a bundle has changed.BundleAdapterBuilder remove(InstanceCbBundle remove)
remove
- the method reference invoked when a bundle is removed.BundleAdapterBuilder add(InstanceCbBundleComponent add)
add
- the method reference invoked when a bundle is added.BundleAdapterBuilder change(InstanceCbBundleComponent change)
change
- the method reference invoked when a bundle has changed.BundleAdapterBuilder remove(InstanceCbBundleComponent remove)
remove
- the method reference invoked when a bundle is removed.