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