Package org.picocontainer.lifecycle
Class ReflectionLifecycleStrategy
- java.lang.Object
-
- org.picocontainer.lifecycle.AbstractMonitoringLifecycleStrategy
-
- org.picocontainer.lifecycle.ReflectionLifecycleStrategy
-
- All Implemented Interfaces:
Serializable
,ComponentMonitorStrategy
,LifecycleStrategy
public class ReflectionLifecycleStrategy extends AbstractMonitoringLifecycleStrategy
Reflection lifecycle strategy. Starts, stops, disposes of component if appropriate methods are present. The component may implement only one of the three methods.- See Also:
Startable
,Disposable
,StartableLifecycleStrategy
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ReflectionLifecycleStrategy(ComponentMonitor monitor)
Construct a ReflectionLifecycleStrategy.ReflectionLifecycleStrategy(ComponentMonitor monitor, String startMethodName, String stopMethodName, String disposeMethodName)
Construct a ReflectionLifecycleStrategy with individual method names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose(Object component)
Invoke the "dispose" method on the component instance if this is disposable.boolean
hasLifecycle(Class<?> type)
Test if a component instance has a lifecycle.protected void
monitorAndThrowReflectionLifecycleException(Method method, Throwable e, Object component)
void
start(Object component)
Invoke the "start" method on the component instance if this is startable.void
stop(Object component)
Invoke the "stop" method on the component instance if this is stoppable.-
Methods inherited from class org.picocontainer.lifecycle.AbstractMonitoringLifecycleStrategy
changeMonitor, currentMonitor, isLazy
-
-
-
-
Constructor Detail
-
ReflectionLifecycleStrategy
public ReflectionLifecycleStrategy(ComponentMonitor monitor)
Construct a ReflectionLifecycleStrategy.- Parameters:
monitor
- the monitor to use- Throws:
NullPointerException
- if the monitor isnull
-
ReflectionLifecycleStrategy
public ReflectionLifecycleStrategy(ComponentMonitor monitor, String startMethodName, String stopMethodName, String disposeMethodName)
Construct a ReflectionLifecycleStrategy with individual method names. Note, that a lifecycle method does not have any arguments.- Parameters:
monitor
- the monitor to usestartMethodName
- the name of the start methodstopMethodName
- the name of the stop methoddisposeMethodName
- the name of the dispose method- Throws:
NullPointerException
- if the monitor isnull
-
-
Method Detail
-
start
public void start(Object component)
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.- Parameters:
component
- the instance of the component to start
-
stop
public void stop(Object component)
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.- Parameters:
component
- the instance of the component to stop
-
dispose
public void dispose(Object component)
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.- Parameters:
component
- the instance of the component to dispose
-
monitorAndThrowReflectionLifecycleException
protected void monitorAndThrowReflectionLifecycleException(Method method, Throwable e, Object component)
-
hasLifecycle
public boolean hasLifecycle(Class<?> type)
Test if a component instance has a lifecycle. The component has a lifecycle if at least one of the three methods is present.- Parameters:
type
- the component's type- Returns:
true
if the component has a lifecycle
-
-