public interface MutablePicoContainer extends PicoContainer, Startable, Disposable
Modifier and Type | Method and Description |
---|---|
MutablePicoContainer |
addAdapter(ComponentAdapter<?> componentAdapter)
Register a component via a ComponentAdapter.
|
MutablePicoContainer |
addChildContainer(PicoContainer child)
Add a child container.
|
MutablePicoContainer |
addComponent(Object implOrInstance)
Register an arbitrary object.
|
MutablePicoContainer |
addComponent(Object componentKey,
Object componentImplementationOrInstance,
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.
|
MutablePicoContainer |
addConfig(String name,
Object val)
Register a config item.
|
MutablePicoContainer |
as(Properties... properties)
You can set for the following operation only the characteristic of registration of a component on the fly.
|
MutablePicoContainer |
change(Properties... properties)
You can change the characteristic of registration of all subsequent components in this container.
|
LifecycleState |
getLifecycleState()
Allow querying of the current lifecycle state of a MutablePicoContainer.
|
String |
getName()
Retrieve the name set (if any).
|
MutablePicoContainer |
makeChildContainer()
Make a child container, using both the same implementation of MutablePicoContainer as the parent
and identical behaviors as well.
|
boolean |
removeChildContainer(PicoContainer child)
Remove a child container from this container.
|
<T> ComponentAdapter<T> |
removeComponent(Object componentKey)
Unregister a component by key.
|
<T> ComponentAdapter<T> |
removeComponentByInstance(T componentInstance)
Unregister a component by instance.
|
void |
setLifecycleState(LifecycleState lifecycleState)
To assist ThreadLocal usage, LifecycleState can be set.
|
void |
setName(String name)
Name the container instance, to assist debugging or other indexing.
|
accept, getComponent, getComponent, getComponent, getComponent, getComponentAdapter, getComponentAdapter, getComponentAdapter, getComponentAdapters, getComponentAdapters, getComponentAdapters, getComponents, getComponents, getParent
dispose
MutablePicoContainer addComponent(Object componentKey, Object componentImplementationOrInstance, Parameter... parameters)
new ComponentParameter(), new ComponentParameter("someService")
The default constructor for the component parameter indicates auto-wiring should take place for
that parameter.
new Parameter[0]
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.componentImplementationOrInstance
- the component's implementation class. This must be a concrete class (ie, a
class that can be instantiated). Or an intance of the compoent.parameters
- the 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.PicoCompositionException
- if registration of the component fails.Parameter
,
ConstantParameter
,
ComponentParameter
MutablePicoContainer addComponent(Object implOrInstance)
addComponent(componentImplementation, componentImplementation)
.implOrInstance
- Component implementation or instancePicoCompositionException
- if registration fails.MutablePicoContainer addConfig(String name, Object val)
name
- the name of the config itemval
- the value of the config itemPicoCompositionException
- if registration fails.MutablePicoContainer addAdapter(ComponentAdapter<?> componentAdapter)
componentAdapter
- the adapterPicoCompositionException
- if registration fails.<T> ComponentAdapter<T> removeComponent(Object componentKey)
componentKey
- key of the component to unregister.<T> ComponentAdapter<T> removeComponentByInstance(T componentInstance)
componentInstance
- the component instance to unregister.MutablePicoContainer makeChildContainer()
Note that for long-lived parent containers, you need to unregister child containers made with this call before disposing or you will leak memory. (Experience speaking here! )
Incorrect Example:
MutablePicoContainer parent = new PicoBuilder().withCaching().withLifecycle().build(); MutablePicoContainer child = parent.makeChildContainer(); child = null; //Child still retains in memory because parent still holds reference.
Correct Example:
MutablePicoContainer parent = new PicoBuilder().withCaching().withLifecycle().build(); MutablePicoContainer child = parent.makeChildContainer(); parent.removeChildContainer(child); //Remove the bi-directional references. child = null;
MutablePicoContainer addChildContainer(PicoContainer child)
child
- the child containerboolean removeChildContainer(PicoContainer child)
child
- the child containertrue
if the child container has been removed.MutablePicoContainer change(Properties... properties)
properties
- MutablePicoContainer as(Properties... properties)
properties
- void setName(String name)
name
- the name to call it.void setLifecycleState(LifecycleState lifecycleState)
lifecycleState
- the lifecyle state to use.String getName()
setName
.LifecycleState getLifecycleState()
Copyright © 2003–2015 Codehaus. All rights reserved.