org.picocontainer.defaults
Class InstanceComponentAdapter

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

public class InstanceComponentAdapter
extends AbstractComponentAdapter
implements LifecycleManager, LifecycleStrategy

Component adapter which wraps a component instance.

This component adapter supports both a LifecycleManager 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.

Version:
$Revision: 2823 $
Author:
Aslak Hellesøy, Paul Hammant, Mauro Talevi
See Also:
Serialized Form

Field Summary
private  java.lang.Object componentInstance
           
private  LifecycleStrategy lifecycleStrategy
           
 
Constructor Summary
InstanceComponentAdapter(java.lang.Object componentKey, java.lang.Object componentInstance)
           
InstanceComponentAdapter(java.lang.Object componentKey, java.lang.Object componentInstance, LifecycleStrategy lifecycleStrategy)
           
 
Method Summary
 void dispose(java.lang.Object component)
          Invoke the "dispose" method on the component instance if this is disposable.
 void dispose(PicoContainer container)
          Invoke the "dispose" method on the container's components.
 java.lang.Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
private static java.lang.Class getInstanceClass(java.lang.Object componentInstance)
           
 boolean hasLifecycle()
          Test if a container's component has a lifecycle.
 boolean hasLifecycle(java.lang.Class type)
          Test if a component instance has a lifecycle.
 void start(java.lang.Object component)
          Invoke the "start" method on the component instance if this is startable.
 void start(PicoContainer container)
          Invoke the "start" method on the container's components.
 void stop(java.lang.Object component)
          Invoke the "stop" method on the component instance if this is stoppable.
 void stop(PicoContainer container)
          Invoke the "stop" method on the container's components.
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisifed.
 
Methods inherited from class org.picocontainer.defaults.AbstractComponentAdapter
accept, checkTypeCompatibility, getComponentImplementation, getComponentKey, toString
 
Methods inherited from class org.picocontainer.defaults.MonitoringComponentAdapter
changeMonitor, currentMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

componentInstance

private java.lang.Object componentInstance

lifecycleStrategy

private LifecycleStrategy lifecycleStrategy
Constructor Detail

InstanceComponentAdapter

public InstanceComponentAdapter(java.lang.Object componentKey,
                                java.lang.Object componentInstance)
                         throws AssignabilityRegistrationException,
                                NotConcreteRegistrationException
Throws:
AssignabilityRegistrationException
NotConcreteRegistrationException

InstanceComponentAdapter

public InstanceComponentAdapter(java.lang.Object componentKey,
                                java.lang.Object componentInstance,
                                LifecycleStrategy lifecycleStrategy)
                         throws AssignabilityRegistrationException,
                                NotConcreteRegistrationException
Throws:
AssignabilityRegistrationException
NotConcreteRegistrationException
Method Detail

getInstanceClass

private static java.lang.Class getInstanceClass(java.lang.Object componentInstance)

getComponentInstance

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

verify

public void verify(PicoContainer container)
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.

start

public void start(PicoContainer container)
Description copied from interface: 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)
Description copied from interface: 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)
Description copied from interface: 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()
Description copied from interface: 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)
Description copied from interface: 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)
Description copied from interface: 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)
Description copied from interface: 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)
Description copied from interface: 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