1 |
| package org.apache.tapestry.annotations; |
2 |
| |
3 |
| import java.util.ArrayList; |
4 |
| import java.util.Collections; |
5 |
| import java.util.List; |
6 |
| |
7 |
| import org.apache.hivemind.ApplicationRuntimeException; |
8 |
| import org.apache.hivemind.Location; |
9 |
| import org.apache.tapestry.enhance.EnhancementOperation; |
10 |
| import org.apache.tapestry.spec.IComponentSpecification; |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| public class MetaAnnotationWorker implements ClassAnnotationEnhancementWorker |
23 |
| { |
24 |
| |
25 |
3
| public void performEnhancement(EnhancementOperation op, IComponentSpecification spec,
|
26 |
| Class baseClass, Location location) |
27 |
| { |
28 |
3
| List<Meta> metas = assembleMetas(baseClass);
|
29 |
| |
30 |
3
| for (Meta meta : metas)
|
31 |
4
| applyPropertiesFromMeta(meta, spec, location);
|
32 |
| } |
33 |
| |
34 |
3
| private List<Meta> assembleMetas(Class baseClass)
|
35 |
| { |
36 |
3
| Class searchClass = baseClass;
|
37 |
3
| List<Meta> result = new ArrayList<Meta>();
|
38 |
3
| Meta lastMeta = null;
|
39 |
| |
40 |
3
| while (true)
|
41 |
| { |
42 |
7
| Meta meta = (Meta) searchClass.getAnnotation(Meta.class);
|
43 |
| |
44 |
| |
45 |
7
| if (meta == null)
|
46 |
3
| break;
|
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
4
| if (meta != lastMeta)
|
52 |
4
| result.add(meta);
|
53 |
| |
54 |
4
| searchClass = searchClass.getSuperclass();
|
55 |
| } |
56 |
| |
57 |
3
| Collections.reverse(result);
|
58 |
| |
59 |
3
| return result;
|
60 |
| } |
61 |
| |
62 |
4
| private void applyPropertiesFromMeta(Meta meta, IComponentSpecification spec, Location location)
|
63 |
| { |
64 |
4
| String[] pairs = meta.value();
|
65 |
| |
66 |
4
| for (String pair : pairs)
|
67 |
| { |
68 |
6
| int equalx = pair.indexOf('=');
|
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
6
| if (equalx < 0)
|
74 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.missingEqualsInMeta(pair),
|
75 |
| location, null); |
76 |
| |
77 |
5
| String key = pair.substring(0, equalx);
|
78 |
5
| String value = pair.substring(equalx + 1);
|
79 |
| |
80 |
5
| spec.setProperty(key, value);
|
81 |
| } |
82 |
| } |
83 |
| } |