org.picocontainer.classname
Class DefaultClassLoadingPicoContainer

java.lang.Object
  extended by org.picocontainer.containers.AbstractDelegatingPicoContainer
      extended by org.picocontainer.containers.AbstractDelegatingMutablePicoContainer
          extended by org.picocontainer.classname.DefaultClassLoadingPicoContainer
All Implemented Interfaces:
Serializable, ClassLoadingPicoContainer, ComponentMonitorStrategy, Converting, Disposable, MutablePicoContainer, PicoContainer, Startable

public class DefaultClassLoadingPicoContainer
extends AbstractDelegatingMutablePicoContainer
implements ClassLoadingPicoContainer, ComponentMonitorStrategy

Default implementation of ClassLoadingPicoContainer.

Author:
Paul Hammant, Mauro Talevi, Michael Rimov
See Also:
Serialized Form

Field Summary
protected  Map<String,PicoContainer> namedChildContainers
           
 
Constructor Summary
DefaultClassLoadingPicoContainer()
           
DefaultClassLoadingPicoContainer(ClassLoader classLoader)
           
DefaultClassLoadingPicoContainer(ClassLoader classLoader, ComponentFactory componentFactory, PicoContainer parent)
           
DefaultClassLoadingPicoContainer(ClassLoader classLoader, MutablePicoContainer delegate)
           
DefaultClassLoadingPicoContainer(ClassLoader classLoader, PicoContainer parent, ComponentMonitor componentMonitor)
           
DefaultClassLoadingPicoContainer(ComponentFactory componentFactory)
           
DefaultClassLoadingPicoContainer(ComponentFactory componentFactory, LifecycleStrategy lifecycleStrategy, PicoContainer parent, ClassLoader cl, ComponentMonitor componentMonitor)
           
DefaultClassLoadingPicoContainer(MutablePicoContainer delegate)
           
