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     * Original code by Mauro Talevi                                             *
009     *****************************************************************************/
010    package org.picocontainer.defaults;
011    
012    import java.io.Serializable;
013    
014    import org.picocontainer.ComponentMonitor;
015    
016    /**
017     * Abstract {@link ComponentAdapterFactory ComponentAdapterFactory} supporting a 
018     * {@link ComponentMonitorStrategy ComponentMonitorStrategy}.
019     * It provides a {@link DelegatingComponentMonitor default ComponentMonitor},
020     * but does not allow to use <code>null</code> for the component monitor.
021     *  
022     * @author Mauro Talevi
023     * @see ComponentAdapterFactory
024     * @see ComponentMonitorStrategy
025     * @since 1.2
026     */
027    public abstract class MonitoringComponentAdapterFactory implements ComponentAdapterFactory, ComponentMonitorStrategy, Serializable {
028        private ComponentMonitor componentMonitor;
029    
030        /**
031         * Constructs a MonitoringComponentAdapterFactory with a custom monitor 
032         * @param monitor the ComponentMonitor used by the factory
033         */
034        protected MonitoringComponentAdapterFactory(ComponentMonitor monitor) {
035            if (monitor == null){
036                throw new NullPointerException("componentMonitor");
037            }
038            this.componentMonitor = monitor;
039        }
040    
041        /**
042         * Constructs a  MonitoringComponentAdapterFactory with a {@link DelegatingComponentMonitor default monitor}.
043         */
044        protected MonitoringComponentAdapterFactory() {
045            this(new DelegatingComponentMonitor());
046        }
047        
048        public void changeMonitor(ComponentMonitor monitor) {
049            this.componentMonitor = monitor;
050        }
051    
052        /**
053         * Returns the monitor currently used
054         * @return The ComponentMonitor currently used
055         */
056        public ComponentMonitor currentMonitor(){
057            return componentMonitor;
058        }
059    
060    }