public class DefaultPicoContainer extends java.lang.Object implements MutablePicoContainer
Modifier and Type | Class and Description |
---|---|
static class |
DefaultPicoContainer.InstanceComponentAdapter |
Constructor and Description |
---|
DefaultPicoContainer() |
DefaultPicoContainer(PicoContainer parent) |
Modifier and Type | Method and Description |
---|---|
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<ComponentAdapter> |
getComponentAdapters()
Retrieve all the component adapters inside this container.
|
java.util.List<ComponentAdapter> |
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.
|
PicoContainer |
getParent()
Retrieve the parent container of this container.
|
<T> T |
getService(java.lang.Class<T> serviceClass) |
ComponentAdapter |
getServiceAdapter(java.lang.String key) |
ComponentAdapter |
registerComponent(ComponentAdapter componentAdapter)
Register a component via a ComponentAdapter.
|
ComponentAdapter |
registerComponentImplementation(java.lang.Class componentImplementation)
Register a component using the componentImplementation as key.
|
ComponentAdapter |
registerComponentImplementation(java.lang.Object componentKey,
java.lang.Class componentImplementation)
Register a component.
|
ComponentAdapter |
registerComponentImplementation(java.lang.Object componentKey,
java.lang.Class componentImplementation,
Parameter[] parameters)
Register a component.
|
ComponentAdapter |
registerComponentInstance(java.lang.Object component)
Register an arbitrary object.
|
ComponentAdapter |
registerComponentInstance(java.lang.Object componentKey,
java.lang.Object componentInstance)
Register an arbitrary object as a component in the container.
|
void |
release() |
java.lang.String |
toString() |
ComponentAdapter |
unregisterComponent(java.lang.Object componentKey)
Unregister a component by key.
|
public DefaultPicoContainer(PicoContainer parent)
public DefaultPicoContainer()
public java.util.Collection<ComponentAdapter> getComponentAdapters()
PicoContainer
getComponentAdapters
in interface PicoContainer
ComponentAdapter
s inside this container. The collection will not
be modifiable.a variant of this method which returns the component adapters inside this
container that are associated with the specified type.
public final ComponentAdapter getComponentAdapter(java.lang.Object componentKey)
PicoContainer
getComponentAdapter
in interface PicoContainer
componentKey
- the key that the component was registered with.null
if no component has been
registered for the specified key.public void release()
public ComponentAdapter getComponentAdapterOfType(java.lang.Class componentType)
PicoContainer
getComponentAdapterOfType
in interface PicoContainer
componentType
- the type of the component.null
if no component has been
registered for the specified key.public java.util.List<ComponentAdapter> getComponentAdaptersOfType(java.lang.Class componentType)
PicoContainer
getComponentAdaptersOfType
in interface PicoContainer
componentType
- the type of the components.ComponentAdapter
s inside this container that are associated with
the specified type. Changes to this collection will not be reflected in the container itself.public ComponentAdapter registerComponent(ComponentAdapter componentAdapter)
MutablePicoContainer
registerComponent
in interface MutablePicoContainer
componentAdapter
- the adapterpublic ComponentAdapter unregisterComponent(java.lang.Object componentKey)
MutablePicoContainer
unregisterComponent
in interface MutablePicoContainer
componentKey
- key of the component to unregister.public java.lang.Object getComponentInstance(java.lang.Object componentKey)
PicoContainer
getComponentInstance
in interface PicoContainer
componentKey
- the key that the component was registered with.null
if no component has been registered for the specified
key.public <T> T getService(java.lang.Class<T> serviceClass)
public final ComponentAdapter getServiceAdapter(java.lang.String key)
public java.lang.Object getComponentInstanceOfType(java.lang.Class componentType)
PicoContainer
getComponentInstanceOfType
in interface PicoContainer
componentType
- the type of the componentnull
if no component has been registered
with a matching typepublic ComponentAdapter registerComponentInstance(java.lang.Object component)
MutablePicoContainer
registerComponentImplementation(componentImplementation, componentImplementation)
.registerComponentInstance
in interface MutablePicoContainer
getXXX()
methods of the
PicoContainer
interface can be used to retrieve a reference to the component later on.public ComponentAdapter registerComponentInstance(java.lang.Object componentKey, java.lang.Object componentInstance)
MutablePicoContainer
registerComponentInstance
in interface MutablePicoContainer
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.getXXX()
methods of the
PicoContainer
interface can be used to retrieve a reference to the component later on.public ComponentAdapter registerComponentImplementation(java.lang.Class componentImplementation)
MutablePicoContainer
registerComponentImplementation(componentImplementation, componentImplementation)
.registerComponentImplementation
in interface MutablePicoContainer
componentImplementation
- the concrete component class.getXXX()
methods of the
PicoContainer
interface can be used to retrieve a reference to the component later on.public ComponentAdapter registerComponentImplementation(java.lang.Object componentKey, java.lang.Class componentImplementation)
MutablePicoContainer
registerComponentImplementation
in interface MutablePicoContainer
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).getXXX()
methods of the
PicoContainer
interface can be used to retrieve a reference to the component later on.a variant of this method that allows more control
over the parameters passed into the componentImplementation constructor when constructing an instance.
public ComponentAdapter registerComponentImplementation(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters)
MutablePicoContainer
registerComponentImplementation
in interface MutablePicoContainer
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.getXXX()
methods of the
PicoContainer
interface can be used to retrieve a reference to the component later on.public PicoContainer getParent()
PicoContainer
getParent
in interface PicoContainer
PicoContainer
instance, or null
if this container does not have a parent.public java.lang.String toString()
toString
in class java.lang.Object