net.sourceforge.hiveutils.service
Interface ObjectBuilder

All Known Implementing Classes:
ObjectBuilderImpl

public interface ObjectBuilder

Service that builds simple objects instances (not HiveMind services) but can inject dependencies into them, according to contributions to a specific configuration point.

Note this service does not cache any created objects.

Author:
Jean-Francois Poilpret

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... args)
          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 removeObjectBuilderListener(ObjectBuilderListener listener)
          Remove a listener from the list of listeners that are notified of the creation of POJO instances.
 

Method Detail

create

<T> T create(java.lang.String name,
             java.lang.Object... args)
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.

Parameters:
name - the unique id of the object definition in the ObjectBuilderObjects.
args - 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.

get

<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. If the object has not been constructed yet (by a call to one of create methods), then no object will be returned.

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).

addObjectBuilderListener

void addObjectBuilderListener(ObjectBuilderListener listener)
Add a listener to the creation of POJO instances.

Parameters:
listener - listener to be notified whenever a new POJO instance is created

removeObjectBuilderListener

void removeObjectBuilderListener(ObjectBuilderListener listener)
Remove a listener from the list of listeners that are notified of the creation of POJO instances.

Parameters:
listener - listener to be removed from the list