Annotation Type BundleDependency


@Retention(CLASS) @Target(METHOD) public @interface 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 Elements
    Modifier and Type
    Optional Element
    Description
    Returns the callback method to be invoked when the bundle have been updated
    Returns the ldap filter dependency matching some bundle manifest headers
    The name used when dynamically configuring this dependency from the init method.
    boolean
    Specifies 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.
    boolean
    Returns whether the dependency is required or not.
    int
    Returns the bundle state mask
  • Element Details

    • changed

      String changed
      Returns the callback method to be invoked when the bundle have been updated
      Returns:
      the change callback
      Default:
      ""
    • removed

      String removed
      Returns the callback method to invoke when the bundle is lost.
      Returns:
      the remove callback
      Default:
      ""
    • required

      boolean required
      Returns whether the dependency is required or not.
      Returns:
      the required flag
      Default:
      true
    • filter

      String filter
      Returns the ldap filter dependency matching some bundle manifest headers
      Returns:
      the filter
      Default:
      ""
    • stateMask

      int stateMask
      Returns the bundle state mask
      Returns:
      the state mask
      Default:
      38
    • propagate

      boolean propagate
      Specifies 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 name
      The name used when dynamically configuring this dependency from the init method. Specifying this attribute allows to dynamically configure the dependency filter and required flag 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 Init annotation 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:
      ""