org.apache.felix.dm
Class DependencyManager

java.lang.Object
  extended by org.apache.felix.dm.DependencyManager

public class DependencyManager
extends Object

The dependency manager manages all components and their dependencies. Using this API you can declare all components and their dependencies. Under normal circumstances, you get passed an instance of this class through the DependencyActivatorBase subclass you use as your BundleActivator, but it is also possible to create your own instance.

Author:
Felix Project Team

Field Summary
static String ASPECT
           
 
Constructor Summary
DependencyManager(BundleContext context)
          Creates a new dependency manager.
 
Method Summary
 void add(Component service)
          Adds a new service to the dependency manager.
 Component createAdapterService(Class serviceInterface, String serviceFilter)
          Creates a new adapter.
 Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String attributeName)
          Creates a new aspect.
 Component createBundleAdapterService(int bundleStateMask, String bundleFilter, boolean propagate)
          Creates a new bundle adapter.
 BundleDependency createBundleDependency()
          Creates a new bundle dependency.
 Component createComponent()
          Creates a new service.
 ConfigurationDependency createConfigurationDependency()
          Creates a new configuration dependency.
 Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate)
          Creates a new Managed Service Factory Configuration Adapter.
 Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate, String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData)
          Creates a new Managed Service Factory Configuration Adapter with meta type support.
 PropertyMetaData createPropertyMetaData()
          Creates a new configuration property metadata.
 Component createResourceAdapterService(String resourceFilter, boolean propagate, Object callbackInstance, String callbackChanged)
          Creates a new resource adapter.
 Component createResourceAdapterService(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackChanged)
           
 ResourceDependency createResourceDependency()
          Creates a new resource dependency.
 ServiceDependency createServiceDependency()
          Creates a new service dependency.
 TemporalServiceDependency createTemporalServiceDependency()
          Creates a new temporal service dependency.
 List getServices()
          Returns a list of services.
 void remove(Component service)
          Removes a service from the dependency manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASPECT

public static final String ASPECT
See Also:
Constant Field Values
Constructor Detail

DependencyManager

public DependencyManager(BundleContext context)
Creates a new dependency manager. You need to supply the BundleContext to be used by the dependency manager to register services and communicate with the framework.

Parameters:
context - the bundle context
Method Detail

add

public void add(Component service)
Adds a new service to the dependency manager. After the service was added it will be started immediately.

Parameters:
service - the service to add

remove

public void remove(Component service)
Removes a service from the dependency manager. Before the service is removed it is stopped first.

Parameters:
service - the service to remove

createComponent

public Component createComponent()
Creates a new service.

Returns:
the new service

createServiceDependency

public ServiceDependency createServiceDependency()
Creates a new service dependency.

Returns:
the service dependency

createTemporalServiceDependency

public TemporalServiceDependency createTemporalServiceDependency()
Creates a new temporal service dependency.

Returns:
a new temporal service dependency

createConfigurationDependency

public ConfigurationDependency createConfigurationDependency()
Creates a new configuration dependency.

Returns:
the configuration dependency

createPropertyMetaData

public PropertyMetaData createPropertyMetaData()
Creates a new configuration property metadata.

Returns:
the configuration property metadata.

createBundleDependency

public BundleDependency createBundleDependency()
Creates a new bundle dependency.

Returns:
a new BundleDependency instance.

createResourceDependency

public ResourceDependency createResourceDependency()
Creates a new resource dependency.

Returns:
the resource dependency

createAspectService

public Component createAspectService(Class serviceInterface,
                                     String serviceFilter,
                                     int ranking,
                                     String attributeName)
Creates a new aspect. The aspect will be applied to any service that matches the specified interface and filter. For each matching service an aspect will be created based on the aspect implementation class. The aspect will be registered with the same interface and properties as the original service, plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.

Usage Example

  manager.createAspectService(ExistingService.class, "(foo=bar)", 10, "m_aspect")
         .setImplementation(ExistingServiceAspect.class)
         .setServiceProperties(new Hashtable() {{ put("additional", "properties"); }});
 

Parameters:
serviceInterface - the service interface to apply the aspect to
serviceFilter - the filter condition to use with the service interface
ranking - the level used to organize the aspect chain ordering
attributeName - the aspect implementation field name where to inject original service. If null, any field matching the original service will be injected.
Returns:
a service that acts as a factory for generating aspects

createAdapterService

public Component createAdapterService(Class serviceInterface,
                                      String serviceFilter)
Creates a new adapter. The adapter will be applied to any service that matches the specified interface and filter. For each matching service an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original service plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.

Usage Example

  manager.createAdapterService(AdapteeService.class, "(foo=bar)")
         // The interface to use when registering adapter
         .setInterface(AdapterService.class, new Hashtable() {{ put("additional", "properties"); }})
         // the implementation of the adapter
         .setImplementation(AdapterImpl.class);
 

Parameters:
serviceInterface - the service interface to apply the adapter to
serviceFilter - the filter condition to use with the service interface
Returns:
a service that acts as a factory for generating adapters

createResourceAdapterService

public Component createResourceAdapterService(String resourceFilter,
                                              boolean propagate,
                                              Object callbackInstance,
                                              String callbackChanged)
