org.picocontainer.extras
Class DefaultLifecyclePicoContainer

java.lang.Object
  extended byorg.picocontainer.extras.DefaultLifecyclePicoContainer
All Implemented Interfaces:
Disposable, Lifecycle, LifecyclePicoAdapter, MutablePicoContainer, PicoContainer, Startable, Stoppable

public class DefaultLifecyclePicoContainer
extends Object
implements LifecyclePicoAdapter, MutablePicoContainer


Constructor Summary
DefaultLifecyclePicoContainer()
           
DefaultLifecyclePicoContainer(LifecyclePicoAdapter lifecyclePicoAdapter, MutablePicoContainer mutablePicoContainer)
           
DefaultLifecyclePicoContainer(MutablePicoContainer mutablePicoContainer)
           
 
Method Summary
 void addChild(MutablePicoContainer child)
          Adds a Child container.
 void addOrderedComponentAdapter(ComponentAdapter componentAdapter)
          Adds a component instance to the container.
 void addParent(MutablePicoContainer parent)
          Adds a Parent container.
 void dispose()
           
 ComponentAdapter findComponentAdapter(Object componentKey)
          Finds a ComponentAdapter matching the key.
 Collection getChildContainers()
          Get the child containers of this container.
 Object getComponentInstance(Object componentKey)
          Gets a component instance.
 List getComponentInstances()
          Gets all the registered component instances in the container.
 Collection getComponentKeys()
          Get all the component keys.
 Object getComponentMulticaster()
          Shorthand for getComponentMulticaster(boolean, boolean)
 Object getComponentMulticaster(boolean callInInstantiationOrder, boolean callUnmanagedComponents)
          Returns an object (in fact, a dynamic proxy) that implements the union of all the interfaces of the currently registered components.
 List getParentContainers()
          Get the parent containers of this container.
 PicoContainer getPicoContainer()
           
 boolean hasComponent(Object componentKey)
          Checks for the presence of a particular component.
 boolean isDisposed()
           
 boolean isStarted()
           
 boolean isStopped()
           
 Object registerComponentImplementation(Class componentImplementation)
          Registers a component using the componentImplementation as key.
 Object registerComponentImplementation(Object componentKey, Class componentImplementation)
          Registers a component.
 Object registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters)
          Registers a component.
 Object registerComponentInstance(Object componentInstance)
          Registers an arbitrary object, using itself as a key.
 Object registerComponentInstance(Object componentKey, Object componentInstance)
          Registers an arbitrary object as a compoent in the container.
 void start()
           
 void stop()
           
 Object unregisterComponent(Object componentKey)
          Unregisters a component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLifecyclePicoContainer

public DefaultLifecyclePicoContainer(LifecyclePicoAdapter lifecyclePicoAdapter,
                                     MutablePicoContainer mutablePicoContainer)

DefaultLifecyclePicoContainer

public DefaultLifecyclePicoContainer(MutablePicoContainer mutablePicoContainer)

DefaultLifecyclePicoContainer

public DefaultLifecyclePicoContainer()
Method Detail

findComponentAdapter

public ComponentAdapter findComponentAdapter(Object componentKey)
                                      throws PicoIntrospectionException
Description copied from interface: PicoContainer
Finds a ComponentAdapter matching the key. This method is an "expert" method, and should normally not be called by clients of this API. (It is called by the implementation).

Specified by:
findComponentAdapter in interface PicoContainer
Parameters:
componentKey - key of the component.
Throws:
PicoIntrospectionException

dispose

public void dispose()
Specified by:
dispose in interface Disposable

start

public void start()
Specified by:
start in interface Startable

getPicoContainer

public PicoContainer getPicoContainer()
Specified by:
getPicoContainer in interface LifecyclePicoAdapter

isStarted

public boolean isStarted()
Specified by:
isStarted in interface LifecyclePicoAdapter

getComponentInstance

public Object getComponentInstance(Object componentKey)
                            throws PicoException
Description copied from interface: PicoContainer
Gets a component instance.

Specified by:
getComponentInstance in interface PicoContainer
Parameters:
componentKey - key the component was registered with.
Returns:
an instantiated component.
Throws:
PicoException - if the component could not be instantiated or dependencies could not be properly resolved.

getChildContainers

public Collection getChildContainers()
Description copied from interface: PicoContainer
Get the child containers of this container. Any given container instance should not use the child containers to resolve components, but rahter their parents. This method is available merely to be able to traverse trees of containers, and is not used by the container itself.

Specified by:
getChildContainers in interface PicoContainer
Returns:
a Collection of PicoContainer.
See Also:
PicoContainer.getParentContainers()

stop

public void stop()
Specified by:
stop in interface Stoppable

isDisposed

public boolean isDisposed()
Specified by:
isDisposed in interface LifecyclePicoAdapter

getComponentMulticaster

public Object getComponentMulticaster()
                               throws PicoException
Description copied from interface: PicoContainer
Shorthand for PicoContainer.getComponentMulticaster(boolean, boolean)
(true, false)
, which is the most common usage scenario.

Specified by:
getComponentMulticaster in interface PicoContainer
Returns:
a multicaster object.
Throws:
PicoException

getComponentKeys

public Collection getComponentKeys()
Description copied from interface: PicoContainer
Get all the component keys.

Specified by:
getComponentKeys in interface PicoContainer
Returns:
all the component keys.

isStopped

public boolean isStopped()
Specified by:
isStopped in interface LifecyclePicoAdapter

hasComponent

public boolean hasComponent(Object componentKey)
Description copied from interface: PicoContainer
Checks for the presence of a particular component.

Specified by:
hasComponent in interface PicoContainer
Parameters:
componentKey - key of the component to look for.
Returns:
true if there is a component for this key.

