org.picocontainer.defaults
Class DefaultPicoContainer

java.lang.Object
  extended byorg.picocontainer.defaults.DefaultPicoContainer
All Implemented Interfaces:
PicoContainer, RegistrationPicoContainer, Serializable
Direct Known Subclasses:
DefaultPicoContainer.Default, DefaultPicoContainer.WithComponentFactory, DefaultPicoContainer.WithComponentRegistry

public class DefaultPicoContainer
extends Object
implements RegistrationPicoContainer, Serializable

Abstract baseclass for various PicoContainer implementations.

Version:
$Revision: 1.8 $
Author:
Aslak Hellesoy
See Also:
Serialized Form

Nested Class Summary
static class DefaultPicoContainer.Default
           
static class DefaultPicoContainer.WithComponentFactory
           
static class DefaultPicoContainer.WithComponentRegistry
           
 
Field Summary
protected  List unmanagedComponents
           
 
Constructor Summary
DefaultPicoContainer(ComponentFactory componentFactory, ComponentRegistry componentRegistry)
           
 
Method Summary
 void addParameterToComponent(Object componentKey, Class parameter, Object arg)
          Add a parameter to a component.
 Object getComponent(Object componentKey)
          Get a component for a component type.
 Collection getComponentKeys()
          Get all component types (random order).
 Object getComponentMulticaster()
          Shorthand for getComponentMulticaster(boolean, boolean)(true, true).
 Object getComponentMulticaster(boolean callInInstantiationOrder, boolean callUnmanagedComponents)
          Returns a proxy that implements the union of all the components' interfaces.
 Collection getComponents()
          Get all components (random order).
 boolean hasComponent(Object componentKey)
          Does the internals have a partilcilar component type?
 void instantiateComponents()
          Initialize the internals.
 void registerComponent(Object componentKey, Class componentImplementation)
          Alternate way of registering components with additional component type.
 void registerComponent(Object componentKey, Class componentImplementation, Parameter[] parameters)
          Register component with key, implementation and bindings for its parameters.
 void registerComponent(Object componentKey, Object component)
          Registers a component that is instantiated and configured outside the internals.
 void registerComponentByClass(Class componentImplementation)
          Registers a component.
 void registerComponentByInstance(Object component)
          Registers an instantiated component.
 void unregisterComponent(Object componentKey)
          TODO promote to RegistrationPicoContainer, it's all Pauls fault anyway
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unmanagedComponents

protected List unmanagedComponents
Constructor Detail

DefaultPicoContainer

public DefaultPicoContainer(ComponentFactory componentFactory,
                            ComponentRegistry componentRegistry)
Method Detail

getComponentMulticaster

public final Object getComponentMulticaster()
Description copied from interface: PicoContainer
Shorthand for PicoContainer.getComponentMulticaster(boolean, boolean)(true, true).

Specified by:
getComponentMulticaster in interface PicoContainer
Returns:
a proxy.

getComponentMulticaster

public final Object getComponentMulticaster(boolean callInInstantiationOrder,
                                            boolean callUnmanagedComponents)
Description copied from interface: PicoContainer
Returns a proxy that implements the union of all the components' interfaces. Calling a method on the returned Object will call the method on all components in the internals that implement that interface.

Specified by:
getComponentMulticaster in interface PicoContainer
Parameters:
callInInstantiationOrder - whether to call the methods in the order of instantiation (true) or reverse (false)
callUnmanagedComponents - whether to exclude components registered via instance rather than class

registerComponent

public void registerComponent(Object componentKey,
                              Class componentImplementation)
                       throws DuplicateComponentKeyRegistrationException,
                              AssignabilityRegistrationException,
                              NotConcreteRegistrationException,
                              PicoIntrospectionException
Description copied from interface: RegistrationPicoContainer
Alternate way of registering components with additional component type.

Specified by:
registerComponent in interface RegistrationPicoContainer
Parameters:
componentKey - Component type
componentImplementation - The class of the component to instantiate
Throws:
DuplicateComponentKeyRegistrationException
AssignabilityRegistrationException
NotConcreteRegistrationException
PicoIntrospectionException

registerComponent

public void registerComponent(Object componentKey,
                              Class componentImplementation,
                              Parameter[] parameters)
                       throws NotConcreteRegistrationException,
                              AssignabilityRegistrationException,
                              DuplicateComponentKeyRegistrationException
