org.picocontainer.defaults
Class CachingComponentAdapter

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

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

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.
 Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
 boolean hasLifecycle()
          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
 

Constructor Detail

CachingComponentAdapter

public CachingComponentAdapter(ComponentAdapter delegate)

CachingComponentAdapter

public CachingComponentAdapter(ComponentAdapter delegate,
                               ObjectReference instanceReference)
Method Detail

getComponentInstance

public 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
Throws:
PicoInitializationException
PicoIntrospectionException
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

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

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

hasLifecycle

public boolean hasLifecycle()
Description copied from interface: LifecycleManager
Test if a container's component has a lifecycle.

Specified by:
hasLifecycle in interface LifecycleManager
Overrides:
hasLifecycle in class DecoratingComponentAdapter


Copyright © 2003-2007 Codehaus. All Rights Reserved.