Coverage Report - org.seasar.teeda.extension.annotation.handler.TigerConverterAnnotationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
TigerConverterAnnotationHandler
94%
34/36
64%
9/14
0
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 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  
  * @author higa
 35  
  * @author shot
 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  
 }