org.picocontainer.adapters
Class InstanceAdapter

java.lang.Object
  extended by org.picocontainer.adapters.AbstractAdapter
      extended by org.picocontainer.adapters.InstanceAdapter
All Implemented Interfaces:
Serializable, Behavior, ComponentAdapter, ComponentMonitorStrategy, LifecycleStrategy

public final class InstanceAdapter
extends AbstractAdapter
implements Behavior, LifecycleStrategy

Component adapter which wraps a component instance.

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

Author:
Aslak Hellesøy, Paul Hammant, Mauro Talevi
See Also:
Serialized Form

Constructor Summary
InstanceAdapter(Object componentKey, Object componentInstance, LifecycleStrategy lifecycleStrategy, ComponentMonitor componentMonitor)
           
 
Method Summary
 boolean componentHasLifecycle()
          Test if a component honors a lifecycle.
 void dispose(Object component)
          Invoke the "dispose" method on the component instance if this is disposable.
 void dispose(PicoContainer container)
          Invoke the "dispose" method on the component.
 Object getComponentInstance(PicoContainer container)
          Retrieve the component instance.
 boolean hasLifecycle(Class type)
          Test if a component instance has a lifecycle.
 void start(Object component)
          Invoke the "start" method on the component instance if this is startable.
 void start(PicoContainer container)
          Invoke the "start" method on the component.
 void stop(Object component)
          Invoke the "stop" method on the component instance if this is stoppable.
 void stop(PicoContainer container)
          Invoke the "stop" method on the component.
 String toString()
           
 void verify(PicoContainer container)
          Verify that all dependencies for this adapter can be satisifed.
 
Methods inherited from class org.picocontainer.adapters.AbstractAdapter
accept, changeMonitor, checkTypeCompatibility, currentMonitor, findAdapterOfType, getComponentImplementation, getComponentKey, getDelegate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.picocontainer.ComponentAdapter
accept, findAdapterOfType, getComponentImplementation, getComponentKey, getDelegate
 

Constructor Detail

InstanceAdapter

public InstanceAdapter(Object componentKey,
                       Object componentInstance,
                       LifecycleStrategy lifecycleStrategy,
                       ComponentMonitor componentMonitor)
                throws PicoCompositionException
Throws:
PicoCompositionException
Method Detail

getComponentInstance

public 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, Cached 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: Behavior
Invoke the "start" method on the component.

Specified by:
start in interface Behavior
Parameters:
container - the container to "start" the component

stop

public void stop(PicoContainer container)
Description copied from interface: Behavior
Invoke the "stop" method on the component.

Specified by:
stop in interface Behavior
Parameters:
container - the container to "stop" the component

dispose

public void dispose(PicoContainer container)
Description copied from interface: Behavior
Invoke the "dispose" method on the component.

Specified by:
dispose in interface Behavior
Parameters:
container - the container to "dispose" the component

componentHasLifecycle

public boolean componentHasLifecycle()
Description copied from interface: Behavior
Test if a component honors a lifecycle.

Specified by:
componentHasLifecycle in interface Behavior
Returns:
true if the component has a lifecycle

start

public void start(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(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(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(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

toString

public String toString()
Overrides:
toString in class AbstractAdapter
Returns:
Returns the ComponentAdapter's class name and the component's key.
See Also:
Object.toString()


Copyright © 2003-2007 Codehaus. All Rights Reserved.