org.apache.felix.ipojo
Class IPojoFactory

java.lang.Object
  extended by org.apache.felix.ipojo.IPojoFactory
All Implemented Interfaces:
Factory, org.osgi.service.cm.ManagedServiceFactory
Direct Known Subclasses:
ComponentFactory

public abstract class IPojoFactory
extends java.lang.Object
implements Factory, org.osgi.service.cm.ManagedServiceFactory

This class abstracts iPOJO factories.

Author:
Felix Project Team

Nested Class Summary
protected  class IPojoFactory.RequiredHandler
          Structure storing required handlers.
 
Field Summary
protected  ComponentTypeDescription m_componentDesc
          Component-Type description exposed by the factory service.
protected  java.util.Map m_componentInstances
          List of the managed instance managers.
protected  org.apache.felix.ipojo.metadata.Element m_componentMetadata
          Component Type provided by this factory.
protected  org.osgi.framework.BundleContext m_context
          The bundle context reference.
protected  java.lang.String m_factoryName
          Factory Name.
protected static java.util.List m_instancesName
          List of the managed instance name.
protected  boolean m_isPublic
          Is the factory public (expose as a service).
protected  java.util.List m_listeners
          List of listeners.
protected  Logger m_logger
          Logger for the factory (and all component instance).
protected  java.util.List m_requiredHandlers
          List of required handler.
protected  org.osgi.framework.ServiceRegistration m_sr
          Service Registration of this factory (Factory & ManagedServiceFactory).
protected  int m_state
          Factory state.
 
Fields inherited from interface org.apache.felix.ipojo.Factory
INVALID, VALID
 
Constructor Summary
IPojoFactory(org.osgi.framework.BundleContext context, org.apache.felix.ipojo.metadata.Element metadata)
          Constructor.
 
Method Summary
 void addFactoryStateListener(FactoryStateListener listener)
          Add a factory listener.
 void checkAcceptability(java.util.Dictionary conf)
          Check if the configuration is acceptable.
protected  void computeDescription()
          Compute the component type description.
protected  void computeFactoryState()
          Compute factory state.
 ComponentInstance createComponentInstance(java.util.Dictionary configuration)
          Create an instance.
 ComponentInstance createComponentInstance(java.util.Dictionary configuration, ServiceContext serviceContext)
          Create an instance.
abstract  ComponentInstance createInstance(java.util.Dictionary config, IPojoContext context, HandlerManager[] handlers)
          Create an instance.
 void deleted(java.lang.String name)
          Delete an instance.
 void disposed(ComponentInstance instance)
          Callback called by instance when disposed.
protected  java.lang.String generateName()
          Helping method generating a new unique name.
 org.osgi.framework.BundleContext getBundleContext()
          Get the bundle context of the factory.
abstract  java.lang.String getClassName()
          Get the factory class name.
 ComponentTypeDescription getComponentDescription()
          Get the component type description.
 ComponentTypeDescription getComponentTypeDescription()
           
 org.apache.felix.ipojo.metadata.Element getDescription()
          Get the component type description (Element-Attribute form).
abstract  java.lang.String getFactoryName()
          Compute the factory name.
protected  HandlerManager getHandler(IPojoFactory.RequiredHandler req, ServiceContext context)
          Return the handler object for the given required handler.
 Logger getLogger()
          Get the logger used by instances of he current factory.
 java.util.List getMissingHandlers()
          Compute the list of missing handlers.
 java.lang.String getName()
          Return the factory name.
abstract  java.util.List getRequiredHandlerList()
          Compute the required handler list.
 java.util.List getRequiredHandlers()
          Get the list of required handlers.
 int getState()
          Return the state of the factory.
 boolean isAcceptable(java.util.Dictionary conf)
          Check if the configuration is acceptable.
protected  boolean match(IPojoFactory.RequiredHandler req, org.osgi.framework.ServiceReference ref)
          Check if the given handler identifier and the service reference can match.
 void reconfigure(java.util.Dictionary properties)
          Reconfigure an existing instance.
 void removeFactoryStateListener(FactoryStateListener listener)
          Remove a factory listener.
 void start()
          Start the factory.
abstract  void starting()
          Starting method.
 void stop()
          Stop all the instance managers.
abstract  void stopping()
          Stopping method.
 void updated(java.lang.String name, java.util.Dictionary properties)
          Create of update an instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_instancesName

protected static java.util.List m_instancesName
List of the managed instance name. This list is shared by all factories.


m_componentDesc

protected ComponentTypeDescription m_componentDesc
Component-Type description exposed by the factory service.


m_componentInstances

