| 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 | 6 | public class TigerValidatorAnnotationHandler extends |
| 37 | |
ConstantValidatorAnnotationHandler { |
| 38 | |
|
| 39 | 6 | protected Class<? extends Annotation> metaAnnotationType = org.seasar.teeda.extension.annotation.validator.Validator.class; |
| 40 | |
|
| 41 | |
@Override |
| 42 | |
protected void processProperty(S2Container container, Class componentClass, |
| 43 | |
String componentName, NamingConvention namingConvention, |
| 44 | |
PropertyDesc propertyDesc, Field[] fields) { |
| 45 | 20 | Field field = propertyDesc.getField(); |
| 46 | 20 | if (field != null) { |
| 47 | 20 | processField(container, componentName, field); |
| 48 | |
} |
| 49 | 20 | if (propertyDesc.hasWriteMethod()) { |
| 50 | 20 | processSetterMethod(container, componentName, propertyDesc); |
| 51 | |
} |
| 52 | 20 | super.processProperty(container, componentClass, componentName, |
| 53 | |
namingConvention, propertyDesc, fields); |
| 54 | 20 | } |
| 55 | |
|
| 56 | |
protected void processField(S2Container container, String componentName, |
| 57 | |
Field field) { |
| 58 | 35 | for (Annotation annotation : field.getDeclaredAnnotations()) { |
| 59 | 15 | processAnnotation(container, componentName, field.getName(), |
| 60 | |
annotation); |
| 61 | |
} |
| 62 | 20 | } |
| 63 | |
|
| 64 | |
protected void processAnnotation(S2Container container, |
| 65 | |
String componentName, String propertyName, Annotation annotation) { |
| 66 | 20 | Class<? extends Annotation> annotationType = annotation |
| 67 | |
.annotationType(); |
| 68 | 20 | Annotation metaAnnotation = annotationType |
| 69 | |
.getAnnotation(metaAnnotationType); |
| 70 | 20 | if (metaAnnotation == null) { |
| 71 | 0 | return; |
| 72 | |
} |
| 73 | 20 | String validatorName = getValidatorName(metaAnnotation); |
| 74 | 20 | Map<String, Object> props = AnnotationUtil.getProperties(annotation); |
| 75 | 20 | if (HotdeployUtil.isHotdeploy()) { |
| 76 | 0 | props = EnumUtil.convertEnumToName(props); |
| 77 | |
} |
| 78 | 20 | registerValidator(componentName, propertyName, validatorName, props); |
| 79 | 20 | } |
| 80 | |
|
| 81 | |
protected void processSetterMethod(S2Container container, |
| 82 | |
String componentName, PropertyDesc propertyDesc) { |
| 83 | 20 | Annotation[] annotations = propertyDesc.getWriteMethod() |
| 84 | |
.getDeclaredAnnotations(); |
| 85 | 25 | for (Annotation annotation : annotations) { |
| 86 | 5 | processAnnotation(container, componentName, propertyDesc |
| 87 | |
.getPropertyName(), annotation); |
| 88 | |
} |
| 89 | 20 | } |
| 90 | |
|
| 91 | |
protected String getValidatorName(Annotation annotation) { |
| 92 | 20 | Class<? extends Annotation> annoType = annotation.annotationType(); |
| 93 | 20 | Method m = ClassUtil.getMethod(annoType, "value", null); |
| 94 | 20 | return (String) MethodUtil.invoke(m, annotation, null); |
| 95 | |
} |
| 96 | |
|
| 97 | |
} |