|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.picocontainer.defaults.DefaultPicoContainer
public class 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
.
Nested Class Summary | |
---|---|
private class |
DefaultPicoContainer.OrderedComponentAdapterLifecycleManager
Implementation of lifecycle manager which delegates to the container's component adapters. |
Field Summary | |
---|---|
private java.util.Set |
children
|
private java.util.Set |
childrenStarted
|
private ComponentAdapterFactory |
componentAdapterFactory
|
private java.util.List |
componentAdapters
|
private java.util.Map |
componentKeyToAdapterCache
|
private boolean |
disposed
|
private LifecycleManager |
lifecycleManager
|
private LifecycleStrategy |
lifecycleStrategyForInstanceRegistrations
|
private java.util.List |
orderedComponentAdapters
|
private PicoContainer |
parent
|
private boolean |
started
|
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. |
private void |
addOrderedComponentAdapter(ComponentAdapter componentAdapter)
|
void |
changeMonitor(ComponentMonitor monitor)
Changes monitor in the ComponentAdapterFactory, the component adapters and the child containers, if these support a ComponentMonitorStrategy. |
private boolean |
childStarted(PicoContainer child)
Checks the status of the child container to see if it's been started to prevent IllegalStateException upon stop |
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(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 |
getComponentAdapters()
Retrieve all the component adapters inside this container. |
java.util.List |
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. |
java.util.List |
getComponentInstances()
Retrieve all the registered component instances in the container, (not including those in the parent container). |
java.util.List |
getComponentInstancesOfType(java.lang.Class componentType)
Returns a List of components of a certain componentType. |
private java.lang.Object |
getInstance(ComponentAdapter componentAdapter)
|
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. |
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,
java.util.List parameters)
Same as registerComponentImplementation(java.lang.Object, java.lang.Class, org.picocontainer.Parameter[])
but with parameters as a List . |
ComponentAdapter |
registerComponentImplementation(java.lang.Object componentKey,
java.lang.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. |
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. |
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(java.lang.Object componentKey)
Unregister a component by key. |
ComponentAdapter |
unregisterComponentByInstance(java.lang.Object componentInstance)
Unregister a component by instance. |
void |
verify()
Deprecated. since 1.1 - Use "new VerifyingVisitor().traverse(this)" |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.util.Map componentKeyToAdapterCache
private ComponentAdapterFactory componentAdapterFactory
private PicoContainer parent
private java.util.Set children
private java.util.List componentAdapters
private java.util.List orderedComponentAdapters
private boolean started
private boolean disposed
private java.util.Set childrenStarted
private LifecycleManager lifecycleManager
private LifecycleStrategy lifecycleStrategyForInstanceRegistrations
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 java.util.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(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 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 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)
ComponentAdapterFactory
passed to the constructor of this container.
registerComponent
in interface MutablePicoContainer
componentAdapter
- the adapter
public ComponentAdapter unregisterComponent(java.lang.Object componentKey)
MutablePicoContainer
unregisterComponent
in interface MutablePicoContainer
componentKey
- key of the component to unregister.
public ComponentAdapter registerComponentInstance(java.lang.Object component)
registerComponentImplementation(componentImplementation, componentImplementation)
.
The returned ComponentAdapter will be an InstanceComponentAdapter
.
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)
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(java.lang.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(java.lang.Object componentKey, java.lang.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(java.lang.Object componentKey, java.lang.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(java.lang.Object componentKey, java.lang.Class componentImplementation, java.util.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).
private void addOrderedComponentAdapter(ComponentAdapter componentAdapter)
public java.util.List getComponentInstances() throws PicoException
PicoContainer
getComponentInstances
in interface PicoContainer
PicoException
- if the instantiation of the component failspublic java.util.List getComponentInstancesOfType(java.lang.Class componentType)
PicoContainer
getComponentInstancesOfType
in interface PicoContainer
componentType
- the searched type.
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 java.lang.Object getComponentInstanceOfType(java.lang.Class componentType)
PicoContainer
getComponentInstanceOfType
in interface PicoContainer
componentType
- the type of the component
null
if no component has been registered
with a matching typeprivate java.lang.Object getInstance(ComponentAdapter componentAdapter)
public PicoContainer getParent()
PicoContainer
getParent
in interface PicoContainer
PicoContainer
instance, or null
if this container does not have a parent.public ComponentAdapter unregisterComponentByInstance(java.lang.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
DefaultPicoContainer.OrderedComponentAdapterLifecycleManager
,
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
DefaultPicoContainer.OrderedComponentAdapterLifecycleManager
,
LifecycleStrategy
,
makeChildContainer()
,
addChildContainer(PicoContainer)
,
removeChildContainer(PicoContainer)
private boolean childStarted(PicoContainer child)
child
- the child PicoContainer
true
if the container is startedpublic void dispose()
lifecycle manager
.
The actual lifecycle strategy
supported
depends on the concrete implementation of the adapter.
dispose
in interface Disposable
DefaultPicoContainer.OrderedComponentAdapterLifecycleManager
,
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 |