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