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: * Original code by *
09: *****************************************************************************/package org.picocontainer.injectors;
10:
11: import org.picocontainer.ComponentAdapter;
12: import org.picocontainer.ComponentMonitor;
13: import org.picocontainer.LifecycleStrategy;
14: import org.picocontainer.Parameter;
15: import org.picocontainer.PicoCompositionException;
16: import org.picocontainer.InjectionFactory;
17: import org.picocontainer.Characteristics;
18: import org.picocontainer.behaviors.AbstractBehaviorFactory;
19: import org.picocontainer.annotations.Inject;
20:
21: import java.util.Properties;
22: import java.io.Serializable;
23: import java.lang.annotation.Annotation;
24:
25: /**
26: * A {@link org.picocontainer.InjectionFactory} for Guice-style annotated fields.
27: * The factory creates {@link AnnotatedFieldInjector}.
28: *
29: * @author Paul Hammant
30: */
31: public class AnnotatedFieldInjection implements InjectionFactory,
32: Serializable {
33:
34: /**
35: * Serialization UUID.
36: */
37: private static final long serialVersionUID = -7470345740391531008L;
38:
39: private final Class<? extends Annotation> injectionAnnotation;
40:
41: public AnnotatedFieldInjection(
42: Class<? extends Annotation> injectionAnnotation) {
43: this .injectionAnnotation = injectionAnnotation;
44: }
45:
46: public AnnotatedFieldInjection() {
47: this (Inject.class);
48: }
49:
50: public <T> ComponentAdapter<T> createComponentAdapter(
51: ComponentMonitor componentMonitor,
52: LifecycleStrategy lifecycleStrategy,
53: Properties componentProperties, Object componentKey,
54: Class<T> componentImplementation, Parameter... parameters)
55: throws PicoCompositionException {
56: boolean useNames = AbstractBehaviorFactory
57: .removePropertiesIfPresent(componentProperties,
58: Characteristics.USE_NAMES);
59: return new AnnotatedFieldInjector(componentKey,
60: componentImplementation, parameters, componentMonitor,
61: lifecycleStrategy, injectionAnnotation, useNames);
62: }
63: }
|