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 org.picocontainer.ComponentMonitor;
011    import org.picocontainer.LifecycleStrategy;
012    import org.picocontainer.ComponentMonitorStrategy;
013    
014    import java.io.Serializable;
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        private ComponentMonitor componentMonitor;
024    
025        /**
026         * Construct a AbstractMonitoringLifecycleStrategy.
027         * 
028         * @param monitor the componentMonitor to use
029         * @throws NullPointerException if the monitor is <code>null</code>
030         */
031        public AbstractMonitoringLifecycleStrategy(ComponentMonitor monitor) {
032            changeMonitor(monitor);
033        }
034        
035        public void changeMonitor(ComponentMonitor monitor) {
036            if (monitor == null) {
037                throw new NullPointerException("Monitor is null");
038            }
039            this.componentMonitor = monitor;
040        }
041    
042        public ComponentMonitor currentMonitor() {
043            return componentMonitor;
044        }
045    
046    }