net.sourceforge.hiveutils.service.impl
Class ObjectBuilderImpl

java.lang.Object
  extended by net.sourceforge.hiveutils.service.impl.ObjectBuilderImpl
All Implemented Interfaces:
ObjectBuilder

public class ObjectBuilderImpl
extends java.lang.Object
implements ObjectBuilder

Implementation of the ObjectBuilder service.

Author:
Jean-Francois Poilpret

Constructor Summary
ObjectBuilderImpl(org.apache.commons.logging.Log logger, java.util.Map<java.lang.String,ObjectContribution> config, org.apache.hivemind.schema.Translator objectTranslator, org.apache.hivemind.service.EventLinker linker)
           
 
Method Summary
 void addObjectBuilderListener(ObjectBuilderListener listener)
          Add a listener to the creation of POJO instances.
<T> T
create(java.lang.String name, java.lang.Object... userArgs)
          Creates an object according to its definition in hiveutils.ObjectBuilderObjects configuration point.
<T> T
get(java.lang.String name, java.lang.Object... args)
          Returns a cached object if it has been already created according to its definition in hiveutils.ObjectBuilderObjects configuration point.
 void injectListeners(java.lang.Object object, ObjectContribution contrib)
           
 void removeObjectBuilderListener(ObjectBuilderListener listener)
          Remove a listener from the list of listeners that are notified of the creation of POJO instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectBuilderImpl

public ObjectBuilderImpl(org.apache.commons.logging.Log logger,
                         java.util.Map<java.lang.String,ObjectContribution> config,
                         org.apache.hivemind.schema.Translator objectTranslator,
                         org.apache.hivemind.service.EventLinker linker)
Method Detail

addObjectBuilderListener

public void addObjectBuilderListener(ObjectBuilderListener listener)
Description copied from interface: ObjectBuilder
Add a listener to the creation of POJO instances.

Specified by:
addObjectBuilderListener in interface ObjectBuilder
Parameters:
listener - listener to be notified whenever a new POJO instance is created

removeObjectBuilderListener

public void removeObjectBuilderListener(ObjectBuilderListener listener)
Description copied from interface: ObjectBuilder
Remove a listener from the list of listeners that are notified of the creation of POJO instances.

Specified by:
removeObjectBuilderListener in interface ObjectBuilder
Parameters:
listener - listener to be removed from the list

get

public <T> T get(java.lang.String name,
                 java.lang.Object... args)
Description copied from interface: ObjectBuilder
Returns a cached object if it has been already created according to its definition in hiveutils.ObjectBuilderObjects configuration point. If the object has not been constructed yet (by a call to one of create methods), then no object will be returned.

Specified by:
get in interface ObjectBuilder
Parameters:
name - the unique id of the object definition in the ObjectBuilderObjects.
args - additional arguments that have been provided to the constructor when the object was created (args are at positions according to the object definition)
Returns:
the instance of an object that was constructed according to the definition for name, and cached, or null if name does not exist in the configuration, or if this object was not created yet, or if it was created but not cached (defined as per its configuration).

create

public <T> T create(java.lang.String name,
                    java.lang.Object... userArgs)
Description copied from interface: ObjectBuilder
Creates an object according to its definition in hiveutils.ObjectBuilderObjects configuration point. According to the definition, any necessary dependencies will be injected (in constructor or through setters). Repeated calls with the same name will create a new object every time, except if this object is configured to be cached.

Specified by:
create in interface ObjectBuilder
Parameters:
name - the unique id of the object definition in the ObjectBuilderObjects.
userArgs - additional arguments to be provided to the constructor (at a position according to the object definition)
Returns:
a new instance according to the definition for name, or null if name does not exist in the configuration.

injectListeners

public void injectListeners(java.lang.Object object,
                            ObjectContribution contrib)