1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.spec; |
16 |
| |
17 |
| import java.util.ArrayList; |
18 |
| import java.util.Collection; |
19 |
| import java.util.Collections; |
20 |
| import java.util.HashMap; |
21 |
| import java.util.HashSet; |
22 |
| import java.util.Iterator; |
23 |
| import java.util.List; |
24 |
| import java.util.Map; |
25 |
| import java.util.Set; |
26 |
| |
27 |
| import org.apache.hivemind.ApplicationRuntimeException; |
28 |
| import org.apache.hivemind.HiveMind; |
29 |
| import org.apache.hivemind.Resource; |
30 |
| import org.apache.hivemind.util.ToStringBuilder; |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| public class ComponentSpecification extends LocatablePropertyHolder implements |
59 |
| IComponentSpecification |
60 |
| { |
61 |
| private String _componentClassName; |
62 |
| |
63 |
| |
64 |
| |
65 |
| private String _description; |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| protected Map _components; |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| protected Map _assets; |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| protected Map _parameters; |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| protected Map _beans; |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
| protected Set _reservedParameterNames; |
102 |
| |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| private boolean _allowBody = true; |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| private boolean _allowInformalParameters = true; |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| private String _publicId; |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
| |
129 |
| private boolean _pageSpecification; |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| private Resource _specificationLocation; |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| private Map _propertySpecifications; |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| private List _injectSpecifications; |
154 |
| |
155 |
| |
156 |
| |
157 |
| |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| private Map _claimedProperties; |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| private boolean _deprecated = false; |
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
| |
175 |
46
| public void addAsset(String name, IAssetSpecification asset)
|
176 |
| { |
177 |
46
| if (_assets == null)
|
178 |
38
| _assets = new HashMap();
|
179 |
| |
180 |
46
| IAssetSpecification existing = (IAssetSpecification) _assets.get(name);
|
181 |
| |
182 |
46
| if (existing != null)
|
183 |
1
| throw new ApplicationRuntimeException(SpecMessages.duplicateAsset(name, existing),
|
184 |
| asset.getLocation(), null); |
185 |
| |
186 |
45
| claimProperty(asset.getPropertyName(), asset);
|
187 |
| |
188 |
45
| _assets.put(name, asset);
|
189 |
| |
190 |
| } |
191 |
| |
192 |
| |
193 |
| |
194 |
| |
195 |
| |
196 |
| |
197 |
275
| public void addComponent(String id, IContainedComponent component)
|
198 |
| { |
199 |
275
| if (_components == null)
|
200 |
86
| _components = new HashMap();
|
201 |
| |
202 |
275
| IContainedComponent existing = (IContainedComponent) _components.get(id);
|
203 |
| |
204 |
275
| if (existing != null)
|
205 |
1
| throw new ApplicationRuntimeException(SpecMessages.duplicateComponent(id, existing),
|
206 |
| component.getLocation(), null); |
207 |
| |
208 |
274
| _components.put(id, component);
|
209 |
| |
210 |
274
| claimProperty(component.getPropertyName(), component);
|
211 |
| } |
212 |
| |
213 |
| |
214 |
| |
215 |
| |
216 |
| |
217 |
| |
218 |
| |
219 |
| |
220 |
1109
| public void addParameter(IParameterSpecification spec)
|
221 |
| { |
222 |
1109
| if (_parameters == null)
|
223 |
292
| _parameters = new HashMap();
|
224 |
| |
225 |
1109
| String name = spec.getParameterName();
|
226 |
| |
227 |
1109
| addParameterByName(name, spec);
|
228 |
| |
229 |
1108
| Iterator i = spec.getAliasNames().iterator();
|
230 |
1108
| while (i.hasNext())
|
231 |
| { |
232 |
6
| String alias = (String) i.next();
|
233 |
| |
234 |
6
| addParameterByName(alias, spec);
|
235 |
| } |
236 |
| |
237 |
1108
| claimProperty(spec.getPropertyName(), spec);
|
238 |
| } |
239 |
| |
240 |
1115
| private void addParameterByName(String name, IParameterSpecification spec)
|
241 |
| { |
242 |
1115
| IParameterSpecification existing = (IParameterSpecification) _parameters.get(name);
|
243 |
| |
244 |
1115
| if (existing != null)
|
245 |
1
| throw new ApplicationRuntimeException(SpecMessages.duplicateParameter(name, existing),
|
246 |
| spec.getLocation(), null); |
247 |
| |
248 |
1114
| _parameters.put(name, spec);
|
249 |
| |
250 |
1114
| addReservedParameterName(name);
|
251 |
| } |
252 |
| |
253 |
| |
254 |
| |
255 |
| |
256 |
| |
257 |
| |
258 |
| |
259 |
| |
260 |
2497
| public boolean getAllowBody()
|
261 |
| { |
262 |
2497
| return _allowBody;
|
263 |
| } |
264 |
| |
265 |
| |
266 |
| |
267 |
| |
268 |
| |
269 |
| |
270 |
| |
271 |
| |
272 |
| |
273 |
| |
274 |
| |
275 |
| |
276 |
439
| public boolean getAllowInformalParameters()
|
277 |
| { |
278 |
439
| return _allowInformalParameters;
|
279 |
| } |
280 |
| |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
100
| public IAssetSpecification getAsset(String name)
|
289 |
| { |
290 |
| |
291 |
100
| return (IAssetSpecification) get(_assets, name);
|
292 |
| } |
293 |
| |
294 |
| |
295 |
| |
296 |
| |
297 |
| |
298 |
1511
| public List getAssetNames()
|
299 |
| { |
300 |
1511
| return sortedKeys(_assets);
|
301 |
| } |
302 |
| |
303 |
| |
304 |
| |
305 |
| |
306 |
| |
307 |
| |
308 |
| |
309 |
| |
310 |
1495
| public IContainedComponent getComponent(String id)
|
311 |
| { |
312 |
1495
| return (IContainedComponent) get(_components, id);
|
313 |
| } |
314 |
| |
315 |
1101
| public String getComponentClassName()
|
316 |
| { |
317 |
1101
| return _componentClassName;
|
318 |
| } |
319 |
| |
320 |
| |
321 |
| |
322 |
| |
323 |
| |
324 |
| |
325 |
| |
326 |
| |
327 |
1512
| public List getComponentIds()
|
328 |
| { |
329 |
1512
| return sortedKeys(_components);
|
330 |
| } |
331 |
| |
332 |
| |
333 |
| |
334 |
| |
335 |
| |
336 |
| |
337 |
| |
338 |
| |
339 |
13009
| public IParameterSpecification getParameter(String name)
|
340 |
| { |
341 |
13009
| return (IParameterSpecification) get(_parameters, name);
|
342 |
| } |
343 |
| |
344 |
1073
| public Collection getRequiredParameters()
|
345 |
| { |
346 |
1073
| if (_parameters == null)
|
347 |
175
| return Collections.EMPTY_LIST;
|
348 |
| |
349 |
898
| Collection result = new ArrayList();
|
350 |
| |
351 |
898
| Iterator i = _parameters.entrySet().iterator();
|
352 |
898
| while (i.hasNext())
|
353 |
| { |
354 |
3370
| Map.Entry entry = (Map.Entry) i.next();
|
355 |
3370
| String name = (String) entry.getKey();
|
356 |
3370
| IParameterSpecification spec = (IParameterSpecification) entry.getValue();
|
357 |
| |
358 |
3370
| if (!spec.isRequired())
|
359 |
2820
| continue;
|
360 |
| |
361 |
550
| if (!name.equals(spec.getParameterName()))
|
362 |
2
| continue;
|
363 |
| |
364 |
548
| result.add(spec);
|
365 |
| } |
366 |
| |
367 |
898
| return result;
|
368 |
| } |
369 |
| |
370 |
| |
371 |
| |
372 |
| |
373 |
| |
374 |
| |
375 |
| |
376 |
1486
| public List getParameterNames()
|
377 |
| { |
378 |
1486
| return sortedKeys(_parameters);
|
379 |
| } |
380 |
| |
381 |
336
| public void setAllowBody(boolean value)
|
382 |
| { |
383 |
336
| _allowBody = value;
|
384 |
| } |
385 |
| |
386 |
336
| public void setAllowInformalParameters(boolean value)
|
387 |
| { |
388 |
336
| _allowInformalParameters = value;
|
389 |
| } |
390 |
| |
391 |
376
| public void setComponentClassName(String value)
|
392 |
| { |
393 |
376
| _componentClassName = value;
|
394 |
| } |
395 |
| |
396 |
| |
397 |
| |
398 |
| |
399 |
| |
400 |
| |
401 |
| |
402 |
37
| public void addBeanSpecification(String name, IBeanSpecification specification)
|
403 |
| { |
404 |
37
| if (_beans == null)
|
405 |
34
| _beans = new HashMap();
|
406 |
| |
407 |
37
| IBeanSpecification existing = (IBeanSpecification) _beans.get(name);
|
408 |
| |
409 |
37
| if (existing != null)
|
410 |
1
| throw new ApplicationRuntimeException(SpecMessages.duplicateBean(name, existing),
|
411 |
| specification.getLocation(), null); |
412 |
| |
413 |
36
| claimProperty(specification.getPropertyName(), specification);
|
414 |
| |
415 |
36
| _beans.put(name, specification);
|
416 |
| } |
417 |
| |
418 |
| |
419 |
| |
420 |
| |
421 |
| |
422 |
| |
423 |
| |
424 |
| |
425 |
202
| public IBeanSpecification getBeanSpecification(String name)
|
426 |
| { |
427 |
202
| return (IBeanSpecification) get(_beans, name);
|
428 |
| } |
429 |
| |
430 |
| |
431 |
| |
432 |
| |
433 |
| |
434 |
437
| public Collection getBeanNames()
|
435 |
| { |
436 |
437
| if (_beans == null)
|
437 |
393
| return Collections.EMPTY_LIST;
|
438 |
| |
439 |
44
| return Collections.unmodifiableCollection(_beans.keySet());
|
440 |
| } |
441 |
| |
442 |
| |
443 |
| |
444 |
| |
445 |
| |
446 |
| |
447 |
| |
448 |
| |
449 |
| |
450 |
1220
| public void addReservedParameterName(String value)
|
451 |
| { |
452 |
1220
| if (_reservedParameterNames == null)
|
453 |
292
| _reservedParameterNames = new HashSet();
|
454 |
| |
455 |
1220
| _reservedParameterNames.add(value.toLowerCase());
|
456 |
| } |
457 |
| |
458 |
| |
459 |
| |
460 |
| |
461 |
| |
462 |
| |
463 |
| |
464 |
| |
465 |
| |
466 |
| |
467 |
85
| public boolean isReservedParameterName(String value)
|
468 |
| { |
469 |
85
| if (_reservedParameterNames == null)
|
470 |
0
| return false;
|
471 |
| |
472 |
85
| return _reservedParameterNames.contains(value.toLowerCase());
|
473 |
| } |
474 |
| |
475 |
0
| public String toString()
|
476 |
| { |
477 |
0
| ToStringBuilder builder = new ToStringBuilder(this);
|
478 |
| |
479 |
0
| builder.append("componentClassName", _componentClassName);
|
480 |
0
| builder.append("pageSpecification", _pageSpecification);
|
481 |
0
| builder.append("specificationLocation", _specificationLocation);
|
482 |
0
| builder.append("allowBody", _allowBody);
|
483 |
0
| builder.append("allowInformalParameter", _allowInformalParameters);
|
484 |
| |
485 |
0
| return builder.toString();
|
486 |
| } |
487 |
| |
488 |
| |
489 |
| |
490 |
| |
491 |
| |
492 |
| |
493 |
| |
494 |
1
| public String getDescription()
|
495 |
| { |
496 |
1
| return _description;
|
497 |
| } |
498 |
| |
499 |
| |
500 |
| |
501 |
| |
502 |
| |
503 |
| |
504 |
| |
505 |
282
| public void setDescription(String description)
|
506 |
| { |
507 |
282
| _description = description;
|
508 |
| } |
509 |
| |
510 |
| |
511 |
| |
512 |
| |
513 |
| |
514 |
| |
515 |
| |
516 |
| |
517 |
| |
518 |
| |
519 |
0
| public String getPublicId()
|
520 |
| { |
521 |
0
| return _publicId;
|
522 |
| } |
523 |
| |
524 |
| |
525 |
| |
526 |
0
| public void setPublicId(String publicId)
|
527 |
| { |
528 |
0
| _publicId = publicId;
|
529 |
| } |
530 |
| |
531 |
| |
532 |
| |
533 |
| |
534 |
| |
535 |
| |
536 |
| |
537 |
| |
538 |
| |
539 |
| |
540 |
46
| public boolean isPageSpecification()
|
541 |
| { |
542 |
46
| return _pageSpecification;
|
543 |
| } |
544 |
| |
545 |
| |
546 |
| |
547 |
125
| public void setPageSpecification(boolean pageSpecification)
|
548 |
| { |
549 |
125
| _pageSpecification = pageSpecification;
|
550 |
| } |
551 |
| |
552 |
| |
553 |
| |
554 |
4929
| private List sortedKeys(Map input)
|
555 |
| { |
556 |
4929
| if (input == null)
|
557 |
3432
| return Collections.EMPTY_LIST;
|
558 |
| |
559 |
1497
| List result = new ArrayList(input.keySet());
|
560 |
| |
561 |
1497
| Collections.sort(result);
|
562 |
| |
563 |
1497
| return result;
|
564 |
| } |
565 |
| |
566 |
| |
567 |
| |
568 |
14951
| private Object get(Map map, Object key)
|
569 |
| { |
570 |
14951
| if (map == null)
|
571 |
550
| return null;
|
572 |
| |
573 |
14401
| return map.get(key);
|
574 |
| } |
575 |
| |
576 |
| |
577 |
| |
578 |
1076
| public Resource getSpecificationLocation()
|
579 |
| { |
580 |
1076
| return _specificationLocation;
|
581 |
| } |
582 |
| |
583 |
| |
584 |
| |
585 |
477
| public void setSpecificationLocation(Resource specificationLocation)
|
586 |
| { |
587 |
477
| _specificationLocation = specificationLocation;
|
588 |
| } |
589 |
| |
590 |
| |
591 |
| |
592 |
| |
593 |
| |
594 |
| |
595 |
| |
596 |
| |
597 |
123
| public void addPropertySpecification(IPropertySpecification spec)
|
598 |
| { |
599 |
123
| if (_propertySpecifications == null)
|
600 |
61
| _propertySpecifications = new HashMap();
|
601 |
| |
602 |
123
| String name = spec.getName();
|
603 |
123
| IPropertySpecification existing = (IPropertySpecification) _propertySpecifications
|
604 |
| .get(name); |
605 |
| |
606 |
123
| if (existing != null)
|
607 |
0
| throw new ApplicationRuntimeException(SpecMessages.duplicateProperty(name, existing),
|
608 |
| spec.getLocation(), null); |
609 |
| |
610 |
123
| claimProperty(name, spec);
|
611 |
| |
612 |
123
| _propertySpecifications.put(name, spec);
|
613 |
| } |
614 |
| |
615 |
| |
616 |
| |
617 |
| |
618 |
| |
619 |
| |
620 |
| |
621 |
| |
622 |
420
| public List getPropertySpecificationNames()
|
623 |
| { |
624 |
420
| return sortedKeys(_propertySpecifications);
|
625 |
| } |
626 |
| |
627 |
| |
628 |
| |
629 |
| |
630 |
| |
631 |
| |
632 |
| |
633 |
| |
634 |
| |
635 |
145
| public IPropertySpecification getPropertySpecification(String name)
|
636 |
| { |
637 |
145
| return (IPropertySpecification) get(_propertySpecifications, name);
|
638 |
| } |
639 |
| |
640 |
378
| public void addInjectSpecification(InjectSpecification spec)
|
641 |
| { |
642 |
378
| if (_injectSpecifications == null)
|
643 |
175
| _injectSpecifications = new ArrayList();
|
644 |
| |
645 |
378
| claimProperty(spec.getProperty(), spec);
|
646 |
| |
647 |
377
| _injectSpecifications.add(spec);
|
648 |
| } |
649 |
| |
650 |
421
| public List getInjectSpecifications()
|
651 |
| { |
652 |
421
| return safeList(_injectSpecifications);
|
653 |
| } |
654 |
| |
655 |
421
| private List safeList(List input)
|
656 |
| { |
657 |
421
| if (input == null)
|
658 |
246
| return Collections.EMPTY_LIST;
|
659 |
| |
660 |
175
| return Collections.unmodifiableList(input);
|
661 |
| } |
662 |
| |
663 |
1964
| private void claimProperty(String propertyName, Object subSpecification)
|
664 |
| { |
665 |
1964
| if (propertyName == null)
|
666 |
356
| return;
|
667 |
| |
668 |
1608
| if (_claimedProperties == null)
|
669 |
331
| _claimedProperties = new HashMap();
|
670 |
| |
671 |
1608
| Object existing = _claimedProperties.get(propertyName);
|
672 |
| |
673 |
1608
| if (existing != null)
|
674 |
1
| throw new ApplicationRuntimeException(SpecMessages.claimedProperty(
|
675 |
| propertyName, |
676 |
| existing), HiveMind.getLocation(subSpecification), null); |
677 |
| |
678 |
1607
| _claimedProperties.put(propertyName, subSpecification);
|
679 |
| } |
680 |
| |
681 |
| |
682 |
970
| public boolean isDeprecated()
|
683 |
| { |
684 |
970
| return _deprecated;
|
685 |
| } |
686 |
| |
687 |
| |
688 |
336
| public void setDeprecated(boolean deprecated)
|
689 |
| { |
690 |
336
| _deprecated = deprecated;
|
691 |
| } |
692 |
| } |