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 public class ImplementationHiding extends AbstractBehaviorFactory {
027
028 public ComponentAdapter createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class componentImplementation, Parameter... parameters) throws PicoCompositionException {
029 ComponentAdapter componentAdapter = super.createComponentAdapter(componentMonitor, lifecycleStrategy,
030 componentProperties, componentKey, componentImplementation, parameters);
031 if (removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) {
032 return componentAdapter;
033 }
034 removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL);
035 return new HiddenImplementation(componentAdapter);
036
037 }
038
039 public ComponentAdapter addComponentAdapter(ComponentMonitor componentMonitor,
040 LifecycleStrategy lifecycleStrategy,
041 Properties componentProperties,
042 ComponentAdapter adapter) {
043 if (removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) {
044 return adapter;
045 }
046 removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL);
047 return new HiddenImplementation(super.addComponentAdapter(componentMonitor,
048 lifecycleStrategy,
049 componentProperties,
050 adapter));
051
052 }
053 }