Coverage Report - org.seasar.uruma.desc.impl.FormDescImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
FormDescImpl
96%
48/50
90%
18/20
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 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.uruma.desc.impl;
 17  
 
 18  
 import java.lang.reflect.Field;
 19  
 import java.util.ArrayList;
 20  
 import java.util.Collections;
 21  
 import java.util.List;
 22  
 
 23  
 import org.seasar.framework.beans.BeanDesc;
 24  
 import org.seasar.framework.beans.PropertyDesc;
 25  
 import org.seasar.framework.beans.factory.BeanDescFactory;
 26  
 import org.seasar.framework.exception.EmptyRuntimeException;
 27  
 import org.seasar.uruma.annotation.ExportSelection;
 28  
 import org.seasar.uruma.annotation.ExportValue;
 29  
 import org.seasar.uruma.annotation.ImportExportValue;
 30  
 import org.seasar.uruma.annotation.ImportSelection;
 31  
 import org.seasar.uruma.annotation.ImportValue;
 32  
 import org.seasar.uruma.desc.FormDesc;
 33  
 
 34  
 /**
 35  
  * {@link FormDesc} の実装クラスです。<br />
 36  
  * 
 37  
  * @author y-komori
 38  
  */
 39  
 public class FormDescImpl implements FormDesc {
 40  
     private Class<?> formClass;
 41  
 
 42  
     private BeanDesc beanDesc;
 43  
 
 44  128
     private List<PropertyDesc> importValueProps = new ArrayList<PropertyDesc>(1);
 45  
 
 46  128
     private List<PropertyDesc> exportValueProps = new ArrayList<PropertyDesc>(1);
 47  
 
 48  128
     private List<PropertyDesc> importSelectionProps = new ArrayList<PropertyDesc>(
 49  
             1);;
 50  
 
 51  128
     private List<PropertyDesc> exportSelectionProps = new ArrayList<PropertyDesc>(
 52  
             1);;
 53  
 
 54  
     /**
 55  
      * {@link FormDescImpl} を構築します。<br />
 56  
      * 
 57  
      * @param formClass
 58  
      *            フォームクラスの {@link Class} オブジェクト
 59  
      * @throws EmptyRuntimeException
 60  
      *             <code>formClass</code> が <code>null</code> であった場合
 61  
      */
 62  128
     public FormDescImpl(final Class<?> formClass) throws EmptyRuntimeException {
 63  128
         if (formClass == null) {
 64  0
             throw new EmptyRuntimeException("formClass");
 65  
         }
 66  
 
 67  128
         this.formClass = formClass;
 68  128
         this.beanDesc = BeanDescFactory.getBeanDesc(formClass);
 69  
 
 70  128
         setupFields();
 71  
 
 72  128
         importValueProps = Collections.unmodifiableList(importValueProps);
 73  128
         exportValueProps = Collections.unmodifiableList(exportValueProps);
 74  128
         importSelectionProps = Collections
 75  
                 .unmodifiableList(importSelectionProps);
 76  128
         exportSelectionProps = Collections
 77  
                 .unmodifiableList(exportSelectionProps);
 78  128
     }
 79  
 
 80  
     protected void setupFields() {
 81  128
         setupFieldsByClass(formClass);
 82  128
         Class<?> superClass = formClass.getSuperclass();
 83  592
         while (superClass != Object.class && superClass != null) {
 84  464
             setupFieldsByClass(superClass);
 85  464
             superClass = superClass.getSuperclass();
 86  
         }
 87  128
     }
 88  
 
 89  
     protected void setupFieldsByClass(final Class<?> targetClass) {
 90  592
         Field[] fields = targetClass.getDeclaredFields();
 91  3324
         for (int i = 0; i < fields.length; i++) {
 92  2732
             Field field = fields[i];
 93  
 
 94  2732
             setupImportValueField(field);
 95  2732
             setupExportvalueField(field);
 96  2732
             setupImportSelectionField(field);
 97  2732
             setupExportSelectionField(field);
 98  
         }
 99  592
     }
 100  
 
 101  
     protected void setupImportValueField(final Field field) {
 102  2732
         if (field.isAnnotationPresent(ImportValue.class)
 103  
                 || field.isAnnotationPresent(ImportExportValue.class)) {
 104  60
             PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
 105  60
             importValueProps.add(pd);
 106  
         }
 107  2732
     }
 108  
 
 109  
     protected void setupExportvalueField(final Field field) {
 110  2732
         if (field.isAnnotationPresent(ExportValue.class)
 111  
                 || field.isAnnotationPresent(ImportExportValue.class)) {
 112  80
             PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
 113  80
             exportValueProps.add(pd);
 114  
         }
 115  2732
     }
 116  
 
 117  
     protected void setupImportSelectionField(final Field field) {
 118  2732
         if (field.isAnnotationPresent(ImportSelection.class)) {
 119  48
             PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
 120  48
             importSelectionProps.add(pd);
 121  
         }
 122  2732
     }
 123  
 
 124  
     protected void setupExportSelectionField(final Field field) {
 125  2732
         if (field.isAnnotationPresent(ExportSelection.class)) {
 126  36
             PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
 127  36
             exportSelectionProps.add(pd);
 128  
         }
 129  2732
     }
 130  
 
 131  
     /*
 132  
      * @see org.seasar.uruma.desc.FormDesc#getFormClass()
 133  
      */
 134  
     public Class<?> getFormClass() {
 135  0
         return this.formClass;
 136  
     }
 137  
 
 138  
     /*
 139  
      * @see org.seasar.uruma.desc.FormDesc#getExportSelectionProperties()
 140  
      */
 141  
     public List<PropertyDesc> getExportSelectionProperties() {
 142  152
         return exportSelectionProps;
 143  
     }
 144  
 
 145  
     /*
 146  
      * @see org.seasar.uruma.desc.FormDesc#getExportValueProperties()
 147  
      */
 148  
     public List<PropertyDesc> getExportValueProperties() {
 149  152
         return exportValueProps;
 150  
     }
 151  
 
 152  
     /*
 153  
      * @see org.seasar.uruma.desc.FormDesc#getImportSelectionProperties()
 154  
      */
 155  
     public List<PropertyDesc> getImportSelectionProperties() {
 156  48
         return importSelectionProps;
 157  
     }
 158  
 
 159  
     /*
 160  
      * @see org.seasar.uruma.desc.FormDesc#getImportValueProperties()
 161  
      */
 162  
     public List<PropertyDesc> getImportValueProperties() {
 163  48
         return importValueProps;
 164  
     }
 165  
 
 166  
 }