|
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.Collections; |
|
19 |
| import java.util.HashMap; |
|
20 |
| import java.util.Iterator; |
|
21 |
| import java.util.List; |
|
22 |
| import java.util.Map; |
|
23 |
| |
|
24 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
25 |
| import org.apache.hivemind.Location; |
|
26 |
| import org.apache.hivemind.Resource; |
|
27 |
| import org.apache.hivemind.util.ToStringBuilder; |
|
28 |
| import org.apache.tapestry.Tapestry; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| public class LibrarySpecification extends LocatablePropertyHolder implements ILibrarySpecification |
|
39 |
| { |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| private Map _pages; |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| private Map _components; |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| private Map _libraries; |
|
56 |
| |
|
57 |
| private String _description; |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| private Map _extensions; |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| private Map _instantiatedExtensions; |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| private String _publicId; |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| private Resource _specificationLocation; |
|
84 |
| |
|
85 |
51
| public String getLibrarySpecificationPath(String id)
|
|
86 |
| { |
|
87 |
51
| return (String) get(_libraries, id);
|
|
88 |
| } |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
63
| public void setLibrarySpecificationPath(String id, String path)
|
|
98 |
| { |
|
99 |
63
| if (_libraries == null)
|
|
100 |
60
| _libraries = new HashMap();
|
|
101 |
| |
|
102 |
63
| if (_libraries.containsKey(id))
|
|
103 |
0
| throw new IllegalArgumentException(Tapestry.format(
|
|
104 |
| "LibrarySpecification.duplicate-child-namespace-id", |
|
105 |
| id)); |
|
106 |
| |
|
107 |
63
| _libraries.put(id, path);
|
|
108 |
| } |
|
109 |
| |
|
110 |
3
| public List getLibraryIds()
|
|
111 |
| { |
|
112 |
3
| return sortedKeys(_libraries);
|
|
113 |
| } |
|
114 |
| |
|
115 |
513
| public String getPageSpecificationPath(String name)
|
|
116 |
| { |
|
117 |
513
| return (String) get(_pages, name);
|
|
118 |
| } |
|
119 |
| |
|
120 |
1464
| public void setPageSpecificationPath(String name, String path)
|
|
121 |
| { |
|
122 |
1464
| if (_pages == null)
|
|
123 |
207
| _pages = new HashMap();
|
|
124 |
| |
|
125 |
1464
| if (_pages.containsKey(name))
|
|
126 |
0
| throw new IllegalArgumentException(Tapestry.format(
|
|
127 |
| "LibrarySpecification.duplicate-page-name", |
|
128 |
| name)); |
|
129 |
| |
|
130 |
1464
| _pages.put(name, path);
|
|
131 |
| } |
|
132 |
| |
|
133 |
3
| public List getPageNames()
|
|
134 |
| { |
|
135 |
3
| return sortedKeys(_pages);
|
|
136 |
| } |
|
137 |
| |
|
138 |
5838
| public void setComponentSpecificationPath(String alias, String path)
|
|
139 |
| { |
|
140 |
5838
| if (_components == null)
|
|
141 |
195
| _components = new HashMap();
|
|
142 |
| |
|
143 |
5838
| if (_components.containsKey(alias))
|
|
144 |
0
| throw new IllegalArgumentException(Tapestry.format(
|
|
145 |
| "LibrarySpecification.duplicate-component-alias", |
|
146 |
| alias)); |
|
147 |
| |
|
148 |
5838
| _components.put(alias, path);
|
|
149 |
| } |
|
150 |
| |
|
151 |
2148
| public String getComponentSpecificationPath(String alias)
|
|
152 |
| { |
|
153 |
2148
| return (String) get(_components, alias);
|
|
154 |
| } |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
6
| public List getComponentTypes()
|
|
161 |
| { |
|
162 |
6
| return sortedKeys(_components);
|
|
163 |
| } |
|
164 |
| |
|
165 |
0
| public String getServiceClassName(String name)
|
|
166 |
| { |
|
167 |
0
| throw new UnsupportedOperationException();
|
|
168 |
| } |
|
169 |
| |
|
170 |
0
| public List getServiceNames()
|
|
171 |
| { |
|
172 |
0
| return Collections.EMPTY_LIST;
|
|
173 |
| } |
|
174 |
| |
|
175 |
0
| public void setServiceClassName(String name, String className)
|
|
176 |
| { |
|
177 |
0
| throw new UnsupportedOperationException();
|
|
178 |
| } |
|
179 |
| |
|
180 |
12
| private List sortedKeys(Map map)
|
|
181 |
| { |
|
182 |
12
| if (map == null)
|
|
183 |
0
| return Collections.EMPTY_LIST;
|
|
184 |
| |
|
185 |
12
| List result = new ArrayList(map.keySet());
|
|
186 |
| |
|
187 |
12
| Collections.sort(result);
|
|
188 |
| |
|
189 |
12
| return result;
|
|
190 |
| } |
|
191 |
| |
|
192 |
2712
| private Object get(Map map, Object key)
|
|
193 |
| { |
|
194 |
2712
| if (map == null)
|
|
195 |
567
| return null;
|
|
196 |
| |
|
197 |
2145
| return map.get(key);
|
|
198 |
| } |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
3
| public String getDescription()
|
|
205 |
| { |
|
206 |
3
| return _description;
|
|
207 |
| } |
|
208 |
| |
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
3
| public void setDescription(String description)
|
|
214 |
| { |
|
215 |
3
| _description = description;
|
|
216 |
| } |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
0
| public Map getExtensionSpecifications()
|
|
225 |
| { |
|
226 |
0
| if (_extensions == null)
|
|
227 |
0
| return null;
|
|
228 |
| |
|
229 |
0
| return Collections.unmodifiableMap(_extensions);
|
|
230 |
| } |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
30
| public void addExtensionSpecification(String name, IExtensionSpecification extension)
|
|
240 |
| { |
|
241 |
30
| if (_extensions == null)
|
|
242 |
30
| _extensions = new HashMap();
|
|
243 |
| |
|
244 |
30
| if (_extensions.containsKey(name))
|
|
245 |
0
| throw new IllegalArgumentException(Tapestry.format(
|
|
246 |
| "LibrarySpecification.duplicate-extension-name", |
|
247 |
| this, |
|
248 |
| name)); |
|
249 |
| |
|
250 |
30
| _extensions.put(name, extension);
|
|
251 |
| } |
|
252 |
| |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
0
| public synchronized List getExtensionNames()
|
|
259 |
| { |
|
260 |
0
| return sortedKeys(_instantiatedExtensions);
|
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
30
| public IExtensionSpecification getExtensionSpecification(String name)
|
|
268 |
| { |
|
269 |
30
| if (_extensions == null)
|
|
270 |
0
| return null;
|
|
271 |
| |
|
272 |
30
| return (IExtensionSpecification) _extensions.get(name);
|
|
273 |
| } |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
468
| public boolean checkExtension(String name)
|
|
280 |
| { |
|
281 |
468
| if (_extensions == null)
|
|
282 |
456
| return false;
|
|
283 |
| |
|
284 |
12
| return _extensions.containsKey(name);
|
|
285 |
| } |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
6
| public synchronized Object getExtension(String name)
|
|
295 |
| { |
|
296 |
6
| return getExtension(name, null);
|
|
297 |
| } |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
18
| public synchronized Object getExtension(String name, Class typeConstraint)
|
|
302 |
| { |
|
303 |
18
| if (_instantiatedExtensions == null)
|
|
304 |
18
| _instantiatedExtensions = new HashMap();
|
|
305 |
| |
|
306 |
18
| Object result = _instantiatedExtensions.get(name);
|
|
307 |
18
| IExtensionSpecification spec = getExtensionSpecification(name);
|
|
308 |
| |
|
309 |
18
| if (spec == null)
|
|
310 |
0
| throw new IllegalArgumentException(Tapestry.format(
|
|
311 |
| "LibrarySpecification.no-such-extension", |
|
312 |
| name)); |
|
313 |
| |
|
314 |
18
| if (result == null)
|
|
315 |
| { |
|
316 |
| |
|
317 |
18
| result = spec.instantiateExtension();
|
|
318 |
| |
|
319 |
18
| _instantiatedExtensions.put(name, result);
|
|
320 |
| } |
|
321 |
| |
|
322 |
18
| if (typeConstraint != null)
|
|
323 |
12
| applyTypeConstraint(name, result, typeConstraint, spec.getLocation());
|
|
324 |
| |
|
325 |
12
| return result;
|
|
326 |
| } |
|
327 |
| |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
12
| protected void applyTypeConstraint(String name, Object extension, Class typeConstraint,
|
|
337 |
| Location location) |
|
338 |
| { |
|
339 |
12
| Class extensionClass = extension.getClass();
|
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
| |
|
344 |
12
| if (typeConstraint.isAssignableFrom(extensionClass))
|
|
345 |
6
| return;
|
|
346 |
| |
|
347 |
6
| String key = typeConstraint.isInterface() ? "LibrarySpecification.extension-does-not-implement-interface"
|
|
348 |
| : "LibrarySpecification.extension-not-a-subclass"; |
|
349 |
| |
|
350 |
6
| throw new ApplicationRuntimeException(Tapestry.format(
|
|
351 |
| key, |
|
352 |
| name, |
|
353 |
| extensionClass.getName(), |
|
354 |
| typeConstraint.getName()), location, null); |
|
355 |
| } |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
300
| public synchronized void instantiateImmediateExtensions()
|
|
363 |
| { |
|
364 |
300
| if (_extensions == null)
|
|
365 |
270
| return;
|
|
366 |
| |
|
367 |
30
| Iterator i = _extensions.entrySet().iterator();
|
|
368 |
| |
|
369 |
30
| while (i.hasNext())
|
|
370 |
| { |
|
371 |
30
| Map.Entry entry = (Map.Entry) i.next();
|
|
372 |
| |
|
373 |
30
| IExtensionSpecification spec = (IExtensionSpecification) entry.getValue();
|
|
374 |
| |
|
375 |
30
| if (!spec.isImmediate())
|
|
376 |
27
| continue;
|
|
377 |
| |
|
378 |
3
| String name = (String) entry.getKey();
|
|
379 |
| |
|
380 |
3
| getExtension(name);
|
|
381 |
| } |
|
382 |
| |
|
383 |
| } |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| |
|
390 |
| |
|
391 |
0
| protected Map getExtensions()
|
|
392 |
| { |
|
393 |
0
| return _extensions;
|
|
394 |
| } |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
| |
|
404 |
| |
|
405 |
0
| protected void setExtensions(Map extension)
|
|
406 |
| { |
|
407 |
0
| _extensions = extension;
|
|
408 |
| } |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
| |
|
415 |
| |
|
416 |
0
| protected Map getLibraries()
|
|
417 |
| { |
|
418 |
0
| return _libraries;
|
|
419 |
| } |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
| |
|
426 |
| |
|
427 |
| |
|
428 |
| |
|
429 |
| |
|
430 |
0
| protected void setLibraries(Map libraries)
|
|
431 |
| { |
|
432 |
0
| _libraries = libraries;
|
|
433 |
| } |
|
434 |
| |
|
435 |
| |
|
436 |
| |
|
437 |
| |
|
438 |
| |
|
439 |
| |
|
440 |
| |
|
441 |
0
| protected Map getPages()
|
|
442 |
| { |
|
443 |
0
| return _pages;
|
|
444 |
| } |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
| |
|
450 |
| |
|
451 |
| |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
0
| protected void setPages(Map pages)
|
|
456 |
| { |
|
457 |
0
| _pages = pages;
|
|
458 |
| } |
|
459 |
| |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
| |
|
464 |
| |
|
465 |
| |
|
466 |
| |
|
467 |
0
| protected Map getServices()
|
|
468 |
| { |
|
469 |
0
| return Collections.EMPTY_MAP;
|
|
470 |
| } |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
| |
|
475 |
| |
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
| |
|
480 |
| |
|
481 |
| |
|
482 |
| |
|
483 |
0
| protected void setServices(Map services)
|
|
484 |
| { |
|
485 |
| } |
|
486 |
| |
|
487 |
| |
|
488 |
| |
|
489 |
| |
|
490 |
| |
|
491 |
| |
|
492 |
| |
|
493 |
0
| protected Map getComponents()
|
|
494 |
| { |
|
495 |
0
| return _components;
|
|
496 |
| } |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
| |
|
504 |
| |
|
505 |
| |
|
506 |
0
| protected void setComponents(Map components)
|
|
507 |
| { |
|
508 |
0
| _components = components;
|
|
509 |
| } |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
| |
|
516 |
| |
|
517 |
| |
|
518 |
0
| public String getPublicId()
|
|
519 |
| { |
|
520 |
0
| return _publicId;
|
|
521 |
| } |
|
522 |
| |
|
523 |
0
| public void setPublicId(String publicId)
|
|
524 |
| { |
|
525 |
0
| _publicId = publicId;
|
|
526 |
| } |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
3552
| public Resource getSpecificationLocation()
|
|
531 |
| { |
|
532 |
3552
| return _specificationLocation;
|
|
533 |
| } |
|
534 |
| |
|
535 |
| |
|
536 |
| |
|
537 |
390
| public void setSpecificationLocation(Resource specificationLocation)
|
|
538 |
| { |
|
539 |
390
| _specificationLocation = specificationLocation;
|
|
540 |
| } |
|
541 |
| |
|
542 |
| |
|
543 |
| |
|
544 |
0
| public synchronized String toString()
|
|
545 |
| { |
|
546 |
0
| ToStringBuilder builder = new ToStringBuilder(this);
|
|
547 |
| |
|
548 |
0
| builder.append("components", _components);
|
|
549 |
0
| builder.append("description", _description);
|
|
550 |
0
| builder.append("instantiatedExtensions", _instantiatedExtensions);
|
|
551 |
0
| builder.append("libraries", _libraries);
|
|
552 |
0
| builder.append("pages", _pages);
|
|
553 |
0
| builder.append("publicId", _publicId);
|
|
554 |
0
| builder.append("specificationLocation", _specificationLocation);
|
|
555 |
| |
|
556 |
0
| extendDescription(builder);
|
|
557 |
| |
|
558 |
0
| return builder.toString();
|
|
559 |
| } |
|
560 |
| |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
| |
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
0
| protected void extendDescription(ToStringBuilder builder)
|
|
569 |
| { |
|
570 |
| } |
|
571 |
| |
|
572 |
| } |