1 package org.exolab.castor.mapping.loader;
2
3 import java.util.Comparator;
4 import java.util.HashMap;
5 import java.util.HashSet;
6 import java.util.Map;
7 import java.util.Set;
8
9 import org.exolab.castor.mapping.ClassDescriptor;
10 import org.exolab.castor.mapping.FieldDescriptor;
11 import org.exolab.castor.mapping.FieldHandler;
12 import org.exolab.castor.mapping.xml.types.FieldMappingCollectionType;
13
14 public class FieldDescriptorImpl implements FieldDescriptor {
15
16
17 private ClassDescriptor _parent;
18
19
20 private String _fieldName;
21
22
23 private Class<?> _fieldType;
24
25
26 private ClassDescriptor _classDescriptor;
27
28
29 private FieldHandler _handler;
30
31
32 private boolean _transient;
33
34
35 private boolean _immutable;
36
37
38 private boolean _required;
39
40
41 private boolean _direct;
42
43
44 private boolean _lazy;
45
46
47 private boolean _multivalued;
48
49
50 private boolean _identity;
51
52
53 private String _comparator;
54
55
56 private String _getMethod;
57
58
59 private String _setMethod;
60
61
62 private String _createMethod;
63
64
65 private FieldMappingCollectionType _collection;
66
67
68
69
70 private Map<String, Object> _properties = new HashMap<String, Object>();
71
72
73
74
75 private Set<String> _natures = new HashSet<String>();
76
77
78
79
80 protected FieldDescriptorImpl() {}
81
82
83
84
85
86
87
88
89
90 public FieldDescriptorImpl(final String fieldName, final TypeInfo typeInfo,
91 final FieldHandler handler, final boolean isTransitive) {
92
93 if (fieldName == null) {
94 throw new IllegalArgumentException("Internal error. Field name not specified.");
95 }
96
97 if (handler == null) {
98 throw new IllegalArgumentException("Internal error. No FieldHandler provided.");
99 }
100
101 setFieldName(fieldName);
102 setFieldType(typeInfo.getFieldType());
103 setHandler(handler);
104 setTransient(isTransitive);
105 setImmutable(typeInfo.isImmutable());
106 setRequired(typeInfo.isRequired());
107 setMultivalued(typeInfo.getCollectionHandler() != null);
108 }
109
110
111
112
113
114 public final void setContainingClassDescriptor(final ClassDescriptor parent) {
115 _parent = parent;
116 }
117
118
119
120
121 public final ClassDescriptor getContainingClassDescriptor() {
122 return _parent;
123 }
124
125
126
127
128
129
130 public final void setFieldName(final String fieldName) {
131 _fieldName = fieldName;
132 }
133
134
135
136
137 public final String getFieldName() {
138 return _fieldName;
139 }
140
141
142
143
144
145
146 public final void setFieldType(final Class<?> fieldType) {
147 _fieldType = fieldType;
148 }
149
150
151
152
153 public final Class<?> getFieldType() {
154 return _fieldType;
155 }
156
157
158
159
160
161
162 public final void setClassDescriptor(final ClassDescriptor classDescriptor) {
163 _classDescriptor = classDescriptor;
164 }
165
166
167
168
169 public final ClassDescriptor getClassDescriptor() {
170 return _classDescriptor;
171 }
172
173
174
175
176
177
178 public final void setHandler(final FieldHandler handler) {
179 _handler = handler;
180 }
181
182
183
184
185 public final FieldHandler getHandler() {
186 return _handler;
187 }
188
189
190
191
192
193
194 public final void setTransient(final boolean isTransient) {
195 _transient = isTransient;
196 }
197
198
199
200
201 public final boolean isTransient() {
202 return _transient;
203 }
204
205
206
207
208
209
210
211
212 public final void setImmutable(final boolean immutable) {
213 _immutable = immutable;
214 }
215
216
217
218
219 public final boolean isImmutable() {
220 return _immutable;
221 }
222
223
224
225
226
227
228 public final void setRequired(final boolean required) {
229 _required = required;
230 }
231
232
233
234
235 public final boolean isRequired() {
236 return _required;
237 }
238
239
240
241
242
243
244 public final void setMultivalued(final boolean multivalued) {
245 _multivalued = multivalued;
246 }
247
248
249
250
251 public final boolean isMultivalued() {
252 return _multivalued;
253 }
254
255
256
257
258
259
260 public final void setIdentity(final boolean identity) {
261 _identity = identity;
262 }
263
264
265
266
267
268
269 public final boolean isIdentity() {
270 return _identity;
271 }
272
273
274
275
276
277
278 public Object getProperty(final String name) {
279 return _properties.get(name);
280 }
281
282
283
284
285
286
287
288 public void setProperty(final String name, final Object value) {
289 _properties.put(name, value);
290 }
291
292
293
294
295
296 public void addNature(final String nature) {
297 _natures.add(nature);
298 }
299
300
301
302
303
304
305 public boolean hasNature(final String nature) {
306 return _natures.contains(nature);
307 }
308
309 public String getComparator() {
310 return _comparator;
311 }
312
313 public void setComparator(String comparator) {
314 _comparator = comparator;
315 }
316
317 public FieldMappingCollectionType getCollection() {
318 return _collection;
319 }
320
321 public void setCollection(FieldMappingCollectionType collection) {
322 _collection = collection;
323 }
324
325 public boolean isDirect() {
326 return _direct;
327 }
328
329 public void setDirect(boolean direct) {
330 _direct = direct;
331 }
332
333 public String getGetMethod() {
334 return _getMethod;
335 }
336
337 public void setGetMethod(String getMethod) {
338 _getMethod = getMethod;
339 }
340
341 public String getSetMethod() {
342 return _setMethod;
343 }
344
345 public void setSetMethod(String setMethod) {
346 _setMethod = setMethod;
347 }
348
349 public String getCreateMethod() {
350 return _createMethod;
351 }
352
353 public void setCreateMethod(String createMethod) {
354 _createMethod = createMethod;
355 }
356
357 public boolean isLazy() {
358 return _lazy;
359 }
360
361 public void setLazy(boolean lazy) {
362 _lazy = lazy;
363 }
364
365 public String toString() {
366 return new StringBuilder().append(getFieldName()).append('(').append(getFieldType().getName())
367 .append(')').toString();
368
369
370
371
372
373
374
375
376
377
378
379
380 }
381
382 }