Description copied from interface: RegistrationPicoContainer
Register component with key, implementation and bindings for its parameters.

Specified by:
registerComponent in interface RegistrationPicoContainer
Parameters:
componentKey - Component type
componentImplementation - The class of the component to instantiate
Throws:
NotConcreteRegistrationException
AssignabilityRegistrationException
DuplicateComponentKeyRegistrationException

registerComponentByInstance

public void registerComponentByInstance(Object component)
                                 throws PicoRegistrationException,
                                        PicoIntrospectionException
Description copied from interface: RegistrationPicoContainer
Registers an instantiated component. This might be because you are creating trees of Pico containers or if you have a class that you want treated as a component, but is not Pico component compatible. Will use the components class as key.

Specified by:
registerComponentByInstance in interface RegistrationPicoContainer
Parameters:
component - The pre instantiated component to register
Throws:
PicoRegistrationException
PicoIntrospectionException

registerComponent

public void registerComponent(Object componentKey,
                              Object component)
                       throws PicoRegistrationException,
                              PicoIntrospectionException
Description copied from interface: RegistrationPicoContainer
Registers a component that is instantiated and configured outside the internals. Useful in cases where pico doesn't have sufficient knowledge to instantiate a component.

Specified by:
registerComponent in interface RegistrationPicoContainer
Parameters:
componentKey - Component type
component - preinstantiated component
Throws:
PicoRegistrationException - If a registration problem
PicoIntrospectionException

addParameterToComponent

public void addParameterToComponent(Object componentKey,
                                    Class parameter,
                                    Object arg)
                             throws PicoIntrospectionException
Description copied from interface: RegistrationPicoContainer
Add a parameter to a component. Used for configuring them. Very liekly to change before release.

Specified by:
addParameterToComponent in interface RegistrationPicoContainer
Parameters:
componentKey - The component type
parameter - The parameter it pertains to
arg - The argukemt to pass in.
Throws:
PicoIntrospectionException

registerComponentByClass

public void registerComponentByClass(Class componentImplementation)
                              throws DuplicateComponentKeyRegistrationException,
                                     AssignabilityRegistrationException,
                                     NotConcreteRegistrationException,
                                     PicoIntrospectionException
Description copied from interface: RegistrationPicoContainer
Registers a component. Same as calling RegistrationPicoContainer.registerComponent(Object, Class) with the componentImplementation as key.

Specified by:
registerComponentByClass in interface RegistrationPicoContainer
Parameters:
componentImplementation - The class of the component to instantiate
Throws:
DuplicateComponentKeyRegistrationException
AssignabilityRegistrationException
NotConcreteRegistrationException
PicoIntrospectionException

unregisterComponent

public void unregisterComponent(Object componentKey)
TODO promote to RegistrationPicoContainer, it's all Pauls fault anyway

Parameters:
componentKey -

instantiateComponents

public void instantiateComponents()
                           throws PicoInitializationException,
                                  PicoInvocationTargetInitializationException
Description copied from interface: PicoContainer
Initialize the internals.

Specified by:
instantiateComponents in interface PicoContainer
Throws:
PicoInitializationException
PicoInvocationTargetInitializationException

getComponent

public Object getComponent(Object componentKey)
Description copied from interface: PicoContainer
Get a component for a component type.

Specified by:
getComponent in interface PicoContainer
Parameters:
componentKey - The component type to look for.
Returns:
the component, or null of no such component.

getComponents

public Collection getComponents()
Description copied from interface: PicoContainer
Get all components (random order).

Specified by:
getComponents in interface PicoContainer
Returns:
A collection of components.

getComponentKeys

public Collection getComponentKeys()
Description copied from interface: PicoContainer
Get all component types (random order).

Specified by:
getComponentKeys in interface PicoContainer
Returns:
A collection of component types.

hasComponent

public final boolean hasComponent(Object componentKey)
Description copied from interface: PicoContainer
Does the internals have a partilcilar component type?

Specified by:
hasComponent in interface PicoContainer
Parameters:
componentKey - The component type to look for.
Returns:
true if it does have the component type


Copyright © 2003 Codehaus. All Rights Reserved.