|
![]() |
||||||||||
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
.
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,
PicoContainer parent)
Creates a new container with a custom ComponentAdapterFactory and a parent container. |
|
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 |
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. The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor. |
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(PicoContainer parent)
DefaultComponentAdapterFactory
and a parent container.
public DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory)
componentAdapterFactory
- the ComponentAdapterFactory to use.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) throws AmbiguousComponentResolutionException
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.
AmbiguousComponentResolutionException
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) throws DuplicateComponentKeyRegistrationException
ComponentAdapterFactory
passed to the constructor of this container.
registerComponent
in interface MutablePicoContainer
componentAdapter
- the adapter
DuplicateComponentKeyRegistrationException
public ComponentAdapter unregisterComponent(Object componentKey)
MutablePicoContainer
unregisterComponent
in interface MutablePicoContainer
componentKey
- key of the component to unregister.
public ComponentAdapter registerComponentInstance(Object component) throws PicoRegistrationException
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.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentInstance(Object componentKey, Object componentInstance) throws PicoRegistrationException
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.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentImplementation(Class componentImplementation) throws PicoRegistrationException
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.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation) throws PicoRegistrationException
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.
PicoRegistrationException
- if registration of the component fails.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) throws PicoRegistrationException
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.
PicoRegistrationException
- if registration of the component fails.public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, List parameters) throws PicoRegistrationException
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).
PicoRegistrationException
public List getComponentInstances() throws PicoException
PicoContainer
getComponentInstances
in interface PicoContainer
PicoException
public List getComponentInstancesOfType(Class componentType) throws PicoException
PicoContainer
getComponentInstancesOfType
in interface PicoContainer
componentType
- the searched type.
PicoException
public Object getComponentInstance(Object componentKey) throws PicoException
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.
PicoException
public Object getComponentInstanceOfType(Class componentType)
PicoContainer
getComponentInstanceOfType
in interface PicoContainer
componentType
- the type of the component.
public 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()
Startable
will be started.
start
in interface Startable
makeChildContainer()
,
addChildContainer(PicoContainer)
,
removeChildContainer(PicoContainer)
public void stop()
Startable
will be stopped.
stop
in interface Startable
makeChildContainer()
,
addChildContainer(PicoContainer)
,
removeChildContainer(PicoContainer)
public void dispose()
Disposable
will be disposed.
dispose
in interface Disposable
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 visitor
|
![]() |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |