org.picocontainer.containers
Class AbstractDelegatingMutablePicoContainer

java.lang.Object
  extended by org.picocontainer.containers.AbstractDelegatingMutablePicoContainer
All Implemented Interfaces:
Serializable, Disposable, MutablePicoContainer, PicoContainer, Startable

public abstract class AbstractDelegatingMutablePicoContainer
extends Object
implements MutablePicoContainer, Serializable

Author:
Paul Hammant
See Also:
Serialized Form

Constructor Summary
AbstractDelegatingMutablePicoContainer(MutablePicoContainer delegate)
           
 
Method Summary
 void accept(PicoVisitor visitor)
          Accepts a visitor that should visit the child containers, component adapters and component instances.
 MutablePicoContainer addAdapter(ComponentAdapter componentAdapter)
          Register a component via a ComponentAdapter.
 MutablePicoContainer addChildContainer(PicoContainer child)
          Add a child container.
 MutablePicoContainer addComponent(Object implOrInstance)
          Register an arbitrary object.
 MutablePicoContainer addComponent(Object componentKey, Object componentImplementationOrInstance, Parameter... parameters)
          Register a component and creates specific instructions on which constructor to use, along with which components and/or constants to provide as constructor arguments.
 MutablePicoContainer addConfig(String name, Object val)
          Register a config item.
 MutablePicoContainer as(Properties... properties)
          You can set for the following operation only the characteristic of registration of a component on the fly.
 MutablePicoContainer change(Properties... properties)
          You can change the characteristic of registration of all subsequent components in this container.
 void dispose()
          Dispose this component.
 boolean equals(Object obj)
           
<T> T
getComponent(Class<T> componentType)
           
 Object getComponent(Object componentKeyOrType)
          Retrieve a component instance registered with a specific key or type.
<T> ComponentAdapter<T>
getComponentAdapter(Class<T> componentType, ParameterName componentParameterName)
          Find a component adapter associated with the specified type.
 ComponentAdapter<?> getComponentAdapter(Object componentKey)
          Find a component adapter associated with the specified key.
 Collection<ComponentAdapter<?>> getComponentAdapters()
          Retrieve all the component adapters inside this container.
<T> List<ComponentAdapter<T>>
getComponentAdapters(Class<T> componentType)
          Retrieve all component adapters inside this container that are associated with the specified type.
 List getComponents()
          Retrieve all the registered component instances in the container, (not including those in the parent container).
<T> List<T>
getComponents(Class<T> type)
          Returns a List of components of a certain componentType.
protected  MutablePicoContainer getDelegate()
           
 PicoContainer getParent()
          Retrieve the parent container of this container.
 boolean removeChildContainer(PicoContainer child)
          Remove a child container from this container.
 ComponentAdapter removeComponent(Object componentKey)
          Unregister a component by key.
 ComponentAdapter removeComponentByInstance(Object componentInstance)
          Unregister a component by instance.
 void start()
          Start this component.
 void stop()
          Stop this component.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.picocontainer.MutablePicoContainer
makeChildContainer
 

Constructor Detail

AbstractDelegatingMutablePicoContainer

public AbstractDelegatingMutablePicoContainer(MutablePicoContainer delegate)
Method Detail

getDelegate

protected MutablePicoContainer getDelegate()

addComponent

public MutablePicoContainer addComponent(Object componentKey,
                                         Object componentImplementationOrInstance,
                                         Parameter... parameters)
                                  throws PicoCompositionException
Description copied from interface: MutablePicoContainer
Register a component and creates specific instructions on which constructor to use, along with which components and/or constants to provide as constructor arguments. These "directives" are provided through an array of Parameter objects. Parameter[0] correspondes to the first constructor argument, Parameter[N] corresponds to the N+1th constructor argument.

Tips for Parameter usage


addComponent

public MutablePicoContainer addComponent(Object implOrInstance)
                                  throws PicoCompositionException
Description copied from interface: MutablePicoContainer
Register an arbitrary object. The class of the object will be used as a key. Calling this method is equivalent to calling addComponent(componentImplementation, componentImplementation).

Specified by:
addComponent in interface MutablePicoContainer
Parameters:
implOrInstance - Component implementation or instance
Returns:
the same instance of MutablePicoContainer
Throws:
PicoCompositionException - if registration fails.

addConfig

public MutablePicoContainer addConfig(String name,
                                      Object val)
Description copied from interface: MutablePicoContainer
Register a config item.

Specified by:
addConfig in interface MutablePicoContainer
Parameters:
name - the name of the config item
val - the value of the config item
Returns:
the same instance of MutablePicoContainer

addAdapter

public MutablePicoContainer addAdapter(ComponentAdapter componentAdapter)
                                throws PicoCompositionException
Description copied from interface: MutablePicoContainer
Register a component via a ComponentAdapter. Use this if you need fine grained control over what ComponentAdapter to use for a specific component.

Specified by:
addAdapter in interface MutablePicoContainer
Parameters:
componentAdapter - the addAdapter
Returns:
the same instance of MutablePicoContainer
Throws:
PicoCompositionException - if registration fails.

removeComponent

public ComponentAdapter removeComponent(Object componentKey)
Description copied from interface: MutablePicoContainer
Unregister a component by key.

Specified by:
removeComponent in interface MutablePicoContainer
Parameters:
componentKey - key of the component to unregister.
Returns:
the ComponentAdapter that was associated with this component.

removeComponentByInstance

public ComponentAdapter removeComponentByInstance(Object componentInstance)
Description copied from interface: MutablePicoContainer
Unregister a component by instance.

