| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 36 | |
|
| 37 | |
|
| 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 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 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 | |
|
| 133 | |
|
| 134 | |
public Class<?> getFormClass() { |
| 135 | 0 | return this.formClass; |
| 136 | |
} |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public List<PropertyDesc> getExportSelectionProperties() { |
| 142 | 152 | return exportSelectionProps; |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
public List<PropertyDesc> getExportValueProperties() { |
| 149 | 152 | return exportValueProps; |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public List<PropertyDesc> getImportSelectionProperties() { |
| 156 | 48 | return importSelectionProps; |
| 157 | |
} |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
public List<PropertyDesc> getImportValueProperties() { |
| 163 | 48 | return importValueProps; |
| 164 | |
} |
| 165 | |
|
| 166 | |
} |