Creates a new resource adapter. The adapter will be applied to any resource that matches the specified filter condition. For each matching resource an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface and existing properties from the original resource plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.

Usage Example

  manager.createResourceAdapterService("(&(path=/test)(repository=TestRepository))", true)
         // The interface to use when registering adapter
         .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
         // the implementation of the adapter
         .setImplementation(AdapterServiceImpl.class);
 

Parameters:
resourceFilter - the filter condition to use with the resource
propagate - true if properties from the resource should be propagated to the service
callbackInstance -
callbackChanged -
Returns:
a service that acts as a factory for generating resource adapters
See Also:
Resource

createResourceAdapterService

public Component createResourceAdapterService(String resourceFilter,
                                              Object propagateCallbackInstance,
                                              String propagateCallbackMethod,
                                              Object callbackInstance,
                                              String callbackChanged)

createBundleAdapterService

public Component createBundleAdapterService(int bundleStateMask,
                                            String bundleFilter,
                                            boolean propagate)
Creates a new bundle adapter. The adapter will be applied to any bundle that matches the specified bundle state mask and filter condition. For each matching bundle an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface TODO and existing properties from the original resource plus any extra properties you supply here. It will also inherit all dependencies, and if you declare the original service as a member it will be injected.

Usage Example

  manager.createBundleAdapterService(Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE, 
                                     "(Bundle-SymbolicName=org.apache.felix.dependencymanager)",
                                     true)
         // The interface to use when registering adapter
         .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
         // the implementation of the adapter
         .setImplementation(AdapterServiceImpl.class);
 

Parameters:
bundleStateMask - the bundle state mask to apply
bundleFilter - the filter to apply to the bundle manifest
propagate - true if properties from the bundle should be propagated to the service
Returns:
a service that acts as a factory for generating bundle adapters

createFactoryConfigurationAdapterService

public Component createFactoryConfigurationAdapterService(String factoryPid,
                                                          String update,
                                                          boolean propagate)
Creates a new Managed Service Factory Configuration Adapter. For each new Config Admin factory configuration matching the factoryPid, an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface, and with the specified adapter service properties. Depending on the propagate parameter, every public factory configuration properties (which don't start with ".") will be propagated along with the adapter service properties. It will also inherit all dependencies.

Usage Example

  manager.createFactoryConfigurationAdapterService("MyFactoryPid",  "update", true)
         // The interface to use when registering adapter
         .setInterface(AdapterService.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
         // the implementation of the adapter
         .setImplementation(AdapterServiceImpl.class);
 

Parameters:
factoryPid - the pid matching the factory configuration
update - the adapter method name that will be notified when the factory configuration is created/updated.
propagate - true if public factory configuration should be propagated to the adapter service properties
Returns:
a service that acts as a factory for generating the managed service factory configuration adapter

createFactoryConfigurationAdapterService

public Component createFactoryConfigurationAdapterService(String factoryPid,
                                                          String update,
                                                          boolean propagate,
                                                          String heading,
                                                          String desc,
                                                          String localization,
                                                          PropertyMetaData[] propertiesMetaData)
Creates a new Managed Service Factory Configuration Adapter with meta type support. For each new Config Admin factory configuration matching the factoryPid, an adapter will be created based on the adapter implementation class. The adapter will be registered with the specified interface, and with the specified adapter service properties. Depending on the propagate parameter, every public factory configuration properties (which don't start with ".") will be propagated along with the adapter service properties. It will also inherit all dependencies.

Usage Example

       PropertyMetaData[] propertiesMetaData = new PropertyMetaData[] {
            manager.createPropertyMetaData()
               .setCardinality(Integer.MAX_VALUE)
               .setType(String.class)
               .setHeading("English words")
               .setDescription("Declare here some valid english words")
               .setDefaults(new String[] {"hello", "world"})
               .setId("words")
       };
 
       manager.add(createFactoryConfigurationAdapterService("FactoryPid", 
                                                            "updated",
                                                            true, // propagate CM settings
                                                            "EnglishDictionary",
                                                            "English dictionary configuration properties",
                                                            null,
                                                            propertiesMetaData)
               .setImplementation(Adapter.class));
 

Parameters:
factoryPid - the pid matching the factory configuration
update - the adapter method name that will be notified when the factory configuration is created/updated.
propagate - true if public factory configuration should be propagated to the adapter service properties
heading - The label used to display the tab name (or section) where the properties are displayed. Example: "Printer Service"
desc - A human readable description of the factory PID this configuration is associated with. Example: "Configuration for the PrinterService bundle"
localization - Points to the basename of the Properties file that can localize the Meta Type informations. The default localization base name for the properties is OSGI-INF/l10n/bundle, but can be overridden by the manifest Bundle-Localization header (see core specification, in section Localization on page 68). You can specify a specific localization basename file using this parameter (e.g. "person" will match person_du_NL.properties in the root bundle directory).
propertiesMetaData - Array of MetaData regarding configuration properties
Returns:
a service that acts as a factory for generating the managed service factory configuration adapter

getServices

public List getServices()
Returns a list of services.

Returns:
a list of services


Copyright © 2011 Apache Software Foundation. All Rights Reserved.