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 *****************************************************************************/
010package org.picocontainer.behaviors;
011
012import org.picocontainer.ComponentAdapter;
013import org.picocontainer.Parameter;
014import org.picocontainer.PicoCompositionException;
015import org.picocontainer.ComponentMonitor;
016import org.picocontainer.LifecycleStrategy;
017import org.picocontainer.Characteristics;
018import org.picocontainer.behaviors.AbstractBehaviorFactory;
019
020import 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")
027public class ImplementationHiding extends AbstractBehaviorFactory {
028
029    public ComponentAdapter createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class componentImplementation, Parameter... parameters) throws PicoCompositionException {
030
031        removePropertiesIfPresent(componentProperties, Characteristics.ENABLE_CIRCULAR);
032
033        ComponentAdapter componentAdapter = super.createComponentAdapter(componentMonitor, lifecycleStrategy,
034                                                                         componentProperties, componentKey, componentImplementation, parameters);
035        if (removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) {
036            return componentAdapter;
037        }
038        removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL);
039        return componentMonitor.newBehavior(new HiddenImplementation(componentAdapter));
040
041    }
042
043    public ComponentAdapter addComponentAdapter(ComponentMonitor componentMonitor,
044                                                LifecycleStrategy lifecycleStrategy,
045                                                Properties componentProperties,
046                                                ComponentAdapter adapter) {
047        if (removePropertiesIfPresent(componentProperties, Characteristics.NO_HIDE_IMPL)) {
048            return adapter;
049        }
050        removePropertiesIfPresent(componentProperties, Characteristics.HIDE_IMPL);
051        return componentMonitor.newBehavior(new HiddenImplementation(super.addComponentAdapter(componentMonitor,
052                                                                          lifecycleStrategy,
053                                                                          componentProperties,
054                                                                          adapter)));
055
056    }
057}