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

java.lang.Object
  extended by org.apache.felix.scr.impl.manager.AbstractComponentManager
      extended by org.apache.felix.scr.impl.manager.ComponentFactoryImpl
All Implemented Interfaces:
Component, ComponentHolder, ComponentFactory

public class ComponentFactoryImpl
extends AbstractComponentManager
implements ComponentFactory, ComponentHolder

The ComponentFactoryImpl extends the AbstractComponentManager class to implement the component factory functionality. As such the OSGi Declarative Services ComponentFactory interface is implemented.

In addition the ComponentHolder interface is implemented to use this class directly as the holder for component instances created by the newInstance(Dictionary) method.

Finally, if the ds.factory.enabled bundle context property is set to true, component instances can be created by factory configurations. This functionality is present for backwards compatibility with earlier releases of the Apache Felix Declarative Services implementation. But keep in mind, that this is non-standard behaviour.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.felix.scr.impl.manager.AbstractComponentManager
AbstractComponentManager.Activating, AbstractComponentManager.Active, AbstractComponentManager.Deactivating, AbstractComponentManager.Disabled, AbstractComponentManager.Disabling, AbstractComponentManager.Disposed, AbstractComponentManager.Disposing, AbstractComponentManager.Enabling, AbstractComponentManager.Factory, AbstractComponentManager.FactoryInstance, AbstractComponentManager.Registered, AbstractComponentManager.Satisfied, AbstractComponentManager.State, 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
ComponentFactoryImpl(BundleComponentActivator activator, ComponentMetadata metadata)
           
 
Method Summary
 void configurationDeleted(String pid)
          The configuration with the given PID has been deleted from the Configuration Admin service.
 void configurationUpdated(String pid, Dictionary configuration)
          Configure a component with configuration from the given PID.
protected  boolean createComponent()
          The component factory does not have a component to create.
protected  void deleteComponent(int reason)
          The component factory does not have a component to delete.
 void disableComponents()
          A component factory component holder disables the held components by disabling itself.
 void disposeComponents(int reason)
          Disposes off all components ever created by this component holder.
 void disposed(ImmediateComponentManager component)
          Informs the holder that the component has been disposed as a result of calling the dispose method.
 void enableComponents()
          A component factory component holder enables the held components by enabling itself.
 ComponentInstance getComponentInstance()
          Returns the org.osgi.service.component.ComponentInstance representing this component or null if this component is not been activated yet.
 Component[] getComponents()
          Returns all Component instances held by this holder.
 Object getInstance()
          Get the object that is implementing this descriptor
 Dictionary getProperties()
          Returns the properties of the Component.
protected  Object getService()
          Returns the service object to be registered if the service element is specified.
 boolean hasConfiguration()
           
 ComponentInstance newInstance(Dictionary dictionary)
          Create and activate a new component configuration.
protected  ServiceRegistration registerService()
           
 
Methods inherited from class org.apache.felix.scr.impl.manager.AbstractComponentManager
copyTo, copyTo, disable, dispose, enable, getActivate, getActivator, getBundle, getClassName, getComponentMetadata, getConfigurationPolicy, getDeactivate, getFactory, getId, getModified, getName, getReferences, getServiceProperties, getServices, getState, isActivateDeclared, isDeactivateDeclared, isDefaultEnabled, isImmediate, isLogEnabled, isServiceFactory, log, log, registerComponentService, state, toString, unregisterComponentService, verifyDependencyManagers
 
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.impl.config.ComponentHolder
getActivator, getComponentMetadata
 

Constructor Detail

ComponentFactoryImpl

public ComponentFactoryImpl(BundleComponentActivator activator,
                            ComponentMetadata metadata)
Method Detail

newInstance

public ComponentInstance newInstance(Dictionary dictionary)
Description copied from interface: ComponentFactory
Create and activate a new component configuration. Additional properties may be provided for the component configuration.

Specified by:
newInstance in interface ComponentFactory
Parameters:
dictionary - Additional properties for the component configuration or null if there are no additional properties.
Returns:
A ComponentInstance object encapsulating the component instance of the component configuration. The component configuration has been activated and, if the component specifies a service element, the component instance has been registered as a service.

createComponent

protected boolean createComponent()
The component factory does not have a component to create.

But in the backwards compatible case any instances created for factory configuration instances are to enabled as a consequence of activating the component factory.

Specified by:
createComponent in class AbstractComponentManager
Returns:
true if creation of the component succeeded. If false is returned, the cause should have been logged.

deleteComponent

protected void deleteComponent(int reason)
The component factory does not have a component to delete.

But in the backwards compatible case any instances created for factory configuration instances are to disabled as a consequence of deactivating the component factory.

Specified by:
deleteComponent in class AbstractComponentManager

registerService

protected ServiceRegistration registerService()
Overrides:
registerService in class AbstractComponentManager

getInstance

public Object getInstance()
Description copied from class: AbstractComponentManager
Get the object that is implementing this descriptor

Returns:
the object that implements the services

hasConfiguration

public boolean hasConfiguration()
Specified by:
hasConfiguration in class AbstractComponentManager

getProperties

public 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
Specified by:
getProperties in class AbstractComponentManager

getService

protected Object getService()
Description copied from class: AbstractComponentManager
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.

Specified by:
getService in class AbstractComponentManager
Returns:

getComponentInstance

public ComponentInstance getComponentInstance()
Description copied from interface: Component
Returns the org.osgi.service.component.ComponentInstance representing this component or null if this component is not been activated yet.

Specified by:
getComponentInstance in interface Component

configurationDeleted

public void configurationDeleted(String pid)
Description copied from interface: ComponentHolder
The configuration with the given PID has been deleted from the Configuration Admin service.

Specified by:
configurationDeleted in interface ComponentHolder
Parameters:
pid - The PID of the deleted configuration

configurationUpdated

public void configurationUpdated(String pid,
                                 Dictionary configuration)
Description copied from interface: ComponentHolder
Configure a component with configuration from the given PID.

Specified by:
configurationUpdated in interface ComponentHolder
Parameters:
pid - The PID of the configuration used to configure the component

getComponents

public Component[] getComponents()
Description copied from interface: ComponentHolder
Returns all Component instances held by this holder.

Specified by:
getComponents in interface ComponentHolder

enableComponents

public void enableComponents()
A component factory component holder enables the held components by enabling itself.

Specified by:
enableComponents in interface ComponentHolder

disableComponents

public void disableComponents()
A component factory component holder disables the held components by disabling itself.

Specified by:
disableComponents in interface ComponentHolder

disposeComponents

public void disposeComponents(int reason)
Disposes off all components ever created by this component holder. This method is called if either the Declarative Services runtime is stopping or if the owning bundle is stopped. In both cases all components created by this holder must be disposed off.

Specified by:
disposeComponents in interface ComponentHolder

disposed

public void disposed(ImmediateComponentManager component)
Description copied from interface: ComponentHolder
Informs the holder that the component has been disposed as a result of calling the dispose method.

Specified by:
disposed in interface ComponentHolder


Copyright © 2011 Apache Software Foundation. All Rights Reserved.