1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.config;
22
23 import java.lang.reflect.InvocationTargetException;
24
25
26
27
28
29
30
31
32
33
34 public class ExceptionConfig extends BaseConfig {
35
36
37
38
39
40
41
42 protected String bundle = null;
43
44
45
46
47
48 protected String inherit = null;
49
50
51
52
53 protected boolean extensionProcessed = false;
54
55
56
57
58
59 protected String handler = "org.apache.struts.action.ExceptionHandler";
60
61
62
63
64
65 protected String key = null;
66
67
68
69
70
71 protected String path = null;
72
73
74
75
76
77 protected String scope = "request";
78
79
80
81
82
83 protected String type = null;
84
85 public String getBundle() {
86 return (this.bundle);
87 }
88
89 public void setBundle(String bundle) {
90 if (configured) {
91 throw new IllegalStateException("Configuration is frozen");
92 }
93
94 this.bundle = bundle;
95 }
96
97 public String getExtends() {
98 return (this.inherit);
99 }
100
101 public void setExtends(String inherit) {
102 if (configured) {
103 throw new IllegalStateException("Configuration is frozen");
104 }
105
106 this.inherit = inherit;
107 }
108
109 public boolean isExtensionProcessed() {
110 return extensionProcessed;
111 }
112
113 public String getHandler() {
114 return (this.handler);
115 }
116
117 public void setHandler(String handler) {
118 if (configured) {
119 throw new IllegalStateException("Configuration is frozen");
120 }
121
122 this.handler = handler;
123 }
124
125 public String getKey() {
126 return (this.key);
127 }
128
129 public void setKey(String key) {
130 if (configured) {
131 throw new IllegalStateException("Configuration is frozen");
132 }
133
134 this.key = key;
135 }
136
137 public String getPath() {
138 return (this.path);
139 }
140
141 public void setPath(String path) {
142 if (configured) {
143 throw new IllegalStateException("Configuration is frozen");
144 }
145
146 this.path = path;
147 }
148
149 public String getScope() {
150 return (this.scope);
151 }
152
153 public void setScope(String scope) {
154 if (configured) {
155 throw new IllegalStateException("Configuration is frozen");
156 }
157
158 this.scope = scope;
159 }
160
161 public String getType() {
162 return (this.type);
163 }
164
165 public void setType(String type) {
166 if (configured) {
167 throw new IllegalStateException("Configuration is frozen");
168 }
169
170 this.type = type;
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184
185 protected boolean checkCircularInheritance(ModuleConfig moduleConfig,
186 ActionConfig actionConfig) {
187 String ancestorType = getExtends();
188
189 if (ancestorType == null) {
190 return false;
191 }
192
193
194 ExceptionConfig ancestor = null;
195
196
197 if (actionConfig != null) {
198 ancestor = actionConfig.findExceptionConfig(ancestorType);
199
200
201 if (ancestor == this) {
202 ancestor = null;
203 }
204 }
205
206
207 if (ancestor == null) {
208 ancestor = moduleConfig.findExceptionConfig(ancestorType);
209
210 if (ancestor != null) {
211
212
213
214 actionConfig = null;
215 }
216 }
217
218 while (ancestor != null) {
219
220 if (ancestor == this) {
221 return true;
222 }
223
224
225 ancestorType = ancestor.getExtends();
226
227
228 if (ancestor.getType().equals(ancestorType)) {
229
230
231
232 if (actionConfig == null) {
233 return false;
234 } else {
235
236
237 actionConfig = null;
238 }
239 }
240
241 ancestor = null;
242
243
244 if (actionConfig != null) {
245 ancestor = actionConfig.findExceptionConfig(ancestorType);
246 }
247
248
249 if (ancestor == null) {
250 ancestor = moduleConfig.findExceptionConfig(ancestorType);
251
252 if (ancestor != null) {
253
254 actionConfig = null;
255 }
256 }
257 }
258
259 return false;
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289 public void inheritFrom(ExceptionConfig config)
290 throws ClassNotFoundException, IllegalAccessException,
291 InstantiationException, InvocationTargetException {
292 if (configured) {
293 throw new IllegalStateException("Configuration is frozen");
294 }
295
296
297 if (getBundle() == null) {
298 setBundle(config.getBundle());
299 }
300
301 if (getHandler().equals("org.apache.struts.action.ExceptionHandler")) {
302 setHandler(config.getHandler());
303 }
304
305 if (getKey() == null) {
306 setKey(config.getKey());
307 }
308
309 if (getPath() == null) {
310 setPath(config.getPath());
311 }
312
313 if (getScope().equals("request")) {
314 setScope(config.getScope());
315 }
316
317 if (getType() == null) {
318 setType(config.getType());
319 }
320
321 inheritProperties(config);
322 }
323
324
325
326
327
328
329
330
331
332
333
334
335
336 public void processExtends(ModuleConfig moduleConfig,
337 ActionConfig actionConfig)
338 throws ClassNotFoundException, IllegalAccessException,
339 InstantiationException, InvocationTargetException {
340 if (configured) {
341 throw new IllegalStateException("Configuration is frozen");
342 }
343
344 String ancestorType = getExtends();
345
346 if ((!extensionProcessed) && (ancestorType != null)) {
347 ExceptionConfig baseConfig = null;
348
349
350 boolean checkActionConfig =
351 (this != moduleConfig.findExceptionConfig(getType()));
352
353
354 checkActionConfig &= (actionConfig != null);
355
356
357
358
359 checkActionConfig &= !ancestorType.equals(getType());
360
361
362 if (checkActionConfig) {
363 baseConfig = actionConfig.findExceptionConfig(ancestorType);
364 }
365
366
367 if (baseConfig == null) {
368 baseConfig = moduleConfig.findExceptionConfig(ancestorType);
369 }
370
371 if (baseConfig == null) {
372 throw new NullPointerException("Unable to find "
373 + "handler for '" + ancestorType + "' to extend.");
374 }
375
376
377
378 if (checkCircularInheritance(moduleConfig, actionConfig)) {
379 throw new IllegalArgumentException(
380 "Circular inheritance detected for forward " + getType());
381 }
382
383 if (!baseConfig.isExtensionProcessed()) {
384 baseConfig.processExtends(moduleConfig, actionConfig);
385 }
386
387
388 inheritFrom(baseConfig);
389 }
390
391 extensionProcessed = true;
392 }
393
394
395
396
397 public String toString() {
398 StringBuffer sb = new StringBuffer("ExceptionConfig[");
399
400 sb.append("type=");
401 sb.append(this.type);
402
403 if (this.bundle != null) {
404 sb.append(",bundle=");
405 sb.append(this.bundle);
406 }
407
408 if (this.inherit != null) {
409 sb.append(",extends=");
410 sb.append(this.inherit);
411 }
412
413 sb.append(",handler=");
414 sb.append(this.handler);
415 sb.append(",key=");
416 sb.append(this.key);
417 sb.append(",path=");
418 sb.append(this.path);
419 sb.append(",scope=");
420 sb.append(this.scope);
421 sb.append("]");
422
423 return (sb.toString());
424 }
425 }