Package org.picocontainer.containers
Class ImmutablePicoContainer
- java.lang.Object
-
- org.picocontainer.containers.ImmutablePicoContainer
-
- All Implemented Interfaces:
java.io.Serializable,Converting,PicoContainer
public final class ImmutablePicoContainer extends java.lang.Object implements PicoContainer, Converting, java.io.Serializable
wrap pico container to achieve immutability Typically its used to mock a parent container.- Author:
- Konstantin Pribluda
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ImmutablePicoContainer(PicoContainer delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(PicoVisitor visitor)Accepts a visitor that should visit the child containers, component adapters and component instances.booleanequals(java.lang.Object obj)<T> TgetComponent(java.lang.Class<T> componentType)Retrieve a component keyed by the component type.<T> TgetComponent(java.lang.Class<T> componentType, java.lang.Class<? extends java.lang.annotation.Annotation> binding)Retrieve a component keyed by the component type and binding type.java.lang.ObjectgetComponent(java.lang.Object componentKeyOrType)Retrieve a component instance registered with a specific key or type.java.lang.ObjectgetComponent(java.lang.Object componentKeyOrType, java.lang.reflect.Type into)<T> ComponentAdapter<T>getComponentAdapter(java.lang.Class<T> componentType, java.lang.Class<? extends java.lang.annotation.Annotation> binding)Find a component adapter associated with the specified type and binding type.<T> ComponentAdapter<T>getComponentAdapter(java.lang.Class<T> componentType, NameBinding componentNameBinding)Find a component adapter associated with the specified type and binding name.ComponentAdapter<?>getComponentAdapter(java.lang.Object componentKey)Find a component adapter associated with the specified key.java.util.Collection<ComponentAdapter<?>>getComponentAdapters()Retrieve all the component adapters inside this container.<T> java.util.List<ComponentAdapter<T>>getComponentAdapters(java.lang.Class<T> componentType)Retrieve all component adapters inside this container that are associated with the specified type.<T> java.util.List<ComponentAdapter<T>>getComponentAdapters(java.lang.Class<T> componentType, java.lang.Class<? extends java.lang.annotation.Annotation> binding)Retrieve all component adapters inside this container that are associated with the specified type and binding type.java.util.ListgetComponents()Retrieve all the registered component instances in the container, (not including those in the parent container).<T> java.util.List<T>getComponents(java.lang.Class<T> componentType)Returns a List of components of a certain componentType.ConvertersgetConverters()Retrieve the set of converters for transforming string parameters into objects.PicoContainergetParent()Retrieve the parent container of this container.inthashCode()java.lang.StringtoString()
-
-
-
Constructor Detail
-
ImmutablePicoContainer
public ImmutablePicoContainer(PicoContainer delegate)
-
-
Method Detail
-
getComponent
public java.lang.Object getComponent(java.lang.Object componentKeyOrType)
Description copied from interface:PicoContainerRetrieve 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:
getComponentin interfacePicoContainer- Parameters:
componentKeyOrType- the key or Type that the component was registered with.- Returns:
- an instantiated component, or
nullif no component has been registered for the specified key.
-
getComponent
public java.lang.Object getComponent(java.lang.Object componentKeyOrType, java.lang.reflect.Type into)- Specified by:
getComponentin interfacePicoContainer
-
getComponent
public <T> T getComponent(java.lang.Class<T> componentType)
Description copied from interface:PicoContainerRetrieve a component keyed by the component type.- Specified by:
getComponentin interfacePicoContainer- Parameters:
componentType- the type of the component- Returns:
- the typed resulting object instance or null if the object does not exist.
-
getComponent
public <T> T getComponent(java.lang.Class<T> componentType, java.lang.Class<? extends java.lang.annotation.Annotation> binding)Description copied from interface:PicoContainerRetrieve a component keyed by the component type and binding type.- Specified by:
getComponentin interfacePicoContainer- Parameters:
componentType- the type of the componentbinding- the binding type of the component- Returns:
- the typed resulting object instance or null if the object does not exist.
-
getComponents
public java.util.List getComponents()
Description copied from interface:PicoContainerRetrieve 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.- Specified by:
getComponentsin interfacePicoContainer- Returns:
- all the components.
-
getParent
public PicoContainer getParent()
Description copied from interface:PicoContainerRetrieve the parent container of this container.- Specified by:
getParentin interfacePicoContainer- Returns:
- a
PicoContainerinstance, ornullif this container does not have a parent.
-
getComponentAdapter
public ComponentAdapter<?> getComponentAdapter(java.lang.Object componentKey)
Description copied from interface:PicoContainerFind 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:
getComponentAdapterin interfacePicoContainer- Parameters:
componentKey- the key that the component was registered with.- Returns:
- the component adapter associated with this key, or
nullif no component has been registered for the specified key.
-
getComponentAdapter
public <T> ComponentAdapter<T> getComponentAdapter(java.lang.Class<T> componentType, NameBinding componentNameBinding)
Description copied from interface:PicoContainerFind a component adapter associated with the specified type and binding name. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.- Specified by:
getComponentAdapterin interfacePicoContainer- Parameters:
componentType- the type of the component.componentNameBinding- the name binding to use- Returns:
- the component adapter associated with this class, or
nullif no component has been registered for the specified key.
-
getComponentAdapter
public <T> ComponentAdapter<T> getComponentAdapter(java.lang.Class<T> componentType, java.lang.Class<? extends java.lang.annotation.Annotation> binding)
Description copied from interface:PicoContainerFind a component adapter associated with the specified type and binding type. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.- Specified by:
getComponentAdapterin interfacePicoContainer- Parameters:
componentType- the type of the component.binding- the typed binding to use- Returns:
- the component adapter associated with this class, or
nullif no component has been registered for the specified key.
-
getComponentAdapters
public java.util.Collection<ComponentAdapter<?>> getComponentAdapters()
Description copied from interface:PicoContainerRetrieve all the component adapters inside this container. The component adapters from the parent container are not returned.- Specified by:
getComponentAdaptersin interfacePicoContainer- 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.
-
getComponentAdapters
public <T> java.util.List<ComponentAdapter<T>> getComponentAdapters(java.lang.Class<T> componentType)
Description copied from interface:PicoContainerRetrieve all component adapters inside this container that are associated with the specified type. The addComponent adapters from the parent container are not returned.- Specified by:
getComponentAdaptersin interfacePicoContainer- 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.
-
getComponentAdapters
public <T> java.util.List<ComponentAdapter<T>> getComponentAdapters(java.lang.Class<T> componentType, java.lang.Class<? extends java.lang.annotation.Annotation> binding)
Description copied from interface:PicoContainerRetrieve all component adapters inside this container that are associated with the specified type and binding type. The addComponent adapters from the parent container are not returned.- Specified by:
getComponentAdaptersin interfacePicoContainer- Parameters:
componentType- the type of the components.binding- the typed binding to use- 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.
-
getComponents
public <T> java.util.List<T> getComponents(java.lang.Class<T> componentType)
Description copied from interface:PicoContainerReturns a List of components of a certain componentType. The list is ordered by instantiation order, starting with the components instantiated first at the beginning.- Specified by:
getComponentsin interfacePicoContainer- Parameters:
componentType- the searched type.- Returns:
- a List of components.
-
accept
public final void accept(PicoVisitor visitor)
Description copied from interface:PicoContainerAccepts a visitor that should visit the child containers, component adapters and component instances.- Specified by:
acceptin interfacePicoContainer- Parameters:
visitor- the visitor
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getConverters
public Converters getConverters()
Description copied from interface:ConvertingRetrieve the set of converters for transforming string parameters into objects.- Specified by:
getConvertersin interfaceConverting- Returns:
- converter set instance.
-
-