org.apache.felix.scr.impl.manager
Class AbstractComponentManager

java.lang.Object
  extended by org.apache.felix.scr.impl.manager.AbstractComponentManager
All Implemented Interfaces:
Component
Direct Known Subclasses:
ComponentFactoryImpl, ImmediateComponentManager

public abstract class AbstractComponentManager
extends Object
implements Component

The default ComponentManager. Objects of this class are responsible for managing implementation object's lifecycle.


Nested Class Summary
protected static class AbstractComponentManager.Activating
           
protected static class AbstractComponentManager.Active
          The Active state is the satisified state of an immediate component after activation.
protected static class AbstractComponentManager.Deactivating
           
protected static class AbstractComponentManager.Disabled
           
protected static class AbstractComponentManager.Disabling
           
protected static class AbstractComponentManager.Disposed
           
protected static class AbstractComponentManager.Disposing
           
protected static class AbstractComponentManager.Enabling
           
protected static class AbstractComponentManager.Factory
          The Factory state is the satisfied state of component factory components.
protected static class AbstractComponentManager.FactoryInstance
          The FactoryInstance state is the satisfied state of instances of component factory components created with the ComponentFactory.newInstance method.
protected static class AbstractComponentManager.Registered
          The Registered state is the statisfied state of a delayed or service factory component before the actual service instance is (first) retrieved.
protected static class AbstractComponentManager.Satisfied
           
protected static class AbstractComponentManager.State
          There are 12 states in all.
protected static class AbstractComponentManager.Unsatisfied
           
 
Field Summary
 
Fields inherited from interface org.apache.felix.scr.Component
STATE_ACTIVATING, STATE_ACTIVE, STATE_DEACTIVATING, STATE_DESTROYED, STATE_DISABLED, STATE_DISABLING, STATE_DISPOSED, STATE_DISPOSING, STATE_ENABLED, STATE_ENABLING, STATE_FACTORY, STATE_REGISTERED, STATE_UNSATISFIED
 
Constructor Summary
protected AbstractComponentManager(BundleComponentActivator activator, ComponentMetadata metadata)
          The constructor receives both the activator and the metadata
 
Method Summary
protected static Dictionary copyTo(Dictionary target, Dictionary source)
          Copies the properties from the source Dictionary into the target Dictionary.
protected static Dictionary copyTo(Dictionary target, Dictionary source, boolean allProps)
          Copies the properties from the source Dictionary into the target Dictionary except for private properties (whose name has a leading dot) which are only copied if the allProps parameter is true.
protected abstract  boolean createComponent()
          Method is called by #activate() in STATE_ACTIVATING or by DelayedComponentManager.getService(Bundle, ServiceRegistration) in STATE_REGISTERED.
protected abstract  void deleteComponent(int reason)
           
 void disable()
          Disables this component and - if active - first deactivates it.
 void dispose(int reason)
          Disposes off this component deactivating and disabling it first as required.
 void enable()
          Enables this component and - if satisfied - also activates it.
 String getActivate()
          Returns the name of the method to be called when the component is being activated.
 BundleComponentActivator getActivator()
           
 Bundle getBundle()
          Returns the Bundle providing this component.
 String getClassName()
          Returns the class name of the Component implementation.
 ComponentMetadata getComponentMetadata()
           
 String getConfigurationPolicy()
          Reuturns the configuration policy declared in the component descriptor.
 String getDeactivate()
          Returns the name of the method to be called when the component is being deactivated.
 String getFactory()
          Returns the component factory name or null if this component is not defined as a component factory.
 long getId()
          Returns the component ID of this component.
 String getModified()
          Returns the name of the method to be called when the component configuration has been updated or null if such a method is not declared in the component descriptor.
 String getName()
          Returns the name of the component, which is also used as the service PID.
abstract  Dictionary getProperties()
          Returns the properties of the Component.
 Reference[] getReferences()
          Returns an array of Reference instances representing the service references (or dependencies) of this Component.
protected abstract  Object getService()
          Returns the service object to be registered if the service element is specified.
 Dictionary getServiceProperties()
          Returns the subset of component properties to be used as service properties.
 String[] getServices()
          Returns an array of service names provided by this Component or null if the Component is not registered as a service.
 int getState()
          Returns the current state of the Component, which is one of the STATE_* constants defined in this interface.
