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.behaviors;
011    
012    import org.picocontainer.ComponentAdapter;
013    import org.picocontainer.Parameter;
014    import org.picocontainer.PicoCompositionException;
015    import org.picocontainer.ComponentMonitor;
016    import org.picocontainer.LifecycleStrategy;
017    import org.picocontainer.Characteristics;
018    import org.picocontainer.behaviors.AbstractBehaviorFactory;
019    
020    import java.util.Properties;
021    
022    /**
023     * @author Aslak Hellesøy
024     * @see org.picocontainer.gems.adapters.HotSwappingComponentFactory for a more feature-rich version of the class
025     */
026    @SuppressWarnings("serial")
027    public class ImplementationHiding extends AbstractBehaviorFactory {
028    
029        public ComponentAdapter createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class componentImplementation, Parameter... parameters) throws PicoCompositionException {
030            ComponentAdapter componentAdapter = super.createComponentAdapter(componentMonitor, lifecycleStrategy,
031                                                                             componentProperties, componentKey, componentImplementation, parameters);
032            if (removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) {
033                return componentAdapter;
034            }
035            removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL);
036            return new HiddenImplementation(componentAdapter);
037    
038        }
039    
040        public ComponentAdapter addComponentAdapter(ComponentMonitor componentMonitor,
041                                                    LifecycleStrategy lifecycleStrategy,
042                                                    Properties componentProperties,
043                                                    ComponentAdapter adapter) {
044            if (removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) {
045                return adapter;
046            }
047            removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL);
048            return new HiddenImplementation(super.addComponentAdapter(componentMonitor,
049                                                                              lifecycleStrategy,
050                                                                              componentProperties,
051                                                                              adapter));
052    
053        }
054    }