|
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 |
132
| public void addAsset(String name, IAssetSpecification asset)
|
|
176 |
| { |
|
177 |
132
| if (_assets == null)
|
|
178 |
108
| _assets = new HashMap();
|
|
179 |
| |
|
180 |
132
| IAssetSpecification existing = (IAssetSpecification) _assets.get(name);
|
|
181 |
| |
|
182 |
132
| if (existing != null)
|
|
183 |
3
| throw new ApplicationRuntimeException(SpecMessages.duplicateAsset(name, existing),
|
|
184 |
| asset.getLocation(), null); |
|
185 |
| |
|
186 |
129
| claimProperty(asset.getPropertyName(), asset);
|
|
187 |
| |
|
188 |
129
| _assets.put(name, asset);
|
|
189 |
| |
|
190 |
| } |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
753
| public void addComponent(String id, IContainedComponent component)
|
|
198 |
| { |
|
199 |
753
| if (_components == null)
|
|
200 |
246
| _components = new HashMap();
|
|
201 |
| |
|
202 |
753
| IContainedComponent existing = (IContainedComponent) _components.get(id);
|
|
203 |
| |
|
204 |
753
| if (existing != null)
|
|
205 |
3
| throw new ApplicationRuntimeException(SpecMessages.duplicateComponent(id, existing),
|
|
206 |
| component.getLocation(), null); |
|
207 |
| |
|
208 |
750
| _components.put(id, component);
|
|
209 |
| |
|
210 |
750
| claimProperty(component.getPropertyName(), component);
|
|
211 |
| } |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
3519
| public void addParameter(IParameterSpecification spec)
|
|
221 |
| { |
|
222 |
3519
| if (_parameters == null)
|
|
223 |
819
| _parameters = new HashMap();
|
|
224 |
| |
|
225 |
3519
| String name = spec.getParameterName();
|
|
226 |
| |
|
227 |
3519
| addParameterByName(name, spec);
|
|
228 |
| |
|
229 |
3516
| Iterator i = spec.getAliasNames().iterator();
|
|
230 |
3516
| while (i.hasNext())
|
|
231 |
| { |
|
232 |
24
| String alias = (String) i.next();
|
|
233 |
| |
|
234 |
24
| addParameterByName(alias, spec);
|
|
235 |
| } |
|
236 |
| |
|
237 |
3516
| claimProperty(spec.getPropertyName(), spec);
|
|
238 |
| } |
|
239 |
| |
|
240 |
3543
| private void addParameterByName(String name, IParameterSpecification spec)
|
|
241 |
| { |
|
242 |
3543
| IParameterSpecification existing = (IParameterSpecification) _parameters.get(name);
|
|
243 |
| |
|
244 |
3543
| if (existing != null)
|
|
245 |
3
| throw new ApplicationRuntimeException(SpecMessages.duplicateParameter(name, existing),
|
|
246 |
| spec.getLocation(), null); |
|
247 |
| |
|
248 |
3540
| _parameters.put(name, spec);
|
|
249 |
| |
|
250 |
3540
| addReservedParameterName(name);
|
|
251 |
| } |
|
252 |
| |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
| |
|
259 |
| |
|
260 |
6780
| public boolean getAllowBody()
|
|
261 |
| { |
|
262 |
6780
| return _allowBody;
|
|
263 |
| } |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
| |
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| |
|
276 |
1167
| public boolean getAllowInformalParameters()
|
|
277 |
| { |
|
278 |
1167
| return _allowInformalParameters;
|
|
279 |
| } |
|
280 |
| |
|
281 |
| |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
| |
|
286 |
| |
|
287 |
| |
|
288 |
282
| public IAssetSpecification getAsset(String name)
|
|
289 |
| { |
|
290 |
| |
|
291 |
282
| return (IAssetSpecification) get(_assets, name);
|
|
292 |
| } |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| |
|
297 |
| |
|
298 |
4176
| public List getAssetNames()
|
|
299 |
| { |
|
300 |
4176
| return sortedKeys(_assets);
|
|
301 |
| } |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
4095
| public IContainedComponent getComponent(String id)
|
|
311 |
| { |
|
312 |
4095
| return (IContainedComponent) get(_components, id);
|
|
313 |
| } |
|
314 |
| |
|
315 |
3036
| public String getComponentClassName()
|
|
316 |
| { |
|
317 |
3036
| return _componentClassName;
|
|
318 |
| } |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
4179
| public List getComponentIds()
|
|
328 |
| { |
|
329 |
4179
| return sortedKeys(_components);
|
|
330 |
| } |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
33291
| public IParameterSpecification getParameter(String name)
|
|
340 |
| { |
|
341 |
33291
| return (IParameterSpecification) get(_parameters, name);
|
|
342 |
| } |
|
343 |
| |
|
344 |
2949
| public Collection getRequiredParameters()
|
|
345 |
| { |
|
346 |
2949
| if (_parameters == null)
|
|
347 |
486
| return Collections.EMPTY_LIST;
|
|
348 |
| |
|
349 |
2463
| Collection result = new ArrayList();
|
|
350 |
| |
|
351 |
2463
| Iterator i = _parameters.entrySet().iterator();
|
|
352 |
2463
| while (i.hasNext())
|
|
353 |
| { |
|
354 |
9972
| Map.Entry entry = (Map.Entry) i.next();
|
|
355 |
9972
| String name = (String) entry.getKey();
|
|
356 |
9972
| IParameterSpecification spec = (IParameterSpecification) entry.getValue();
|
|
357 |
| |
|
358 |
9972
| if (!spec.isRequired())
|
|
359 |
8379
| continue;
|
|
360 |
| |
|
361 |
1593
| if (!name.equals(spec.getParameterName()))
|
|
362 |
6
| continue;
|
|
363 |
| |
|
364 |
1587
| result.add(spec);
|
|
365 |
| } |
|
366 |
| |
|
367 |
2463
| return result;
|
|
368 |
| } |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
| |
|
375 |
| |
|
376 |
4116
| public List getParameterNames()
|
|
377 |
| { |
|
378 |
4116
| return sortedKeys(_parameters);
|
|
379 |
| } |
|
380 |
| |
|
381 |
945
| public void setAllowBody(boolean value)
|
|
382 |
| { |
|
383 |
945
| _allowBody = value;
|
|
384 |
| } |
|
385 |
| |
|
386 |
945
| public void setAllowInformalParameters(boolean value)
|
|
387 |
| { |
|
388 |
945
| _allowInformalParameters = value;
|
|
389 |
| } |
|
390 |
| |
|
391 |
1050
| public void setComponentClassName(String value)
|
|
392 |
| { |
|
393 |
1050
| _componentClassName = value;
|
|
394 |
| } |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
| |
|
401 |
| |
|
402 |
96
| public void addBeanSpecification(String name, IBeanSpecification specification)
|
|
403 |
| { |
|
404 |
96
| if (_beans == null)
|
|
405 |
93
| _beans = new HashMap();
|
|
406 |
| |
|
407 |
96
| IBeanSpecification existing = (IBeanSpecification) _beans.get(name);
|
|
408 |
| |
|
409 |
96
| if (existing != null)
|
|
410 |
3
| throw new ApplicationRuntimeException(SpecMessages.duplicateBean(name, existing),
|
|
411 |
| specification.getLocation(), null); |
|
412 |
| |
|
413 |
93
| claimProperty(specification.getPropertyName(), specification);
|
|
414 |
| |
|
415 |
93
| _beans.put(name, specification);
|
|
416 |
| } |
|
417 |
| |
|
418 |
| |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
564
| public IBeanSpecification getBeanSpecification(String name)
|
|
426 |
| { |
|
427 |
564
| return (IBeanSpecification) get(_beans, name);
|
|
428 |
| } |
|
429 |
| |
|
430 |
| |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
1209
| public Collection getBeanNames()
|
|
435 |
| { |
|
436 |
1209
| if (_beans == null)
|
|
437 |
1101
| return Collections.EMPTY_LIST;
|
|
438 |
| |
|
439 |
108
| return Collections.unmodifiableCollection(_beans.keySet());
|
|
440 |
| } |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
| |
|
450 |
3867
| public void addReservedParameterName(String value)
|
|
451 |
| { |
|
452 |
3867
| if (_reservedParameterNames == null)
|
|
453 |
819
| _reservedParameterNames = new HashSet();
|
|
454 |
| |
|
455 |
3867
| _reservedParameterNames.add(value.toLowerCase());
|
|
456 |
| } |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
| |
|
464 |
| |
|
465 |
| |
|
466 |
| |
|
467 |
240
| public boolean isReservedParameterName(String value)
|
|
468 |
| { |
|
469 |
240
| if (_reservedParameterNames == null)
|
|
470 |
0
| return false;
|
|
471 |
| |
|
472 |
240
| return _reservedParameterNames.contains(value.toLowerCase());
|
|
473 |
| } |
|
474 |
| |
|
475 |
783
| public String toString()
|
|
476 |
| { |
|
477 |
783
| ToStringBuilder builder = new ToStringBuilder(this);
|
|
478 |
| |
|
479 |
783
| builder.append("componentClassName", _componentClassName);
|
|
480 |
783
| builder.append("pageSpecification", _pageSpecification);
|
|
481 |
783
| builder.append("specificationLocation", _specificationLocation);
|
|
482 |
783
| builder.append("allowBody", _allowBody);
|
|
483 |
783
| builder.append("allowInformalParameter", _allowInformalParameters);
|
|
484 |
| |
|
485 |
783
| return builder.toString();
|
|
486 |
| } |
|
487 |
| |
|
488 |
| |
|
489 |
| |
|
490 |
| |
|
491 |
| |
|
492 |
| |
|
493 |
| |
|
494 |
3
| public String getDescription()
|
|
495 |
| { |
|
496 |
3
| return _description;
|
|
497 |
| } |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
| |
|
504 |
| |
|
505 |
813
| public void setDescription(String description)
|
|
506 |
| { |
|
507 |
813
| _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 |
180
| public boolean isPageSpecification()
|
|
541 |
| { |
|
542 |
180
| return _pageSpecification;
|
|
543 |
| } |
|
544 |
| |
|
545 |
| |
|
546 |
| |
|
547 |
354
| public void setPageSpecification(boolean pageSpecification)
|
|
548 |
| { |
|
549 |
354
| _pageSpecification = pageSpecification;
|
|
550 |
| } |
|
551 |
| |
|
552 |
| |
|
553 |
| |
|
554 |
13644
| private List sortedKeys(Map input)
|
|
555 |
| { |
|
556 |
13644
| if (input == null)
|
|
557 |
9513
| return Collections.EMPTY_LIST;
|
|
558 |
| |
|
559 |
4131
| List result = new ArrayList(input.keySet());
|
|
560 |
| |
|
561 |
4131
| Collections.sort(result);
|
|
562 |
| |
|
563 |
4131
| return result;
|
|
564 |
| } |
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
38649
| private Object get(Map map, Object key)
|
|
569 |
| { |
|
570 |
38649
| if (map == null)
|
|
571 |
1590
| return null;
|
|
572 |
| |
|
573 |
37059
| return map.get(key);
|
|
574 |
| } |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
6816
| public Resource getSpecificationLocation()
|
|
579 |
| { |
|
580 |
6816
| return _specificationLocation;
|
|
581 |
| } |
|
582 |
| |
|
583 |
| |
|
584 |
| |
|
585 |
1353
| public void setSpecificationLocation(Resource specificationLocation)
|
|
586 |
| { |
|
587 |
1353
| _specificationLocation = specificationLocation;
|
|
588 |
| } |
|
589 |
| |
|
590 |
| |
|
591 |
| |
|
592 |
| |
|
593 |
| |
|
594 |
| |
|
595 |
| |
|
596 |
| |
|
597 |
351
| public void addPropertySpecification(IPropertySpecification spec)
|
|
598 |
| { |
|
599 |
351
| if (_propertySpecifications == null)
|
|
600 |
174
| _propertySpecifications = new HashMap();
|
|
601 |
| |
|
602 |
351
| String name = spec.getName();
|
|
603 |
351
| IPropertySpecification existing = (IPropertySpecification) _propertySpecifications
|
|
604 |
| .get(name); |
|
605 |
| |
|
606 |
351
| if (existing != null)
|
|
607 |
0
| throw new ApplicationRuntimeException(SpecMessages.duplicateProperty(name, existing),
|
|
608 |
| spec.getLocation(), null); |
|
609 |
| |
|
610 |
351
| claimProperty(name, spec);
|
|
611 |
| |
|
612 |
351
| _propertySpecifications.put(name, spec);
|
|
613 |
| } |
|
614 |
| |
|
615 |
| |
|
616 |
| |
|
617 |
| |
|
618 |
| |
|
619 |
| |
|
620 |
| |
|
621 |
| |
|
622 |
1173
| public List getPropertySpecificationNames()
|
|
623 |
| { |
|
624 |
1173
| return sortedKeys(_propertySpecifications);
|
|
625 |
| } |
|
626 |
| |
|
627 |
| |
|
628 |
| |
|
629 |
| |
|
630 |
| |
|
631 |
| |
|
632 |
| |
|
633 |
| |
|
634 |
| |
|
635 |
417
| public IPropertySpecification getPropertySpecification(String name)
|
|
636 |
| { |
|
637 |
417
| return (IPropertySpecification) get(_propertySpecifications, name);
|
|
638 |
| } |
|
639 |
| |
|
640 |
1179
| public void addInjectSpecification(InjectSpecification spec)
|
|
641 |
| { |
|
642 |
1179
| if (_injectSpecifications == null)
|
|
643 |
537
| _injectSpecifications = new ArrayList();
|
|
644 |
| |
|
645 |
1179
| claimProperty(spec.getProperty(), spec);
|
|
646 |
| |
|
647 |
1176
| _injectSpecifications.add(spec);
|
|
648 |
| } |
|
649 |
| |
|
650 |
1176
| public List getInjectSpecifications()
|
|
651 |
| { |
|
652 |
1176
| return safeList(_injectSpecifications);
|
|
653 |
| } |
|
654 |
| |
|
655 |
1176
| private List safeList(List input)
|
|
656 |
| { |
|
657 |
1176
| if (input == null)
|
|
658 |
639
| return Collections.EMPTY_LIST;
|
|
659 |
| |
|
660 |
537
| return Collections.unmodifiableList(input);
|
|
661 |
| } |
|
662 |
| |
|
663 |
6018
| private void claimProperty(String propertyName, Object subSpecification)
|
|
664 |
| { |
|
665 |
6018
| if (propertyName == null)
|
|
666 |
978
| return;
|
|
667 |
| |
|
668 |
5040
| if (_claimedProperties == null)
|
|
669 |
930
| _claimedProperties = new HashMap();
|
|
670 |
| |
|
671 |
5040
| Object existing = _claimedProperties.get(propertyName);
|
|
672 |
| |
|
673 |
5040
| if (existing != null)
|
|
674 |
3
| throw new ApplicationRuntimeException(SpecMessages.claimedProperty(
|
|
675 |
| propertyName, |
|
676 |
| existing), HiveMind.getLocation(subSpecification), null); |
|
677 |
| |
|
678 |
5037
| _claimedProperties.put(propertyName, subSpecification);
|
|
679 |
| } |
|
680 |
| |
|
681 |
| |
|
682 |
2667
| public boolean isDeprecated()
|
|
683 |
| { |
|
684 |
2667
| return _deprecated;
|
|
685 |
| } |
|
686 |
| |
|
687 |
| |
|
688 |
945
| public void setDeprecated(boolean deprecated)
|
|
689 |
| { |
|
690 |
945
| _deprecated = deprecated;
|
|
691 |
| } |
|
692 |
| |
|
693 |
12
| public Set getReservedParameterNames()
|
|
694 |
| { |
|
695 |
12
| if (_reservedParameterNames == null)
|
|
696 |
3
| return Collections.EMPTY_SET;
|
|
697 |
| |
|
698 |
9
| return Collections.unmodifiableSet(_reservedParameterNames);
|
|
699 |
| } |
|
700 |
| } |