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 ParentChildResourceLoader(ResourceLoader parent, ResourceLoader child) {
37 if (parent == null) {
38 throw new IllegalArgumentException("parent resource loader was null");
39 }
40 if (child == null) {
41 throw new IllegalArgumentException("child resource loader was null");
42 }
43 this.parent = parent;
44 this.child = child;
45 this.name = new QName(child.getName().toString() + " to parent " + parent.getName().toString());
46 }
47
48 @Override
49 public <T> T getObject(ObjectDefinition definition) {
50 T object = child.<T>getObject(definition);
51 if (object == null) {
52 object = parent.<T>getObject(definition);
53 }
54 return object;
55 }
56
57 @Override
58 public <T> T getService(QName qname) {
59 T service = child.<T>getService(qname);
60 if (service == null) {
61 service = parent.<T>getService(qname);
62 }
63 return service;
64 }
65
66
67
68
69
70
71
72
73 @Override
74 public void start() throws Exception {
75 if (!child.isStarted()) {
76 child.start();
77 }
78 }
79
80
81
82
83
84
85 @Override
86 public void stop() throws Exception {
87 if (child.isStarted()) {
88 child.stop();
89 }
90 }
91
92 @Override
93 public void addResourceLoader(ResourceLoader resourceLoader) {
94 this.child.addResourceLoader(resourceLoader);
95 }
96
97 @Override
98 public void addResourceLoaderFirst(ResourceLoader resourceLoader) {
99 this.child.addResourceLoaderFirst(resourceLoader);
100 }
101
102 @Override
103 public ResourceLoader getResourceLoader(QName name) {
104 ResourceLoader resourceLoader = this.child.getResourceLoader(name);
105 if (resourceLoader == null && parent != null) {
106 return parent.getResourceLoader(name);
107 } else {
108 return resourceLoader;
109 }
110 }
111
112 @Override
113 public List<QName> getResourceLoaderNames() {
114 return this.child.getResourceLoaderNames();
115 }
116
117 @Override
118 public List<ResourceLoader> getResourceLoaders() {
119 return this.child.getResourceLoaders();
120 }
121
122 @Override
123 public void removeResourceLoader(QName name) {
124 this.child.removeResourceLoader(name);
125 }
126
127
128
129
130
131
132 @Override
133 public boolean isStarted() {
134
135 return false;
136 }
137
138 @Override
139 public void setName(QName name) {
140 this.name = name;
141 }
142
143 @Override
144 public QName getName() {
145 return this.name;
146 }
147
148
149
150
151
152
153 @Override
154 public String getContents(String indent, boolean servicePerLine) {
155 StringBuilder contents = new StringBuilder();
156 contents.append(parent.getContents(indent, servicePerLine)).append("\n");
157 contents.append(child.getContents(indent, servicePerLine));
158 return contents.toString();
159 }
160
161
162
163 }