    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 Object invoking(PicoContainer container,
    054                               ComponentAdapter<?> componentAdapter,
    055                               Member member,
    056                               Object instance, Object[] args) {
    057            return KEEP;
    058        }
    059
    060        public void invoked(PicoContainer container,
    061                            ComponentAdapter<?> componentAdapter,
    062                            Member member,
    063                            Object instance,
    064                            long duration, Object[] args, Object retVal) {
    065        }
    066
    067        public void invocationFailed(Member member, Object instance, Exception e) {
    068        }
    069
    070        public void lifecycleInvocationFailed(MutablePicoContainer container,
    071                                              ComponentAdapter<?> componentAdapter, Method method,
    072                                              Object instance,
    073                                              RuntimeException cause) {
    074            if (cause instanceof PicoLifecycleException) {
    075                throw cause;
    076            }
    077            throw new PicoLifecycleException(method, instance, cause);
    078        }
    079
    080        public Object noComponentFound(MutablePicoContainer container, Object componentKey) {
    081            return null;
    082        }
    083
    084        public Injector newInjector(Injector injector) {
    085            return injector;
    086        }
    087
    088        /** {@inheritDoc} **/
    089        public Behavior newBehavior(Behavior behavior) {
    090            return behavior;
    091        }
    092
    093
    094    }