org.picocontainer

Interface PicoContainer

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 method). In order to register components in a PicoContainer, use a MutablePicoContainer, such as org.picocontainer.defaults.DefaultPicoContainer.

Since: 1.0

See Also: See package description for basic overview how to use PicoContainer.

Method Summary
voidaccept(PicoVisitor visitor)
Accepts a visitor that should visit the child containers, component adapters and component instances.
ComponentAdaptergetComponentAdapter(Object componentKey)
Find a component adapter associated with the specified key.
ComponentAdaptergetComponentAdapterOfType(Class componentType)
Find a component adapter associated with the specified type.
CollectiongetComponentAdapters()
Retrieve all the component adapters inside this container.
ListgetComponentAdaptersOfType(Class componentType)
Retrieve all component adapters inside this container that are associated with the specified type.
ObjectgetComponentInstance(Object componentKey)
Retrieve a component instance registered with a specific key.
ObjectgetComponentInstanceOfType(Class componentType)
Find a component instance matching the specified type.
ListgetComponentInstances()
Retrieve all the registered component instances in the container, (not including those in the parent container).
ListgetComponentInstancesOfType(Class componentType)
Returns a List of components of a certain componentType.
PicoContainergetParent()
Retrieve the parent container of this container.
voidverify()
Verify that the dependencies for all the registered components can be satisfied.

Method Detail

accept

public 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

getComponentAdapter

public ComponentAdapter getComponentAdapter(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

public ComponentAdapter getComponentAdapterOfType(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

public 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

public List getComponentAdaptersOfType(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.

getComponentInstance

public Object getComponentInstance(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

public Object getComponentInstanceOfType(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

public 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

getComponentInstancesOfType

public List getComponentInstancesOfType(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

getParent

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

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

verify

public void verify()

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.