protected java.util.Map m_componentInstances
List of the managed instance managers. The key of this map is the name (i.e. instance names) of the created instance


m_componentMetadata

protected org.apache.felix.ipojo.metadata.Element m_componentMetadata
Component Type provided by this factory.


m_context

protected org.osgi.framework.BundleContext m_context
The bundle context reference.


m_factoryName

protected java.lang.String m_factoryName
Factory Name. Could be the component class name if the factory name is not set.


m_requiredHandlers

protected java.util.List m_requiredHandlers
List of required handler.


m_listeners

protected java.util.List m_listeners
List of listeners.


m_logger

protected Logger m_logger
Logger for the factory (and all component instance).


m_isPublic

protected boolean m_isPublic
Is the factory public (expose as a service).


m_sr

protected org.osgi.framework.ServiceRegistration m_sr
Service Registration of this factory (Factory & ManagedServiceFactory).


m_state

protected int m_state
Factory state.

Constructor Detail

IPojoFactory

public IPojoFactory(org.osgi.framework.BundleContext context,
                    org.apache.felix.ipojo.metadata.Element metadata)
             throws ConfigurationException
Constructor.

Parameters:
context - : bundle context of the bundle containing the factory.
metadata - : description of the component type.
Throws:
ConfigurationException - occurs when the element describing the factory is malformed.
Method Detail

getComponentTypeDescription

public ComponentTypeDescription getComponentTypeDescription()

addFactoryStateListener

public void addFactoryStateListener(FactoryStateListener listener)
Add a factory listener.

Specified by:
addFactoryStateListener in interface Factory
Parameters:
listener - : the factory listener to add.
See Also:
Factory.addFactoryStateListener(org.apache.felix.ipojo.FactoryStateListener)

getLogger

public Logger getLogger()
Get the logger used by instances of he current factory.

Returns:
the factory logger.

getFactoryName

public abstract java.lang.String getFactoryName()
Compute the factory name.

Returns:
the factory name.

getRequiredHandlerList

public abstract java.util.List getRequiredHandlerList()
Compute the required handler list.

Returns:
the required handler list

createInstance

public abstract ComponentInstance createInstance(java.util.Dictionary config,
                                                 IPojoContext context,
                                                 HandlerManager[] handlers)
                                          throws ConfigurationException
Create an instance.

Parameters:
config - : instance configuration
context - : ipojo context to use
handlers - : handler array to use
Returns:
the new component instance.
Throws:
ConfigurationException - : occurs when the instance creation failed during the configuration process.

createComponentInstance

public ComponentInstance createComponentInstance(java.util.Dictionary configuration)
                                          throws UnacceptableConfiguration,
                                                 MissingHandlerException,
                                                 ConfigurationException
Create an instance. The given configuration needs to contain the 'name' property.

Specified by:
createComponentInstance in interface Factory
Parameters:
configuration - : configuration of the created instance.
Returns:
the created component instance.
Throws:
UnacceptableConfiguration - : occurs if the given configuration is not consistent with the component type of this factory.
MissingHandlerException - : occurs if an handler is unavailable when the instance is created.
ConfigurationException - : occurs when the instance or type configuration are not correct.
See Also:
Factory.createComponentInstance(java.util.Dictionary)

createComponentInstance

public ComponentInstance createComponentInstance(java.util.Dictionary configuration,
                                                 ServiceContext serviceContext)
                                          throws UnacceptableConfiguration,
                                                 MissingHandlerException,
                                                 ConfigurationException
Create an instance. The given configuration needs to contain the 'name' property.

Specified by:
createComponentInstance in interface Factory
Parameters:
configuration - : configuration of the created instance.
serviceContext - : the service context to push for this instance.
Returns:
the created component instance.
Throws:
UnacceptableConfiguration - : occurs if the given configuration is not consistent with the component type of this factory.
MissingHandlerException - : occurs when an handler is unavailable when creating the instance.
ConfigurationException - : when the instance configuration failed.
See Also:
Factory.createComponentInstance(java.util.Dictionary)

getBundleContext

public org.osgi.framework.BundleContext getBundleContext()
Description copied from interface: Factory
Get the bundle context of the factory.

Specified by:
getBundleContext in interface Factory
Returns:
the bundle context of the factory.

getClassName

public abstract java.lang.String getClassName()
Get the factory class name.

Specified by:
getClassName in interface Factory
Returns:
the factory classname.
See Also:
Factory.getClassName()

getComponentDescription

public ComponentTypeDescription getComponentDescription()
Get the component type description.

Specified by:
getComponentDescription in interface Factory
Returns:
the component type description object. Null if not already computed.

