    001    /*****************************************************************************
    002     * Copyright (C) NanoContainer 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 Joerg Schaibe                                            *
    009     *****************************************************************************/
    010
    011    package org.picocontainer.behaviors;
    012
    013    import org.picocontainer.ComponentAdapter;
    014    import org.picocontainer.ComponentMonitor;
    015    import org.picocontainer.LifecycleStrategy;
    016    import org.picocontainer.Parameter;
    017    import org.picocontainer.PicoCompositionException;
    018    import org.picocontainer.behaviors.AbstractBehaviorFactory;
    019
    020    import java.util.Properties;
    021
    022
    023    /**
    024     * BehaviorFactory for Field Decorating. This factory will create {@link org.picocontainer.gems.behaviors.FieldDecorated} that will
    025     * allow you to decorate fields on the component instance that has been created
    026     *
    027     * @author Paul Hammant
    028     */
    029    public abstract class FieldDecorating extends AbstractBehaviorFactory implements FieldDecorated.Decorator {
    030        private final Class<?> fieldClass;
    031
    032        public FieldDecorating(Class<?> fieldClass) {
    033            this.fieldClass = fieldClass;
    034        }
    035
    036        public ComponentAdapter createComponentAdapter(
    037                ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, final Object componentKey, final Class componentImplementation, final Parameter... parameters)
    038                throws PicoCompositionException {
    039            return componentMonitor.newBehavior(new FieldDecorated(
    040                    super.createComponentAdapter(
    041                            componentMonitor, lifecycleStrategy, componentProperties, componentKey, componentImplementation, parameters),
    042                    fieldClass, this));
    043        }
    044
    045
    046        public ComponentAdapter addComponentAdapter(ComponentMonitor componentMonitor,
    047                                                    LifecycleStrategy lifecycleStrategy,
    048                                                    Properties componentProperties,
    049                                                    ComponentAdapter adapter) {
    050            return super.addComponentAdapter(componentMonitor,
    051                    lifecycleStrategy,
    052                    componentProperties,
    053                    adapter);
    054        }
    055    }