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.ComponentFactory;
019    import org.picocontainer.InjectionFactory;
020    
021    import java.io.Serializable;
022    import java.util.Properties;
023    
024    
025    /**
026     * A {@link org.picocontainer.ComponentFactory} for JavaBeans.
027     * The factory creates {@link SetterInjector}.
028     *
029     * @author Jörg Schaible
030     */
031    public class SetterInjection implements InjectionFactory, Serializable {
032    
033        private final String setterMethodPrefix;
034    
035        public SetterInjection(String setterMethodPrefix) {
036            this.setterMethodPrefix = setterMethodPrefix;
037        }
038    
039        public SetterInjection() {
040            this("set");
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 PicoCompositionException if dependencies cannot be solved @throws org.picocontainer.PicoCompositionException
054         *          if the implementation is an interface or an
055         *          abstract class.
056         */
057        public ComponentAdapter createComponentAdapter(ComponentMonitor componentMonitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class componentImplementation, Parameter... parameters)
058                throws PicoCompositionException {
059            return new SetterInjector(componentKey, componentImplementation, parameters, componentMonitor, lifecycleStrategy, setterMethodPrefix);
060        }
061    }