getDescription

public org.apache.felix.ipojo.metadata.Element getDescription()
Get the component type description (Element-Attribute form).

Specified by:
getDescription in interface Factory
Returns:
the component type description.
See Also:
Factory.getDescription()

getMissingHandlers

public java.util.List getMissingHandlers()
Compute the list of missing handlers.

Specified by:
getMissingHandlers in interface Factory
Returns:
list of missing handlers.
See Also:
Factory.getMissingHandlers()

getName

public java.lang.String getName()
Description copied from interface: Factory
Return the factory name.

Specified by:
getName in interface Factory
Specified by:
getName in interface org.osgi.service.cm.ManagedServiceFactory
Returns:
the name of the factory.

getRequiredHandlers

public java.util.List getRequiredHandlers()
Get the list of required handlers.

Specified by:
getRequiredHandlers in interface Factory
Returns:
list of required handlers.
See Also:
Factory.getRequiredHandlers()

getState

public int getState()
Description copied from interface: Factory
Return the state of the factory.

Specified by:
getState in interface Factory
Returns:
the state of the factory

isAcceptable

public boolean isAcceptable(java.util.Dictionary conf)
Check if the configuration is acceptable.

Specified by:
isAcceptable in interface Factory
Parameters:
conf - : the configuration to test.
Returns:
true if the configuration is acceptable.
See Also:
Factory.isAcceptable(java.util.Dictionary)

checkAcceptability

public void checkAcceptability(java.util.Dictionary conf)
                        throws UnacceptableConfiguration,
                               MissingHandlerException
Check if the configuration is acceptable.

Parameters:
conf - : the configuration to test.
Throws:
UnacceptableConfiguration - occurs if the configuration is unacceptable.
MissingHandlerException - occurs if an handler is missing.

reconfigure

public void reconfigure(java.util.Dictionary properties)
                 throws UnacceptableConfiguration,
                        MissingHandlerException
Reconfigure an existing instance.

Specified by:
reconfigure in interface Factory
Parameters:
properties - : the new configuration to push.
Throws:
UnacceptableConfiguration - : occurs if the new configuration is not consistent with the component type.
MissingHandlerException - : occurs if the current factory is not valid.
See Also:
Factory.reconfigure(java.util.Dictionary)

removeFactoryStateListener

public void removeFactoryStateListener(FactoryStateListener listener)
Remove a factory listener.

Specified by:
removeFactoryStateListener in interface Factory
Parameters:
listener - : the factory listener to remove.
See Also:
Factory.removeFactoryStateListener(org.apache.felix.ipojo.FactoryStateListener)

stopping

public abstract void stopping()
Stopping method. This method is call when the factory is stopping.


stop

public void stop()
Stop all the instance managers.


starting

public abstract void starting()
Starting method. This method is called when the factory is starting.


start

public void start()
Start the factory.


updated

public void updated(java.lang.String name,
                    java.util.Dictionary properties)
             throws org.osgi.service.cm.ConfigurationException
Create of update an instance.

Specified by:
updated in interface org.osgi.service.cm.ManagedServiceFactory
Parameters:
name - : name of the instance
properties - : configuration of the instance
Throws:
org.osgi.service.cm.ConfigurationException - : if the configuration is not consistent for this component type
See Also:
ManagedServiceFactory.updated(java.lang.String, java.util.Dictionary)

deleted

public void deleted(java.lang.String name)
Delete an instance.

Specified by:
deleted in interface org.osgi.service.cm.ManagedServiceFactory
Parameters:
name - : name of the instance to delete
See Also:
ManagedServiceFactory.deleted(java.lang.String)

disposed

public void disposed(ComponentInstance instance)
Callback called by instance when disposed.

Parameters:
instance - : the destroyed instance

computeDescription

protected void computeDescription()
Compute the component type description. The factory must be valid when calling this method.


computeFactoryState

protected void computeFactoryState()
Compute factory state.


match

protected boolean match(IPojoFactory.RequiredHandler req,
                        org.osgi.framework.ServiceReference ref)
Check if the given handler identifier and the service reference can match.

Parameters:
req - : the handler identifier.
ref - : the service reference.
Returns:
true if the service reference can fulfill the handler requirement

getHandler

protected HandlerManager getHandler(IPojoFactory.RequiredHandler req,
                                    ServiceContext context)
Return the handler object for the given required handler. The handler is instantiated in the given service context.

Parameters:
req - : handler to create.
context - : service context in which create the handler (instance context).
Returns:
the Handler object.

generateName

protected java.lang.String generateName()
Helping method generating a new unique name.

Returns:
an non already used name