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 *****************************************************************************/
009package org.picocontainer.behaviors;
010
011import org.picocontainer.ComponentAdapter;
012import org.picocontainer.PicoContainer;
013import org.picocontainer.PicoCompositionException;
014import org.picocontainer.behaviors.AbstractBehavior;
015
016import java.lang.reflect.Type;
017
018@SuppressWarnings("serial")
019public class Decorated<T> extends AbstractBehavior<T> {
020    private final Decorator decorator;
021
022
023    public Decorated(ComponentAdapter<T> delegate, Decorator decorator) {
024        super(delegate);
025        this.decorator = decorator;
026    }
027
028    public T getComponentInstance(final PicoContainer container, Type into)
029            throws PicoCompositionException {
030        T 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}