    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 Paul Hammant & Obie Fernandez & Aslak Helles&oslash;y    *
    009     *****************************************************************************/
    010
    011    package org.picocontainer.monitors;
    012
    013    import java.io.Serializable;
    014    import java.lang.reflect.Constructor;
    015    import java.lang.reflect.Member;
    016    import java.lang.reflect.Method;
    017
    018    import org.picocontainer.ComponentAdapter;
    019    import org.picocontainer.ComponentMonitor;
    020    import org.picocontainer.MutablePicoContainer;
    021    import org.picocontainer.PicoContainer;
    022    import org.picocontainer.PicoLifecycleException;
    023    import org.picocontainer.Injector;
    024    import org.picocontainer.Behavior;
    025
    026    /**
    027     * A {@link ComponentMonitor} which does nothing.
    028     *
    029     * @author Paul Hammant
    030     * @author Obie Fernandez
    031     */
    032    @SuppressWarnings("serial")
    033    public class NullComponentMonitor implements ComponentMonitor, Serializable {
    034
    035        public <T> Constructor<T> instantiating(PicoContainer container, ComponentAdapter<T> componentAdapter,
    036                                         Constructor<T> constructor) {
    037            return constructor;
    038        }
    039
    040        public <T> void instantiationFailed(PicoContainer container,
    041                                        ComponentAdapter<T> componentAdapter,
    042                                        Constructor<T> constructor,
    043                                        Exception e) {
    044        }
    045
    046        public <T> void instantiated(PicoContainer container, ComponentAdapter<T>  componentAdapter,
    047                                 Constructor<T>  constructor,
    048                                 Object instantiated,
    049                                 Object[] injected,
    050                                 long duration) {
    051        }
    052
    053        public void invoking(PicoContainer container,
    054                             ComponentAdapter<?> componentAdapter,
    055                             Member member,
    056                             Object instance) {
    057        }
    058
    059        public void invoked(PicoContainer container,
    060                            ComponentAdapter<?> componentAdapter,
    061                            Method method,
    062                            Object instance,
    063                            long duration) {
    064        }
    065
    066        public void invocationFailed(Member member, Object instance, Exception e) {
    067        }
    068
    069        public void lifecycleInvocationFailed(MutablePicoContainer container,
    070                                              ComponentAdapter<?> componentAdapter, Method method,
    071                                              Object instance,
    072                                              RuntimeException cause) {
    073            if (cause instanceof PicoLifecycleException) {
    074                throw cause;
    075            }
    076            throw new PicoLifecycleException(method, instance, cause);
    077        }
    078
    079        public Object noComponentFound(MutablePicoContainer container, Object componentKey) {
    080            return null;
    081        }
    082
    083        public Injector newInjector(Injector injector) {
    084            return injector;
    085        }
    086
    087        /** {@inheritDoc} **/
    088        public Behavior newBehavior(Behavior behavior) {
    089            return behavior;
    090        }
    091
    092
    093    }