org.objectweb.jonathan.libs.kernel

Class GenericFactory

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.

Method Summary

protected void
configure(Object _object, Context _c, Object[] _used_components)
protected Object[]
getUsedComponents(Context _c)
Returns the components of the provided context that should be used to build a new object instance.
protected Object
newInstance()
protected Object
newInstance(Context _c, Object[] _used_components)
Returns a new object created using the provided components, and possibly some information contained in the provided context.
Object
newObject(Context _c)
Returns an object created using information contained in the provided context.
void
register(Object object, Context _configuration)
Registers an instance, using the provided components, in the factory.

Method Details

configure

protected void configure(Object _object,
                         Context _c,
                         Object[] _used_components)
            throws JonathanException


getUsedComponents

protected 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 Object newInstance()
            throws JonathanException


newInstance

protected Object newInstance(Context _c,
                             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.


newObject

public 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(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;