getComponentInstances

public List getComponentInstances()
                           throws PicoException
Description copied from interface: PicoContainer
Gets all the registered component instances in the container. The components are returned in their order of instantiation, which depends on the dependency order between components.

Specified by:
getComponentInstances in interface PicoContainer
Returns:
all the components.
Throws:
PicoException - if one of the components could not be instantiated or dependencies could not be properly resolved.

getComponentMulticaster

public Object getComponentMulticaster(boolean callInInstantiationOrder,
                                      boolean callUnmanagedComponents)
                               throws PicoException
Description copied from interface: PicoContainer
Returns an object (in fact, a dynamic proxy) that implements the union of all the interfaces of the currently registered components.

Casting this object to any of those interfaces and then calling a method on it will result in that call being multicast to all the components implementing that given interface.

This is a simple yet extremely powerful way to handle lifecycle of components. Component writers can invent their own lifecycle interfaces, and then use the multicaster to invoke the method in one go.

Specified by:
getComponentMulticaster in interface PicoContainer
Parameters:
callInInstantiationOrder - whether or not to call the method in the order of instantiation, which depends on the components' inter-dependencies.
callUnmanagedComponents - whether or not to multicast to components that are not managed by this container.
Returns:
a multicaster object.
Throws:
PicoException

getParentContainers

public List getParentContainers()
Description copied from interface: PicoContainer
Get the parent containers of this container. In a purely hierarchical (tree structure) container, there will be 0..1 parents. However, it is possible to have several parents. A container will look in its parents if a component can be found in self.

Specified by:
getParentContainers in interface PicoContainer
Returns:
a Collection of PicoContainer.

unregisterComponent

public Object unregisterComponent(Object componentKey)
Description copied from interface: MutablePicoContainer
Unregisters a component.

Specified by:
unregisterComponent in interface MutablePicoContainer
Parameters:
componentKey - key of the component to unregister.
Returns:
the unregistered component.

registerComponentInstance

public Object registerComponentInstance(Object componentKey,
                                        Object componentInstance)
                                 throws PicoRegistrationException
Description copied from interface: MutablePicoContainer
Registers an arbitrary object as a compoent in the container. This is handy when other components in the same container have dependencies on this kind of object, but where letting the container manage and instantiate it is impossible.

Specified by:
registerComponentInstance in interface MutablePicoContainer
Parameters:
componentKey - a key that identifies the compoent. Must be unique within the conainer.
componentInstance - an arbitrary object.
Returns:
the key used for registration.
Throws:
PicoRegistrationException - if registration fails.

addChild

public void addChild(MutablePicoContainer child)
Description copied from interface: MutablePicoContainer
Adds a Child container. Will also add this instance as a parent to child, so calling MutablePicoContainer.addParent(org.picocontainer.MutablePicoContainer) is not necessary.

Specified by:
addChild in interface MutablePicoContainer
Parameters:
child - child container.

addParent

public void addParent(MutablePicoContainer parent)
Description copied from interface: MutablePicoContainer
Adds a Parent container. Will also add this instance as a child to parent, so calling MutablePicoContainer.addChild(org.picocontainer.MutablePicoContainer) is not necessary.

Specified by:
addParent in interface MutablePicoContainer
Parameters:
parent - parent container.

registerComponentImplementation

public Object registerComponentImplementation(Object componentKey,
                                              Class componentImplementation)
                                       throws PicoRegistrationException
Description copied from interface: MutablePicoContainer
Registers a component.

Specified by:
registerComponentImplementation in interface MutablePicoContainer
Parameters:
componentKey - a key that identifies the compoent. Must be unique within the conainer.
componentImplementation - the concrete component class.
Throws:
PicoRegistrationException - if registration fails.

registerComponentInstance

public Object registerComponentInstance(Object componentInstance)
                                 throws PicoRegistrationException
Description copied from interface: MutablePicoContainer
Registers an arbitrary object, using itself as a key.

Specified by:
registerComponentInstance in interface MutablePicoContainer
Parameters:
componentInstance -
Returns:
the key used for registration.
Throws:
PicoRegistrationException

addOrderedComponentAdapter

public void addOrderedComponentAdapter(ComponentAdapter componentAdapter)
Description copied from interface: MutablePicoContainer
Adds a component instance to the container. Do not call this method explicitly. It is used by the internals. Use MutablePicoContainer.registerComponentInstance(java.lang.Object) instead if you wish to register externally instantiated objects.

Specified by:
addOrderedComponentAdapter in interface MutablePicoContainer
Parameters:
componentAdapter - key of the component.

registerComponentImplementation

public Object registerComponentImplementation(Class componentImplementation)
                                       throws PicoRegistrationException
Description copied from interface: MutablePicoContainer
Registers a component using the componentImplementation as key.

Specified by:
registerComponentImplementation in interface MutablePicoContainer
Parameters:
componentImplementation - the concrete component class.
Returns:
the key used for registration.
Throws:
PicoRegistrationException - if registration fails.

registerComponentImplementation

public Object registerComponentImplementation(Object componentKey,
                                              Class componentImplementation,
                                              Parameter[] parameters)
                                       throws PicoRegistrationException
Description copied from interface: MutablePicoContainer
Registers a component.

Specified by:
registerComponentImplementation in interface MutablePicoContainer
Parameters:
componentKey - a key that identifies the compoent. Must be unique within the conainer.
componentImplementation - the concrete component class.
parameters - an array of parameters that gives the container hints about what arguments to pass to the constructor when it is instantiated.
Returns:
the key used for registration.
Throws:
PicoRegistrationException - if registration fails.


Copyright © 2003 Codehaus. All Rights Reserved.