abstract  boolean hasConfiguration()
           
 boolean isActivateDeclared()
          Returns true if the name of the method to be called on component activation (see Component.getActivate() is declared in the component descriptor or not.
 boolean isDeactivateDeclared()
          Returns true if the name of the method to be called on component deactivation (see Component.getDeactivate() is declared in the component descriptor or not.
 boolean isDefaultEnabled()
          Returns whether the Component is declared to be enabled initially.
 boolean isImmediate()
          Returns whether the Component is an Immediate or a Delayed Component.
 boolean isLogEnabled(int level)
          Returns true if logging for the given level is enabled.
 boolean isServiceFactory()
          Returns true if this component is a service factory.
 void log(int level, String message, Object[] arguments, Throwable ex)
           
 void log(int level, String message, Throwable ex)
           
protected  void registerComponentService()
           
protected  ServiceRegistration registerService()
           
protected  AbstractComponentManager.State state()
           
 String toString()
           
protected  void unregisterComponentService()
           
protected  boolean verifyDependencyManagers(Dictionary properties)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.felix.scr.Component
getComponentInstance
 

Constructor Detail

AbstractComponentManager

protected AbstractComponentManager(BundleComponentActivator activator,
                                   ComponentMetadata metadata)
The constructor receives both the activator and the metadata

Parameters:
activator -
metadata -
Method Detail

enable

public final void enable()
Enables this component and - if satisfied - also activates it. If enabling the component fails for any reason, the component ends up disabled.

This method ignores the enabled flag of the component metadata and just enables as requested.

This method enables and activates the component immediately.

Specified by:
enable in interface Component

disable

public final void disable()
Disables this component and - if active - first deactivates it. The component may be reenabled by calling the enable() method.

This method deactivates and disables the component immediately.

Specified by:
disable in interface Component

dispose

public void dispose(int reason)
Disposes off this component deactivating and disabling it first as required. After disposing off the component, it may not be used anymore.

This method unlike the other state change methods immediately takes action and disposes the component. The reason for this is, that this method has to actually complete before other actions like bundle stopping may continue.


getId

public long getId()
Description copied from interface: Component
Returns the component ID of this component. This ID is managed by the SCR. If the component is not currently enabled the ID might not be assigned to the component (yet) and this method will return -1 in this case.

Specified by:
getId in interface Component

getName

public String getName()
Description copied from interface: Component
Returns the name of the component, which is also used as the service PID. This method provides access to the name attribute of the component element.

Specified by:
getName in interface Component

getBundle

public Bundle getBundle()
Returns the Bundle providing this component. If the component as already been disposed off, this method returns null.

Specified by:
getBundle in interface Component

getClassName

public String getClassName()
Description copied from interface: Component
Returns the class name of the Component implementation. This method provides access to the class attribute of the implementation element.

Specified by:
getClassName in interface Component

getFactory

public String getFactory()
Description copied from interface: Component
Returns the component factory name or null if this component is not defined as a component factory. This method provides access to the factory attribute of the component element.

Specified by:
getFactory in interface Component

getReferences

public Reference[] getReferences()
Description copied from interface: Component
Returns an array of Reference instances representing the service references (or dependencies) of this Component. If the Component has no references, null is returned.

Specified by:
getReferences in interface Component

isImmediate

public boolean isImmediate()
Description copied from interface: Component
Returns whether the Component is an Immediate or a Delayed Component. This method provides access to the immediate attribute of the component element.

Specified by:
isImmediate in interface Component

isDefaultEnabled

public boolean isDefaultEnabled()
Description copied from interface: Component
Returns whether the Component is declared to be enabled initially. This method provides access to the enabled attribute of the component element.

Specified by:
isDefaultEnabled in interface Component

getActivate

public String getActivate()
Description copied from interface: Component
Returns the name of the method to be called when the component is being activated.

This method never returns null, that is, if this method is not declared in the component descriptor this method returns the default value activate.

Specified by:
getActivate in interface Component

isActivateDeclared

public boolean isActivateDeclared()
Description copied from interface: Component
Returns true if the name of the method to be called on component activation (see Component.getActivate() is declared in the component descriptor or not.

For a component declared in a Declarative Services 1.0 descriptor, this method always returns false.

Specified by:
isActivateDeclared in interface Component

getDeactivate

public String getDeactivate()
Description copied from interface: Component
Returns the name of the method to be called when the component is being deactivated.

This method never returns null, that is, if this method is not declared in the component descriptor this method returns the default value deactivate.

Specified by:
getDeactivate in interface Component

isDeactivateDeclared

public boolean isDeactivateDeclared()
Description copied from interface: Component
Returns true if the name of the method to be called on component deactivation (see Component.getDeactivate() is declared in the component descriptor or not.

For a component declared in a Declarative Services 1.0 descriptor, this method always returns false.

Specified by:
isDeactivateDeclared in interface Component

getModified

public String getModified()
Description copied from interface: Component
Returns the name of the method to be called when the component configuration has been updated or null if such a method is not declared in the component descriptor.

For a component declared in a Declarative Services 1.0 descriptor, this method always returns null.

Specified by:
getModified in interface Component

getConfigurationPolicy

public String getConfigurationPolicy()
Description copied from interface: Component
Reuturns the configuration policy declared in the component descriptor. If the component descriptor is a Declarative Services 1.0 descriptor or not configuration poliy has been declared, the default value optional is returned.

The returned string is one of the three policies defined in the Declarative Services specification 1.1:

optional
Configuration from the Configuration Admin service is supplied to the component if available. Otherwise the component is activated without Configuration Admin configuration. This is the default value reflecting the behaviour of Declarative Services 1.0
require
Configuration is required. The component remains unsatisfied until configuartion is available from the Configuration Admin service.
ignore
Configuration is ignored. No Configuration Admin service configuration is supplied to the component.

Specified by:
getConfigurationPolicy in interface Component

isServiceFactory

public boolean isServiceFactory()
Description copied from interface: Component
Returns true if this component is a service factory. This method returns the value of the serviceFactory attribute of the service element. If the component has no service element, this method returns false.

Specified by:
isServiceFactory in interface Component

getServices

public String[] getServices()
Description copied from interface: Component
Returns an array of service names provided by this Component or null if the Component is not registered as a service. This method provides access to the interface attributes of the provide elements.

Specified by:
getServices in interface Component

createComponent

protected abstract boolean createComponent()
Method is called by #activate() in STATE_ACTIVATING or by DelayedComponentManager.getService(Bundle, ServiceRegistration) in STATE_REGISTERED.

Returns:
true if creation of the component succeeded. If false is returned, the cause should have been logged.

deleteComponent

protected abstract void deleteComponent(int reason)

getService

protected abstract Object getService()
Returns the service object to be registered if the service element is specified.

Extensions of this class may overwrite this method to return a ServiceFactory to register in the case of a delayed or a service factory component.

Returns:

registerService

protected ServiceRegistration registerService()

registerComponentService

protected void registerComponentService()

unregisterComponentService

protected final void unregisterComponentService()

getActivator

public BundleComponentActivator getActivator()

isLogEnabled

public boolean isLogEnabled(int level)
Returns true if logging for the given level is enabled.


log

public void log(int level,
                String message,
                Throwable ex)

log

public void log(int level,
                String message,
                Object[] arguments,
                Throwable ex)

toString

public String toString()
Overrides:
toString in class Object

verifyDependencyManagers

protected boolean verifyDependencyManagers(Dictionary properties)

hasConfiguration

public abstract boolean hasConfiguration()

getProperties

public abstract Dictionary getProperties()
Description copied from interface: Component
Returns the properties of the Component. The Dictionary returned is a private copy of the actual properties and contains the same entries as are used to register the Component as a service and are returned by the ComponentContext.getProperties() method.

Specified by:
getProperties in interface Component

getServiceProperties

public Dictionary getServiceProperties()
Returns the subset of component properties to be used as service properties. These properties are all component properties where property name does not start with dot (.), properties which are considered private.


copyTo

protected static Dictionary copyTo(Dictionary target,
                                   Dictionary source)
Copies the properties from the source Dictionary into the target Dictionary.

Parameters:
target - The Dictionary into which to copy the properties. If null a new Hashtable is created.
source - The Dictionary providing the properties to copy. If null or empty, nothing is copied.
Returns:
The target is returned, which may be empty if source is null or empty and target was null.

copyTo

protected static Dictionary copyTo(Dictionary target,
                                   Dictionary source,
                                   boolean allProps)
Copies the properties from the source Dictionary into the target Dictionary except for private properties (whose name has a leading dot) which are only copied if the allProps parameter is true.

Parameters:
target - The Dictionary into which to copy the properties. If null a new Hashtable is created.
source - The Dictionary providing the properties to copy. If null or empty, nothing is copied.
allProps - Whether all properties (true) or only the public properties (false) are to be copied.
Returns:
The target is returned, which may be empty if source is null or empty and target was null or all properties are private and had not to be copied

getComponentMetadata

public ComponentMetadata getComponentMetadata()

getState

public int getState()
Description copied from interface: Component
Returns the current state of the Component, which is one of the STATE_* constants defined in this interface.

Specified by:
getState in interface Component

state

protected AbstractComponentManager.State state()


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