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    
013    import org.picocontainer.ComponentAdapter;
014    import org.picocontainer.Parameter;
015    import org.picocontainer.PicoCompositionException;
016    import org.picocontainer.ComponentMonitor;
017    import org.picocontainer.LifecycleStrategy;
018    import org.picocontainer.Characteristics;
019    import org.picocontainer.behaviors.AbstractBehaviorFactory;
020    import org.picocontainer.behaviors.PropertyApplicator;
021    
022    import java.util.Properties;
023    
024    /**
025     * A {@link org.picocontainer.ComponentFactory} that creates
026     * {@link PropertyApplicator} instances.
027     * 
028     * @author Aslak Hellesøy
029     */
030    public final class PropertyApplying extends AbstractBehaviorFactory {
031    
032        public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor,
033                LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey,
034                Class<T> componentImplementation, Parameter... parameters) throws PicoCompositionException {
035            ComponentAdapter<?> decoratedAdapter = super.createComponentAdapter(componentMonitor, lifecycleStrategy,
036                    componentProperties, componentKey, componentImplementation, parameters);
037            removePropertiesIfPresent(componentProperties, Characteristics.PROPERTY_APPLYING);
038            return new PropertyApplicator(decoratedAdapter);
039        }
040    
041        public <T> ComponentAdapter<T> addComponentAdapter(ComponentMonitor componentMonitor,
042                LifecycleStrategy lifecycleStrategy, Properties componentProperties, ComponentAdapter<T> adapter) {
043            removePropertiesIfPresent(componentProperties, Characteristics.PROPERTY_APPLYING);
044            return new PropertyApplicator(super.addComponentAdapter(componentMonitor, lifecycleStrategy,
045                    componentProperties, adapter));
046        }
047    }