org.picocontainer.PicoContainer Maven / Gradle / Ivy
/*****************************************************************************
* Copyright (C) PicoContainer Organization. All rights reserved. *
* ------------------------------------------------------------------------- *
* The software in this package is published under the terms of the BSD *
* style license a copy of which has been included with this distribution in *
* the LICENSE.txt file. *
* *
* Original code by *
*****************************************************************************/
package org.picocontainer;
import java.util.Collection;
import java.util.List;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* 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 {@link #accept(PicoVisitor)} method). In order to register components in a
* PicoContainer, use a {@link MutablePicoContainer}, such as {@link DefaultPicoContainer}.
*
* @author Paul Hammant
* @author Aslak Hellesøy
* @author Jon Tirsén
* @see See package description for basic overview how to use
* PicoContainer.
*/
public 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.
*
* @param componentKeyOrType the key or Type that the component was registered with.
* @return an instantiated component, or null
if no component has been registered for the specified
* key.
*/
Object getComponent(Object componentKeyOrType);
Object getComponent(Object componentKeyOrType, Type into);
/**
* Retrieve a component keyed by the component type.
* @param componentType the type of the component
* @return the typed resulting object instance or null if the object does not exist.
*/
T getComponent(Class componentType);
/**
* Retrieve a component keyed by the component type and binding type.
* @param componentType the type of the component
* @param binding the binding type of the component
* @return the typed resulting object instance or null if the object does not exist.
*/
T getComponent(Class componentType, Class extends Annotation> binding);
/**
* 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.
*
* @return all the components.
* @throws PicoException if the instantiation of the component fails
*/
List