org.oddjob.arooa.registry
Class SimpleComponentPool

java.lang.Object
  extended by org.oddjob.arooa.registry.SimpleComponentPool
All Implemented Interfaces:
ComponentPool

public class SimpleComponentPool
extends Object
implements ComponentPool

An simple implementation of a ComponentPool.

This class is thread safe for the addition an removal of components. It is not thread safe for configuration an saving. This is left to the calling code. Oddjob for instance achieves thread safety for for these operations by locking on State.

Author:
rob

Constructor Summary
SimpleComponentPool()
           
 
Method Summary
 Iterable<ComponentTrinity> allTrinities()
          Provide a way of iterating over all trinities.
 void configure(Object component)
          Configure the component.
 ArooaContext contextFor(Object either)
          Get the components ArooaContext.
 String getIdFor(Object either)
          Provide the Id for either a component or it's proxy.
 void registerComponent(ComponentTrinity componentTrinity, String id)
          Register a ComponentTrinity.
 void remove(Object either)
          Remove a component.
 void save(Object component)
          Possibly save the component to a persistent store, if everything is in place for this to happen.
 ComponentTrinity trinityFor(Object either)
          Get the ComponentTrinity for either the component or proxy.
 ComponentTrinity trinityForContext(ArooaContext context)
          Get the ComponentTrinity for the given ArooaContext.
 ComponentTrinity trinityForId(String id)
          Provide the ComponentTrinity for a given id, if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleComponentPool

public SimpleComponentPool()
Method Detail

configure

public void configure(Object component)
               throws ArooaConfigurationException
Description copied from interface: ComponentPool
Configure the component. The is a shortcut method equivalent to contextFor(component).getRuntime().configure().

Specified by:
configure in interface ComponentPool
Parameters:
component - The component or it's proxy.
Throws:
ArooaConfigurationException

save

public void save(Object component)
          throws ComponentPersistException
Description copied from interface: ComponentPool
Possibly save the component to a persistent store, if everything is in place for this to happen.

If a ComponentPersister is in operation and the component was registered with an id then the ComponentPersister is invoked with the component.

Specified by:
save in interface ComponentPool
Parameters:
component - A component or it's proxy.
Throws:
ComponentPersistException

remove

public void remove(Object either)
            throws ComponentPersistException
Description copied from interface: ComponentPool
Remove a component.

Specified by:
remove in interface ComponentPool
Parameters:
either - A component or it's proxy.
Throws:
ComponentPersistException

contextFor

public ArooaContext contextFor(Object either)
Description copied from interface: ComponentPool
Get the components ArooaContext.

Specified by:
contextFor in interface ComponentPool
Parameters:
either - The component or the proxy.
Returns:
The context or null if the component/proxy is not in this pool.

trinityForContext

public ComponentTrinity trinityForContext(ArooaContext context)
Description copied from interface: ComponentPool
Get the ComponentTrinity for the given ArooaContext.

This is required for ContextHierarchyServiceFinder.

Specified by:
trinityForContext in interface ComponentPool
Parameters:
context - A context;
Returns:
The trinity or null.

trinityFor

public ComponentTrinity trinityFor(Object either)
Description copied from interface: ComponentPool
Get the ComponentTrinity for either the component or proxy.

Specified by:
trinityFor in interface ComponentPool
Parameters:
either - Either the component or the proxy.
Returns:
The component trinity or null if it can't be found.

trinityForId

public ComponentTrinity trinityForId(String id)
Description copied from interface: ComponentPool
Provide the ComponentTrinity for a given id, if possible.

Specified by:
trinityForId in interface ComponentPool
Parameters:
id - The id.
Returns:
The trinity, or null if none exists for the given id.

getIdFor

public String getIdFor(Object either)
Description copied from interface: ComponentPool
Provide the Id for either a component or it's proxy.

Specified by:
getIdFor in interface ComponentPool
Parameters:
either - Either a component or it's proxy.
Returns:
The id, or null if the component wasn't registered with an id, or the component doesn't exist in pool.

allTrinities

public Iterable<ComponentTrinity> allTrinities()
Description copied from interface: ComponentPool
Provide a way of iterating over all trinities.

Specified by:
allTrinities in interface ComponentPool
Returns:
An Iterable of trinities. Will never be null.

registerComponent

public void registerComponent(ComponentTrinity componentTrinity,
                              String id)
Description copied from interface: ComponentPool
Register a ComponentTrinity.

Specified by:
registerComponent in interface ComponentPool
Parameters:
componentTrinity - The trinity.
id - The id. May be null.