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