org.apache.felix.ipojo
Class ComponentFactory

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

public class ComponentFactory
extends IPojoFactory
implements TrackerCustomizer

The component factory manages component instance objects. This management consist in creating and managing component instance build with the component factory. This class could export Factory and ManagedServiceFactory services.

Author:
Felix Project Team

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.felix.ipojo.IPojoFactory
IPojoFactory.RequiredHandler
 
Field Summary
protected  Tracker m_tracker
          Tracker used to track required handler factories.
 
Fields inherited from class org.apache.felix.ipojo.IPojoFactory
m_componentDesc, m_componentInstances, m_componentMetadata, m_context, m_factoryName, m_instancesName, m_isPublic, m_listeners, m_logger, m_requiredHandlers, m_sr, m_state
 
Fields inherited from interface org.apache.felix.ipojo.Factory
INVALID, VALID
 
Constructor Summary
ComponentFactory(org.osgi.framework.BundleContext context, byte[] clazz, org.apache.felix.ipojo.metadata.Element element)
          Create a instance manager factory.
ComponentFactory(org.osgi.framework.BundleContext context, org.apache.felix.ipojo.metadata.Element element)
          Create a instance manager factory.
 
Method Summary
 void addedService(org.osgi.framework.ServiceReference reference)
          A matching service has been added to the tracker, we can no compute the factory state.
 boolean addingService(org.osgi.framework.ServiceReference reference)
          A new handler factory is detected.
 void check(org.apache.felix.ipojo.metadata.Element element)
          Check method : allow a factory to check if given element are correct.
 ComponentInstance createInstance(java.util.Dictionary config, IPojoContext context, HandlerManager[] handlers)
          Create a primitive instance.
 java.lang.Class defineClass(java.lang.String name, byte[] clazz, java.security.ProtectionDomain domain)
          Define a class.
 java.lang.String getClassName()
          Get the factory class name.
 ComponentTypeDescription getComponentTypeDescription()
           
 java.lang.String getFactoryName()
          Compute the factory name.
 PojoMetadata getPojoMetadata()
          Returns manipulation metadata of this component type.
 java.util.List getRequiredHandlerList()
          Compute required handlers.
 java.net.URL getResource(java.lang.String resName)
          Return the URL of a resource.
 java.lang.Class loadClass(java.lang.String className)
          Load a class.
 void modifiedService(org.osgi.framework.ServiceReference reference, java.lang.Object service)
          A used handler factory is modified.
 void removedService(org.osgi.framework.ServiceReference reference, java.lang.Object service)
          A used factory disappears.
 void starting()
          Start the factory.
 void stopping()
          Stop all the instance managers.
 
Methods inherited from class org.apache.felix.ipojo.IPojoFactory
addFactoryStateListener, checkAcceptability, computeDescription, computeFactoryState, createComponentInstance, createComponentInstance, deleted, disposed, generateName, getBundleContext, getComponentDescription, getDescription, getHandler, getLogger, getMissingHandlers, getName, getRequiredHandlers, getState, isAcceptable, match, reconfigure, removeFactoryStateListener, start, stop, updated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_tracker

protected Tracker m_tracker
Tracker used to track required handler factories.

Constructor Detail

ComponentFactory

public ComponentFactory(org.osgi.framework.BundleContext context,
                        byte[] clazz,
                        org.apache.felix.ipojo.metadata.Element element)
                 throws ConfigurationException
Create a instance manager factory. The class is given in parameter. The component type is not a composite.

Parameters:
context - : bundle context
clazz - : the component class
element - : metadata of the component
Throws:
ConfigurationException - occurs when the element describing the factory is malformed.

ComponentFactory

public ComponentFactory(org.osgi.framework.BundleContext context,
                        org.apache.felix.ipojo.metadata.Element element)
                 throws ConfigurationException
Create a instance manager factory.

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

getComponentTypeDescription

public ComponentTypeDescription getComponentTypeDescription()
Overrides:
getComponentTypeDescription in class IPojoFactory

check

public void check(org.apache.felix.ipojo.metadata.Element element)
           throws ConfigurationException
Check method : allow a factory to check if given element are correct. A component factory metadata are correct if they contain the 'classname' attribute.

Parameters:
element - : the metadata
Throws:
ConfigurationException - occurs when the element describing the factory is malformed.

getClassName

public java.lang.String getClassName()
Description copied from class: IPojoFactory
Get the factory class name.

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

createInstance

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

Specified by:
createInstance in class IPojoFactory
Parameters:
config - : instance configuration
context - : service context.
handlers - : handler to use
Returns:
the created instance
Throws:
ConfigurationException - : if the configuration process failed.
See Also:
IPojoFactory.createInstance(java.util.Dictionary, org.apache.felix.ipojo.IPojoContext, org.apache.felix.ipojo.HandlerManager[])

defineClass

public java.lang.Class defineClass(java.lang.String name,
                                   byte[] clazz,
                                   java.security.ProtectionDomain domain)
Define a class.

Parameters:
name - : qualified name of the class
clazz - : byte array of the class
domain - : protection domain of the class
Returns:
the defined class object

getResource

public java.net.URL getResource(java.lang.String resName)
Return the URL of a resource.

Parameters:
resName - : resource name
Returns:
the URL of the resource

loadClass

public java.lang.Class loadClass(java.lang.String className)
                          throws java.lang.ClassNotFoundException
Load a class.

Parameters:
className - : name of the class to load
Returns:
the resulting Class object
Throws:
java.lang.ClassNotFoundException
java.lang.ClassNotFoundException - : happen when the class is not found

starting

public void starting()
Start the factory.

Specified by:
starting in class IPojoFactory

stopping

public void stopping()
Stop all the instance managers.

Specified by:
stopping in class IPojoFactory

getFactoryName

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

Specified by:
getFactoryName in class IPojoFactory
Returns:
the factory name.

getRequiredHandlerList

public java.util.List getRequiredHandlerList()
Compute required handlers.

Specified by:
getRequiredHandlerList in class IPojoFactory
Returns:
the required handler list.

addingService

public boolean addingService(org.osgi.framework.ServiceReference reference)
A new handler factory is detected. Test if the factory can be used or not.

Specified by:
addingService in interface TrackerCustomizer
Parameters:
reference - : the new service reference.
Returns:
true if the given factory reference match with a required handler.
See Also:
TrackerCustomizer.addingService(org.osgi.framework.ServiceReference)

addedService

public void addedService(org.osgi.framework.ServiceReference reference)
A matching service has been added to the tracker, we can no compute the factory state.

Specified by:
addedService in interface TrackerCustomizer
Parameters:
reference - : added reference.
See Also:
TrackerCustomizer.addedService(org.osgi.framework.ServiceReference)

removedService

public void removedService(org.osgi.framework.ServiceReference reference,
                           java.lang.Object service)
A used factory disappears.

Specified by:
removedService in interface TrackerCustomizer
Parameters:
reference - : service reference.
service - : factory object.
See Also:
TrackerCustomizer.removedService(org.osgi.framework.ServiceReference, java.lang.Object)

modifiedService

public void modifiedService(org.osgi.framework.ServiceReference reference,
                            java.lang.Object service)
A used handler factory is modified.

Specified by:
modifiedService in interface TrackerCustomizer
Parameters:
reference - : the service reference
service - : the Factory object (if already get)
See Also:
TrackerCustomizer.modifiedService(org.osgi.framework.ServiceReference, java.lang.Object)

getPojoMetadata

public PojoMetadata getPojoMetadata()
Returns manipulation metadata of this component type. The returned object is computed at the first call and then is cached.

Returns:
manipulation metadata of this component type.