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