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