Apache
Home » Documentation » Apache Felix Subproject Documentation » Apache Felix Dependency Manager

Dependency Manager - Bundle Dependency

A bundle dependency allows you to depend on a bundle in a certain set of states, as indicated by a state mask. You can also use a filter condition that is matched against all manifest entries. Finally you can provide a reference to an existing bundle.

@BundleDependency

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.

Attributes:

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.
    }
}
Rev. 1665812 by marrs on Wed, 11 Mar 2015 09:02:04 +0000
Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.