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     * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
009     *****************************************************************************/
010    
011    package org.picocontainer.injectors;
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.InjectionFactory;
019    import org.picocontainer.annotations.Inject;
020    
021    import java.io.Serializable;
022    import java.util.Properties;
023    
024    
025    /**
026     * A {@link org.picocontainer.ComponentFactory} for Guice style annotated methods.
027     * The factory creates {@link AnnotatedMethodInjector}.
028     *
029     * @author Paul Hammant
030     */
031    public class AnnotatedMethodInjection implements InjectionFactory, Serializable {
032    
033        private final Class injectionAnnotation;
034    
035        public AnnotatedMethodInjection(Class injectionAnnotation) {
036            this.injectionAnnotation = injectionAnnotation;
037        }
038    
039        public AnnotatedMethodInjection() {
040            this(Inject.class);
041        }
042    
043        /**
044         * Create a {@link SetterInjector}.
045         *
046         * @param componentMonitor
047         * @param lifecycleStrategy
048         * @param componentProperties
049         * @param componentKey            The component's key
050         * @param componentImplementation The class of the bean.
051         * @param parameters              Any parameters for the setters. If null the adapter solves the
052         *                                dependencies for all setters internally. Otherwise the number parameters must match
053         *                                the number of the setter. @return Returns a new {@link SetterInjector}. @throws org.picocontainer.PicoCompositionException if dependencies 
054         *                                cannot be solved or if the implementation is an interface or an abstract class.
055         */
056        public ComponentAdapter createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class componentImplementation, Parameter... parameters)
057                throws PicoCompositionException {
058            return new AnnotatedMethodInjector(componentKey, componentImplementation, parameters, componentMonitor, lifecycleStrategy, injectionAnnotation);
059        }
060    }