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