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    @SuppressWarnings("serial")
031    public final class PropertyApplying extends AbstractBehaviorFactory {
032    
033        public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor componentMonitor,
034                LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey,
035                Class<T> componentImplementation, Parameter... parameters) throws PicoCompositionException {
036            ComponentAdapter<?> decoratedAdapter = super.createComponentAdapter(componentMonitor, lifecycleStrategy,
037                    componentProperties, componentKey, componentImplementation, parameters);
038            removePropertiesIfPresent(componentProperties, Characteristics.PROPERTY_APPLYING);
039            return componentMonitor.newBehavior(new PropertyApplicator(decoratedAdapter));
040        }
041    
042        public <T> ComponentAdapter<T> addComponentAdapter(ComponentMonitor componentMonitor,
043                LifecycleStrategy lifecycleStrategy, Properties componentProperties, ComponentAdapter<T> adapter) {
044            removePropertiesIfPresent(componentProperties, Characteristics.PROPERTY_APPLYING);
045            return componentMonitor.newBehavior(new PropertyApplicator(super.addComponentAdapter(componentMonitor, lifecycleStrategy,
046                    componentProperties, adapter)));
047        }
048    }