Annotation Type BundleDependency
Annotates a class or method for a bundle dependency. A bundle dependency allows you to
depend on a bundle in a certain set of states (INSTALLED|RESOLVED|STARTED|...), as
indicated by a state mask. You can also use a filter condition that is matched against
all manifest entries. When applied on a class field, optional unavailable dependencies
are injected with a NullObject.
Usage Examples
In the following example, the "SCR" Component allows to track all bundles containing a specific "Service-Component" OSGi header, in order to load and manage all Declarative Service components specified in the SCR xml documents referenced by the header:
@Component
public class SCR {
@BundleDependency(required = false, removed = "unloadServiceComponents", filter = "(Service-Component=*)", stateMask = Bundle.ACTIVE)
void loadServiceComponents(Bundle b) {
String descriptorPaths = (String) b.getHeaders().get("Service-Component");
// load all service component specified in the XML descriptorPaths files ...
}
void unloadServiceComponents(Bundle b) {
// unload all service component we loaded from our "loadServiceComponents" method.
}
}
- Author:
- Felix Project Team
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionReturns the callback method to be invoked when the bundle have been updatedReturns the ldap filter dependency matching some bundle manifest headersThe name used when dynamically configuring this dependency from the init method.booleanSpecifies if the manifest headers from the bundle should be propagated to the service properties.Returns the callback method to invoke when the bundle is lost.booleanReturns whether the dependency is required or not.intReturns the bundle state mask
-
Element Details
-
changed
String changedReturns the callback method to be invoked when the bundle have been updated- Returns:
- the change callback
- Default:
""
-
removed
String removedReturns the callback method to invoke when the bundle is lost.- Returns:
- the remove callback
- Default:
""
-
required
boolean requiredReturns whether the dependency is required or not.- Returns:
- the required flag
- Default:
true
-
filter
String filterReturns the ldap filter dependency matching some bundle manifest headers- Returns:
- the filter
- Default:
""
-
stateMask
int stateMaskReturns the bundle state mask- Returns:
- the state mask
- Default:
38
-
propagate
boolean propagateSpecifies if the manifest headers from the bundle should be propagated to the service properties. The provided service properties take precedence over the propagated bundle manifest headers. It means a bundle manifest header won't override a component service property having the same name.- Returns:
- the propagation flag
- Default:
false
-
name
String nameThe name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependencyfilterandrequiredflag from the Service's init method. All unnamed dependencies will be injected before the init() method; so from the init() method, you can then pick up whatever information needed from already injected (unnamed) dependencies, and configure dynamically your named dependencies, which will then be calculated once the init() method returns.See
Initannotation for an example usage of a dependency dynamically configured from the init method.- Returns:
- the dependency name used to dynamically configure the dependency from the init callback
- Default:
""
-