Package org.picocontainer.behaviors
Class AbstractBehavior<T>
java.lang.Object
org.picocontainer.behaviors.AbstractBehavior<T>
- All Implemented Interfaces:
Serializable,Behavior<T>,ComponentAdapter<T>,ComponentLifecycle<T>,ComponentMonitorStrategy,LifecycleStrategy
- Direct Known Subclasses:
Automated,Decorated,FieldDecorated,Guarded,HiddenImplementation,Locked,PropertyApplicator,Stored,Synchronized
public abstract class AbstractBehavior<T>
extends Object
implements Behavior<T>, ComponentMonitorStrategy, LifecycleStrategy, Serializable
Component adapter which decorates another adapter.
This adapter supports a component monitor strategy
and will propagate change of monitor to the delegate if the delegate itself
support the monitor strategy.
This adapter also supports a lifecycle manager and a
lifecycle strategy if the delegate does.
- Author:
- Jon Tirsen, Aslak Hellesoy, Mauro Talevi
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.picocontainer.ComponentAdapter
ComponentAdapter.NOTHING -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(PicoVisitor visitor) Accepts a visitor for this ComponentAdapter.voidchangeMonitor(ComponentMonitor monitor) Delegates change of monitor if the delegate supports a component monitor strategy.booleanInvokes delegate hasLifecycle method if the delegate is a Behavior Test if a component honors a lifecycle.Returns delegate's current monitor if the delegate supports a component monitor strategy.voidInvokes delegate dispose method if the delegate is a LifecycleStrategy Invoke the "dispose" method on the component instance if this is disposable.voiddispose(PicoContainer container) Invokes delegate dispose method if the delegate is a Behavior Invoke the "dispose" method on the component.final <U extends ComponentAdapter>
UfindAdapterOfType(Class<U> adapterType) Locates a component adapter of type componentAdapterType in the ComponentAdapter chain.Retrieve the class of the component.getComponentInstance(PicoContainer container) Retrieve the component instance.getComponentInstance(PicoContainer container, Type into) Retrieve the component instance.Retrieve the key associated with the component.final ComponentAdapter<T> Component adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.booleanhasLifecycle(Class<?> type) Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy 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() ).booleanvoidInvokes delegate start method if the delegate is a LifecycleStrategy Invoke the "start" method on the component instance if this is startable.voidstart(PicoContainer container) Invokes delegate start method if the delegate is a Behavior Invoke the "start" method on the component.voidInvokes delegate stop method if the delegate is a LifecycleStrategy Invoke the "stop" method on the component instance if this is stoppable.voidstop(PicoContainer container) Invokes delegate stop method if the delegate is a Behavior 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.picocontainer.ComponentAdapter
getDescriptor
-
Field Details
-
delegate
-
-
Constructor Details
-
AbstractBehavior
-
-
Method Details
-
getComponentKey
Description copied from interface:ComponentAdapterRetrieve the key associated with the component.- Specified by:
getComponentKeyin interfaceComponentAdapter<T>- Returns:
- the component's key. Should either be a class type (normally an interface) or an identifier that is unique (within the scope of the current PicoContainer).
-
getComponentImplementation
Description copied from interface:ComponentAdapterRetrieve the class of the component.- Specified by:
getComponentImplementationin interfaceComponentAdapter<T>- Returns:
- the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).
-
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.- Returns:
- the component instance.
- Throws:
PicoCompositionException- if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambigous situation within the container.
-
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.
- Throws:
PicoCompositionException- if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambiguous situation within the container.
-
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.- Throws:
PicoCompositionException- if one or more dependencies cannot be resolved.
-
getDelegate
Description copied from interface:ComponentAdapterComponent adapters may be nested in a chain, and this method is used to grab the next ComponentAdapter in the chain.- Specified by:
getDelegatein interfaceComponentAdapter<T>- Returns:
- the next component adapter in line or null if there is no delegate ComponentAdapter.
-
findAdapterOfType
Description copied from interface:ComponentAdapterLocates a component adapter of type componentAdapterType in the ComponentAdapter chain. Will return null if there is no adapter of the given type.- Specified by:
findAdapterOfTypein interfaceComponentAdapter<T>- Type Parameters:
U- the type of ComponentAdapter being located.- Parameters:
adapterType- the class of the adapter type being located. Never null.- Returns:
- the appropriate component adapter of type U. May return null if the component adapter type is not returned.
-
accept
Description copied from interface:ComponentAdapterAccepts a visitor for this ComponentAdapter. The method is normally called by visiting aPicoContainer, that cascades the visitor also down to all its ComponentAdapter instances.- Specified by:
acceptin interfaceComponentAdapter<T>- Parameters:
visitor- the visitor.
-
changeMonitor
Delegates change of monitor if the delegate supports a component monitor strategy. Changes the component monitor used- Specified by:
changeMonitorin interfaceComponentMonitorStrategy- Parameters:
monitor- the new ComponentMonitor to use
-
currentMonitor
Returns delegate's current monitor if the delegate supports a component monitor strategy. Returns the monitor currently used- Specified by:
currentMonitorin interfaceComponentMonitorStrategy- Returns:
- The ComponentMonitor currently used
- Throws:
PicoCompositionException- if no component monitor is found in delegate
-
start
Invokes delegate start method if the delegate is a Behavior Invoke the "start" method on the component.- Specified by:
startin interfaceComponentLifecycle<T>- Parameters:
container- the container to "start" the component
-
stop
Invokes delegate stop method if the delegate is a Behavior Invoke the "stop" method on the component.- Specified by:
stopin interfaceComponentLifecycle<T>- Parameters:
container- the container to "stop" the component
-
dispose
Invokes delegate dispose method if the delegate is a Behavior Invoke the "dispose" method on the component.- Specified by:
disposein interfaceComponentLifecycle<T>- Parameters:
container- the container to "dispose" the component
-
componentHasLifecycle
public boolean componentHasLifecycle()Invokes delegate hasLifecycle method if the delegate is a Behavior Test 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
Invokes delegate start method if the delegate is a LifecycleStrategy Invoke 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
Invokes delegate stop method if the delegate is a LifecycleStrategy Invoke 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
Invokes delegate dispose method if the delegate is a LifecycleStrategy Invoke 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
Invokes delegate hasLifecycle(Class) method if the delegate is a LifecycleStrategy Test 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
-
toString
-