001 /*****************************************************************************
002 * Copyright (C) PicoContainer Organization. All rights reserved. *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD *
005 * style license a copy of which has been included with this distribution in *
006 * the LICENSE.txt file. *
007 *****************************************************************************/
008 package org.picocontainer.lifecycle;
009
010 import java.io.Serializable;
011
012 import org.picocontainer.ComponentMonitor;
013 import org.picocontainer.ComponentMonitorStrategy;
014 import org.picocontainer.LifecycleStrategy;
015
016 /**
017 * Abstract base class for lifecycle strategy implementation supporting a {@link ComponentMonitor}.
018 *
019 * @author Jörg Schaible
020 */
021 public abstract class AbstractMonitoringLifecycleStrategy implements LifecycleStrategy, ComponentMonitorStrategy, Serializable {
022
023 /**
024 * Component monitor that receives lifecycle state.
025 */
026 private ComponentMonitor componentMonitor;
027
028
029 /**
030 * Construct a AbstractMonitoringLifecycleStrategy.
031 *
032 * @param monitor the componentMonitor to use
033 * @throws NullPointerException if the monitor is <code>null</code>
034 */
035 public AbstractMonitoringLifecycleStrategy(final ComponentMonitor monitor) {
036 changeMonitor(monitor);
037 }
038
039 /**
040 * Swaps the current monitor with a replacement.
041 * @param monitor The new monitor.
042 * @throws NullPointerException if the passed in monitor is null.
043 */
044 public void changeMonitor(final ComponentMonitor monitor) {
045 if (monitor == null) {
046 throw new NullPointerException("Monitor is null");
047 }
048 this.componentMonitor = monitor;
049 }
050
051 /**
052 * Retrieves access to the current monitor.
053 */
054 public ComponentMonitor currentMonitor() {
055 return componentMonitor;
056 }
057
058 }