org.picocontainer
Interface PicoContainer

All Superinterfaces:
Disposable, Startable
All Known Subinterfaces:
MutablePicoContainer
All Known Implementing Classes:
AbstractDelegatingMutablePicoContainer, CachingPicoContainer, DefaultPicoContainer, EmptyPicoContainer, ImmutablePicoContainer, ImplementationHidingCachingPicoContainer, ImplementationHidingPicoContainer

public interface PicoContainer
extends Startable, Disposable

This is the core interface for PicoContainer. It is used to retrieve component instances from the container; it only has accessor methods (in addition to the accept(PicoVisitor) method). In order to register components in a PicoContainer, use a MutablePicoContainer, such as DefaultPicoContainer.

Since:
1.0
Version:
$Revision: 2285 $
Author:
Paul Hammant, Aslak Hellesøy, Jon Tirsén
See Also:
See package description for basic overview how to use PicoContainer.

Method Summary
 void accept(PicoVisitor visitor)
          Accepts a visitor that should visit the child containers, component adapters and component instances.
 ComponentAdapter getComponentAdapter(java.lang.Object componentKey)
          Find a component adapter associated with the specified key.
 ComponentAdapter getComponentAdapterOfType(java.lang.Class componentType)
          Find a component adapter associated with the specified type.
 java.util.Collection getComponentAdapters()
          Retrieve all the component adapters inside this container.
 java.util.List getComponentAdaptersOfType(java.lang.Class componentType)
          Retrieve all component adapters inside this container that are associated with the specified type.
 java.lang.Object getComponentInstance(java.lang.Object componentKey)
          Retrieve a component instance registered with a specific key.
 java.lang.Object getComponentInstanceOfType(java.lang.Class componentType)
          Find a component instance matching the specified type.
 java.util.List getComponentInstances()
          Retrieve all the registered component instances in the container, (not including those in the parent container).
 java.util.List getComponentInstancesOfType(java.lang.Class componentType)
          Returns a List of components of a certain componentType.
 PicoContainer getParent()
          Retrieve the parent container of this container.
 void verify()
          Deprecated. since 1.1 - Use "new VerifyingVisitor().traverse(this)"
 
Methods inherited from interface org.picocontainer.Startable
start, stop
 
Methods inherited from interface org.picocontainer.Disposable
dispose
 

Method Detail

getComponentInstance

java.lang.Object getComponentInstance(java.lang.Object componentKey)
Retrieve a component instance registered with a specific key. If a component cannot be found in this container, the parent container (if one exists) will be searched.

Parameters:
componentKey - the key that the component was registered with.
Returns:
an instantiated component, or null if no component has been registered for the specified key.

getComponentInstanceOfType

java.lang.Object getComponentInstanceOfType(java.lang.Class componentType)
Find a component instance matching the specified type.

Parameters:
componentType - the type of the component
Returns:
an instantiated component matching the class, or null if no component has been registered with a matching type
Throws:
PicoException - if the instantiation of the component fails

getComponentInstances

java.util.List getComponentInstances()
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.

Returns:
all the components.
Throws:
PicoException - if the instantiation of the component fails

getParent

PicoContainer getParent()
Retrieve the parent container of this container.

Returns:
a PicoContainer instance, or null if this container does not have a parent.

getComponentAdapter

ComponentAdapter getComponentAdapter(java.lang.Object componentKey)
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.

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.

getComponentAdapterOfType

ComponentAdapter getComponentAdapterOfType(java.lang.Class componentType)
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.

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

java.util.Collection getComponentAdapters()
Retrieve all the component adapters inside this container. The component adapters from the parent container are not returned.

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.

getComponentAdaptersOfType

java.util.List getComponentAdaptersOfType(java.lang.Class componentType)
Retrieve all component adapters inside this container that are associated with the specified type. The component adapters from the parent container are not returned.

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.

verify

void verify()
            throws PicoVerificationException
Deprecated. since 1.1 - Use "new VerifyingVisitor().traverse(this)"

Verify that the dependencies for all the registered components can be satisfied. No components are instantiated during the verification process.

Throws:
PicoVerificationException - if there are unsatisifiable dependencies.

getComponentInstancesOfType

java.util.List getComponentInstancesOfType(java.lang.Class componentType)
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.

Parameters:
componentType - the searched type.
Returns:
a List of components.
Throws:
PicoException - if the instantiation of a component fails
Since:
1.1

accept

void accept(PicoVisitor visitor)
Accepts a visitor that should visit the child containers, component adapters and component instances.

Parameters:
visitor - the visitor
Since:
1.1