    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     *****************************************************************************/
    009    package org.picocontainer.behaviors;
    010
    011    import org.picocontainer.ComponentAdapter;
    012    import org.picocontainer.PicoContainer;
    013    import org.picocontainer.PicoCompositionException;
    014    import org.picocontainer.behaviors.AbstractBehavior;
    015
    016    import java.lang.reflect.Type;
    017
    018    @SuppressWarnings("serial")
    019    public class Decorated extends AbstractBehavior {
    020        private final Decorator decorator;
    021
    022
    023        public Decorated(ComponentAdapter delegate, Decorator decorator) {
    024            super(delegate);
    025            this.decorator = decorator;
    026        }
    027
    028        public Object getComponentInstance(final PicoContainer container, Type into)
    029                throws PicoCompositionException {
    030            Object instance = super.getComponentInstance(container, into);
    031            decorator.decorate(instance);
    032            return instance;
    033        }
    034
    035
    036        public String getDescriptor() {
    037            return "FieldDecorated";
    038        }
    039
    040        interface Decorator {
    041
    042            void decorate(Object instance);
    043
    044
    045        }
    046
    047    }