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,
91 final TypeInfo typeInfo,
92 final FieldHandler handler,
93 final boolean isTransitive) {
94
95 if (fieldName == null) {
96 throw new IllegalArgumentException("Internal error. Field name not specified.");
97 }
98
99 if (handler == null) {
100 throw new IllegalArgumentException("Internal error. No FieldHandler provided.");
101 }
102
103 setFieldName(fieldName);
104 setFieldType(typeInfo.getFieldType());
105 setHandler(handler);
106 setTransient(isTransitive);
107 setImmutable(typeInfo.isImmutable());
108 setRequired(typeInfo.isRequired());
109 setMultivalued(typeInfo.getCollectionHandler() != null);
110 }
111
112
113
114
115
116
117 public final void setContainingClassDescriptor(final ClassDescriptor parent) {
118 _parent = parent;
119 }
120
121
122
123
124
125 public final ClassDescriptor getContainingClassDescriptor() {
126 return _parent;
127 }
128
129
130
131
132
133
134 public final void setFieldName(final String fieldName) {
135 _fieldName = fieldName;
136 }
137
138
139
140
141
142 public final String getFieldName() {
143 return _fieldName;
144 }
145
146
147
148
149
150
151 public final void setFieldType(final Class<?> fieldType) {
152 _fieldType = fieldType;
153 }
154
155
156
157
158
159 public final Class<?> getFieldType() {
160 return _fieldType;
161 }
162
163
164
165
166
167
168 public final void setClassDescriptor(final ClassDescriptor classDescriptor) {
169 _classDescriptor = classDescriptor;
170 }
171
172
173
174
175
176 public final ClassDescriptor getClassDescriptor() {
177 return _classDescriptor;
178 }
179
180
181
182
183
184
185 public final void setHandler(final FieldHandler handler) {
186 _handler = handler;
187 }
188
189
190
191
192
193 public final FieldHandler getHandler() {
194 return _handler;
195 }
196
197
198
199
200
201
202 public final void setTransient(final boolean isTransient) {
203 _transient = isTransient;
204 }
205
206
207
208
209
210 public final boolean isTransient() {
211 return _transient;
212 }
213
214
215
216
217
218
219
220
221 public final void setImmutable(final boolean immutable) {
222 _immutable = immutable;
223 }
224
225
226
227
228
229 public final boolean isImmutable() {
230 return _immutable;
231 }
232
233
234
235
236
237
238 public final void setRequired(final boolean required) {
239 _required = required;
240 }
241
242
243
244
245
246 public final boolean isRequired() {
247 return _required;
248 }
249
250
251
252
253
254
255 public final void setMultivalued(final boolean multivalued) {
256 _multivalued = multivalued;
257 }
258
259
260
261
262
263 public final boolean isMultivalued() {
264 return _multivalued;
265 }
266
267
268
269
270
271
272 public final void setIdentity(final boolean identity) {
273 _identity = identity;
274 }
275
276
277
278
279
280
281 public final boolean isIdentity() {
282 return _identity;
283 }
284
285
286
287
288
289
290
291
292 public Object getProperty(final String name) {
293 return _properties.get(name);
294 }
295
296
297
298
299
300
301
302
303
304 public void setProperty(final String name, final Object value) {
305 _properties.put(name, value);
306 }
307
308
309
310
311
312
313
314 public void addNature(final String nature) {
315 _natures.add(nature);
316 }
317
318
319
320
321
322
323
324
325 public boolean hasNature(final String nature) {
326 return _natures.contains(nature);
327 }
328
329 public String getComparator() {
330 return _comparator;
331 }
332
333 public void setComparator(String comparator) {
334 _comparator = comparator;
335 }
336
337 public FieldMappingCollectionType getCollection() {
338 return _collection;
339 }
340
341 public void setCollection(FieldMappingCollectionType collection) {
342 _collection = collection;
343 }
344
345 public boolean isDirect() {
346 return _direct;
347 }
348
349 public void setDirect(boolean direct) {
350 _direct = direct;
351 }
352
353 public String getGetMethod() {
354 return _getMethod;
355 }
356
357 public void setGetMethod(String getMethod) {
358 _getMethod = getMethod;
359 }
360
361 public String getSetMethod() {
362 return _setMethod;
363 }
364
365 public void setSetMethod(String setMethod) {
366 _setMethod = setMethod;
367 }
368
369 public String getCreateMethod() {
370 return _createMethod;
371 }
372
373 public void setCreateMethod(String createMethod) {
374 _createMethod = createMethod;
375 }
376
377 public boolean isLazy() {
378 return _lazy;
379 }
380
381 public void setLazy(boolean lazy) {
382 _lazy = lazy;
383 }
384
385 public String toString() {
386 StringBuffer buffer = new StringBuffer();
387 buffer.append(getFieldName() + "(" + getFieldType().getName() + ")");
388
389
390
391
392
393
394
395
396
397
398
399 return buffer.toString();
400 }
401
402 }