org.apache.felix.dm.annotation.api
Annotation Type BundleDependency


@Retention(value=CLASS)
@Target(value=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.
     }
 }
 


Optional Element Summary
 String changed
          Returns the callback method to be invoked when the service have changed.
 String filter
          Returns the filter dependency
 String name
          The name used when dynamically configuring this dependency from the init method.
 boolean propagate
          Specifies if the manifest headers from the bundle should be propagated to the service properties.
 String removed
          Returns the callback method to invoke when the service is lost.
 boolean required
          Returns whether the dependency is required or not.
 int stateMask
          Returns the bundle state mask
 

changed

public abstract String changed
Returns the callback method to be invoked when the service have changed.

Default:
""

removed

public abstract String removed
Returns the callback method to invoke when the service is lost.

Default:
""

required

public abstract boolean required
Returns whether the dependency is required or not.

Default:
true

filter

public abstract String filter
Returns the filter dependency

Default:
""

stateMask

public abstract int stateMask
Returns the bundle state mask

Default:
38

propagate

public abstract boolean propagate
Specifies if the manifest headers from the bundle should be propagated to the service properties.

Default:
false

name

public abstract 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.

Default:
""


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.