|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ComponentParameter.java | 91.7% | 94.1% | 100% | 93.8% |
|
1 |
package org.picocontainer.internals;
|
|
2 |
|
|
3 |
import org.picocontainer.PicoContainer;
|
|
4 |
import org.picocontainer.PicoInitializationException;
|
|
5 |
import org.picocontainer.defaults.UnsatisfiedDependencyInstantiationException;
|
|
6 |
import org.picocontainer.internals.Parameter;
|
|
7 |
import org.picocontainer.internals.ComponentRegistry;
|
|
8 |
import org.picocontainer.internals.ComponentSpecification;
|
|
9 |
|
|
10 |
import java.io.Serializable;
|
|
11 |
|
|
12 |
/**
|
|
13 |
* @author Jon Tirsen (tirsen@codehaus.org)
|
|
14 |
* @version $Revision: 1.4 $
|
|
15 |
*/
|
|
16 |
public class ComponentParameter implements Parameter, Serializable { |
|
17 |
|
|
18 |
private Object componentKey;
|
|
19 |
|
|
20 | 87 |
public ComponentParameter() {
|
21 |
} |
|
22 |
|
|
23 | 2 |
public ComponentParameter(Object componentKey) {
|
24 | 2 |
this.componentKey = componentKey;
|
25 |
} |
|
26 |
|
|
27 | 69 |
public Object resolve(ComponentRegistry componentRegistry, ComponentSpecification compSpec, Class requestedType)
|
28 |
throws PicoInitializationException {
|
|
29 |
|
|
30 | 69 |
Object componentInstance; |
31 | 69 |
ComponentSpecification componentSpecification = null;
|
32 |
|
|
33 | 69 |
if (componentKey != null) { |
34 |
|
|
35 |
// is specified dependency already instantiated?
|
|
36 | 2 |
componentInstance = componentRegistry.getComponentInstance(componentKey); |
37 |
|
|
38 | 2 |
if (componentInstance == null) { |
39 |
// try to find the component based on the key
|
|
40 | 0 |
componentSpecification = componentRegistry.getComponentSpec(componentKey); |
41 |
} |
|
42 |
|
|
43 |
} else {
|
|
44 |
|
|
45 |
// try to find it directly using the requestType as the key
|
|
46 | 67 |
componentInstance = componentRegistry.getComponentInstance(requestedType); |
47 |
|
|
48 | 67 |
if (componentInstance == null) { |
49 |
|
|
50 |
// is there already an instantiated instance that satisfies the dependency?
|
|
51 | 27 |
componentInstance = componentRegistry.findImplementingComponent(requestedType); |
52 |
|
|
53 |
|
|
54 | 26 |
if (componentInstance == null) { |
55 |
// try to find components that satisfy the interface (implements the component service asked for)
|
|
56 | 19 |
componentSpecification = componentRegistry.findImplementingComponentSpecification(requestedType); |
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 | 67 |
if (componentSpecification != null) { |
63 |
// if the component does not exist yet, instantiate it
|
|
64 | 15 |
componentInstance = componentRegistry.createComponent(componentSpecification); |
65 |
} |
|
66 |
|
|
67 | 67 |
if (componentInstance == null) { |
68 | 3 |
throw new UnsatisfiedDependencyInstantiationException(compSpec.getComponentImplementation(), componentKey, requestedType); |
69 |
} |
|
70 |
|
|
71 | 64 |
return componentInstance;
|
72 |
} |
|
73 |
} |
|
74 |
|
|