1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| package org.picocontainer.alternatives; |
10 |
| |
11 |
| import org.picocontainer.ComponentAdapter; |
12 |
| import org.picocontainer.MutablePicoContainer; |
13 |
| import org.picocontainer.Parameter; |
14 |
| import org.picocontainer.PicoContainer; |
15 |
| import org.picocontainer.PicoRegistrationException; |
16 |
| import org.picocontainer.LifecycleManager; |
17 |
| import org.picocontainer.defaults.ComponentAdapterFactory; |
18 |
| import org.picocontainer.defaults.DefaultComponentAdapterFactory; |
19 |
| import org.picocontainer.defaults.DefaultPicoContainer; |
20 |
| import org.picocontainer.defaults.DefaultLifecycleManager; |
21 |
| |
22 |
| import java.io.Serializable; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class ImplementationHidingPicoContainer extends AbstractDelegatingMutablePicoContainer implements Serializable { |
34 |
| |
35 |
| private ComponentAdapterFactory caf; |
36 |
| private LifecycleManager lifecycleManager; |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
198
| public ImplementationHidingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent, LifecycleManager lifecycleManager) {
|
42 |
198
| super(new DefaultPicoContainer(caf, parent, lifecycleManager));
|
43 |
198
| this.caf = caf;
|
44 |
198
| this.lifecycleManager = lifecycleManager;
|
45 |
| } |
46 |
| |
47 |
| |
48 |
86
| public ImplementationHidingPicoContainer(ComponentAdapterFactory caf, PicoContainer parent) {
|
49 |
86
| this(caf, parent, new DefaultLifecycleManager());
|
50 |
| } |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
84
| public ImplementationHidingPicoContainer(PicoContainer parent) {
|
56 |
84
| this(new DefaultComponentAdapterFactory(), parent);
|
57 |
| } |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
14
| public ImplementationHidingPicoContainer() {
|
64 |
14
| this(null);
|
65 |
| } |
66 |
| |
67 |
46
| public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation) throws PicoRegistrationException {
|
68 |
46
| if (componentKey instanceof Class) {
|
69 |
20
| Class clazz = (Class) componentKey;
|
70 |
20
| if (clazz.isInterface()) {
|
71 |
16
| ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, null);
|
72 |
16
| return getDelegate().registerComponent(new ImplementationHidingComponentAdapter(delegate, true));
|
73 |
| } |
74 |
| } |
75 |
30
| return getDelegate().registerComponentImplementation(componentKey, componentImplementation);
|
76 |
| } |
77 |
| |
78 |
18
| public ComponentAdapter registerComponentImplementation(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoRegistrationException {
|
79 |
18
| if (componentKey instanceof Class) {
|
80 |
6
| Class clazz = (Class) componentKey;
|
81 |
6
| if (clazz.isInterface()) {
|
82 |
2
| ComponentAdapter delegate = caf.createComponentAdapter(componentKey, componentImplementation, parameters);
|
83 |
2
| ImplementationHidingComponentAdapter ihDelegate = new ImplementationHidingComponentAdapter(delegate, true);
|
84 |
2
| return getDelegate().registerComponent(ihDelegate);
|
85 |
| } |
86 |
| } |
87 |
16
| return getDelegate().registerComponentImplementation(componentKey, componentImplementation, parameters);
|
88 |
| } |
89 |
| |
90 |
8
| public MutablePicoContainer makeChildContainer() {
|
91 |
8
| ImplementationHidingPicoContainer pc = new ImplementationHidingPicoContainer(caf, this, lifecycleManager);
|
92 |
8
| getDelegate().addChildContainer(pc);
|
93 |
8
| return pc;
|
94 |
| } |
95 |
| |
96 |
| } |