1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.api.resourceloader; |
18 | |
|
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.xml.namespace.QName; |
22 | |
|
23 | |
import org.kuali.rice.core.api.reflect.ObjectDefinition; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
class ParentChildResourceLoader implements ResourceLoader { |
32 | |
|
33 | |
private final ResourceLoader parent; |
34 | |
private final ResourceLoader child; |
35 | |
private QName name; |
36 | |
|
37 | 0 | ParentChildResourceLoader(ResourceLoader parent, ResourceLoader child) { |
38 | 0 | if (parent == null) { |
39 | 0 | throw new IllegalArgumentException("parent resource loader was null"); |
40 | |
} |
41 | 0 | if (child == null) { |
42 | 0 | throw new IllegalArgumentException("child resource loader was null"); |
43 | |
} |
44 | 0 | this.parent = parent; |
45 | 0 | this.child = child; |
46 | 0 | this.name = new QName(child.getName().toString() + " to parent " + parent.getName().toString()); |
47 | 0 | } |
48 | |
|
49 | |
@Override |
50 | |
public <T> T getObject(ObjectDefinition definition) { |
51 | 0 | T object = child.<T>getObject(definition); |
52 | 0 | if (object == null) { |
53 | 0 | object = parent.<T>getObject(definition); |
54 | |
} |
55 | 0 | return object; |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public <T> T getService(QName qname) { |
60 | 0 | T service = child.<T>getService(qname); |
61 | 0 | if (service == null) { |
62 | 0 | service = parent.<T>getService(qname); |
63 | |
} |
64 | 0 | return service; |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@Override |
75 | |
public void start() throws Exception { |
76 | 0 | if (!child.isStarted()) { |
77 | 0 | child.start(); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
@Override |
87 | |
public void stop() throws Exception { |
88 | 0 | if (child.isStarted()) { |
89 | 0 | child.stop(); |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
@Override |
94 | |
public void addResourceLoader(ResourceLoader resourceLoader) { |
95 | 0 | this.child.addResourceLoader(resourceLoader); |
96 | 0 | } |
97 | |
|
98 | |
@Override |
99 | |
public void addResourceLoaderFirst(ResourceLoader resourceLoader) { |
100 | 0 | this.child.addResourceLoaderFirst(resourceLoader); |
101 | 0 | } |
102 | |
|
103 | |
@Override |
104 | |
public ResourceLoader getResourceLoader(QName name) { |
105 | 0 | ResourceLoader resourceLoader = this.child.getResourceLoader(name); |
106 | 0 | if (resourceLoader == null && parent != null) { |
107 | 0 | return parent.getResourceLoader(name); |
108 | |
} else { |
109 | 0 | return resourceLoader; |
110 | |
} |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public List<QName> getResourceLoaderNames() { |
115 | 0 | return this.child.getResourceLoaderNames(); |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public List<ResourceLoader> getResourceLoaders() { |
120 | 0 | return this.child.getResourceLoaders(); |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
public void removeResourceLoader(QName name) { |
125 | 0 | this.child.removeResourceLoader(name); |
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
@Override |
134 | |
public boolean isStarted() { |
135 | |
|
136 | 0 | return false; |
137 | |
} |
138 | |
|
139 | |
@Override |
140 | |
public void setName(QName name) { |
141 | 0 | this.name = name; |
142 | 0 | } |
143 | |
|
144 | |
@Override |
145 | |
public QName getName() { |
146 | 0 | return this.name; |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
@Override |
155 | |
public String getContents(String indent, boolean servicePerLine) { |
156 | 0 | StringBuilder contents = new StringBuilder(); |
157 | 0 | contents.append(parent.getContents(indent, servicePerLine)).append("\n"); |
158 | 0 | contents.append(child.getContents(indent, servicePerLine)); |
159 | 0 | return contents.toString(); |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
} |