DefaultClassLoadingPicoContainer(PicoContainer parent)
           
 
Method Summary
 MutablePicoContainer addAdapter(ComponentAdapter<?> componentAdapter)
          Register a component via a ComponentAdapter.
 MutablePicoContainer addChildContainer(PicoContainer child)
          Add a child container.
 ClassLoadingPicoContainer addChildContainer(String name, PicoContainer child)
          Addes a child container with a given name
 ClassPathElement addClassLoaderURL(URL url)
          Adds a new URL that will be used in classloading
 MutablePicoContainer addComponent(Object implOrInstance)
          Register an arbitrary object.
 MutablePicoContainer addComponent(Object key, 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 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 changeMonitor(ComponentMonitor monitor)
          Propagates the monitor change down the delegate chain if a delegate that implements ComponentMonitorStrategy exists.
protected  DefaultClassLoadingPicoContainer createChildContainer()
           
 ComponentMonitor currentMonitor()
          Returns the monitor currently used
 Object getComponent(Object componentKeyOrType)
          Retrieve a component instance registered with a specific key or type.
 ComponentAdapter<?> getComponentAdapter(Object componentKey)
          Find a component adapter associated with the specified key.
 ClassLoader getComponentClassLoader()
          Returns class loader that is the aggregate of the URLs added.
protected  Map<String,PicoContainer> getNamedContainers()
           
 MutablePicoContainer makeChildContainer()
          Make a child container, using the same implementation of MutablePicoContainer as the parent.
 ClassLoadingPicoContainer makeChildContainer(String name)
          Makes a child container with the same basic characteristics of this object (ComponentFactory, PicoContainer type, Behavior, etc)
 boolean removeChildContainer(PicoContainer child)
          Remove a child container from this container.
 
Methods inherited from class org.picocontainer.containers.AbstractDelegatingMutablePicoContainer
addConfig, dispose, getDelegate, removeComponent, removeComponentByInstance, setLifecycleState, setName, start, stop
 
Methods inherited from class org.picocontainer.containers.AbstractDelegatingPicoContainer
accept, equals, getComponent, getComponent, getComponent, getComponentAdapter, getComponentAdapter, getComponentAdapters, getComponentAdapters, getComponentAdapters, getComponents, getComponents, getConverters, getParent, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.picocontainer.MutablePicoContainer
addConfig, removeComponent, removeComponentByInstance, setLifecycleState, setName
 
Methods inherited from interface org.picocontainer.PicoContainer
accept, getComponent, getComponent, getComponent, getComponentAdapter, getComponentAdapter, getComponentAdapters, getComponentAdapters, getComponentAdapters, getComponents, getComponents, getParent
 
Methods inherited from interface org.picocontainer.Startable
start, stop
 
Methods inherited from interface org.picocontainer.Disposable
dispose
 

Field Detail

namedChildContainers

protected final Map<String,PicoContainer> namedChildContainers
Constructor Detail

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(ClassLoader classLoader,
                                        ComponentFactory componentFactory,
                                        PicoContainer parent)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(ClassLoader classLoader,
                                        MutablePicoContainer delegate)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(ClassLoader classLoader,
                                        PicoContainer parent,
                                        ComponentMonitor componentMonitor)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(ComponentFactory componentFactory)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(PicoContainer parent)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(MutablePicoContainer delegate)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(ClassLoader classLoader)

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer()

DefaultClassLoadingPicoContainer

public DefaultClassLoadingPicoContainer(ComponentFactory componentFactory,
                                        LifecycleStrategy lifecycleStrategy,
                                        PicoContainer parent,
                                        ClassLoader cl,
                                        ComponentMonitor componentMonitor)
Method Detail

createChildContainer

protected DefaultClassLoadingPicoContainer createChildContainer()

changeMonitor

public void changeMonitor(ComponentMonitor monitor)
Propagates the monitor change down the delegate chain if a delegate that implements ComponentMonitorStrategy exists. Because of the ComponentMonitorStrategy API, not all delegates can have their API changed. If a delegate implementing ComponentMonitorStrategy cannot be found, an exception is thrown.

Specified by:
changeMonitor in interface ComponentMonitorStrategy
Parameters:
monitor - the monitor to swap.
Throws:
IllegalStateException - if no delegate can be found that implements ComponentMonitorStrategy.

currentMonitor

public ComponentMonitor currentMonitor()
Description copied from interface: ComponentMonitorStrategy
Returns the monitor currently used

Specified by:
currentMonitor in interface ComponentMonitorStrategy
Returns:
The ComponentMonitor currently used

getComponent

public final Object getComponent(Object componentKeyOrType)
                          throws PicoException
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
Overrides:
getComponent in class AbstractDelegatingPicoContainer
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.
Throws:
PicoException

makeChildContainer

public final MutablePicoContainer makeChildContainer()
Description copied from interface: MutablePicoContainer
Make a child container, using the same implementation of MutablePicoContainer as the parent. It will have a reference to this as parent. This will list the resulting MPC as a child. Lifecycle events will be cascaded from parent to child as a consequence of this.

Specified by:
makeChildContainer in interface MutablePicoContainer
Overrides:
makeChildContainer in class AbstractDelegatingMutablePicoContainer
Returns:
the new child container.

makeChildContainer

public ClassLoadingPicoContainer makeChildContainer(String name)
Makes a child container with the same basic characteristics of this object (ComponentFactory, PicoContainer type, Behavior, etc)

Specified by:
makeChildContainer in interface ClassLoadingPicoContainer
Parameters:
name - the name of the child container
Returns:
The child 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
Overrides:
removeChildContainer in class AbstractDelegatingMutablePicoContainer
Parameters:
child - the child container
Returns:
true if the child container has been removed.

getNamedContainers

protected final Map<String,PicoContainer> getNamedContainers()

addClassLoaderURL

public ClassPathElement addClassLoaderURL(URL url)
Description copied from interface: ClassLoadingPicoContainer
Adds a new URL that will be used in classloading

Specified by:
addClassLoaderURL in interface ClassLoadingPicoContainer
Parameters:
url - url of the jar to find components in.
Returns:
ClassPathElement to add permissions to (subject to security policy)

addComponent

public MutablePicoContainer addComponent(Object implOrInstance)
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
Overrides:
addComponent in class AbstractDelegatingMutablePicoContainer
Parameters:
implOrInstance - Component implementation or instance
Returns:
the same instance of MutablePicoContainer

addComponent

public MutablePicoContainer addComponent(Object key,
                                         Object componentImplementationOrInstance,
                                         Parameter... parameters)
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


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. The adapter will be wrapped in whatever behaviors that the the container has been set up with. If you want to bypass that behavior for the adapter you are adding, you should use Characteristics.NONE like so pico.as(Characteristics.NONE).addAdapter(...)

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

getComponentClassLoader

public ClassLoader getComponentClassLoader()
Description copied from interface: ClassLoadingPicoContainer
Returns class loader that is the aggregate of the URLs added.

Specified by:
getComponentClassLoader in interface ClassLoadingPicoContainer
Returns:
A ClassLoader

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
Overrides:
addChildContainer in class AbstractDelegatingMutablePicoContainer
Parameters:
child - the child container
Returns:
the same instance of MutablePicoContainer

addChildContainer

public ClassLoadingPicoContainer addChildContainer(String name,
                                                   PicoContainer child)
Description copied from interface: ClassLoadingPicoContainer
Addes a child container with a given name

Specified by:
addChildContainer in interface ClassLoadingPicoContainer
Parameters:
name - the container name
child - the child PicoContainer

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
Overrides:
getComponentAdapter in class AbstractDelegatingPicoContainer
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.

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
Overrides:
change in class AbstractDelegatingMutablePicoContainer
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
Overrides:
as in class AbstractDelegatingMutablePicoContainer
Returns:
the same Pico instance with temporary properties


Copyright © 2003-2010 Codehaus. All Rights Reserved.