Package org.picocontainer.adapters
Class InstanceAdapter<T>
java.lang.Object
org.picocontainer.adapters.AbstractAdapter<T>
org.picocontainer.adapters.InstanceAdapter<T>
- All Implemented Interfaces:
Serializable,ComponentAdapter<T>,ComponentLifecycle<T>,ComponentMonitorStrategy,LifecycleStrategy
public final class InstanceAdapter<T>
extends AbstractAdapter<T>
implements ComponentLifecycle<T>, LifecycleStrategy
Component adapter which wraps a component instance.
This component adapter supports both a Behavior and a
LifecycleStrategy to control the lifecycle of the component.
The lifecycle manager methods simply delegate to the lifecycle strategy methods
on the component instance.
- Author:
- Aslak Hellesøy, Paul Hammant, Mauro Talevi
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING -
Constructor Summary
ConstructorsConstructorDescriptionInstanceAdapter(Object componentKey, T componentInstance) InstanceAdapter(Object componentKey, T componentInstance, ComponentMonitor componentMonitor) InstanceAdapter(Object componentKey, T componentInstance, LifecycleStrategy lifecycleStrategy) InstanceAdapter(Object componentKey, T componentInstance, LifecycleStrategy lifecycleStrategy, ComponentMonitor componentMonitor) -
Method Summary
Modifier and TypeMethodDescriptionbooleanTest if a component honors a lifecycle.voidInvoke the "dispose" method on the component instance if this is disposable.voiddispose(PicoContainer container) Invoke the "dispose" method on the component.getComponentInstance(PicoContainer container, Type into) Retrieve the component instance.Get a string key descriptor of the component adapter for use in toString()booleanhasLifecycle(Class<?> type) Test if a component instance has a lifecycle.booleanisLazy(ComponentAdapter<?> adapter) Is a component eager (not lazy) in that it should start when start() or equivalent is called, or lazy (it will only start on first getComponent() ).booleanvoidInvoke the "start" method on the component instance if this is startable.voidstart(PicoContainer container) Invoke the "start" method on the component.voidInvoke the "stop" method on the component instance if this is stoppable.voidstop(PicoContainer container) Invoke the "stop" method on the component.toString()voidverify(PicoContainer container) Verify that all dependencies for this adapter can be satisfied.Methods inherited from class org.picocontainer.adapters.AbstractAdapter
accept, changeMonitor, checkTypeCompatibility, currentMonitor, findAdapterOfType, getComponentImplementation, getComponentInstance, getComponentKey, getDelegate
-
Constructor Details
-
InstanceAdapter
public InstanceAdapter(Object componentKey, T componentInstance, LifecycleStrategy lifecycleStrategy, ComponentMonitor componentMonitor) throws PicoCompositionException - Throws:
PicoCompositionException
-
InstanceAdapter
-
InstanceAdapter
public InstanceAdapter(Object componentKey, T componentInstance, LifecycleStrategy lifecycleStrategy) -
InstanceAdapter
-
-
Method Details
-
getComponentInstance
Description copied from interface:ComponentAdapterRetrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example,Cachedwill always return the same instance.- Specified by:
getComponentInstancein interfaceComponentAdapter<T>- Parameters:
container- thePicoContainer, that is used to resolve any possible dependencies of the instance.into- the class that is about to be injected into. Use ComponentAdapter.NOTHING.class if this is not important to you.- Returns:
- the component instance.
-
verify
Description copied from interface:ComponentAdapterVerify that all dependencies for this adapter can be satisfied. Normally, the adapter should verify this by checking that the associated PicoContainer contains all the needed dependencies.- Specified by:
verifyin interfaceComponentAdapter<T>- Parameters:
container- thePicoContainer, that is used to resolve any possible dependencies of the instance.
-
getDescriptor
Description copied from interface:ComponentAdapterGet a string key descriptor of the component adapter for use in toString()- Specified by:
getDescriptorin interfaceComponentAdapter<T>- Returns:
- the descriptor
-
toString
- Overrides:
toStringin classAbstractAdapter<T>- Returns:
- Returns the ComponentAdapter's class name and the component's key.
- See Also:
-
start
Description copied from interface:ComponentLifecycleInvoke the "start" method on the component.- Specified by:
startin interfaceComponentLifecycle<T>- Parameters:
container- the container to "start" the component
-
stop
Description copied from interface:ComponentLifecycleInvoke the "stop" method on the component.- Specified by:
stopin interfaceComponentLifecycle<T>- Parameters:
container- the container to "stop" the component
-
dispose
Description copied from interface:ComponentLifecycleInvoke the "dispose" method on the component.- Specified by:
disposein interfaceComponentLifecycle<T>- Parameters:
container- the container to "dispose" the component
-
componentHasLifecycle
public boolean componentHasLifecycle()Description copied from interface:ComponentLifecycleTest if a component honors a lifecycle.- Specified by:
componentHasLifecyclein interfaceComponentLifecycle<T>- Returns:
trueif the component has a lifecycle
-
isStarted
public boolean isStarted()- Specified by:
isStartedin interfaceComponentLifecycle<T>
-
start
Description copied from interface:LifecycleStrategyInvoke the "start" method on the component instance if this is startable. It is up to the implementation of the strategy what "start" and "startable" means.- Specified by:
startin interfaceLifecycleStrategy- Parameters:
component- the instance of the component to start
-
stop
Description copied from interface:LifecycleStrategyInvoke the "stop" method on the component instance if this is stoppable. It is up to the implementation of the strategy what "stop" and "stoppable" means.- Specified by:
stopin interfaceLifecycleStrategy- Parameters:
component- the instance of the component to stop
-
dispose
Description copied from interface:LifecycleStrategyInvoke the "dispose" method on the component instance if this is disposable. It is up to the implementation of the strategy what "dispose" and "disposable" means.- Specified by:
disposein interfaceLifecycleStrategy- Parameters:
component- the instance of the component to dispose
-
hasLifecycle
Description copied from interface:LifecycleStrategyTest if a component instance has a lifecycle.- Specified by:
hasLifecyclein interfaceLifecycleStrategy- Parameters:
type- the component's type- Returns:
trueif the component has a lifecycle
-
isLazy
Description copied from interface:LifecycleStrategyIs a component eager (not lazy) in that it should start when start() or equivalent is called, or lazy (it will only start on first getComponent() ). The default is the first of those two.- Specified by:
isLazyin interfaceLifecycleStrategy- Parameters:
adapter-- Returns:
- true if lazy, false if not lazy
-