01: /*****************************************************************************
02: * Copyright (c) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant *
09: *****************************************************************************/package org.picocontainer.injectors;
10:
11: import java.io.Serializable;
12: import java.util.Properties;
13:
14: import org.picocontainer.Characteristics;
15: import org.picocontainer.ComponentAdapter;
16: import org.picocontainer.ComponentMonitor;
17: import org.picocontainer.InjectionFactory;
18: import org.picocontainer.LifecycleStrategy;
19: import org.picocontainer.Parameter;
20: import org.picocontainer.PicoCompositionException;
21: import org.picocontainer.behaviors.AbstractBehaviorFactory;
22:
23: /**
24: * A {@link org.picocontainer.InjectionFactory} for JavaBeans.
25: * The factory creates {@link SetterInjector}.
26: *
27: * @author Jörg Schaible
28: */
29: public class SetterInjection implements InjectionFactory, Serializable {
30:
31: private final String setterMethodPrefix;
32:
33: public SetterInjection(String setterMethodPrefix) {
34: this .setterMethodPrefix = setterMethodPrefix;
35: }
36:
37: public SetterInjection() {
38: this ("set");
39: }
40:
41: /**
42: * Create a {@link SetterInjector}.
43: *
44: * @param componentMonitor
45: * @param lifecycleStrategy
46: * @param componentProperties
47: * @param componentKey The component's key
48: * @param componentImplementation The class of the bean.
49: * @param parameters Any parameters for the setters. If null the adapter
50: * solves the dependencies for all setters internally. Otherwise
51: * the number parameters must match the number of the setter.
52: * @return Returns a new {@link SetterInjector}.
53: * @throws PicoCompositionException if dependencies cannot be solved
54: * @throws org.picocontainer.PicoCompositionException if the implementation
55: * is an interface or an abstract class.
56: */
57: public <T> ComponentAdapter<T> createComponentAdapter(
58: ComponentMonitor componentMonitor,
59: LifecycleStrategy lifecycleStrategy,
60: Properties componentProperties, Object componentKey,
61: Class<T> componentImplementation, Parameter... parameters)
62: throws PicoCompositionException {
63: boolean useNames = AbstractBehaviorFactory
64: .removePropertiesIfPresent(componentProperties,
65: Characteristics.USE_NAMES);
66: return new SetterInjector(componentKey,
67: componentImplementation, parameters, componentMonitor,
68: lifecycleStrategy, setterMethodPrefix, useNames);
69: }
70: }
|