org.picocontainer
Interface MutablePicoContainer

All Superinterfaces:
Disposable, PicoContainer, Startable
All Known Implementing Classes:
DefaultPicoContainer

public interface MutablePicoContainer
extends PicoContainer

This is the core interface used for registration of components with a container. It is possible to register an implementation class, an instance or a ComponentAdapter.

Since:
1.0
Version:
$Revision: 1.30 $
Author:
Paul Hammant, Aslak Hellesøy, Jon Tirsén
See Also:
"The The package description has a basic overview of how to use the picocontainer package."

Method Summary
 ComponentAdapter registerComponent(ComponentAdapter componentAdapter)
          Register a component via a ComponentAdapter.
 ComponentAdapter registerComponentImplementation(Class componentImplementation)
          Register a component using the componentImplementation as key.
 ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation)
          Register a component.
 ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters)
          Register a component.
 ComponentAdapter registerComponentInstance(Object componentInstance)
          Register an arbitrary object.
 ComponentAdapter registerComponentInstance(Object componentKey, Object componentInstance)
          Register an arbitrary object as a component in the container.
 void setParent(PicoContainer parent)
          Deprecated. This will probably go away. implementations should take the parent in the constructor (constructor injection!)
 ComponentAdapter unregisterComponent(Object componentKey)
          Unregister a component by key.
 ComponentAdapter unregisterComponentByInstance(Object componentInstance)
          Unregister a component by instance.
 
Methods inherited from interface org.picocontainer.PicoContainer
addOrderedComponentAdapter, getComponentAdapter, getComponentAdapterOfType, getComponentAdapters, getComponentAdaptersOfType, getComponentInstance, getComponentInstanceOfType, getComponentInstances, getParent, verify
 
Methods inherited from interface org.picocontainer.Startable
start, stop
 
Methods inherited from interface org.picocontainer.Disposable
dispose
 

Method Detail

registerComponentImplementation

public ComponentAdapter registerComponentImplementation(Object componentKey,
                                                        Class componentImplementation)
                                                 throws PicoRegistrationException
Register a component.

Parameters:
componentKey - a key that identifies the component. Must be unique within the container. The type of the key object has no semantic significance unless explicitly specified in the documentation of the implementing container.
componentImplementation - the component's implementation class. This must be a concrete class (ie, a class that can be instantiated).
Returns:
the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the PicoContainer interface can be used to retrieve a reference to the component later on.
Throws:
PicoRegistrationException - if registration of the component fails.
See Also:
a variant of this method that allows more control over the parameters passed into the componentImplementation constructor when constructing an instance.

registerComponentImplementation

public ComponentAdapter registerComponentImplementation(Object componentKey,
                                                        Class componentImplementation,
                                                        Parameter[] parameters)
                                                 throws PicoRegistrationException
Register a component.

Parameters:
componentKey - a key that identifies the component. Must be unique within the container. The type of the key object has no semantic significance unless explicitly specified in the documentation of the implementing container.
componentImplementation - the component's implementation class. This must be a concrete class (ie, a class that can be instantiated).
parameters - an array of parameters that gives the container hints about what arguments to pass to the constructor when it is instantiated. Container implementations may ignore one or more of these hints.
Returns:
the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the PicoContainer interface can be used to retrieve a reference to the component later on.
Throws:
PicoRegistrationException - if registration of the component fails.

registerComponentImplementation

public ComponentAdapter registerComponentImplementation(Class componentImplementation)
                                                 throws PicoRegistrationException
Register a component using the componentImplementation as key. Calling this method is equivalent to calling registerComponentImplementation(componentImplementation, componentImplementation).

Parameters:
componentImplementation - the concrete component class.
Returns:
the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the PicoContainer interface can be used to retrieve a reference to the component later on.
Throws:
PicoRegistrationException - if registration fails.

registerComponentInstance

public ComponentAdapter registerComponentInstance(Object componentInstance)
                                           throws PicoRegistrationException
Register an arbitrary object. The class of the object will be used as a key. Calling this method is equivalent to calling * registerComponentImplementation(componentImplementation, componentImplementation).

Parameters:
componentInstance -
Returns:
the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the PicoContainer interface can be used to retrieve a reference to the component later on.
Throws:
PicoRegistrationException - if registration fails.

registerComponentInstance

public ComponentAdapter registerComponentInstance(Object componentKey,
                                                  Object componentInstance)
                                           throws PicoRegistrationException
Register an arbitrary object as a component 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.

Beware that too much use of this method is an antipattern.

Parameters:
componentKey - a key that identifies the component. Must be unique within the conainer. The type of the key object has no semantic significance unless explicitly specified in the implementing container.
componentInstance - an arbitrary object.
Returns:
the ComponentAdapter that has been associated with this component. In the majority of cases, this return value can be safely ignored, as one of the getXXX() methods of the PicoContainer interface can be used to retrieve a reference to the component later on.
Throws:
PicoRegistrationException - if registration fails.

registerComponent

public ComponentAdapter registerComponent(ComponentAdapter componentAdapter)
                                   throws PicoRegistrationException
Register a component via a ComponentAdapter. Use this if you need fine grained control over what ComponentAdapter to use for a specific component.

Parameters:
componentAdapter - the adapter
Returns:
the same adapter that was passed as an argument.
Throws:
PicoRegistrationException - if registration fails.

unregisterComponent

public ComponentAdapter unregisterComponent(Object componentKey)
Unregister a component by key.

Parameters:
componentKey - key of the component to unregister.
Returns:
the ComponentAdapter that was associated with this component.

unregisterComponentByInstance

public ComponentAdapter unregisterComponentByInstance(Object componentInstance)
Unregister a component by instance.

Parameters:
componentInstance - the component instance to unregister.
Returns:
the ComponentAdapter that was associated with this component.

setParent

public void setParent(PicoContainer parent)
Deprecated. This will probably go away. implementations should take the parent in the constructor (constructor injection!)

Set the Parent container.

Parameters:
parent - parent container.


Copyright © 2003-2004 Codehaus. All Rights Reserved.