org.picocontainer.defaults
Class DecoratingComponentAdapter

java.lang.Object
  extended by org.picocontainer.defaults.DecoratingComponentAdapter
All Implemented Interfaces:
java.io.Serializable, ComponentAdapter, ComponentMonitorStrategy, LifecycleStrategy, LifecycleManager
Direct Known Subclasses:
BeanPropertyComponentAdapter, CachingComponentAdapter, ImplementationHidingComponentAdapter, SynchronizedComponentAdapter

public class DecoratingComponentAdapter
extends java.lang.Object
implements ComponentAdapter, ComponentMonitorStrategy, LifecycleManager, LifecycleStrategy, java.io.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.

Version:
$Revision: 2631 $
Author:
Jon Tirsen, Aslak Hellesoy, Mauro Talevi
See Also:
Serialized Form

Field Summary
private  ComponentAdapter delegate
           
 
Constructor Summary
DecoratingComponentAdapter(ComponentAdapter delegate)
           
 
Method Summary
 void accept(PicoVisitor visitor)
          Accepts a visitor for this ComponentAdapter.
 void changeMonitor(ComponentMonitor monitor)
          Delegates change of monitor if the delegate supports a component monitor strategy.
 ComponentMonitor currentMonitor()
          Returns delegate's current monitor if the delegate supports a component monitor strategy.
 void dispose(java.lang.Object component)
          Invokes delegate dispose method if the delegate is a LifecycleStrategy Invoke the "dispose" method on the component instance if this is disposable.
 void dispose(PicoContainer container)
          Invokes delegate dispose method if the delegate is a LifecycleManager Invoke the "dispose" method on the container's components.
 java.lang.Class getComponentImplementation()
          Retrieve the class of the component.
 java.lang.Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
 java.lang.Object getComponentKey()
          Retrieve the key associated with the component.
 ComponentAdapter getDelegate()
           
private  java.lang.String getPrintableClassName()
           
 boolean hasLifecycle()
          Invokes delegate hasLifecylce method if the delegate is a LifecycleManager Test if a container's component has a lifecycle.
 boolean hasLifecycle(java.lang.Class type)
          Invokes delegate hasLifecylce(Class) method if the delegate is a LifecycleStrategy Test if a component instance has a lifecycle.
 void start(java.lang.Object component)
          Invokes delegate start method if the delegate is a LifecycleStrategy Invoke the "start" method on the component instance if this is startable.
 void start(PicoContainer container)
          Invokes delegate start method if the delegate is a LifecycleManager Invoke the "start" method on the container's components.
 void stop(java.lang.Object component)
          Invokes delegate stop method if the delegate is a LifecycleStrategy Invoke the "stop" method on the component instance if this is stoppable.
 void stop(PicoContainer container)
          Invokes delegate stop method if the delegate is a LifecycleManager Invoke the "stop" method on the container's components.
 java.lang.String toString()
           
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisifed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

delegate

private ComponentAdapter delegate
Constructor Detail

DecoratingComponentAdapter

public DecoratingComponentAdapter(ComponentAdapter delegate)
Method Detail

getComponentKey

public java.lang.Object getComponentKey()
Description copied from interface: ComponentAdapter
Retrieve the key associated with the component.

Specified by:
getComponentKey in interface ComponentAdapter
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

public java.lang.Class getComponentImplementation()
Description copied from interface: ComponentAdapter
Retrieve the class of the component.

Specified by:
getComponentImplementation in interface ComponentAdapter
Returns:
the component's implementation class. Should normally be a concrete class (ie, a class that can be instantiated).

getComponentInstance

public java.lang.Object getComponentInstance(PicoContainer container)
                                      throws PicoInitializationException,
                                             PicoIntrospectionException
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
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.

verify

public void verify(PicoContainer container)
            throws PicoIntrospectionException
Description copied from interface: ComponentAdapter
Verify that all dependencies for this adapter can be satisifed. Normally, the adapter should verify this by checking that the associated PicoContainer contains all the needed dependnecies.

Specified by:
verify in interface ComponentAdapter
Parameters:
container - the PicoContainer, that is used to resolve any possible dependencies of the instance.
Throws:
PicoIntrospectionException - if one or more dependencies cannot be resolved.

getDelegate

public ComponentAdapter getDelegate()

accept

public void accept(PicoVisitor visitor)
Description copied from interface: ComponentAdapter
Accepts a visitor for this ComponentAdapter. The method is normally called by visiting a PicoContainer, that cascades the visitor also down to all its ComponentAdapter instances.

Specified by:
accept in interface ComponentAdapter
Parameters:
visitor - the visitor.

changeMonitor

public void changeMonitor(ComponentMonitor monitor)
Delegates change of monitor if the delegate supports a component monitor strategy. Changes the component monitor used

Specified by:
changeMonitor in interface ComponentMonitorStrategy
Parameters:
monitor - the new ComponentMonitor to use

currentMonitor

public ComponentMonitor currentMonitor()
Returns delegate's current monitor if the delegate supports a component monitor strategy. Returns the monitor currently used

Specified by:
currentMonitor in interface ComponentMonitorStrategy
Returns:
The ComponentMonitor currently used
Throws:
PicoIntrospectionException - if no component monitor is found in delegate

start

public void start(PicoContainer container)
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
Parameters:
container - the container to "start" its components' lifecycle

stop

public void stop(PicoContainer container)
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
Parameters:
container - the container to "stop" its components' lifecycle

dispose

public void dispose(PicoContainer container)
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
Parameters:
container - the container to "dispose" its components' lifecycle

hasLifecycle

public boolean hasLifecycle()
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
Returns:
true if the component has a lifecycle

start

public void start(java.lang.Object component)
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:
start in interface LifecycleStrategy
Parameters:
component - the instance of the component to start

stop

public void stop(java.lang.Object component)
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:
stop in interface LifecycleStrategy
Parameters:
component - the instance of the component to stop

dispose

public void dispose(java.lang.Object component)
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:
dispose in interface LifecycleStrategy
Parameters:
component - the instance of the component to dispose

hasLifecycle

public boolean hasLifecycle(java.lang.Class type)
Invokes delegate hasLifecylce(Class) method if the delegate is a LifecycleStrategy Test if a component instance has a lifecycle.

Specified by:
hasLifecycle in interface LifecycleStrategy
Parameters:
type - the component's type
Returns:
true if the component has a lifecycle

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getPrintableClassName

private java.lang.String getPrintableClassName()