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 private List<PropertyDesc> importValueProps = new ArrayList<PropertyDesc>(1);
45
46 private List<PropertyDesc> exportValueProps = new ArrayList<PropertyDesc>(1);
47
48 private List<PropertyDesc> importSelectionProps = new ArrayList<PropertyDesc>(
49 1);;
50
51 private List<PropertyDesc> exportSelectionProps = new ArrayList<PropertyDesc>(
52 1);;
53
54
55
56
57
58
59
60
61
62 public FormDescImpl(final Class<?> formClass) throws EmptyRuntimeException {
63 if (formClass == null) {
64 throw new EmptyRuntimeException("formClass");
65 }
66
67 this.formClass = formClass;
68 this.beanDesc = BeanDescFactory.getBeanDesc(formClass);
69
70 setupFields();
71
72 importValueProps = Collections.unmodifiableList(importValueProps);
73 exportValueProps = Collections.unmodifiableList(exportValueProps);
74 importSelectionProps = Collections
75 .unmodifiableList(importSelectionProps);
76 exportSelectionProps = Collections
77 .unmodifiableList(exportSelectionProps);
78 }
79
80 protected void setupFields() {
81 setupFieldsByClass(formClass);
82 Class<?> superClass = formClass.getSuperclass();
83 while (superClass != Object.class && superClass != null) {
84 setupFieldsByClass(superClass);
85 superClass = superClass.getSuperclass();
86 }
87 }
88
89 protected void setupFieldsByClass(final Class<?> targetClass) {
90 Field[] fields = targetClass.getDeclaredFields();
91 for (int i = 0; i < fields.length; i++) {
92 Field field = fields[i];
93
94 setupImportValueField(field);
95 setupExportvalueField(field);
96 setupImportSelectionField(field);
97 setupExportSelectionField(field);
98 }
99 }
100
101 protected void setupImportValueField(final Field field) {
102 if (field.isAnnotationPresent(ImportValue.class)
103 || field.isAnnotationPresent(ImportExportValue.class)) {
104 PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
105 importValueProps.add(pd);
106 }
107 }
108
109 protected void setupExportvalueField(final Field field) {
110 if (field.isAnnotationPresent(ExportValue.class)
111 || field.isAnnotationPresent(ImportExportValue.class)) {
112 PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
113 exportValueProps.add(pd);
114 }
115 }
116
117 protected void setupImportSelectionField(final Field field) {
118 if (field.isAnnotationPresent(ImportSelection.class)) {
119 PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
120 importSelectionProps.add(pd);
121 }
122 }
123
124 protected void setupExportSelectionField(final Field field) {
125 if (field.isAnnotationPresent(ExportSelection.class)) {
126 PropertyDesc pd = beanDesc.getPropertyDesc(field.getName());
127 exportSelectionProps.add(pd);
128 }
129 }
130
131
132
133
134 public Class<?> getFormClass() {
135 return this.formClass;
136 }
137
138
139
140
141 public List<PropertyDesc> getExportSelectionProperties() {
142 return exportSelectionProps;
143 }
144
145
146
147
148 public List<PropertyDesc> getExportValueProperties() {
149 return exportValueProps;
150 }
151
152
153
154
155 public List<PropertyDesc> getImportSelectionProperties() {
156 return importSelectionProps;
157 }
158
159
160
161
162 public List<PropertyDesc> getImportValueProperties() {
163 return importValueProps;
164 }
165
166 }