Specified by:
removeComponentByInstance in interface MutablePicoContainer
Parameters:
componentInstance - the component instance to unregister.
Returns:
the same instance of MutablePicoContainer

getComponent

public Object getComponent(Object componentKeyOrType)
Description copied from interface: PicoContainer
Retrieve a component instance registered with a specific key or type. If a component cannot be found in this container, the parent container (if one exists) will be searched.

Specified by:
getComponent in interface PicoContainer
Parameters:
componentKeyOrType - the key or Type that the component was registered with.
Returns:
an instantiated component, or null if no component has been registered for the specified key.

getComponent

public <T> T getComponent(Class<T> componentType)
Specified by:
getComponent in interface PicoContainer

getComponents

public List getComponents()
Description copied from interface: PicoContainer
Retrieve all the registered component instances in the container, (not including those in the parent container). The components are returned in their order of instantiation, which depends on the dependency order between them.

Specified by:
getComponents in interface PicoContainer
Returns:
all the components.

getParent

public PicoContainer getParent()
Description copied from interface: PicoContainer
Retrieve the parent container of this container.

Specified by:
getParent in interface PicoContainer
Returns:
a PicoContainer instance, or null if this container does not have a parent.

getComponentAdapter

public ComponentAdapter<?> getComponentAdapter(Object componentKey)
Description copied from interface: PicoContainer
Find a component adapter associated with the specified key. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.

Specified by:
getComponentAdapter in interface PicoContainer
Parameters:
componentKey - the key that the component was registered with.
Returns:
the component adapter associated with this key, or null if no component has been registered for the specified key.

getComponentAdapter

public <T> ComponentAdapter<T> getComponentAdapter(Class<T> componentType,
                                                   ParameterName componentParameterName)
Description copied from interface: PicoContainer
Find a component adapter associated with the specified type. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.

Specified by:
getComponentAdapter in interface PicoContainer
Parameters:
componentType - the type of the component.
Returns:
the component adapter associated with this class, or null if no component has been registered for the specified key.

getComponentAdapters

public Collection<ComponentAdapter<?>> getComponentAdapters()
Description copied from interface: PicoContainer
Retrieve all the component adapters inside this container. The component adapters from the parent container are not returned.

Specified by:
getComponentAdapters in interface PicoContainer
Returns:
a collection containing all the ComponentAdapters inside this container. The collection will not be modifiable.
See Also:
a variant of this method which returns the component adapters inside this container that are associated with the specified type.

getComponentAdapters

public <T> List<ComponentAdapter<T>> getComponentAdapters(Class<T> componentType)
Description copied from interface: PicoContainer
Retrieve all component adapters inside this container that are associated with the specified type. The addComponent adapters from the parent container are not returned.

Specified by:
getComponentAdapters in interface PicoContainer
Parameters:
componentType - the type of the components.
Returns:
a collection containing all the ComponentAdapters inside this container that are associated with the specified type. Changes to this collection will not be reflected in the container itself.

start

public void start()
Description copied from interface: Startable
Start this component. Called initially at the begin of the lifecycle. It can be called again after a stop.

Specified by:
start in interface Startable

stop

public void stop()
Description copied from interface: Startable
Stop this component. Called near the end of the lifecycle. It can be called again after a further start. Implement Disposable if you need a single call at the definite end of the lifecycle.

Specified by:
stop in interface Startable

dispose

public void dispose()
Description copied from interface: Disposable
Dispose this component. The component should deallocate all resources. The contract for this method defines a single call at the end of this component's life.

Specified by:
dispose in interface Disposable

addChildContainer

public MutablePicoContainer addChildContainer(PicoContainer child)
Description copied from interface: MutablePicoContainer
Add a child container. This action will list the the 'child' as exactly that in the parents scope. It will not change the child's view of a parent. That is determined by the constructor arguments of the child itself. Lifecycle events will be cascaded from parent to child as a consequence of calling this method.

Specified by:
addChildContainer in interface MutablePicoContainer
Parameters:
child - the child container
Returns:
the same instance of MutablePicoContainer

removeChildContainer

public boolean removeChildContainer(PicoContainer child)
Description copied from interface: MutablePicoContainer
Remove a child container from this container. It will not change the child's view of a parent. Lifecycle event will no longer be cascaded from the parent to the child.

Specified by:
removeChildContainer in interface MutablePicoContainer
Parameters:
child - the child container
Returns:
true if the child container has been removed.

accept

public void accept(PicoVisitor visitor)
Description copied from interface: PicoContainer
Accepts a visitor that should visit the child containers, component adapters and component instances.

Specified by:
accept in interface PicoContainer
Parameters:
visitor - the visitor

getComponents

public <T> List<T> getComponents(Class<T> type)
                      throws PicoException
Description copied from interface: PicoContainer
Returns a List of components of a certain componentType. The list is ordered by instantiation order, starting with the components instantiated first at the beginning.

Specified by:
getComponents in interface PicoContainer
Parameters:
type - the searched type.
Returns:
a List of components.
Throws:
PicoException - if the instantiation of a component fails

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

change

public MutablePicoContainer change(Properties... properties)
Description copied from interface: MutablePicoContainer
You can change the characteristic of registration of all subsequent components in this container.

Specified by:
change in interface MutablePicoContainer
Returns:
the same Pico instance with changed properties

as

public MutablePicoContainer as(Properties... properties)
Description copied from interface: MutablePicoContainer
You can set for the following operation only the characteristic of registration of a component on the fly.

Specified by:
as in interface MutablePicoContainer
Returns:
the same Pico instance with temporary properties


Copyright © 2003-2007 Codehaus. All Rights Reserved.