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: *****************************************************************************/package org.picocontainer.injectors;
09:
10: import org.picocontainer.Parameter;
11: import org.picocontainer.ComponentMonitor;
12: import org.picocontainer.LifecycleStrategy;
13: import org.picocontainer.PicoContainer;
14: import org.picocontainer.PicoCompositionException;
15: import org.picocontainer.annotations.Inject;
16:
17: import java.lang.reflect.Constructor;
18: import java.util.Set;
19:
20: /** @author Paul Hammant */
21: public class MultiInjector extends AbstractInjector {
22:
23: private final ConstructorInjector constuctorInjector;
24: private final SetterInjector setterInjector;
25: private AnnotatedMethodInjector annotatedMethodInjector;
26:
27: public MultiInjector(Object componentKey,
28: Class componentImplementation, Parameter[] parameters,
29: ComponentMonitor componentMonitor,
30: LifecycleStrategy lifecycleStrategy, String setterPrefix,
31: boolean useNames) {
32: super (componentKey, componentImplementation, parameters,
33: componentMonitor, lifecycleStrategy, useNames);
34: constuctorInjector = new ConstructorInjector(componentKey,
35: componentImplementation, parameters, componentMonitor,
36: lifecycleStrategy, useNames);
37: setterInjector = new SetterInjector(componentKey,
38: componentImplementation, parameters, componentMonitor,
39: lifecycleStrategy, setterPrefix, useNames) {
40: protected Object getOrMakeInstance(PicoContainer container,
41: Constructor constructor,
42: ComponentMonitor componentMonitor) {
43: return constuctorInjector
44: .getComponentInstance(container);
45: }
46:
47: protected Constructor getConstructor() {
48: return null;
49: }
50:
51: protected void unsatisfiedDependencies(
52: PicoContainer container,
53: Set<Class> unsatisfiableDependencyTypes) {
54: }
55: };
56: annotatedMethodInjector = new AnnotatedMethodInjector(
57: componentKey, componentImplementation, parameters,
58: componentMonitor, lifecycleStrategy, Inject.class,
59: useNames) {
60: protected Object getOrMakeInstance(PicoContainer container,
61: Constructor constructor,
62: ComponentMonitor componentMonitor) {
63: return setterInjector.getComponentInstance(container);
64: }
65:
66: protected Constructor getConstructor() {
67: return null;
68: }
69:
70: protected void unsatisfiedDependencies(
71: PicoContainer container,
72: Set<Class> unsatisfiableDependencyTypes) {
73: }
74: };
75: }
76:
77: public Object getComponentInstance(PicoContainer container)
78: throws PicoCompositionException {
79: return annotatedMethodInjector.getComponentInstance(container);
80: }
81:
82: public void verify(PicoContainer container)
83: throws PicoCompositionException {
84: constuctorInjector.verify(container);
85: constuctorInjector.verify(container);
86: annotatedMethodInjector.verify(container);
87: }
88:
89: public String getDescriptor() {
90: return "MultiInjector";
91: }
92: }
|