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