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