org.apache.felix.dm
Class DependencyActivatorBase

java.lang.Object
  extended by org.apache.felix.dm.DependencyActivatorBase
All Implemented Interfaces:
BundleActivator
Direct Known Subclasses:
Activator, Activator, Activator, Activator, Activator, Activator, Activator

public abstract class DependencyActivatorBase
extends Object
implements BundleActivator

Base bundle activator class. Subclass this activator if you want to use dependency management in your bundle. There are two methods you should implement: init() and destroy(). Both methods take two arguments, the bundle context and the dependency manager. The dependency manager can be used to define all the dependencies.

Author:
Felix Project Team

Constructor Summary
DependencyActivatorBase()
           
 
Method Summary
 Component createAdapterService(Class serviceInterface, String serviceFilter)
          Creates a new adapter service.
 Component createAspectService(Class serviceInterface, String serviceFilter, int ranking, String attributeName)
          Creates a new aspect service.
 Component createBundleAdapterService(int bundleStateMask, String bundleFilter, boolean propagate)
          Creates a new bundle adapter service.
 BundleDependency createBundleDependency()
          Creates a new bundle dependency.
 Component createComponent()
          Creates a new component.
 ConfigurationDependency createConfigurationDependency()
          Creates a new configuration dependency.
 Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate)
          Creates a new factory configuration adapter service.
 Component createFactoryConfigurationAdapterService(String factoryPid, String update, boolean propagate, String heading, String desc, String localization, PropertyMetaData[] propertiesMetaData)
          Creates a new factory configuration adapter service.
 PropertyMetaData createPropertyMetaData()
          Creates a new configuration property metadata.
 Component createResourceAdapter(String resourceFilter, boolean propagate, Object callbackInstance, String callbackChanged)
          Creates a new resource adapter service.
 Component createResourceAdapter(String resourceFilter, Object propagateCallbackInstance, String propagateCallbackMethod, Object callbackInstance, String callbackChanged)
          Creates a new resource adapter service.
 ResourceDependency createResourceDependency()
          Creates a new resource dependency.
 ServiceDependency createServiceDependency()
          Creates a new service dependency.
 TemporalServiceDependency createTemporalServiceDependency()
          Creates a new temporal service dependency.
abstract  void destroy(BundleContext context, DependencyManager manager)
          Destroy the dependency manager.
 BundleContext getBundleContext()
          Returns the bundle context that is associated with this bundle.
 DependencyManager getDependencyManager()
          Returns the dependency manager that is associated with this bundle.
 Logger getLogger()
          Returns the logger that is associated with this bundle.
abstract  void init(BundleContext context, DependencyManager manager)
          Initialize the dependency manager.
 void start(BundleContext context)
          Start method of the bundle activator.
 void stop(BundleContext context)
          Stop method of the bundle activator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DependencyActivatorBase

public DependencyActivatorBase()
Method Detail

init

public abstract void init(BundleContext context,
                          DependencyManager manager)
                   throws Exception
Initialize the dependency manager. Here you can add all components and their dependencies. If something goes wrong and you do not want your bundle to be started, you can throw an exception. This exception will be passed on to the start() method of the bundle activator, causing the bundle not to start.

Parameters:
context - the bundle context
manager - the dependency manager
Throws:
Exception - if the initialization fails

destroy

public abstract void destroy(BundleContext context,
                             DependencyManager manager)
                      throws Exception
Destroy the dependency manager. Here you can remove all components and their dependencies. Actually, the base class will clean up your dependencies anyway, so most of the time you don't need to do anything here.

If something goes wrong and you do not want your bundle to be stopped, you can throw an exception. This exception will be passed on to the stop() method of the bundle activator, causing the bundle not to stop.

Parameters:
context - the bundle context
manager - the dependency manager
Throws:
Exception - if the destruction fails

start

public void start(BundleContext context)
           throws Exception
Start method of the bundle activator. Initializes the dependency manager and calls init().

Specified by:
start in interface BundleActivator
Parameters:
context - the bundle context
Throws:
Exception - If this method throws an exception, this bundle is marked as stopped and the Framework will remove this bundle's listeners, unregister all services registered by this bundle, and release all services used by this bundle.

stop

public void stop(BundleContext context)
          throws Exception
Stop method of the bundle activator. Calls the destroy() method and cleans up all left over dependencies.

Specified by:
stop in interface BundleActivator
Parameters:
context - the bundle context
Throws:
Exception - If this method throws an exception, the bundle is still marked as stopped, and the Framework will remove the bundle's listeners, unregister all services registered by the bundle, and release all services used by the bundle.

getBundleContext

public BundleContext getBundleContext()
Returns the bundle context that is associated with this bundle.

Returns:
the bundle context

getDependencyManager

public DependencyManager getDependencyManager()
Returns the dependency manager that is associated with this bundle.

Returns:
the dependency manager

getLogger

public Logger getLogger()
Returns the logger that is associated with this bundle. A logger instance is a proxy that will log to a real OSGi logservice if available and standard out if not.

Returns:
the logger

createComponent

public Component createComponent()
Creates a new component.

Returns:
the new component

createServiceDependency

public ServiceDependency createServiceDependency()
Creates a new service dependency.

Returns:
the service dependency

createTemporalServiceDependency

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

Parameters:
timeout - the max number of milliseconds to wait for a service availability.
Returns:
the 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:
the bundle dependency

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 service.

Returns:
the aspect service

createAdapterService

public Component createAdapterService(Class serviceInterface,
                                      String serviceFilter)
Creates a new adapter service.

Returns:
the adapter service

createResourceAdapter

public Component createResourceAdapter(String resourceFilter,
                                       boolean propagate,
                                       Object callbackInstance,
                                       String callbackChanged)
Creates a new resource adapter service.

Returns:
the resource adapter service

createResourceAdapter

public Component createResourceAdapter(String resourceFilter,
                                       Object propagateCallbackInstance,
                                       String propagateCallbackMethod,
                                       Object callbackInstance,
                                       String callbackChanged)
Creates a new resource adapter service.

Returns:
the resource adapter service

createBundleAdapterService

public Component createBundleAdapterService(int bundleStateMask,
                                            String bundleFilter,
                                            boolean propagate)
Creates a new bundle adapter service.

Returns:
the bundle adapter service

createFactoryConfigurationAdapterService

public Component createFactoryConfigurationAdapterService(String factoryPid,
                                                          String update,
                                                          boolean propagate)
Creates a new factory configuration adapter service.

Returns:
the factory configuration adapter service

createFactoryConfigurationAdapterService

public Component createFactoryConfigurationAdapterService(String factoryPid,
                                                          String update,
                                                          boolean propagate,
                                                          String heading,
                                                          String desc,
                                                          String localization,
                                                          PropertyMetaData[] propertiesMetaData)
Creates a new factory configuration adapter service.

Returns:
the factory configuration adapter service


Copyright © 2011 Apache Software Foundation. All Rights Reserved.