    001    /*****************************************************************************
    002     * Copyright (C) NanoContainer 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                                             *
    009     *****************************************************************************/
    010
    011    package org.nanocontainer.reflection;
    012
    013    import java.io.Serializable;
    014
    015    import org.nanocontainer.NanoPicoContainer;
    016    import org.picocontainer.MutablePicoContainer;
    017    import org.picocontainer.PicoContainer;
    018    import org.picocontainer.alternatives.ImplementationHidingPicoContainer;
    019    import org.picocontainer.defaults.ComponentAdapterFactory;
    020    import org.picocontainer.defaults.DefaultComponentAdapterFactory;
    021
    022    /**
    023     * This is a MutablePicoContainer that supports soft composition and hides implementations where it can.
    024     * <p/>
    025     * In terms of implementation it adopts the behaviour of ImplementationHidingPicoContainer
    026     * and DefaulNanoContainer
    027     *
    028     * @author Paul Hammant
    029     * @author Michael Rimov
    030     * @version $Revision: 2964 $
    031     */
    032    public class ImplementationHidingNanoPicoContainer extends AbstractNanoPicoContainer implements NanoPicoContainer, Serializable {
    033
    034        public ImplementationHidingNanoPicoContainer(ClassLoader classLoader, ComponentAdapterFactory caf, PicoContainer parent) {
    035            super(new ImplementationHidingPicoContainer(caf, parent), classLoader);
    036        }
    037
    038
    039        public ImplementationHidingNanoPicoContainer(ClassLoader classLoader, PicoContainer parent) {
    040            super(new ImplementationHidingPicoContainer(new DefaultComponentAdapterFactory(), parent), classLoader);
    041        }
    042
    043        public ImplementationHidingNanoPicoContainer(PicoContainer pc) {
    044            this(ImplementationHidingNanoPicoContainer.class.getClassLoader(), pc);
    045        }
    046
    047        public ImplementationHidingNanoPicoContainer(ClassLoader classLoader) {
    048            this(classLoader, null);
    049        }
    050
    051        public ImplementationHidingNanoPicoContainer() {
    052            this(ImplementationHidingNanoPicoContainer.class.getClassLoader(), null);
    053        }
    054
    055        /**
    056         * Copy Constructor.  Makes a new ImplementationHidingNanoPicoContainer with the same
    057         * attributes - ClassLoader, child PicoContainer type, ComponentAdapterFactory -
    058         * as the parent.
    059         * <p><tt>Note:</tt> This constructor is protected because are existing scripts
    060         * that call <tt>new ImplementationHidingNanoPicoContainer(PicoContainer)</tt>, and they get this
    061         * constructor instead (which has different behavior).</p>
    062         * @param parent ImplementationHidingNanoPicoContainer
    063         */
    064        protected ImplementationHidingNanoPicoContainer(final ImplementationHidingNanoPicoContainer parent) {
    065            super(parent.getDelegate().makeChildContainer(), parent.getComponentClassLoader());
    066        }
    067
    068
    069        protected AbstractNanoPicoContainer createChildContainer() {
    070            return new ImplementationHidingNanoPicoContainer(this);
    071        }
    072    }