org.objectweb.jonathan.libs.kernel
Class GenericFactory

java.lang.Object
  extended byorg.objectweb.jonathan.libs.kernel.GenericFactory
All Implemented Interfaces:
Factory

public abstract class GenericFactory
extends java.lang.Object
implements Factory

Generic Factory implementation.

This class provides a generic mechanism to use a pool of objects and let already constructed objects be reused.


Constructor Summary
GenericFactory()
           
 
Method Summary
protected  void configure(java.lang.Object _object, Context _c, java.lang.Object[] _used_components)
           
protected abstract  java.lang.Object[] getUsedComponents(Context _c)
          Returns the components of the provided context that should be used to build a new object instance.
protected  java.lang.Object newInstance()
           
protected abstract  java.lang.Object newInstance(Context _c, java.lang.Object[] _used_components)
          Returns a new object created using the provided components, and possibly some information contained in the provided context.
 java.lang.Object newObject(Context _c)
          Returns an object created using information contained in the provided context.
 void register(java.lang.Object object, Context _configuration)
          Registers an instance, using the provided components, in the factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericFactory

public GenericFactory()
Method Detail

newObject

public java.lang.Object newObject(Context _c)
                           throws JonathanException
Returns an object created using information contained in the provided context. This method first calls the getUsedComponents() method to retrieve the components that would be used to create a new object. If an object has already been constructed using the same components, it is returned. Otherwise, the newInstance method is called to create a new object. Before being returned, the object is stored, so that it can be reused in future calls.

Specified by:
newObject in interface Factory
Parameters:
_c - a Context object;
Returns:
an object created using information contained in context.
Throws:
JonathanException - if something goes wrong.

register

public void register(java.lang.Object object,
                     Context _configuration)
Registers an instance, using the provided components, in the factory.

Parameters:
object - the instance of an object that could have been created by the target factory;

getUsedComponents

protected abstract java.lang.Object[] getUsedComponents(Context _c)
Returns the components of the provided context that should be used to build a new object instance.

Parameters:
_c - a context;
Returns:
the components of _c that should be used to build a new object

newInstance

protected abstract java.lang.Object newInstance(Context _c,
                                                java.lang.Object[] _used_components)
                                         throws JonathanException
Returns a new object created using the provided components, and possibly some information contained in the provided context.

The provided components must have been obtained using the getUsedComponents method.

Parameters:
_c - a context;
_used_components - components to be used to create a new object;
Returns:
a new object created using _used_components;
Throws:
JonathanException - if something goes wrong.

newInstance

protected java.lang.Object newInstance()
                                throws JonathanException
Throws:
JonathanException

configure

protected void configure(java.lang.Object _object,
                         Context _c,
                         java.lang.Object[] _used_components)
                  throws JonathanException
Throws:
JonathanException