root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / DefaultFeatureAttributeDescriptor.java @ 33281
History | View | Annotate | Download (12.4 KB)
1 |
package org.gvsig.fmap.dal.feature.impl; |
---|---|
2 |
|
3 |
import java.text.DateFormat; |
4 |
import java.util.HashMap; |
5 |
import java.util.Iterator; |
6 |
import java.util.List; |
7 |
import java.util.Map; |
8 |
import java.util.Map.Entry; |
9 |
|
10 |
import org.cresques.cts.IProjection; |
11 |
import org.gvsig.fmap.crs.CRSFactory; |
12 |
import org.gvsig.fmap.dal.DataTypes; |
13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.dal.feature.exception.UnsupportedDataTypeException; |
15 |
import org.gvsig.fmap.geom.Geometry; |
16 |
import org.gvsig.tools.ToolsLocator; |
17 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
18 |
import org.gvsig.tools.dynobject.DynField; |
19 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
20 |
import org.gvsig.tools.dynobject.DynStruct; |
21 |
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException; |
22 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
23 |
import org.gvsig.tools.evaluator.Evaluator; |
24 |
import org.gvsig.tools.persistence.Persistent; |
25 |
import org.gvsig.tools.persistence.PersistentState; |
26 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
27 |
|
28 |
public class DefaultFeatureAttributeDescriptor implements |
29 |
FeatureAttributeDescriptor, Persistent, DynField { |
30 |
|
31 |
protected boolean allowNull; |
32 |
protected int dataType; |
33 |
protected DateFormat dateFormat; |
34 |
protected Object defaultValue; |
35 |
protected int index; |
36 |
protected int maximumOccurrences; |
37 |
protected int minimumOccurrences; |
38 |
protected int size; |
39 |
protected String name; |
40 |
protected Class objectClass; |
41 |
protected int precision; |
42 |
protected Evaluator evaluator;
|
43 |
protected boolean primaryKey; |
44 |
protected boolean readOnly; |
45 |
protected IProjection SRS;
|
46 |
protected int geometryType; |
47 |
protected int geometrySubType; |
48 |
protected Map additionalInfo; |
49 |
protected boolean isAutomatic; |
50 |
|
51 |
|
52 |
protected DefaultFeatureAttributeDescriptor() {
|
53 |
this.allowNull = true; |
54 |
this.dataType = DataTypes.UNKNOWN;
|
55 |
this.dateFormat = null; |
56 |
this.defaultValue = null; |
57 |
this.index = -1; |
58 |
this.maximumOccurrences = 0; |
59 |
this.minimumOccurrences = 0; |
60 |
this.size = 0; |
61 |
this.name = null; |
62 |
this.objectClass = null; |
63 |
this.precision = 0; |
64 |
this.evaluator = null; |
65 |
this.primaryKey = false; |
66 |
this.readOnly = false; |
67 |
this.SRS = null; |
68 |
this.geometryType = Geometry.TYPES.NULL;
|
69 |
this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
|
70 |
this.additionalInfo = null; |
71 |
this.isAutomatic = false; |
72 |
} |
73 |
|
74 |
protected DefaultFeatureAttributeDescriptor(
|
75 |
DefaultFeatureAttributeDescriptor other) { |
76 |
this.allowNull = other.allowNull;
|
77 |
this.dataType = other.dataType;
|
78 |
this.dateFormat = other.dateFormat;
|
79 |
this.defaultValue = other.defaultValue;
|
80 |
this.index = other.index;
|
81 |
this.maximumOccurrences = other.maximumOccurrences;
|
82 |
this.minimumOccurrences = other.minimumOccurrences;
|
83 |
this.size = other.size;
|
84 |
this.name = other.name;
|
85 |
this.objectClass = other.objectClass;
|
86 |
this.precision = other.precision;
|
87 |
this.evaluator = other.evaluator;
|
88 |
this.primaryKey = other.primaryKey;
|
89 |
this.readOnly = other.readOnly;
|
90 |
this.SRS = other.SRS;
|
91 |
this.geometryType = other.geometryType;
|
92 |
this.geometrySubType = other.geometrySubType;
|
93 |
if (other.additionalInfo != null) { |
94 |
Iterator iter = other.additionalInfo.entrySet().iterator();
|
95 |
Map.Entry entry;
|
96 |
this.additionalInfo = new HashMap(); |
97 |
while (iter.hasNext()) {
|
98 |
entry = (Entry) iter.next(); |
99 |
this.additionalInfo.put(entry.getKey(), entry.getValue());
|
100 |
} |
101 |
} else {
|
102 |
this.additionalInfo = null; |
103 |
} |
104 |
this.isAutomatic = other.isAutomatic;
|
105 |
} |
106 |
|
107 |
public String getDataTypeName() { |
108 |
return ToolsLocator.getDataTypesManager().getTypeName(this.getDataType()); |
109 |
} |
110 |
|
111 |
public FeatureAttributeDescriptor getCopy() {
|
112 |
return new DefaultFeatureAttributeDescriptor(this); |
113 |
} |
114 |
|
115 |
public boolean allowNull() { |
116 |
return allowNull;
|
117 |
} |
118 |
|
119 |
public int getDataType() { |
120 |
return this.dataType; |
121 |
} |
122 |
|
123 |
public DateFormat getDateFormat() { |
124 |
return this.dateFormat; |
125 |
} |
126 |
|
127 |
public Object getDefaultValue() { |
128 |
return this.defaultValue; |
129 |
} |
130 |
|
131 |
public Evaluator getEvaluator() {
|
132 |
return this.evaluator; |
133 |
} |
134 |
|
135 |
public int getGeometryType() { |
136 |
return this.geometryType; |
137 |
} |
138 |
|
139 |
public int getGeometrySubType() { |
140 |
return this.geometrySubType; |
141 |
} |
142 |
|
143 |
public int getIndex() { |
144 |
return this.index; |
145 |
} |
146 |
|
147 |
protected FeatureAttributeDescriptor setIndex(int index) { |
148 |
this.index = index;
|
149 |
return this; |
150 |
} |
151 |
|
152 |
public int getMaximumOccurrences() { |
153 |
return this.maximumOccurrences; |
154 |
} |
155 |
|
156 |
public int getMinimumOccurrences() { |
157 |
return this.minimumOccurrences; |
158 |
} |
159 |
|
160 |
public String getName() { |
161 |
return this.name; |
162 |
} |
163 |
|
164 |
public Class getObjectClass() { |
165 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
166 |
if (this.dataType == DataTypes.OBJECT) { |
167 |
return objectClass;
|
168 |
|
169 |
} else if (!manager.isValidType(this.dataType) ) { |
170 |
throw new UnsupportedDataTypeException(this.name, this.dataType); |
171 |
} |
172 |
return manager.getDefaultClass(this.dataType); |
173 |
} |
174 |
|
175 |
public int getPrecision() { |
176 |
return this.precision; |
177 |
} |
178 |
|
179 |
public IProjection getSRS() {
|
180 |
return this.SRS; |
181 |
} |
182 |
|
183 |
public int getSize() { |
184 |
return this.size; |
185 |
} |
186 |
|
187 |
public boolean isPrimaryKey() { |
188 |
return this.primaryKey; |
189 |
} |
190 |
|
191 |
public boolean isReadOnly() { |
192 |
return this.readOnly; |
193 |
} |
194 |
|
195 |
public Object getAdditionalInfo(String infoName) { |
196 |
if (this.additionalInfo == null) { |
197 |
return null; |
198 |
} |
199 |
return this.additionalInfo.get(infoName); |
200 |
} |
201 |
|
202 |
public boolean isAutomatic() { |
203 |
return this.isAutomatic; |
204 |
} |
205 |
|
206 |
|
207 |
private boolean compareObject(Object a, Object b) { |
208 |
if (a != b) {
|
209 |
if (a == null) { |
210 |
return false; |
211 |
} |
212 |
return a.equals(b);
|
213 |
} |
214 |
return true; |
215 |
|
216 |
} |
217 |
|
218 |
public boolean equals(Object obj) { |
219 |
if (this == obj) { |
220 |
return true; |
221 |
} |
222 |
if (!(obj instanceof DefaultFeatureAttributeDescriptor)) { |
223 |
return false; |
224 |
} |
225 |
DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) obj; |
226 |
|
227 |
if (this.allowNull != other.allowNull) { |
228 |
return false; |
229 |
} |
230 |
|
231 |
if (this.index != other.index) { |
232 |
return false; |
233 |
} |
234 |
|
235 |
if (!compareObject(this.name, other.name)) { |
236 |
return false; |
237 |
} |
238 |
|
239 |
if (this.dataType != other.dataType) { |
240 |
return false; |
241 |
} |
242 |
|
243 |
if (this.size != other.size) { |
244 |
return false; |
245 |
} |
246 |
|
247 |
if (!compareObject(this.defaultValue, other.defaultValue)) { |
248 |
return false; |
249 |
} |
250 |
|
251 |
if (!compareObject(this.defaultValue, other.defaultValue)) { |
252 |
return false; |
253 |
} |
254 |
|
255 |
if (this.primaryKey != other.primaryKey) { |
256 |
return false; |
257 |
} |
258 |
|
259 |
if (this.isAutomatic != other.isAutomatic) { |
260 |
return false; |
261 |
} |
262 |
|
263 |
if (this.readOnly != other.readOnly) { |
264 |
return false; |
265 |
} |
266 |
|
267 |
if (this.precision != other.precision) { |
268 |
return false; |
269 |
} |
270 |
|
271 |
if (this.maximumOccurrences != other.maximumOccurrences) { |
272 |
return false; |
273 |
} |
274 |
|
275 |
if (this.minimumOccurrences != other.minimumOccurrences) { |
276 |
return false; |
277 |
} |
278 |
if (this.geometryType != other.geometryType) { |
279 |
return false; |
280 |
} |
281 |
|
282 |
if (this.geometrySubType != other.geometrySubType) { |
283 |
return false; |
284 |
} |
285 |
|
286 |
if (!compareObject(this.evaluator, other.evaluator)) { |
287 |
return false; |
288 |
} |
289 |
|
290 |
if (!compareObject(this.SRS, other.SRS)) { |
291 |
return false; |
292 |
} |
293 |
|
294 |
if (!compareObject(this.dateFormat, other.dateFormat)) { |
295 |
return false; |
296 |
} |
297 |
|
298 |
if (!compareObject(this.objectClass, other.objectClass)) { |
299 |
return false; |
300 |
} |
301 |
|
302 |
return true; |
303 |
} |
304 |
|
305 |
public void loadFromState(PersistentState state) |
306 |
throws PersistenceException {
|
307 |
allowNull = state.getBoolean("allowNull");
|
308 |
dataType = state.getInt("dataType");
|
309 |
// FIXME how persist dateFormat ???
|
310 |
// dateFormat;
|
311 |
defaultValue = state.get("defaultValue");
|
312 |
|
313 |
index = state.getInt("index");
|
314 |
maximumOccurrences = state.getInt("maximumOccurrences");
|
315 |
minimumOccurrences = state.getInt("minimumOccurrences");
|
316 |
size = state.getInt("size");
|
317 |
name = state.getString("name");
|
318 |
try {
|
319 |
objectClass = Class.forName(state.getString("objectClass")); |
320 |
} catch (ClassNotFoundException e) { |
321 |
throw new PersistenceException(e); |
322 |
} |
323 |
precision = state.getInt("precision");
|
324 |
evaluator = (Evaluator) state.get("evaluator");
|
325 |
primaryKey = state.getBoolean("primaryKey");
|
326 |
readOnly = state.getBoolean("readOnly");
|
327 |
String srsId = state.getString("srsId"); |
328 |
if (srsId != null){ |
329 |
SRS = CRSFactory.getCRS(srsId); |
330 |
} |
331 |
geometryType = state.getInt("geometryType");
|
332 |
geometrySubType = state.getInt("geometrySubType");
|
333 |
additionalInfo = (Map) state.get("aditionalInfo"); |
334 |
isAutomatic = state.getBoolean("isAutomatic");
|
335 |
} |
336 |
|
337 |
public void saveToState(PersistentState state) throws PersistenceException { |
338 |
state.set("allowNull", allowNull);
|
339 |
state.set("dataType", dataType);
|
340 |
// FIXME how persist dateFormat ???
|
341 |
// dateFormat;
|
342 |
|
343 |
defaultValue = state.get("defaultValue");
|
344 |
|
345 |
index = state.getInt("index");
|
346 |
maximumOccurrences = state.getInt("maximumOccurrences");
|
347 |
minimumOccurrences = state.getInt("minimumOccurrences");
|
348 |
size = state.getInt("size");
|
349 |
name = state.getString("name");
|
350 |
try {
|
351 |
objectClass = Class.forName(state.getString("objectClass")); |
352 |
} catch (ClassNotFoundException e) { |
353 |
throw new PersistenceException(e); |
354 |
} |
355 |
precision = state.getInt("precision");
|
356 |
evaluator = (Evaluator) state.get("evaluator");
|
357 |
primaryKey = state.getBoolean("primaryKey");
|
358 |
readOnly = state.getBoolean("readOnly");
|
359 |
String srsId = state.getString("srsId"); |
360 |
if (srsId != null) { |
361 |
SRS = CRSFactory.getCRS(srsId); |
362 |
} |
363 |
geometryType = state.getInt("geometryType");
|
364 |
geometrySubType = state.getInt("geometrySubType");
|
365 |
additionalInfo = (Map) state.get("aditionalInfo"); |
366 |
isAutomatic = state.getBoolean("isAutomatic");
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Start of DynField interface Implementation
|
371 |
* READONLY
|
372 |
*/
|
373 |
|
374 |
|
375 |
public DynObjectValueItem[] getAvailableValues() { |
376 |
return null; |
377 |
} |
378 |
|
379 |
public String getDescription() { |
380 |
return null; |
381 |
} |
382 |
|
383 |
public Object getMaxValue() { |
384 |
return null; |
385 |
} |
386 |
|
387 |
public Object getMinValue() { |
388 |
return null; |
389 |
} |
390 |
|
391 |
public int getTheTypeOfAvailableValues() { |
392 |
return 0; |
393 |
} |
394 |
|
395 |
public int getType() { |
396 |
return getDataType();
|
397 |
} |
398 |
|
399 |
public boolean isMandatory() { |
400 |
return false; |
401 |
} |
402 |
|
403 |
public boolean isPersistent() { |
404 |
return false; |
405 |
} |
406 |
|
407 |
public DynField setAvailableValues(DynObjectValueItem[] values) { |
408 |
throw new UnsupportedOperationException(); |
409 |
} |
410 |
|
411 |
public DynField setDescription(String description) { |
412 |
throw new UnsupportedOperationException(); |
413 |
} |
414 |
|
415 |
public DynField setMandatory(boolean mandatory) { |
416 |
throw new UnsupportedOperationException(); |
417 |
} |
418 |
|
419 |
public DynField setMaxValue(Object maxValue) { |
420 |
throw new UnsupportedOperationException(); |
421 |
} |
422 |
|
423 |
public DynField setMinValue(Object minValue) { |
424 |
throw new UnsupportedOperationException(); |
425 |
} |
426 |
|
427 |
public DynField setPersistent(boolean persistent) { |
428 |
throw new UnsupportedOperationException(); |
429 |
} |
430 |
|
431 |
public DynField setTheTypeOfAvailableValues(int type) { |
432 |
throw new UnsupportedOperationException(); |
433 |
} |
434 |
|
435 |
public DynField setType(int type) { |
436 |
throw new UnsupportedOperationException(); |
437 |
} |
438 |
|
439 |
public DynField setDefaultDynValue(Object defaultValue) { |
440 |
throw new UnsupportedOperationException(); |
441 |
} |
442 |
|
443 |
public DynField addElementsType() throws DynFieldIsNotAContainerException { |
444 |
throw new UnsupportedOperationException(); |
445 |
} |
446 |
|
447 |
public Class getClassOfValue() { |
448 |
return null; |
449 |
} |
450 |
|
451 |
public DynField getElementsType() {
|
452 |
return null; |
453 |
} |
454 |
|
455 |
public DynField setClassOfValue(Class theClass) |
456 |
throws DynFieldIsNotAContainerException {
|
457 |
throw new UnsupportedOperationException(); |
458 |
} |
459 |
|
460 |
public DynField setElementsType(DynStruct type)
|
461 |
throws DynFieldIsNotAContainerException {
|
462 |
throw new UnsupportedOperationException(); |
463 |
} |
464 |
|
465 |
public DynField setElementsType(int type) |
466 |
throws DynFieldIsNotAContainerException {
|
467 |
throw new UnsupportedOperationException(); |
468 |
} |
469 |
|
470 |
public DynField setSubtype(String subtype) { |
471 |
throw new UnsupportedOperationException(); |
472 |
} |
473 |
|
474 |
public void validate(Object value) throws DynFieldValidateException { |
475 |
// Do nothing
|
476 |
} |
477 |
|
478 |
public String getSubtype() { |
479 |
return ToolsLocator.getDataTypesManager().getSubtype( this.dataType ); |
480 |
} |
481 |
|
482 |
public Object coerce(Object value) { |
483 |
throw new UnsupportedOperationException(); |
484 |
} |
485 |
|
486 |
public DynField setAvailableValues(List values) { |
487 |
throw new UnsupportedOperationException(); |
488 |
} |
489 |
|
490 |
public String getGroup() { |
491 |
return null; |
492 |
} |
493 |
|
494 |
public int getOder() { |
495 |
return 0; |
496 |
} |
497 |
|
498 |
public DynField setGroup(String groupName) { |
499 |
throw new UnsupportedOperationException(); |
500 |
} |
501 |
|
502 |
public DynField setOrder(int order) { |
503 |
throw new UnsupportedOperationException(); |
504 |
} |
505 |
|
506 |
public DynField setHidden(boolean hidden) { |
507 |
throw new UnsupportedOperationException(); |
508 |
} |
509 |
|
510 |
public boolean isHidden() { |
511 |
return false; |
512 |
} |
513 |
|
514 |
public DynField setReadOnly(boolean arg0) { |
515 |
throw new UnsupportedOperationException(); |
516 |
} |
517 |
|
518 |
public boolean isContainer() { |
519 |
return false; |
520 |
} |
521 |
|
522 |
public Class getClassOfItems() { |
523 |
return null; |
524 |
} |
525 |
|
526 |
public DynField setDefaultFieldValue(Object defaultValue) { |
527 |
throw new UnsupportedOperationException(); |
528 |
} |
529 |
|
530 |
public DynField setClassOfItems(Class theClass) { |
531 |
throw new UnsupportedOperationException(); |
532 |
} |
533 |
|
534 |
} |