svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / DefaultFeatureAttributeDescriptor.java @ 44094
History | View | Annotate | Download (29.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.dal.feature.impl; |
24 |
|
25 |
import java.lang.ref.WeakReference; |
26 |
import java.text.DateFormat; |
27 |
import java.util.HashMap; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
import java.util.Map; |
31 |
import java.util.Map.Entry; |
32 |
import org.apache.commons.lang3.ArrayUtils; |
33 |
import org.cresques.cts.IProjection; |
34 |
import org.gvsig.fmap.crs.CRSFactory; |
35 |
import org.gvsig.fmap.dal.DataStore; |
36 |
import org.gvsig.fmap.dal.DataTypes; |
37 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
38 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
42 |
import org.gvsig.fmap.dal.feature.FeatureType; |
43 |
import org.gvsig.fmap.geom.Geometry; |
44 |
import org.gvsig.fmap.geom.GeometryException; |
45 |
import org.gvsig.fmap.geom.GeometryLocator; |
46 |
import org.gvsig.fmap.geom.type.GeometryType; |
47 |
import org.gvsig.timesupport.Interval; |
48 |
import org.gvsig.timesupport.TimeSupportLocator; |
49 |
import org.gvsig.tools.ToolsLocator; |
50 |
import org.gvsig.tools.dataTypes.CoercionException; |
51 |
import org.gvsig.tools.dataTypes.DataType; |
52 |
import org.gvsig.tools.dynobject.DynField; |
53 |
import org.gvsig.tools.dynobject.DynField_LabelAttribute; |
54 |
import org.gvsig.tools.dynobject.DynField_v2; |
55 |
import org.gvsig.tools.dynobject.DynMethod; |
56 |
import org.gvsig.tools.dynobject.DynObject; |
57 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
58 |
import org.gvsig.tools.dynobject.DynStruct; |
59 |
import org.gvsig.tools.dynobject.Tags; |
60 |
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException; |
61 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
62 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
63 |
import org.gvsig.tools.dynobject.impl.DefaultTags; |
64 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
65 |
import org.gvsig.tools.evaluator.Evaluator; |
66 |
import org.gvsig.tools.evaluator.EvaluatorData; |
67 |
import org.gvsig.tools.evaluator.EvaluatorException; |
68 |
import org.gvsig.tools.persistence.Persistent; |
69 |
import org.gvsig.tools.persistence.PersistentState; |
70 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
71 |
|
72 |
public class DefaultFeatureAttributeDescriptor implements |
73 |
FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute { |
74 |
|
75 |
protected boolean allowNull; |
76 |
protected DataType dataType;
|
77 |
protected DateFormat dateFormat; |
78 |
protected Object defaultValue; |
79 |
protected int index; |
80 |
protected int maximumOccurrences; |
81 |
protected int minimumOccurrences; |
82 |
protected int size; |
83 |
protected String name; |
84 |
protected Class objectClass; |
85 |
protected int precision; |
86 |
protected Evaluator evaluator;
|
87 |
protected boolean primaryKey; |
88 |
protected boolean readOnly; |
89 |
protected IProjection SRS;
|
90 |
protected GeometryType geomType;
|
91 |
protected int geometryType; |
92 |
protected int geometrySubType; |
93 |
protected Map additionalInfo; |
94 |
protected boolean isAutomatic; |
95 |
protected boolean isTime = false; |
96 |
protected Interval interval;
|
97 |
protected FeatureAttributeGetter featureAttributeGetter = null; |
98 |
protected FeatureAttributeEmulator featureAttributeEmulator = null; |
99 |
protected boolean indexed = false; |
100 |
protected boolean isIndexAscending = true; |
101 |
protected boolean allowIndexDuplicateds = true; |
102 |
|
103 |
protected DynObjectValueItem[] availableValues; |
104 |
protected String description; |
105 |
protected Object minValue; |
106 |
protected Object maxValue; |
107 |
protected String label; |
108 |
protected int order; |
109 |
protected boolean hidden; |
110 |
protected String groupName; |
111 |
protected Tags tags = new DefaultTags(); |
112 |
private DynMethod availableValuesMethod;
|
113 |
private DynMethod calculateMethod;
|
114 |
private WeakReference typeRef; |
115 |
|
116 |
protected DefaultFeatureAttributeDescriptor(FeatureType type) {
|
117 |
if( type == null ) { |
118 |
this.typeRef = null; |
119 |
} else {
|
120 |
this.typeRef = new WeakReference(type); |
121 |
} |
122 |
this.allowNull = true; |
123 |
this.dataType = null; |
124 |
this.dateFormat = null; |
125 |
this.defaultValue = null; |
126 |
this.index = -1; |
127 |
this.maximumOccurrences = 0; |
128 |
this.minimumOccurrences = 0; |
129 |
this.size = 0; |
130 |
this.name = null; |
131 |
this.objectClass = null; |
132 |
this.precision = 0; |
133 |
this.evaluator = null; |
134 |
this.primaryKey = false; |
135 |
this.readOnly = false; |
136 |
this.SRS = null; |
137 |
this.geometryType = Geometry.TYPES.NULL;
|
138 |
this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
|
139 |
this.additionalInfo = null; |
140 |
this.isAutomatic = false; |
141 |
this.hidden = false; |
142 |
} |
143 |
|
144 |
protected DefaultFeatureAttributeDescriptor(
|
145 |
DefaultFeatureAttributeDescriptor other |
146 |
) { |
147 |
copyFrom(other); |
148 |
} |
149 |
|
150 |
@Override
|
151 |
public void copyFrom(DynField other1) { |
152 |
if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) { |
153 |
throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor"); |
154 |
} |
155 |
DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1; |
156 |
this.typeRef = other.typeRef;
|
157 |
this.allowNull = other.allowNull;
|
158 |
this.dataType = other.dataType;
|
159 |
this.dateFormat = other.dateFormat;
|
160 |
this.defaultValue = other.defaultValue;
|
161 |
this.index = other.index;
|
162 |
this.maximumOccurrences = other.maximumOccurrences;
|
163 |
this.minimumOccurrences = other.minimumOccurrences;
|
164 |
this.size = other.size;
|
165 |
this.name = other.name;
|
166 |
this.objectClass = other.objectClass;
|
167 |
this.precision = other.precision;
|
168 |
this.evaluator = other.evaluator;
|
169 |
this.primaryKey = other.primaryKey;
|
170 |
this.readOnly = other.readOnly;
|
171 |
this.SRS = other.SRS;
|
172 |
this.geometryType = other.geometryType;
|
173 |
this.geometrySubType = other.geometrySubType;
|
174 |
this.geomType = other.geomType;
|
175 |
if (other.additionalInfo != null) { |
176 |
Iterator iter = other.additionalInfo.entrySet().iterator();
|
177 |
Map.Entry entry;
|
178 |
this.additionalInfo = new HashMap(); |
179 |
while (iter.hasNext()) {
|
180 |
entry = (Entry) iter.next(); |
181 |
this.additionalInfo.put(entry.getKey(), entry.getValue());
|
182 |
} |
183 |
} else {
|
184 |
this.additionalInfo = null; |
185 |
} |
186 |
this.isAutomatic = other.isAutomatic;
|
187 |
this.isTime = other.isTime;
|
188 |
this.featureAttributeEmulator = other.featureAttributeEmulator;
|
189 |
this.indexed = other.indexed;
|
190 |
this.isIndexAscending = other.isIndexAscending;
|
191 |
this.allowIndexDuplicateds = other.allowIndexDuplicateds;
|
192 |
this.hidden = other.hidden;
|
193 |
} |
194 |
|
195 |
@Override
|
196 |
public String getDataTypeName() { |
197 |
if (this.getDataType() == null) { |
198 |
return "(unknow)"; |
199 |
} |
200 |
return this.getDataType().getName(); |
201 |
} |
202 |
|
203 |
@Override
|
204 |
public FeatureAttributeDescriptor getCopy() {
|
205 |
return new DefaultFeatureAttributeDescriptor(this); |
206 |
} |
207 |
|
208 |
@Override
|
209 |
public Object clone() throws CloneNotSupportedException { |
210 |
return new DefaultFeatureAttributeDescriptor(this); |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public boolean allowNull() { |
215 |
return allowNull;
|
216 |
} |
217 |
|
218 |
@Override
|
219 |
public DataType getDataType() {
|
220 |
if (featureAttributeGetter != null) { |
221 |
return featureAttributeGetter.getDataType();
|
222 |
} |
223 |
return this.dataType; |
224 |
} |
225 |
|
226 |
public FeatureAttributeDescriptor setDataType(int type) { |
227 |
this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
228 |
return this; |
229 |
} |
230 |
|
231 |
@Override
|
232 |
public DateFormat getDateFormat() { |
233 |
return this.dateFormat; |
234 |
} |
235 |
|
236 |
@Override
|
237 |
public Object getDefaultValue() { |
238 |
return this.defaultValue; |
239 |
} |
240 |
|
241 |
@Override
|
242 |
public Evaluator getEvaluator() {
|
243 |
return this.evaluator; |
244 |
} |
245 |
|
246 |
@Override
|
247 |
public int getGeometryType() { |
248 |
if( this.dataType.getType()!=DataTypes.GEOMETRY ) { |
249 |
return Geometry.TYPES.UNKNOWN;
|
250 |
} |
251 |
return this.geometryType; |
252 |
} |
253 |
|
254 |
@Override
|
255 |
public int getGeometrySubType() { |
256 |
if( this.dataType.getType()!=DataTypes.GEOMETRY ) { |
257 |
return Geometry.SUBTYPES.UNKNOWN;
|
258 |
} |
259 |
return this.geometrySubType; |
260 |
} |
261 |
|
262 |
@Override
|
263 |
public GeometryType getGeomType() {
|
264 |
if( this.dataType.getType()!=DataTypes.GEOMETRY ) { |
265 |
return null; |
266 |
} |
267 |
if (this.geomType == null) { |
268 |
try {
|
269 |
this.geomType
|
270 |
= GeometryLocator.getGeometryManager().getGeometryType( |
271 |
this.geometryType, this.geometrySubType); |
272 |
} catch (GeometryException e) {
|
273 |
throw new RuntimeException( |
274 |
"Error getting geometry type with type = "
|
275 |
+ this.geometryType + ", subtype = " |
276 |
+ this.geometrySubType, e);
|
277 |
} |
278 |
} |
279 |
return this.geomType; |
280 |
} |
281 |
|
282 |
@Override
|
283 |
public int getIndex() { |
284 |
return this.index; |
285 |
} |
286 |
|
287 |
protected FeatureAttributeDescriptor setIndex(int index) { |
288 |
this.index = index;
|
289 |
return this; |
290 |
} |
291 |
|
292 |
@Override
|
293 |
public int getMaximumOccurrences() { |
294 |
return this.maximumOccurrences; |
295 |
} |
296 |
|
297 |
@Override
|
298 |
public int getMinimumOccurrences() { |
299 |
return this.minimumOccurrences; |
300 |
} |
301 |
|
302 |
@Override
|
303 |
public String getName() { |
304 |
return this.name; |
305 |
} |
306 |
|
307 |
public FeatureAttributeDescriptor setName(String name) { |
308 |
this.name = name;
|
309 |
return this; |
310 |
} |
311 |
|
312 |
@Override
|
313 |
public Class getObjectClass() { |
314 |
if (getDataType().getType() == DataTypes.OBJECT) {
|
315 |
return objectClass;
|
316 |
} |
317 |
return getDataType().getDefaultClass();
|
318 |
} |
319 |
|
320 |
@Override
|
321 |
public int getPrecision() { |
322 |
return this.precision; |
323 |
} |
324 |
|
325 |
@Override
|
326 |
public IProjection getSRS() {
|
327 |
return this.SRS; |
328 |
} |
329 |
|
330 |
@Override
|
331 |
public Interval getInterval() {
|
332 |
return this.interval; |
333 |
} |
334 |
|
335 |
public IProjection getSRS(WeakReference storeRef) { |
336 |
if( this.SRS==null ) { |
337 |
FeatureStore store = (FeatureStore) storeRef.get(); |
338 |
this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
|
339 |
} |
340 |
return this.SRS; |
341 |
} |
342 |
|
343 |
|
344 |
@Override
|
345 |
public int getSize() { |
346 |
return this.size; |
347 |
} |
348 |
|
349 |
@Override
|
350 |
public boolean isPrimaryKey() { |
351 |
return this.primaryKey; |
352 |
} |
353 |
|
354 |
@Override
|
355 |
public boolean isReadOnly() { |
356 |
if (this.readOnly) { |
357 |
return true; |
358 |
} |
359 |
if (this.getEvaluator() != null) { |
360 |
return true; |
361 |
} |
362 |
if (this.featureAttributeEmulator != null) { |
363 |
return !this.featureAttributeEmulator.allowSetting(); |
364 |
} |
365 |
return false; |
366 |
} |
367 |
|
368 |
@Override
|
369 |
public Object getAdditionalInfo(String infoName) { |
370 |
if (this.additionalInfo == null) { |
371 |
return null; |
372 |
} |
373 |
return this.additionalInfo.get(infoName); |
374 |
} |
375 |
|
376 |
@Override
|
377 |
public boolean isAutomatic() { |
378 |
return this.isAutomatic; |
379 |
} |
380 |
|
381 |
private boolean compareObject(Object a, Object b) { |
382 |
if (a != b) {
|
383 |
if (a == null) { |
384 |
return false; |
385 |
} |
386 |
return a.equals(b);
|
387 |
} |
388 |
return true; |
389 |
|
390 |
} |
391 |
|
392 |
@Override
|
393 |
public boolean equals(Object obj) { |
394 |
if (this == obj) { |
395 |
return true; |
396 |
} |
397 |
if (!(obj instanceof DefaultFeatureAttributeDescriptor)) { |
398 |
return false; |
399 |
} |
400 |
DefaultFeatureAttributeDescriptor other |
401 |
= (DefaultFeatureAttributeDescriptor) obj; |
402 |
|
403 |
if (this.allowNull != other.allowNull) { |
404 |
return false; |
405 |
} |
406 |
|
407 |
if (this.index != other.index) { |
408 |
return false; |
409 |
} |
410 |
|
411 |
if (!compareObject(this.name, other.name)) { |
412 |
return false; |
413 |
} |
414 |
|
415 |
if (this.getDataType() != other.getDataType()) { |
416 |
return false; |
417 |
} |
418 |
|
419 |
if (this.size != other.size) { |
420 |
return false; |
421 |
} |
422 |
|
423 |
if (!compareObject(this.defaultValue, other.defaultValue)) { |
424 |
return false; |
425 |
} |
426 |
|
427 |
if (!compareObject(this.defaultValue, other.defaultValue)) { |
428 |
return false; |
429 |
} |
430 |
|
431 |
if (this.primaryKey != other.primaryKey) { |
432 |
return false; |
433 |
} |
434 |
|
435 |
if (this.isAutomatic != other.isAutomatic) { |
436 |
return false; |
437 |
} |
438 |
|
439 |
if (this.readOnly != other.readOnly) { |
440 |
return false; |
441 |
} |
442 |
|
443 |
if (this.precision != other.precision) { |
444 |
return false; |
445 |
} |
446 |
|
447 |
if (this.maximumOccurrences != other.maximumOccurrences) { |
448 |
return false; |
449 |
} |
450 |
|
451 |
if (this.minimumOccurrences != other.minimumOccurrences) { |
452 |
return false; |
453 |
} |
454 |
|
455 |
if (this.geometryType != other.geometryType) { |
456 |
return false; |
457 |
} |
458 |
|
459 |
if (this.geometrySubType != other.geometrySubType) { |
460 |
return false; |
461 |
} |
462 |
|
463 |
if (!compareObject(this.evaluator, other.evaluator)) { |
464 |
return false; |
465 |
} |
466 |
|
467 |
if (!compareObject(this.SRS, other.SRS)) { |
468 |
return false; |
469 |
} |
470 |
|
471 |
if (!compareObject(this.dateFormat, other.dateFormat)) { |
472 |
return false; |
473 |
} |
474 |
|
475 |
if (!compareObject(this.objectClass, other.objectClass)) { |
476 |
return false; |
477 |
} |
478 |
|
479 |
return true; |
480 |
} |
481 |
|
482 |
@Override
|
483 |
public void loadFromState(PersistentState state) |
484 |
throws PersistenceException {
|
485 |
allowNull = state.getBoolean("allowNull");
|
486 |
dataType = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
|
487 |
// FIXME how persist dateFormat ???
|
488 |
// dateFormat;
|
489 |
defaultValue = state.get("defaultValue");
|
490 |
|
491 |
index = state.getInt("index");
|
492 |
maximumOccurrences = state.getInt("maximumOccurrences");
|
493 |
minimumOccurrences = state.getInt("minimumOccurrences");
|
494 |
size = state.getInt("size");
|
495 |
name = state.getString("name");
|
496 |
try {
|
497 |
objectClass = Class.forName(state.getString("objectClass")); |
498 |
} catch (ClassNotFoundException e) { |
499 |
throw new PersistenceException(e); |
500 |
} |
501 |
precision = state.getInt("precision");
|
502 |
evaluator = (Evaluator) state.get("evaluator");
|
503 |
primaryKey = state.getBoolean("primaryKey");
|
504 |
readOnly = state.getBoolean("readOnly");
|
505 |
String srsId = state.getString("srsId"); |
506 |
if (srsId != null) { |
507 |
SRS = CRSFactory.getCRS(srsId); |
508 |
} |
509 |
geometryType = state.getInt("geometryType");
|
510 |
geometrySubType = state.getInt("geometrySubType");
|
511 |
additionalInfo = (Map) state.get("aditionalInfo"); |
512 |
isAutomatic = state.getBoolean("isAutomatic");
|
513 |
isTime = state.getBoolean("isTime");
|
514 |
if( state.hasValue("intervalStart") ) { |
515 |
long intervalStart = state.getLong("intervalStart"); |
516 |
long intervalEnd = state.getLong("intervalEnd"); |
517 |
interval = TimeSupportLocator.getManager().createRelativeInterval(intervalStart, intervalEnd); |
518 |
} else {
|
519 |
interval = null;
|
520 |
} |
521 |
} |
522 |
|
523 |
@Override
|
524 |
public void saveToState(PersistentState state) throws PersistenceException { |
525 |
state.set("allowNull", allowNull);
|
526 |
state.set("dataType", dataType);
|
527 |
// FIXME how persist dateFormat ???
|
528 |
// dateFormat;
|
529 |
|
530 |
defaultValue = state.get("defaultValue");
|
531 |
|
532 |
index = state.getInt("index");
|
533 |
maximumOccurrences = state.getInt("maximumOccurrences");
|
534 |
minimumOccurrences = state.getInt("minimumOccurrences");
|
535 |
size = state.getInt("size");
|
536 |
name = state.getString("name");
|
537 |
try {
|
538 |
objectClass = Class.forName(state.getString("objectClass")); |
539 |
} catch (ClassNotFoundException e) { |
540 |
throw new PersistenceException(e); |
541 |
} |
542 |
precision = state.getInt("precision");
|
543 |
evaluator = (Evaluator) state.get("evaluator");
|
544 |
primaryKey = state.getBoolean("primaryKey");
|
545 |
readOnly = state.getBoolean("readOnly");
|
546 |
String srsId = state.getString("srsId"); |
547 |
if (srsId != null) { |
548 |
SRS = CRSFactory.getCRS(srsId); |
549 |
} |
550 |
geometryType = state.getInt("geometryType");
|
551 |
geometrySubType = state.getInt("geometrySubType");
|
552 |
additionalInfo = (Map) state.get("aditionalInfo"); |
553 |
isAutomatic = state.getBoolean("isAutomatic");
|
554 |
} |
555 |
|
556 |
/*
|
557 |
* Start of DynField interface Implementation
|
558 |
*
|
559 |
*/
|
560 |
|
561 |
@Override
|
562 |
public Tags getTags() {
|
563 |
return tags;
|
564 |
} |
565 |
|
566 |
@Override
|
567 |
public DynObjectValueItem[] getAvailableValues() { |
568 |
return this.availableValues; |
569 |
} |
570 |
|
571 |
@Override
|
572 |
public String getDescription() { |
573 |
if( this.description == null ) { |
574 |
return getName();
|
575 |
} |
576 |
return this.description; |
577 |
} |
578 |
|
579 |
@Override
|
580 |
public Object getMaxValue() { |
581 |
return this.maxValue; |
582 |
} |
583 |
|
584 |
@Override
|
585 |
public Object getMinValue() { |
586 |
return this.minValue; |
587 |
} |
588 |
|
589 |
@Override
|
590 |
public int getTheTypeOfAvailableValues() { |
591 |
return 1; |
592 |
} |
593 |
|
594 |
@Override
|
595 |
public int getType() { |
596 |
if (featureAttributeGetter != null) { |
597 |
return featureAttributeGetter.getDataType().getType();
|
598 |
} |
599 |
return getDataType().getType();
|
600 |
} |
601 |
|
602 |
@Override
|
603 |
public boolean isMandatory() { |
604 |
return !allowNull() || isPrimaryKey();
|
605 |
} |
606 |
|
607 |
@Override
|
608 |
public boolean isPersistent() { |
609 |
return false; |
610 |
} |
611 |
|
612 |
@Override
|
613 |
public DynField setAvailableValues(DynObjectValueItem[] values) { |
614 |
if ( ArrayUtils.isEmpty(values) ) {
|
615 |
this.availableValues = null; |
616 |
} else {
|
617 |
this.availableValues = values;
|
618 |
} |
619 |
return this; |
620 |
} |
621 |
|
622 |
@Override
|
623 |
public DynField setDescription(String description) { |
624 |
this.description = description;
|
625 |
return this; |
626 |
} |
627 |
|
628 |
@Override
|
629 |
public DynField setMandatory(boolean mandatory) { |
630 |
throw new UnsupportedOperationException(); |
631 |
} |
632 |
|
633 |
@Override
|
634 |
public DynField setMaxValue(Object maxValue) { |
635 |
try {
|
636 |
this.maxValue = this.coerce(maxValue); |
637 |
} catch (CoercionException e) {
|
638 |
throw new IllegalArgumentException(e); |
639 |
} |
640 |
return this; |
641 |
} |
642 |
|
643 |
@Override
|
644 |
public DynField setMinValue(Object minValue) { |
645 |
try {
|
646 |
this.maxValue = this.coerce(minValue); |
647 |
} catch (CoercionException e) {
|
648 |
throw new IllegalArgumentException(e); |
649 |
} |
650 |
return this; |
651 |
} |
652 |
|
653 |
@Override
|
654 |
public DynField setPersistent(boolean persistent) { |
655 |
throw new UnsupportedOperationException(); |
656 |
} |
657 |
|
658 |
@Override
|
659 |
public DynField setTheTypeOfAvailableValues(int type) { |
660 |
throw new UnsupportedOperationException(); |
661 |
} |
662 |
|
663 |
@Override
|
664 |
public DynField setType(int type) { |
665 |
throw new UnsupportedOperationException(); |
666 |
} |
667 |
|
668 |
@Override
|
669 |
public DynField setDefaultDynValue(Object defaultValue) { |
670 |
throw new UnsupportedOperationException(); |
671 |
} |
672 |
|
673 |
@Override
|
674 |
public Class getClassOfValue() { |
675 |
return null; |
676 |
} |
677 |
|
678 |
@Override
|
679 |
public DynField getElementsType() {
|
680 |
return null; |
681 |
} |
682 |
|
683 |
@Override
|
684 |
public DynField setClassOfValue(Class theClass) |
685 |
throws DynFieldIsNotAContainerException {
|
686 |
throw new UnsupportedOperationException(); |
687 |
} |
688 |
|
689 |
@Override
|
690 |
public DynField setElementsType(DynStruct type)
|
691 |
throws DynFieldIsNotAContainerException {
|
692 |
throw new UnsupportedOperationException(); |
693 |
} |
694 |
|
695 |
@Override
|
696 |
public DynField setElementsType(int type) |
697 |
throws DynFieldIsNotAContainerException {
|
698 |
throw new UnsupportedOperationException(); |
699 |
} |
700 |
|
701 |
@Override
|
702 |
public DynField setSubtype(String subtype) { |
703 |
throw new UnsupportedOperationException(); |
704 |
} |
705 |
|
706 |
@Override
|
707 |
public void validate(Object value) throws DynFieldValidateException { |
708 |
|
709 |
if (value == null && !this.allowNull()) { |
710 |
throw new DynFieldValidateException(value, this, null); |
711 |
} |
712 |
|
713 |
try {
|
714 |
this.dataType.coerce(value);
|
715 |
} catch (CoercionException e) {
|
716 |
throw new DynFieldValidateException(value, this, e); |
717 |
} |
718 |
|
719 |
/*
|
720 |
* Other checks will be needed
|
721 |
*/
|
722 |
} |
723 |
|
724 |
@Override
|
725 |
public String getSubtype() { |
726 |
if (featureAttributeGetter != null) { |
727 |
return featureAttributeGetter.getDataType().getSubtype();
|
728 |
} |
729 |
return this.dataType.getSubtype(); |
730 |
} |
731 |
|
732 |
@Override
|
733 |
public Object coerce(Object value) throws CoercionException { |
734 |
if ( value == null ) { |
735 |
return value; // O debe devolver this.defaultValue |
736 |
} |
737 |
try {
|
738 |
return this.getDataType().coerce(value); |
739 |
} catch(Exception ex){ |
740 |
throw new RuntimeException(ex); |
741 |
} |
742 |
} |
743 |
|
744 |
@Override
|
745 |
public DynField setAvailableValues(List values) { |
746 |
if ( values == null || values.isEmpty() ) { |
747 |
this.availableValues = null; |
748 |
} else {
|
749 |
this.availableValues = (DynObjectValueItem[]) values.toArray( |
750 |
new DynObjectValueItem[values.size()]
|
751 |
); |
752 |
} |
753 |
return this; |
754 |
} |
755 |
|
756 |
@Override
|
757 |
public String getGroup() { |
758 |
return this.groupName; |
759 |
} |
760 |
|
761 |
@Override
|
762 |
public int getOder() { |
763 |
return this.order; |
764 |
} |
765 |
|
766 |
@Override
|
767 |
public String getLabel() { |
768 |
if( this.label == null ) { |
769 |
return this.getName(); |
770 |
} |
771 |
return this.label; |
772 |
} |
773 |
|
774 |
@Override
|
775 |
public DynField setLabel(String label) { |
776 |
this.label = label;
|
777 |
return this; |
778 |
} |
779 |
|
780 |
@Override
|
781 |
public DynField setGroup(String groupName) { |
782 |
this.groupName = groupName;
|
783 |
return this; |
784 |
} |
785 |
|
786 |
@Override
|
787 |
public DynField setOrder(int order) { |
788 |
this.order = order;
|
789 |
return this; |
790 |
} |
791 |
|
792 |
@Override
|
793 |
public DynField setHidden(boolean hidden) { |
794 |
this.hidden = hidden;
|
795 |
return this; |
796 |
} |
797 |
|
798 |
@Override
|
799 |
public boolean isHidden() { |
800 |
return this.hidden; |
801 |
} |
802 |
|
803 |
@Override
|
804 |
public DynField setReadOnly(boolean arg0) { |
805 |
throw new UnsupportedOperationException(); |
806 |
} |
807 |
|
808 |
@Override
|
809 |
public boolean isContainer() { |
810 |
return false; |
811 |
} |
812 |
|
813 |
@Override
|
814 |
public Class getClassOfItems() { |
815 |
return null; |
816 |
} |
817 |
|
818 |
@Override
|
819 |
public DynField setDefaultFieldValue(Object defaultValue) { |
820 |
throw new UnsupportedOperationException(); |
821 |
} |
822 |
|
823 |
@Override
|
824 |
public DynField setClassOfItems(Class theClass) { |
825 |
throw new UnsupportedOperationException(); |
826 |
} |
827 |
|
828 |
@Override
|
829 |
public DynField setType(DataType type) {
|
830 |
throw new UnsupportedOperationException(); |
831 |
} |
832 |
|
833 |
@Override
|
834 |
public boolean isTime() { |
835 |
return isTime;
|
836 |
} |
837 |
|
838 |
@Override
|
839 |
public FeatureAttributeGetter getFeatureAttributeGetter() {
|
840 |
return featureAttributeGetter;
|
841 |
} |
842 |
|
843 |
@Override
|
844 |
public void setFeatureAttributeGetter( |
845 |
FeatureAttributeGetter featureAttributeTransform) { |
846 |
this.featureAttributeGetter = featureAttributeTransform;
|
847 |
} |
848 |
|
849 |
@Override
|
850 |
public FeatureAttributeEmulator getFeatureAttributeEmulator() {
|
851 |
return this.featureAttributeEmulator; |
852 |
} |
853 |
|
854 |
public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
855 |
this.featureAttributeEmulator = featureAttributeEmulator;
|
856 |
return this; |
857 |
} |
858 |
|
859 |
@Override
|
860 |
public boolean isIndexed() { |
861 |
return this.indexed; |
862 |
} |
863 |
|
864 |
@Override
|
865 |
public boolean allowIndexDuplicateds() { |
866 |
return this.allowIndexDuplicateds; |
867 |
} |
868 |
|
869 |
@Override
|
870 |
public boolean isIndexAscending() { |
871 |
return this.isIndexAscending; |
872 |
} |
873 |
|
874 |
@Override
|
875 |
public DynField setClassOfValue(DynStruct dynStrct) {
|
876 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
877 |
} |
878 |
|
879 |
@Override
|
880 |
public DynField setClassOfValue(String theClassNameOfValue) { |
881 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
882 |
} |
883 |
|
884 |
@Override
|
885 |
public String getClassNameOfValue() { |
886 |
return null; |
887 |
} |
888 |
|
889 |
@Override
|
890 |
public DynStruct getDynClassOfValue() {
|
891 |
return null; |
892 |
} |
893 |
|
894 |
@Override
|
895 |
public DynField setTypeOfItems(int type) { |
896 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
897 |
} |
898 |
|
899 |
@Override
|
900 |
public int getTypeOfItems() { |
901 |
return DataTypes.INVALID;
|
902 |
} |
903 |
|
904 |
@Override
|
905 |
public DynField setClassOfItems(DynStruct dynStrct) {
|
906 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
907 |
} |
908 |
|
909 |
@Override
|
910 |
public DynField setClassOfItems(String theClassNameOfValue) { |
911 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
912 |
} |
913 |
|
914 |
@Override
|
915 |
public String getClassNameOfItems() { |
916 |
return null; |
917 |
} |
918 |
|
919 |
@Override
|
920 |
public DynStruct getDynClassOfItems() {
|
921 |
return null; |
922 |
} |
923 |
|
924 |
@Override
|
925 |
public DynField setRelationType(int relationType) { |
926 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
927 |
} |
928 |
|
929 |
@Override
|
930 |
public int getRelationType() { |
931 |
return RELATION_TYPE_NONE;
|
932 |
} |
933 |
|
934 |
@Override
|
935 |
public DynField setAvailableValues(DynMethod availableValuesMethod) {
|
936 |
this.availableValuesMethod = availableValuesMethod;
|
937 |
return this; |
938 |
} |
939 |
|
940 |
@Override
|
941 |
public DynObjectValueItem[] getAvailableValues(DynObject self) { |
942 |
if( this.availableValuesMethod != null ) { |
943 |
DynObjectValueItem[] values;
|
944 |
try {
|
945 |
values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this}); |
946 |
} catch (DynMethodException ex) {
|
947 |
return this.availableValues; |
948 |
} |
949 |
if( values != null ) { |
950 |
return values;
|
951 |
} |
952 |
} |
953 |
return this.availableValues; |
954 |
} |
955 |
|
956 |
@Override
|
957 |
public DynMethod getAvailableValuesMethod() {
|
958 |
return this.availableValuesMethod; |
959 |
} |
960 |
|
961 |
@Override
|
962 |
public boolean isAvailableValuesCalculated() { |
963 |
return this.availableValuesMethod!=null; |
964 |
} |
965 |
|
966 |
@Override
|
967 |
public DynMethod getCalculateMethod() {
|
968 |
return this.calculateMethod; |
969 |
} |
970 |
|
971 |
@Override
|
972 |
public DynField setCalculateMethod(DynMethod method) {
|
973 |
this.calculateMethod = method;
|
974 |
return this; |
975 |
} |
976 |
|
977 |
@Override
|
978 |
public boolean isCalculated() { |
979 |
return this.calculateMethod != null; |
980 |
} |
981 |
|
982 |
@Override
|
983 |
public Object getCalculatedValue(DynObject self) { |
984 |
try {
|
985 |
return this.calculateMethod.invoke(self, new Object[] { this }); |
986 |
} catch (DynMethodException ex) {
|
987 |
throw new RuntimeException(ex); |
988 |
} |
989 |
} |
990 |
|
991 |
@Override
|
992 |
public DynField setValidateElements(boolean validate) { |
993 |
return this; |
994 |
} |
995 |
|
996 |
@Override
|
997 |
public boolean getValidateElements() { |
998 |
return false; |
999 |
} |
1000 |
|
1001 |
private class ConstantValueEvaluator extends AbstractEvaluator { |
1002 |
|
1003 |
@Override
|
1004 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
1005 |
return defaultValue;
|
1006 |
} |
1007 |
|
1008 |
@Override
|
1009 |
public String getName() { |
1010 |
return "Constant attribute " + name; |
1011 |
} |
1012 |
} |
1013 |
|
1014 |
public void setConstantValue(boolean isConstantValue) { |
1015 |
if (isConstantValue) {
|
1016 |
/* Cuando un attributo tiene asociado un evaluador, este se interpreta
|
1017 |
* como que no debe cargarse de la fuente de datos subyacente, siendo
|
1018 |
* el evaluador el que se encarga de proporcionar su valor.
|
1019 |
* Nos limitamos a asignar un evaluador que retorna simpre el valor
|
1020 |
* por defecto para ese attributo.
|
1021 |
*/
|
1022 |
this.evaluator = new ConstantValueEvaluator(); |
1023 |
} else {
|
1024 |
this.evaluator = null; |
1025 |
} |
1026 |
} |
1027 |
|
1028 |
@Override
|
1029 |
public boolean isComputed() { |
1030 |
return featureAttributeEmulator!=null || evaluator!=null; |
1031 |
} |
1032 |
|
1033 |
@Override
|
1034 |
public FeatureStore getStore() {
|
1035 |
FeatureType ftype = this.getFeatureType();
|
1036 |
if( ftype == null ) { |
1037 |
return null; |
1038 |
} |
1039 |
return ftype.getStore();
|
1040 |
} |
1041 |
|
1042 |
@Override
|
1043 |
public FeatureType getFeatureType() {
|
1044 |
if( this.typeRef==null ) { |
1045 |
return null; |
1046 |
} |
1047 |
return (FeatureType) this.typeRef.get(); |
1048 |
} |
1049 |
|
1050 |
public FeatureAttributeDescriptor setInterval(Interval interval) {
|
1051 |
this.interval = interval;
|
1052 |
return this; |
1053 |
} |
1054 |
|
1055 |
public void fixAll() { |
1056 |
switch(this.getType()) { |
1057 |
case DataTypes.INSTANT:
|
1058 |
case DataTypes.INTERVAL:
|
1059 |
case DataTypes.DATE:
|
1060 |
if( this.getInterval()!=null ) { |
1061 |
this.isTime = true; |
1062 |
} |
1063 |
break;
|
1064 |
} |
1065 |
} |
1066 |
|
1067 |
} |