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 public class ForwardConfig extends BaseConfig {
34 private static final long serialVersionUID = -3983809829201419914L;
35
36
37
38
39
40
41
42 protected String inherit = null;
43
44
45
46
47 protected boolean extensionProcessed = false;
48
49
50
51
52
53 protected String name = null;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 protected String path = null;
82
83
84
85
86
87
88
89
90
91 protected String module = null;
92
93
94
95
96 protected boolean redirect = false;
97
98
99
100
101
102
103 protected String command = null;
104
105
106
107
108
109
110
111
112 protected String catalog = null;
113
114
115
116
117
118
119 public ForwardConfig() {
120 super();
121 }
122
123
124
125
126
127
128
129
130
131 public ForwardConfig(String name, String path, boolean redirect) {
132 super();
133 setName(name);
134 setPath(path);
135 setRedirect(redirect);
136 }
137
138
139
140
141
142
143
144
145
146
147 public ForwardConfig(String name, String path, boolean redirect,
148 String module) {
149 super();
150 setName(name);
151 setPath(path);
152 setRedirect(redirect);
153 setModule(module);
154 }
155
156
157
158
159
160
161
162
163 public ForwardConfig(ForwardConfig copyMe) {
164 this(copyMe.getName(), copyMe.getPath(), copyMe.getRedirect(),
165 copyMe.getModule());
166 }
167
168 public String getExtends() {
169 return (this.inherit);
170 }
171
172 public void setExtends(String inherit) {
173 if (configured) {
174 throw new IllegalStateException("Configuration is frozen");
175 }
176
177 this.inherit = inherit;
178 }
179
180 public boolean isExtensionProcessed() {
181 return extensionProcessed;
182 }
183
184 public String getName() {
185 return (this.name);
186 }
187
188 public void setName(String name) {
189 if (configured) {
190 throw new IllegalStateException("Configuration is frozen");
191 }
192
193 this.name = name;
194 }
195
196 public String getPath() {
197 return (this.path);
198 }
199
200 public void setPath(String path) {
201 if (configured) {
202 throw new IllegalStateException("Configuration is frozen");
203 }
204
205 this.path = path;
206 }
207
208 public String getModule() {
209 return (this.module);
210 }
211
212 public void setModule(String module) {
213 if (configured) {
214 throw new IllegalStateException("Configuration is frozen");
215 }
216
217 this.module = module;
218 }
219
220 public boolean getRedirect() {
221 return (this.redirect);
222 }
223
224 public void setRedirect(boolean redirect) {
225 if (configured) {
226 throw new IllegalStateException("Configuration is frozen");
227 }
228
229 this.redirect = redirect;
230 }
231
232 public String getCommand() {
233 return (this.command);
234 }
235
236 public void setCommand(String command) {
237 if (configured) {
238 throw new IllegalStateException("Configuration is frozen");
239 }
240
241 this.command = command;
242 }
243
244 public String getCatalog() {
245 return (this.catalog);
246 }
247
248 public void setCatalog(String catalog) {
249 if (configured) {
250 throw new IllegalStateException("Configuration is frozen");
251 }
252
253 this.catalog = catalog;
254 }
255
256
257
258
259
260
261
262
263
264
265
266
267
268 protected boolean checkCircularInheritance(ModuleConfig moduleConfig,
269 ActionConfig actionConfig) {
270 String ancestorName = getExtends();
271
272 if (ancestorName == null) {
273 return false;
274 }
275
276
277 ForwardConfig ancestor = null;
278
279
280 if (actionConfig != null) {
281 ancestor = actionConfig.findForwardConfig(ancestorName);
282
283
284 if (ancestor == this) {
285 ancestor = null;
286 }
287 }
288
289
290 if (ancestor == null) {
291 ancestor = moduleConfig.findForwardConfig(ancestorName);
292
293 if (ancestor != null) {
294
295
296
297 actionConfig = null;
298 }
299 }
300
301 while (ancestor != null) {
302
303 if (ancestor == this) {
304 return true;
305 }
306
307
308 ancestorName = ancestor.getExtends();
309
310
311 if (ancestor.getName().equals(ancestorName)) {
312
313
314
315 if (actionConfig == null) {
316 return false;
317 } else {
318
319
320 actionConfig = null;
321 }
322 }
323
324 ancestor = null;
325
326
327 if (actionConfig != null) {
328 ancestor = actionConfig.findForwardConfig(ancestorName);
329 }
330
331
332 if (ancestor == null) {
333 ancestor = moduleConfig.findForwardConfig(ancestorName);
334
335 if (ancestor != null) {
336
337 actionConfig = null;
338 }
339 }
340 }
341
342 return false;
343 }
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372 public void inheritFrom(ForwardConfig config)
373 throws ClassNotFoundException, IllegalAccessException,
374 InstantiationException, InvocationTargetException {
375 if (configured) {
376 throw new IllegalStateException("Configuration is frozen");
377 }
378
379
380 if (getCatalog() == null) {
381 setCatalog(config.getCatalog());
382 }
383
384 if (getCommand() == null) {
385 setCommand(config.getCommand());
386 }
387
388 if (getModule() == null) {
389 setModule(config.getModule());
390 }
391
392 if (getName() == null) {
393 setName(config.getName());
394 }
395
396 if (getPath() == null) {
397 setPath(config.getPath());
398 }
399
400 if (!getRedirect()) {
401 setRedirect(config.getRedirect());
402 }
403
404 inheritProperties(config);
405 }
406
407
408
409
410
411
412
413
414
415
416
417
418
419 public void processExtends(ModuleConfig moduleConfig,
420 ActionConfig actionConfig)
421 throws ClassNotFoundException, IllegalAccessException,
422 InstantiationException, InvocationTargetException {
423 if (configured) {
424 throw new IllegalStateException("Configuration is frozen");
425 }
426
427 String ancestorName = getExtends();
428
429 if ((!extensionProcessed) && (ancestorName != null)) {
430 ForwardConfig baseConfig = null;
431
432
433 boolean checkActionConfig =
434 (this != moduleConfig.findForwardConfig(getName()));
435
436
437 checkActionConfig &= (actionConfig != null);
438
439
440
441
442 checkActionConfig &= !ancestorName.equals(getName());
443
444
445 if (checkActionConfig) {
446 baseConfig = actionConfig.findForwardConfig(ancestorName);
447 }
448
449
450 if (baseConfig == null) {
451 baseConfig = moduleConfig.findForwardConfig(ancestorName);
452 }
453
454 if (baseConfig == null) {
455 throw new NullPointerException("Unable to find " + "forward '"
456 + ancestorName + "' to extend.");
457 }
458
459
460
461 if (checkCircularInheritance(moduleConfig, actionConfig)) {
462 throw new IllegalArgumentException(
463 "Circular inheritance detected for forward " + getName());
464 }
465
466 if (!baseConfig.isExtensionProcessed()) {
467 baseConfig.processExtends(moduleConfig, actionConfig);
468 }
469
470
471 inheritFrom(baseConfig);
472 }
473
474 extensionProcessed = true;
475 }
476
477
478
479
480 public String toString() {
481 StringBuilder sb = new StringBuilder("ForwardConfig[");
482
483 sb.append("name=");
484 sb.append(this.name);
485 sb.append(",path=");
486 sb.append(this.path);
487 sb.append(",redirect=");
488 sb.append(this.redirect);
489 sb.append(",module=");
490 sb.append(this.module);
491 sb.append(",extends=");
492 sb.append(this.inherit);
493 sb.append(",catalog=");
494 sb.append(this.catalog);
495 sb.append(",command=");
496 sb.append(this.command);
497 sb.append("]");
498
499 return (sb.toString());
500 }
501 }