1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.extension.annotation.handler; |
17 | |
|
18 | |
import java.lang.annotation.Annotation; |
19 | |
import java.lang.reflect.Field; |
20 | |
import java.lang.reflect.Method; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import javax.faces.internal.EnumUtil; |
24 | |
|
25 | |
import org.seasar.framework.beans.PropertyDesc; |
26 | |
import org.seasar.framework.container.S2Container; |
27 | |
import org.seasar.framework.container.hotdeploy.HotdeployUtil; |
28 | |
import org.seasar.framework.convention.NamingConvention; |
29 | |
import org.seasar.framework.util.ClassUtil; |
30 | |
import org.seasar.framework.util.MethodUtil; |
31 | |
import org.seasar.framework.util.tiger.AnnotationUtil; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 6 | public class TigerConverterAnnotationHandler extends |
38 | |
ConstantConverterAnnotationHandler { |
39 | |
|
40 | 6 | protected Class<? extends Annotation> metaAnnotationType = org.seasar.teeda.extension.annotation.convert.Converter.class; |
41 | |
|
42 | |
@Override |
43 | |
protected void processProperty(S2Container container, Class componentClass, |
44 | |
String componentName, NamingConvention namingConvention, |
45 | |
PropertyDesc propertyDesc, Field[] fields) { |
46 | 25 | Field field = propertyDesc.getField(); |
47 | 25 | if (field != null) { |
48 | 25 | processField(container, componentClass, componentName, |
49 | |
namingConvention, field); |
50 | |
} |
51 | 25 | if (propertyDesc.hasReadMethod()) { |
52 | 25 | processGetterMethod(container, componentName, propertyDesc); |
53 | |
} |
54 | 25 | if (propertyDesc.hasWriteMethod()) { |
55 | 25 | processSetterMethod(container, componentName, propertyDesc); |
56 | |
} |
57 | 25 | super.processProperty(container, componentClass, componentName, |
58 | |
namingConvention, propertyDesc, fields); |
59 | 25 | } |
60 | |
|
61 | |
protected void processField(S2Container container, Class componentClass, |
62 | |
String componentName, NamingConvention namingConvention, Field field) { |
63 | 35 | for (Annotation annotation : field.getDeclaredAnnotations()) { |
64 | 10 | processAnnotation(container, componentName, field.getName(), |
65 | |
annotation); |
66 | |
} |
67 | 25 | } |
68 | |
|
69 | |
protected void processAnnotation(S2Container container, |
70 | |
String componentName, String propertyName, Annotation annotation) { |
71 | 20 | Class<? extends Annotation> annotationType = annotation |
72 | |
.annotationType(); |
73 | 20 | Annotation metaAnnotation = annotationType |
74 | |
.getAnnotation(metaAnnotationType); |
75 | 20 | if (metaAnnotation == null) { |
76 | 0 | return; |
77 | |
} |
78 | 20 | final String converterName = getConverterName(metaAnnotation); |
79 | 20 | Map<String, Object> props = AnnotationUtil.getProperties(annotation); |
80 | 20 | if (HotdeployUtil.isHotdeploy()) { |
81 | 0 | props = EnumUtil.convertEnumToName(props); |
82 | |
} |
83 | 20 | registerConverter(componentName, propertyName, converterName, props); |
84 | 20 | } |
85 | |
|
86 | |
protected void processAnnotaions(final S2Container container, |
87 | |
final String componentName, final PropertyDesc propertyDesc, |
88 | |
final Annotation[] annotations) { |
89 | 60 | for (Annotation annotation : annotations) { |
90 | 10 | processAnnotation(container, componentName, propertyDesc |
91 | |
.getPropertyName(), annotation); |
92 | |
} |
93 | 50 | } |
94 | |
|
95 | |
protected void processGetterMethod(S2Container container, |
96 | |
String componentName, PropertyDesc propertyDesc) { |
97 | 25 | Annotation[] annotations = propertyDesc.getReadMethod() |
98 | |
.getDeclaredAnnotations(); |
99 | 25 | processAnnotaions(container, componentName, propertyDesc, annotations); |
100 | 25 | } |
101 | |
|
102 | |
protected void processSetterMethod(S2Container container, |
103 | |
String componentName, PropertyDesc propertyDesc) { |
104 | 25 | Annotation[] annotations = propertyDesc.getWriteMethod() |
105 | |
.getDeclaredAnnotations(); |
106 | 25 | processAnnotaions(container, componentName, propertyDesc, annotations); |
107 | 25 | } |
108 | |
|
109 | |
protected String getConverterName(Annotation annotation) { |
110 | 20 | Class<? extends Annotation> annoType = annotation.annotationType(); |
111 | 20 | Method m = ClassUtil.getMethod(annoType, "value", null); |
112 | 20 | return (String) MethodUtil.invoke(m, annotation, null); |
113 | |
} |
114 | |
|
115 | |
} |