01: /*****************************************************************************
02: * Copyright (C) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: *****************************************************************************/package org.picocontainer.lifecycle;
08:
09: import java.io.Serializable;
10:
11: import org.picocontainer.ComponentMonitor;
12: import org.picocontainer.ComponentMonitorStrategy;
13: import org.picocontainer.LifecycleStrategy;
14:
15: /**
16: * Abstract base class for lifecycle strategy implementation supporting a {@link ComponentMonitor}.
17: *
18: * @author Jörg Schaible
19: */
20: public abstract class AbstractMonitoringLifecycleStrategy implements
21: LifecycleStrategy, ComponentMonitorStrategy, Serializable {
22:
23: /**
24: * Component monitor that receives lifecycle state.
25: */
26: private ComponentMonitor componentMonitor;
27:
28: /**
29: * Construct a AbstractMonitoringLifecycleStrategy.
30: *
31: * @param monitor the componentMonitor to use
32: * @throws NullPointerException if the monitor is <code>null</code>
33: */
34: public AbstractMonitoringLifecycleStrategy(
35: final ComponentMonitor monitor) {
36: changeMonitor(monitor);
37: }
38:
39: /**
40: * Swaps the current monitor with a replacement.
41: * @param monitor The new monitor.
42: * @throws NullPointerException if the passed in monitor is null.
43: */
44: public void changeMonitor(final ComponentMonitor monitor) {
45: if (monitor == null) {
46: throw new NullPointerException("Monitor is null");
47: }
48: this .componentMonitor = monitor;
49: }
50:
51: /**
52: * Retrieves access to the current monitor.
53: */
54: public ComponentMonitor currentMonitor() {
55: return componentMonitor;
56: }
57:
58: }
|