|
![]() |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.picocontainer.defaults.DefaultPicoContainer
The Standard
PicoContainer
/MutablePicoContainer
implementation.
Constructing a container c with a parent p container will cause c to look up components
in p if they cannot be found inside c itself.
Using Class
objects as keys to the various registerXXX() methods makes
a subtle semantic difference:
If there are more than one registered components of the same type and one of them are
registered with a Class
key of the corresponding type, this component
will take precedence over other components during type resolution.
Another place where keys that are classes make a subtle difference is in
ImplementationHidingComponentAdapter
.
This implementation of MutablePicoContainer
also supports
ComponentMonitorStrategy
.
Constructor Summary | |
DefaultPicoContainer()
Creates a new container with a (caching) DefaultComponentAdapterFactory and no parent container. |
|
DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory)
Creates a new container with a custom ComponentAdapterFactory and no parent container. |
|
DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory,
LifecycleStrategy lifecycleStrategyForInstanceRegistrations,
PicoContainer parent)
Creates a new container with a custom ComponentAdapterFactory, LifecycleStrategy for instance registration, and a parent container. |
|
DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory,
PicoContainer parent)
Creates a new container with a custom ComponentAdapterFactory and a parent container. |
|
DefaultPicoContainer(ComponentMonitor monitor)
Creates a new container with the DefaultComponentAdapterFactory using a custom ComponentMonitor |
|
DefaultPicoContainer(ComponentMonitor monitor,
LifecycleStrategy lifecycleStrategy,
PicoContainer parent)
Creates a new container with the DefaultComponentAdapterFactory using a custom ComponentMonitor and lifecycle strategy |
|
DefaultPicoContainer(ComponentMonitor monitor,
PicoContainer parent)
Creates a new container with the DefaultComponentAdapterFactory using a custom ComponentMonitor |
|
DefaultPicoContainer(LifecycleStrategy lifecycleStrategy,
PicoContainer parent)
Creates a new container with the DefaultComponentAdapterFactory using a custom lifecycle strategy |
|
DefaultPicoContainer(PicoContainer parent)
Creates a new container with a (caching) DefaultComponentAdapterFactory
and a parent container. |
Method Summary | |
void |
accept(PicoVisitor visitor)
Accepts a visitor that should visit the child containers, component adapters and component instances. |
boolean |
addChildContainer(PicoContainer child)
Add a child container. |
void |
changeMonitor(ComponentMonitor monitor)
Changes monitor in the ComponentAdapterFactory, the component adapters and the child containers, if these support a ComponentMonitorStrategy. |
ComponentMonitor |
currentMonitor()
Returns the first current monitor found in the ComponentAdapterFactory, the component adapters and the child containers, if these support a ComponentMonitorStrategy. |
void |
dispose()
Dispose the components of this PicoContainer and all its logical child containers. |
ComponentAdapter |
getComponentAdapter(Object componentKey)
Find a component adapter associated with the specified key. |
ComponentAdapter |
getComponentAdapterOfType(Class componentType)
Find a component adapter associated with the specified type. |
Collection |
getComponentAdapters()
Retrieve all the component adapters inside this container. |
List |
getComponentAdaptersOfType(Class componentType)
Retrieve all component adapters inside this container that are associated with the specified type. |
Object |
getComponentInstance(Object componentKey)
Retrieve a component instance registered with a specific key. |
Object |
getComponentInstanceOfType(Class componentType)
Find a component instance matching the specified type. |
List |
getComponentInstances()
Retrieve all the registered component instances in the container, (not including those in the parent container). |
List |
getComponentInstancesOfType(Class componentType)
Returns a List of components of a certain componentType. |
PicoContainer |
getParent()
Retrieve the parent container of this container. |
MutablePicoContainer |
makeChildContainer()
Make a child container, using the same implementation of MutablePicoContainer as the parent. |
ComponentAdapter |
registerComponent(ComponentAdapter componentAdapter)
Register a component via a ComponentAdapter. Use this if you need fine grained control over what ComponentAdapter to use for a specific component. This method can be used to override the ComponentAdapter created by the ComponentAdapterFactory
passed to the constructor of this container. |
ComponentAdapter |
registerComponentImplementation(Class componentImplementation)
Register a component using the componentImplementation as key. Calling this method is equivalent to calling registerComponentImplementation(componentImplementation, componentImplementation) .
The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor. |
ComponentAdapter |
registerComponentImplementation(Object componentKey,
Class componentImplementation)
Register a component. The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor. |
ComponentAdapter |
registerComponentImplementation(Object componentKey,
Class componentImplementation,
List parameters)
Same as registerComponentImplementation(java.lang.Object, java.lang.Class, org.picocontainer.Parameter[])
but with parameters as a List . |
ComponentAdapter |
registerComponentImplementation(Object componentKey,
Class componentImplementation,
Parameter[] parameters)
Register a component and creates specific instructions on which constructor to use, along with which components and/or constants to provide as constructor arguments. These "directives" are provided through an array of Parameter objects. Parameter[0] correspondes to the first constructor argument, Parameter[N] corresponds to the N+1th constructor argument. Tips for Parameter usage
|
ComponentAdapter |
registerComponentInstance(Object component)
Register an arbitrary object. The class of the object will be used as a key. Calling this method is equivalent to calling * registerComponentImplementation(componentImplementation, componentImplementation) .
The returned ComponentAdapter will be an InstanceComponentAdapter . |
ComponentAdapter |
registerComponentInstance(Object componentKey,
Object componentInstance)
Register an arbitrary object as a component in the container. This is handy when other components in the same container have dependencies on this kind of object, but where letting the container manage and instantiate it is impossible. Beware that too much use of this method is an antipattern. The returned ComponentAdapter will be an InstanceComponentAdapter . |
boolean |
removeChildContainer(PicoContainer child)
Remove a child container from this container. |
void |
start()
Start the components of this PicoContainer and all its logical child containers. |
void |
stop()
Stop the components of this PicoContainer and all its logical child containers. |
ComponentAdapter |
unregisterComponent(Object componentKey)
Unregister a component by key. |
ComponentAdapter |
unregisterComponentByInstance(Object componentInstance)
Unregister a component by instance. |
void |
verify()
Verify that the dependencies for all the registered components can be satisfied. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory, PicoContainer parent)
CachingComponentAdapter
instances, such as for example
CachingComponentAdapterFactory
. CachingComponentAdapterFactory can delegate to
other ComponentAdapterFactories.
componentAdapterFactory
- the factory to use for creation of ComponentAdapters.parent
- the parent container (used for component dependency lookups).public DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory, LifecycleStrategy lifecycleStrategyForInstanceRegistrations, PicoContainer parent)
CachingComponentAdapter
instances, such as for example
CachingComponentAdapterFactory
. CachingComponentAdapterFactory can delegate to
other ComponentAdapterFactories.
componentAdapterFactory
- the factory to use for creation of ComponentAdapters.lifecycleStrategyForInstanceRegistrations
- the lifecylce strategy chosen for regiered
instance (not implementations!)parent
- the parent container (used for component dependency lookups).public DefaultPicoContainer(ComponentMonitor monitor, PicoContainer parent)
monitor
- the ComponentMonitor to useparent
- the parent container (used for component dependency lookups).public DefaultPicoContainer(ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy, PicoContainer parent)
monitor
- the ComponentMonitor to uselifecycleStrategy
- the lifecycle strategy to use.parent
- the parent container (used for component dependency lookups).public DefaultPicoContainer(LifecycleStrategy lifecycleStrategy, PicoContainer parent)
lifecycleStrategy
- the lifecycle strategy to use.parent
- the parent container (used for component dependency lookups).public DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory)
componentAdapterFactory
- the ComponentAdapterFactory to use.public DefaultPicoContainer(ComponentMonitor monitor)
monitor
- the ComponentMonitor to usepublic DefaultPicoContainer(PicoContainer parent)
DefaultComponentAdapterFactory
and a parent container.
parent
- the parent container (used for component dependency lookups).public DefaultPicoContainer()
DefaultComponentAdapterFactory
and no parent container.
Method Detail |
public Collection 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(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 ComponentAdapter getComponentAdapterOfType(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 List getComponentAdaptersOfType(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)
ComponentAdapterFactory
passed to the constructor of this container.
registerComponent
in interface MutablePicoContainer
componentAdapter
- the adapter
public ComponentAdapter unregisterComponent(Object componentKey)
MutablePicoContainer
unregisterComponent
in interface MutablePicoContainer
componentKey
- key of the component to unregister.
public ComponentAdapter registerComponentInstance(Object component)
registerComponentImplementation(componentImplementation, componentImplementation)
.
The returned ComponentAdapter will be an InstanceComponentAdapter
.
registerComponentInstance
in interface MutablePicoContainer
component
-
getXXX()
methods of the
PicoContainer
interface can be used to retrieve a reference to the component later on.public ComponentAdapter registerComponentInstance(Object componentKey, Object componentInstance)
InstanceComponentAdapter
.
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(Class componentImplementation)
registerComponentImplementation(componentImplementation, componentImplementation)
.
The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor.
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(Object componentKey, Class componentImplementation)
ComponentAdapterFactory
passed to the container's constructor.
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(Object componentKey, Class componentImplementation, Parameter[] parameters)
new Parameter[]{new ComponentParameter(), new ComponentParameter("someService"}
The default constructor for the component parameter indicates auto-wiring should take place for
that parameter.
new Parameter[] {}
ComponentAdapterFactory
passed to the container's constructor.
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.Parameter
,
ConstantParameter
,
ComponentParameter
public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, List parameters)
registerComponentImplementation(java.lang.Object, java.lang.Class, org.picocontainer.Parameter[])
but with parameters as a List
. Makes it possible to use with Groovy arrays (which are actually Lists).
public List getComponentInstances() throws PicoException
PicoContainer
getComponentInstances
in interface PicoContainer
PicoException
- if the instantiation of the component failspublic List getComponentInstancesOfType(Class componentType)
PicoContainer
getComponentInstancesOfType
in interface PicoContainer
componentType
- the searched type.
public Object getComponentInstance(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 Object getComponentInstanceOfType(Class componentType)
PicoContainer
getComponentInstanceOfType
in interface PicoContainer
componentType
- the type of the component
null
if no component has been registered
with a matching typepublic PicoContainer getParent()
PicoContainer
getParent
in interface PicoContainer
PicoContainer
instance, or null
if this container does not have a parent.public ComponentAdapter unregisterComponentByInstance(Object componentInstance)
MutablePicoContainer
unregisterComponentByInstance
in interface MutablePicoContainer
componentInstance
- the component instance to unregister.
public void verify() throws PicoVerificationException
PicoContainer
verify
in interface PicoContainer
PicoVerificationException
- if there are unsatisifiable dependencies.public void start()
lifecycle manager
.
The actual lifecycle strategy
supported
depends on the concrete implementation of the adapter.
start
in interface Startable
LifecycleManager
,
LifecycleStrategy
,
makeChildContainer()
,
addChildContainer(PicoContainer)
,
removeChildContainer(PicoContainer)
public void stop()
lifecycle manager
.
The actual lifecycle strategy
supported
depends on the concrete implementation of the adapter.
stop
in interface Startable
LifecycleManager
,
LifecycleStrategy
,
makeChildContainer()
,
addChildContainer(PicoContainer)
,
removeChildContainer(PicoContainer)
public void dispose()
lifecycle manager
.
The actual lifecycle strategy
supported
depends on the concrete implementation of the adapter.
dispose
in interface Disposable
LifecycleManager
,
LifecycleStrategy
,
makeChildContainer()
,
addChildContainer(PicoContainer)
,
removeChildContainer(PicoContainer)
public MutablePicoContainer makeChildContainer()
MutablePicoContainer
makeChildContainer
in interface MutablePicoContainer
public boolean addChildContainer(PicoContainer child)
MutablePicoContainer
addChildContainer
in interface MutablePicoContainer
child
- the child container
true
if the child container was not already in.public boolean removeChildContainer(PicoContainer child)
MutablePicoContainer
removeChildContainer
in interface MutablePicoContainer
child
- the child container
true
if the child container has been removed.public void accept(PicoVisitor visitor)
PicoContainer
accept
in interface PicoContainer
visitor
- the visitorpublic void changeMonitor(ComponentMonitor monitor)
changeMonitor
in interface ComponentMonitorStrategy
monitor
- the new ComponentMonitor to usepublic ComponentMonitor currentMonitor()
currentMonitor
in interface ComponentMonitorStrategy
PicoIntrospectionException
- if no component monitor is found in container or its children
|
![]() |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |