|
|||||||||||
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()
|
|
DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory)
|
|
DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory,
PicoContainer parent)
|
|
DefaultPicoContainer(PicoContainer parent)
|
Method Summary | |
void |
addOrderedComponentAdapter(ComponentAdapter componentAdapter)
Callback method from the implementation to keep track of the instantiation order. |
void |
dispose()
|
ComponentAdapter |
getComponentAdapter(java.lang.Object componentKey)
Finds a ComponentAdapter matching the key, looking in parent if not found in self (unless parent is null). |
ComponentAdapter |
getComponentAdapterOfType(java.lang.Class componentType)
Finds a ComponentAdapter matching the type, looking in parent if not found in self (unless parent is null). |
java.util.Collection |
getComponentAdapters()
Returns all adapters (not including the adapters from the parent). |
java.lang.Object |
getComponentInstance(java.lang.Object componentKey)
Gets a component instance registered with a specific key. |
java.lang.Object |
getComponentInstanceOfType(java.lang.Class componentType)
Finds a component instance matching the type, looking in parent if not found in self (unless parent is null). |
java.util.List |
getComponentInstances()
Gets all the registered component instances in the container, (not including those in the parent container). |
PicoContainer |
getParent()
Get the parent container of this container. |
void |
registerComponent(ComponentAdapter componentAdapter)
Registers 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(java.lang.Class componentImplementation)
Registers a component using the componentImplementation as key. The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor. |
ComponentAdapter |
registerComponentImplementation(java.lang.Object componentKey,
java.lang.Class componentImplementation)
Registers a component. The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor. |
ComponentAdapter |
registerComponentImplementation(java.lang.Object componentKey,
java.lang.Class componentImplementation,
java.util.List parameters)
|
ComponentAdapter |
registerComponentImplementation(java.lang.Object componentKey,
java.lang.Class componentImplementation,
Parameter[] parameters)
Registers a component. The returned ComponentAdapter will be instantiated by the ComponentAdapterFactory
passed to the container's constructor. |
ComponentAdapter |
registerComponentInstance(java.lang.Object component)
Registers an arbitrary object, using its class as a key. The returned ComponentAdapter will be an InstanceComponentAdapter . |
ComponentAdapter |
registerComponentInstance(java.lang.Object componentKey,
java.lang.Object componentInstance)
Registers an arbitrary object as a compoent 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 . |
void |
setParent(PicoContainer parent)
Sets the Parent container. |
void |
start()
|
void |
stop()
|
ComponentAdapter |
unregisterComponent(java.lang.Object componentKey)
Unregisters a component by key. |
ComponentAdapter |
unregisterComponentByInstance(java.lang.Object componentInstance)
Unregisters a component by instance. |
void |
verify()
Verifies that the dependencies for all the registered components can be satisfied None of the components are instantiated during the verification process. |
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)
public DefaultPicoContainer(PicoContainer parent)
public DefaultPicoContainer(ComponentAdapterFactory componentAdapterFactory)
public DefaultPicoContainer()
Method Detail |
public java.util.Collection getComponentAdapters()
PicoContainer
getComponentAdapters
in interface PicoContainer
ComponentAdapter
.public final ComponentAdapter getComponentAdapter(java.lang.Object componentKey) throws AmbiguousComponentResolutionException
PicoContainer
getComponentAdapter
in interface PicoContainer
componentKey
- key of the component.
AmbiguousComponentResolutionException
public ComponentAdapter getComponentAdapterOfType(java.lang.Class componentType)
PicoContainer
getComponentAdapterOfType
in interface PicoContainer
componentType
- type of the component.
public void registerComponent(ComponentAdapter componentAdapter) throws DuplicateComponentKeyRegistrationException
ComponentAdapterFactory
passed to the constructor of this container.
registerComponent
in interface MutablePicoContainer
componentAdapter
- the adapter
DuplicateComponentKeyRegistrationException
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) throws PicoRegistrationException
InstanceComponentAdapter
.
registerComponentInstance
in interface MutablePicoContainer
component
-
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentInstance(java.lang.Object componentKey, java.lang.Object componentInstance) throws PicoRegistrationException
InstanceComponentAdapter
.
registerComponentInstance
in interface MutablePicoContainer
componentKey
- a key that identifies the compoent. 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.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentImplementation(java.lang.Class componentImplementation) throws PicoRegistrationException
ComponentAdapterFactory
passed to the container's constructor.
registerComponentImplementation
in interface MutablePicoContainer
componentImplementation
- the concrete component class.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentImplementation(java.lang.Object componentKey, java.lang.Class componentImplementation) throws PicoRegistrationException
ComponentAdapterFactory
passed to the container's constructor.
registerComponentImplementation
in interface MutablePicoContainer
componentKey
- a key that identifies the compoent. Must be unique within the conainer.
The type of the key object has no semantic significance unless explicitly specified
in the implementing container.componentImplementation
- the concrete component class.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentImplementation(java.lang.Object componentKey, java.lang.Class componentImplementation, Parameter[] parameters) throws PicoRegistrationException
ComponentAdapterFactory
passed to the container's constructor.
registerComponentImplementation
in interface MutablePicoContainer
componentKey
- a key that identifies the compoent. Must be unique within the conainer.
The type of the key object has no semantic significance unless explicitly specified
in the implementing container.componentImplementation
- the concrete component class.parameters
- an array of parameters that gives the container hints about what arguments
to pass to the constructor when it is instantiated.
PicoRegistrationException
- if registration fails.public ComponentAdapter registerComponentImplementation(java.lang.Object componentKey, java.lang.Class componentImplementation, java.util.List parameters) throws PicoRegistrationException
PicoRegistrationException
public void addOrderedComponentAdapter(ComponentAdapter componentAdapter)
PicoContainer
addOrderedComponentAdapter
in interface PicoContainer
public java.util.List getComponentInstances() throws PicoException
PicoContainer
getComponentInstances
in interface PicoContainer
PicoException
public java.lang.Object getComponentInstance(java.lang.Object componentKey) throws PicoException
PicoContainer
getComponentInstance
in interface PicoContainer
componentKey
- key the component was registered with.
PicoException
public java.lang.Object getComponentInstanceOfType(java.lang.Class componentType)
PicoContainer
getComponentInstanceOfType
in interface PicoContainer
componentType
- type of the component.
public PicoContainer getParent()
PicoContainer
getParent
in interface PicoContainer
PicoContainer
.public void setParent(PicoContainer parent)
MutablePicoContainer
setParent
in interface MutablePicoContainer
parent
- parent container.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()
start
in interface Startable
public void stop()
stop
in interface Startable
public void dispose()
dispose
in interface Disposable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |