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 org.picocontainer.ComponentAdapter;
12: import org.picocontainer.Parameter;
13: import org.picocontainer.PicoCompositionException;
14: import org.picocontainer.ComponentMonitor;
15: import org.picocontainer.LifecycleStrategy;
16: import org.picocontainer.InjectionFactory;
17: import org.picocontainer.annotations.Inject;
18:
19: import java.io.Serializable;
20: import java.lang.annotation.Annotation;
21: import java.util.Properties;
22:
23: /**
24: * A {@link org.picocontainer.InjectionFactory} for Guice-style annotated methods.
25: * The factory creates {@link AnnotatedMethodInjector}.
26: *
27: * @author Paul Hammant
28: */
29: public class AnnotatedMethodInjection implements InjectionFactory,
30: Serializable {
31:
32: /**
33: * Serialization UUID.
34: */
35: private static final long serialVersionUID = 6225372552727902003L;
36:
37: private final Class<? extends Annotation> injectionAnnotation;
38: private final boolean useNames;
39:
40: public AnnotatedMethodInjection(
41: Class<? extends Annotation> injectionAnnotation,
42: boolean useNames) {
43: this .injectionAnnotation = injectionAnnotation;
44: this .useNames = useNames;
45: }
46:
47: public AnnotatedMethodInjection() {
48: this (Inject.class, false);
49: }
50:
51: /**
52: * Create a {@link SetterInjector}.
53: *
54: * @param componentMonitor
55: * @param lifecycleStrategy
56: * @param componentProperties
57: * @param componentKey The component's key
58: * @param componentImplementation The class of the bean.
59: * @param parameters Any parameters for the setters. If null the adapter
60: * solves the dependencies for all setters internally. Otherwise
61: * the number parameters must match the number of the setter.
62: * @return Returns a new {@link SetterInjector}.
63: * @throws org.picocontainer.PicoCompositionException if dependencies cannot
64: * be solved or if the implementation is an interface or an
65: * abstract class.
66: */
67: public <T> ComponentAdapter<T> createComponentAdapter(
68: ComponentMonitor componentMonitor,
69: LifecycleStrategy lifecycleStrategy,
70: Properties componentProperties, Object componentKey,
71: Class<T> componentImplementation, Parameter... parameters)
72: throws PicoCompositionException {
73: return new AnnotatedMethodInjector(componentKey,
74: componentImplementation, parameters, componentMonitor,
75: lifecycleStrategy, injectionAnnotation, useNames);
76: }
77: }
|