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