org.picocontainer.defaults
Class CachingComponentAdapter

java.lang.Object
  extended by org.picocontainer.defaults.DecoratingComponentAdapter
      extended by org.picocontainer.defaults.CachingComponentAdapter
All Implemented Interfaces:
java.io.Serializable, ComponentAdapter, ComponentMonitorStrategy, LifecycleStrategy, LifecycleManager

public class CachingComponentAdapter
extends DecoratingComponentAdapter
implements LifecycleManager

ComponentAdapter implementation that caches the component instance.

This adapter supports components with a lifecycle, as it is a lifecycle manager which will apply the delegate's lifecycle strategy to the cached component instance. The lifecycle state is maintained so that the component instance behaves in the expected way: it can't be started if already started, it can't be started or stopped if disposed, it can't be stopped if not started, it can't be disposed if already disposed.

Version:
$Revision: 2827 $
Author:
Mauro Talevi
See Also:
Serialized Form

Field Summary
private  boolean delegateHasLifecylce
           
private  boolean disposed
           
private  ObjectReference instanceReference
           
private  boolean started
           
 
Constructor Summary
CachingComponentAdapter(ComponentAdapter delegate)
           
CachingComponentAdapter(ComponentAdapter delegate, ObjectReference instanceReference)
           
 
Method Summary
 void dispose(PicoContainer container)
          Disposes the cached component instance Invokes delegate dispose method if the delegate is a LifecycleManager Invoke the "dispose" method on the container's components.
 void flush()
          Flushes the cache.
 java.lang.Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
 boolean hasLifecycle()
          Invokes delegate hasLifecylce method if the delegate is a LifecycleManager Test if a container's component has a lifecycle.
 void start(PicoContainer container)
          Starts the cached component instance Invokes delegate start method if the delegate is a LifecycleManager Invoke the "start" method on the container's components.
 void stop(PicoContainer container)
          Stops the cached component instance Invokes delegate stop method if the delegate is a LifecycleManager Invoke the "stop" method on the container's components.
 
Methods inherited from class org.picocontainer.defaults.DecoratingComponentAdapter
accept, changeMonitor, currentMonitor, dispose, getComponentImplementation, getComponentKey, getDelegate, hasLifecycle, start, stop, toString, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

instanceReference

private ObjectReference instanceReference

disposed

private boolean disposed

started

private boolean started

delegateHasLifecylce

private boolean delegateHasLifecylce
Constructor Detail

CachingComponentAdapter

public CachingComponentAdapter(ComponentAdapter delegate)

CachingComponentAdapter

public CachingComponentAdapter(ComponentAdapter delegate,
                               ObjectReference instanceReference)
Method Detail

getComponentInstance

public java.lang.Object getComponentInstance(PicoContainer container)
                                      throws PicoInitializationException,
                                             PicoIntrospectionException,
                                             AssignabilityRegistrationException,
                                             NotConcreteRegistrationException
Description copied from interface: ComponentAdapter
Retrieve the component instance. This method will usually create a new instance each time it is called, but that is not required. For example, CachingComponentAdapter will always return the same instance.

Specified by:
getComponentInstance in interface ComponentAdapter
Overrides:
getComponentInstance in class DecoratingComponentAdapter
Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
Returns:
the component instance.
Throws:
PicoInitializationException - if the component could not be instantiated.
PicoIntrospectionException - if the component has dependencies which could not be resolved, or instantiation of the component lead to an ambigous situation within the container.
AssignabilityRegistrationException
NotConcreteRegistrationException

flush

public void flush()
Flushes the cache. If the component instance is started is will stop and dispose it before flushing the cache.


start

public void start(PicoContainer container)
Starts the cached component instance Invokes delegate start method if the delegate is a LifecycleManager Invoke the "start" method on the container's components.

Specified by:
start in interface LifecycleManager
Overrides:
start in class DecoratingComponentAdapter
Parameters:
container - the container to "start" its components' lifecycle

stop

public void stop(PicoContainer container)
Stops the cached component instance Invokes delegate stop method if the delegate is a LifecycleManager Invoke the "stop" method on the container's components.

Specified by:
stop in interface LifecycleManager
Overrides:
stop in class DecoratingComponentAdapter
Parameters:
container - the container to "stop" its components' lifecycle

dispose

public void dispose(PicoContainer container)
Disposes the cached component instance Invokes delegate dispose method if the delegate is a LifecycleManager Invoke the "dispose" method on the container's components.

Specified by:
dispose in interface LifecycleManager
Overrides:
dispose in class DecoratingComponentAdapter
Parameters:
container - the container to "dispose" its components' lifecycle

hasLifecycle

public boolean hasLifecycle()
Description copied from class: DecoratingComponentAdapter
Invokes delegate hasLifecylce method if the delegate is a LifecycleManager Test if a container's component has a lifecycle.

Specified by:
hasLifecycle in interface LifecycleManager
Overrides:
hasLifecycle in class DecoratingComponentAdapter
Returns:
true if the component has a lifecycle