001    package org.picocontainer.injectors;
002    
003    import org.picocontainer.ComponentAdapter;
004    import org.picocontainer.ComponentMonitor;
005    import org.picocontainer.LifecycleStrategy;
006    import org.picocontainer.Parameter;
007    import org.picocontainer.PicoCompositionException;
008    
009    import java.util.Properties;
010    
011    public class NamedMethodInjection extends AbstractInjectionFactory {
012    
013        private final String prefix;
014        private final boolean optional;
015    
016        public NamedMethodInjection(String prefix) {
017            this(prefix, true);
018        }
019    
020        public NamedMethodInjection() {
021            this("set");
022        }
023    
024        public NamedMethodInjection(boolean optional) {
025            this("set", optional);
026        }
027    
028        public NamedMethodInjection(String prefix, boolean optional) {
029            this.prefix = prefix;
030            this.optional = optional;
031        }
032    
033        public <T> ComponentAdapter<T> createComponentAdapter(ComponentMonitor monitor, LifecycleStrategy lifecycleStrategy, Properties componentProperties, Object componentKey, Class<T> componentImplementation, Parameter... parameters) throws PicoCompositionException {
034            return wrapLifeCycle(monitor.newInjector(new NamedMethodInjector(componentKey, componentImplementation, parameters, monitor, prefix, optional)), lifecycleStrategy);
035        }
036    }