org.picocontainer.gems.lifecycle
Class ReflectionLifecycleStrategy

java.lang.Object
  extended by org.picocontainer.defaults.AbstractMonitoringLifecycleStrategy
      extended by org.picocontainer.gems.lifecycle.ReflectionLifecycleStrategy
All Implemented Interfaces:
java.io.Serializable, org.picocontainer.defaults.ComponentMonitorStrategy, org.picocontainer.defaults.LifecycleStrategy

public class ReflectionLifecycleStrategy
extends org.picocontainer.defaults.AbstractMonitoringLifecycleStrategy

Reflection lifecycle strategy. Starts, stops, disposes of component if appropriate methods are present. The component may implement only one of the three methods.

Since:
1.2
Author:
Paul Hammant, Mauro Talevi, Jörg Schaible
See Also:
Startable, Disposable, DefaultLifecycleStrategy, Serialized Form

Field Summary
private static int DISPOSE
           
private  java.util.Map methodMap
           
private  java.lang.String[] methodNames
           
private static int START
           
private static int STOP
           
 
Constructor Summary
ReflectionLifecycleStrategy(org.picocontainer.ComponentMonitor monitor)
          Construct a ReflectionLifecycleStrategy.
ReflectionLifecycleStrategy(org.picocontainer.ComponentMonitor monitor, java.lang.String startMethodName, java.lang.String stopMethodName, java.lang.String disposeMethodName)
          Construct a ReflectionLifecycleStrategy with individual method names.
 
Method Summary
 void dispose(java.lang.Object component)
           
 boolean hasLifecycle(java.lang.Class type)
           The component has a lifecylce if at least one of the three methods is present.
private  java.lang.reflect.Method[] init(java.lang.Class type)
           
private  void invokeMethod(java.lang.Object component, java.lang.reflect.Method method)
           
 void start(java.lang.Object component)
           
 void stop(java.lang.Object component)
           
 
Methods inherited from class org.picocontainer.defaults.AbstractMonitoringLifecycleStrategy
changeMonitor, currentMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

START

private static final int START
See Also:
Constant Field Values

STOP

private static final int STOP
See Also:
Constant Field Values

DISPOSE

private static final int DISPOSE
See Also:
Constant Field Values

methodNames

private java.lang.String[] methodNames

methodMap

private final transient java.util.Map methodMap
Constructor Detail

ReflectionLifecycleStrategy

public ReflectionLifecycleStrategy(org.picocontainer.ComponentMonitor monitor)
Construct a ReflectionLifecycleStrategy.

Parameters:
monitor - the monitor to use
Throws:
java.lang.NullPointerException - if the monitor is null

ReflectionLifecycleStrategy

public ReflectionLifecycleStrategy(org.picocontainer.ComponentMonitor monitor,
                                   java.lang.String startMethodName,
                                   java.lang.String stopMethodName,
                                   java.lang.String disposeMethodName)
Construct a ReflectionLifecycleStrategy with individual method names. Note, that a lifecycle method does not have any arguments.

Parameters:
monitor - the monitor to use
startMethodName - the name of the start method
stopMethodName - the name of the stop method
disposeMethodName - the name of the dispose method
Throws:
java.lang.NullPointerException - if the monitor is null
Method Detail

start

public void start(java.lang.Object component)

stop

public void stop(java.lang.Object component)

dispose

public void dispose(java.lang.Object component)

invokeMethod

private void invokeMethod(java.lang.Object component,
                          java.lang.reflect.Method method)

hasLifecycle

public boolean hasLifecycle(java.lang.Class type)
The component has a lifecylce if at least one of the three methods is present.


init

private java.lang.reflect.Method[] init(java.lang.Class type)