1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.annotations; |
16 |
| |
17 |
| import java.lang.annotation.Annotation; |
18 |
| import java.lang.reflect.Method; |
19 |
| import java.util.Map; |
20 |
| |
21 |
| import org.apache.hivemind.ErrorLog; |
22 |
| import org.apache.tapestry.enhance.EnhancementOperation; |
23 |
| import org.apache.tapestry.enhance.EnhancementWorker; |
24 |
| import org.apache.tapestry.spec.IComponentSpecification; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| public class AnnotationEnhancementWorker implements EnhancementWorker |
36 |
| { |
37 |
| private ErrorLog _errorLog; |
38 |
| |
39 |
| private Map _methodWorkers; |
40 |
| |
41 |
| private Map _classWorkers; |
42 |
| |
43 |
6
| public void setClassWorkers(Map classWorkers)
|
44 |
| { |
45 |
6
| _classWorkers = classWorkers;
|
46 |
| } |
47 |
| |
48 |
14
| public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
|
49 |
| { |
50 |
14
| Class clazz = op.getBaseClass();
|
51 |
| |
52 |
14
| for (Annotation a : clazz.getAnnotations())
|
53 |
| { |
54 |
6
| performClassEnhancement(op, spec, clazz, a);
|
55 |
| } |
56 |
| |
57 |
14
| for (Method m : clazz.getMethods())
|
58 |
| { |
59 |
942
| performMethodEnhancement(op, spec, m);
|
60 |
| } |
61 |
| } |
62 |
| |
63 |
6
| void performClassEnhancement(EnhancementOperation op, IComponentSpecification spec,
|
64 |
| Class clazz, Annotation annotation) |
65 |
| { |
66 |
6
| ClassAnnotationEnhancementWorker worker = (ClassAnnotationEnhancementWorker) _classWorkers
|
67 |
| .get(annotation.annotationType()); |
68 |
| |
69 |
6
| if (worker == null)
|
70 |
2
| return;
|
71 |
| |
72 |
4
| try
|
73 |
| { |
74 |
4
| worker.performEnhancement(op, spec, clazz);
|
75 |
| } |
76 |
| catch (Exception ex) |
77 |
| { |
78 |
2
| _errorLog.error(AnnotationMessages.failureProcessingClassAnnotation(
|
79 |
| annotation, |
80 |
| clazz, |
81 |
| ex), null, ex); |
82 |
| } |
83 |
| |
84 |
| } |
85 |
| |
86 |
942
| void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
|
87 |
| Method method) |
88 |
| { |
89 |
942
| for (Annotation a : method.getAnnotations())
|
90 |
| { |
91 |
264
| performMethodEnhancement(op, spec, method, a);
|
92 |
| } |
93 |
| } |
94 |
| |
95 |
264
| void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
|
96 |
| Method method, Annotation annotation) |
97 |
| { |
98 |
264
| MethodAnnotationEnhancementWorker worker = (MethodAnnotationEnhancementWorker) _methodWorkers
|
99 |
| .get(annotation.annotationType()); |
100 |
| |
101 |
264
| if (worker == null)
|
102 |
258
| return;
|
103 |
| |
104 |
6
| try
|
105 |
| { |
106 |
6
| worker.performEnhancement(op, spec, method);
|
107 |
| } |
108 |
| catch (Exception ex) |
109 |
| { |
110 |
2
| _errorLog.error(
|
111 |
| AnnotationMessages.failureProcessingAnnotation(annotation, method, ex), |
112 |
| null, |
113 |
| ex); |
114 |
| } |
115 |
| |
116 |
| } |
117 |
| |
118 |
8
| public void setMethodWorkers(Map methodWorkers)
|
119 |
| { |
120 |
8
| _methodWorkers = methodWorkers;
|
121 |
| } |
122 |
| |
123 |
4
| public void setErrorLog(ErrorLog errorLog)
|
124 |
| { |
125 |
4
| _errorLog = errorLog;
|
126 |
| } |
127 |
| } |