Statistics
| Revision:

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 @ 43362

History | View | Annotate | Download (26.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.text.DateFormat;
26
import java.util.HashMap;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.Map;
30
import java.util.Map.Entry;
31
import org.apache.commons.lang3.ArrayUtils;
32
import org.cresques.cts.IProjection;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
35
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.GeometryException;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.type.GeometryType;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dataTypes.CoercionException;
43
import org.gvsig.tools.dataTypes.DataType;
44
import org.gvsig.tools.dataTypes.DataTypes;
45
import org.gvsig.tools.dynobject.DynField;
46
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
47
import org.gvsig.tools.dynobject.DynField_v2;
48
import org.gvsig.tools.dynobject.DynMethod;
49
import org.gvsig.tools.dynobject.DynObject;
50
import org.gvsig.tools.dynobject.DynObjectValueItem;
51
import org.gvsig.tools.dynobject.DynStruct;
52
import org.gvsig.tools.dynobject.Tags;
53
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
54
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
55
import org.gvsig.tools.dynobject.exception.DynMethodException;
56
import org.gvsig.tools.dynobject.impl.DefaultTags;
57
import org.gvsig.tools.evaluator.AbstractEvaluator;
58
import org.gvsig.tools.evaluator.Evaluator;
59
import org.gvsig.tools.evaluator.EvaluatorData;
60
import org.gvsig.tools.evaluator.EvaluatorException;
61
import org.gvsig.tools.persistence.Persistent;
62
import org.gvsig.tools.persistence.PersistentState;
63
import org.gvsig.tools.persistence.exception.PersistenceException;
64

    
65
public class DefaultFeatureAttributeDescriptor implements
66
        FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute {
67

    
68
    protected boolean allowNull;
69
    protected DataType dataType;
70
    protected DateFormat dateFormat;
71
    protected Object defaultValue;
72
    protected int index;
73
    protected int maximumOccurrences;
74
    protected int minimumOccurrences;
75
    protected int size;
76
    protected String name;
77
    protected Class objectClass;
78
    protected int precision;
79
    protected Evaluator evaluator;
80
    protected boolean primaryKey;
81
    protected boolean readOnly;
82
    protected IProjection SRS;
83
    protected GeometryType geomType;
84
    protected int geometryType;
85
    protected int geometrySubType;
86
    protected Map additionalInfo;
87
    protected boolean isAutomatic;
88
    protected boolean isTime = false;
89
    protected FeatureAttributeGetter featureAttributeGetter = null;
90
    protected FeatureAttributeEmulator featureAttributeEmulator = null;
91
    protected boolean indexed = false;
92
    protected boolean isIndexAscending = true;
93
    protected boolean allowIndexDuplicateds = true;
94

    
95
    protected DynObjectValueItem[] availableValues;
96
    protected String description;
97
    protected Object minValue;
98
    protected Object maxValue;
99
    protected String label;
100
    protected int order;
101
    protected boolean hidden;
102
    protected String groupName;
103
    protected Tags tags = new DefaultTags();
104
    private DynMethod availableValuesMethod;
105
    private DynMethod calculateMethod;
106

    
107
    protected DefaultFeatureAttributeDescriptor() {
108
        this.allowNull = true;
109
        this.dataType = null;
110
        this.dateFormat = null;
111
        this.defaultValue = null;
112
        this.index = -1;
113
        this.maximumOccurrences = 0;
114
        this.minimumOccurrences = 0;
115
        this.size = 0;
116
        this.name = null;
117
        this.objectClass = null;
118
        this.precision = 0;
119
        this.evaluator = null;
120
        this.primaryKey = false;
121
        this.readOnly = false;
122
        this.SRS = null;
123
        this.geometryType = Geometry.TYPES.NULL;
124
        this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
125
        this.additionalInfo = null;
126
        this.isAutomatic = false;
127
        this.hidden = false;
128
    }
129

    
130
    protected DefaultFeatureAttributeDescriptor(
131
            DefaultFeatureAttributeDescriptor other) {
132
        copyFrom(other);
133
    }
134
    
135
    @Override
136
    public void copyFrom(DynField other1) {
137
        if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) {
138
            throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor");
139
        }
140
        DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1;
141
        this.allowNull = other.allowNull;
142
        this.dataType = other.dataType;
143
        this.dateFormat = other.dateFormat;
144
        this.defaultValue = other.defaultValue;
145
        this.index = other.index;
146
        this.maximumOccurrences = other.maximumOccurrences;
147
        this.minimumOccurrences = other.minimumOccurrences;
148
        this.size = other.size;
149
        this.name = other.name;
150
        this.objectClass = other.objectClass;
151
        this.precision = other.precision;
152
        this.evaluator = other.evaluator;
153
        this.primaryKey = other.primaryKey;
154
        this.readOnly = other.readOnly;
155
        this.SRS = other.SRS;
156
        this.geometryType = other.geometryType;
157
        this.geometrySubType = other.geometrySubType;
158
        this.geomType = other.geomType;
159
        if (other.additionalInfo != null) {
160
            Iterator iter = other.additionalInfo.entrySet().iterator();
161
            Map.Entry entry;
162
            this.additionalInfo = new HashMap();
163
            while (iter.hasNext()) {
164
                entry = (Entry) iter.next();
165
                this.additionalInfo.put(entry.getKey(), entry.getValue());
166
            }
167
        } else {
168
            this.additionalInfo = null;
169
        }
170
        this.isAutomatic = other.isAutomatic;
171
        this.isTime = other.isTime;
172
        this.featureAttributeEmulator = other.featureAttributeEmulator;
173
        this.indexed = other.indexed;
174
        this.isIndexAscending = other.isIndexAscending;
175
        this.allowIndexDuplicateds = other.allowIndexDuplicateds;
176
        this.hidden = other.hidden;
177
    }
178
    
179
    @Override
180
    public String getDataTypeName() {
181
        if (this.getDataType() == null) {
182
            return "(unknow)";
183
        }
184
        return this.getDataType().getName();
185
    }
186

    
187
    @Override
188
    public FeatureAttributeDescriptor getCopy() {
189
        return new DefaultFeatureAttributeDescriptor(this);
190
    }
191

    
192
    @Override
193
    public Object clone() throws CloneNotSupportedException {
194
        return new DefaultFeatureAttributeDescriptor(this);
195
    }
196
    
197
    @Override
198
    public boolean allowNull() {
199
        return allowNull;
200
    }
201

    
202
    @Override
203
    public DataType getDataType() {
204
        if (featureAttributeGetter != null) {
205
            return featureAttributeGetter.getDataType();
206
        }
207
        return this.dataType;
208
    }
209

    
210
    @Override
211
    public DateFormat getDateFormat() {
212
        return this.dateFormat;
213
    }
214

    
215
    @Override
216
    public Object getDefaultValue() {
217
        return this.defaultValue;
218
    }
219

    
220
    @Override
221
    public Evaluator getEvaluator() {
222
        return this.evaluator;
223
    }
224

    
225
    @Override
226
    public int getGeometryType() {
227
        return this.geometryType;
228
    }
229

    
230
    @Override
231
    public int getGeometrySubType() {
232
        return this.geometrySubType;
233
    }
234

    
235
    @Override
236
    public GeometryType getGeomType() {
237
        if (this.geomType == null) {
238
            try {
239
                this.geomType
240
                        = GeometryLocator.getGeometryManager().getGeometryType(
241
                                this.geometryType, this.geometrySubType);
242
            } catch (GeometryException e) {
243
                throw new RuntimeException(
244
                        "Error getting geometry type with type = "
245
                        + this.geometryType + ", subtype = "
246
                        + this.geometrySubType, e);
247
            }
248
        }
249
        return this.geomType;
250
    }
251

    
252
    @Override
253
    public int getIndex() {
254
        return this.index;
255
    }
256

    
257
    protected FeatureAttributeDescriptor setIndex(int index) {
258
        this.index = index;
259
        return this;
260
    }
261

    
262
    @Override
263
    public int getMaximumOccurrences() {
264
        return this.maximumOccurrences;
265
    }
266

    
267
    @Override
268
    public int getMinimumOccurrences() {
269
        return this.minimumOccurrences;
270
    }
271

    
272
    @Override
273
    public String getName() {
274
        return this.name;
275
    }
276

    
277
    @Override
278
    public Class getObjectClass() {
279
        if (getDataType().getType() == DataTypes.OBJECT) {
280
            return objectClass;
281
        }
282
        return getDataType().getDefaultClass();
283
    }
284

    
285
    @Override
286
    public int getPrecision() {
287
        return this.precision;
288
    }
289

    
290
    @Override
291
    public IProjection getSRS() {
292
        return this.SRS;
293
    }
294

    
295
    @Override
296
    public int getSize() {
297
        return this.size;
298
    }
299

    
300
    @Override
301
    public boolean isPrimaryKey() {
302
        return this.primaryKey;
303
    }
304

    
305
    @Override
306
    public boolean isReadOnly() {
307
        if (this.readOnly) {
308
            return true;
309
        }
310
        if (this.getEvaluator() != null) {
311
            return true;
312
        }
313
        if (this.featureAttributeEmulator != null) {
314
            return !this.featureAttributeEmulator.allowSetting();
315
        }
316
        return false;
317
    }
318

    
319
    @Override
320
    public Object getAdditionalInfo(String infoName) {
321
        if (this.additionalInfo == null) {
322
            return null;
323
        }
324
        return this.additionalInfo.get(infoName);
325
    }
326

    
327
    @Override
328
    public boolean isAutomatic() {
329
        return this.isAutomatic;
330
    }
331

    
332
    private boolean compareObject(Object a, Object b) {
333
        if (a != b) {
334
            if (a == null) {
335
                return false;
336
            }
337
            return a.equals(b);
338
        }
339
        return true;
340

    
341
    }
342

    
343
    @Override
344
    public boolean equals(Object obj) {
345
        if (this == obj) {
346
            return true;
347
        }
348
        if (!(obj instanceof DefaultFeatureAttributeDescriptor)) {
349
            return false;
350
        }
351
        DefaultFeatureAttributeDescriptor other
352
                = (DefaultFeatureAttributeDescriptor) obj;
353

    
354
        if (this.allowNull != other.allowNull) {
355
            return false;
356
        }
357

    
358
        if (this.index != other.index) {
359
            return false;
360
        }
361

    
362
        if (!compareObject(this.name, other.name)) {
363
            return false;
364
        }
365

    
366
        if (this.getDataType() != other.getDataType()) {
367
            return false;
368
        }
369

    
370
        if (this.size != other.size) {
371
            return false;
372
        }
373

    
374
        if (!compareObject(this.defaultValue, other.defaultValue)) {
375
            return false;
376
        }
377

    
378
        if (!compareObject(this.defaultValue, other.defaultValue)) {
379
            return false;
380
        }
381

    
382
        if (this.primaryKey != other.primaryKey) {
383
            return false;
384
        }
385

    
386
        if (this.isAutomatic != other.isAutomatic) {
387
            return false;
388
        }
389

    
390
        if (this.readOnly != other.readOnly) {
391
            return false;
392
        }
393

    
394
        if (this.precision != other.precision) {
395
            return false;
396
        }
397

    
398
        if (this.maximumOccurrences != other.maximumOccurrences) {
399
            return false;
400
        }
401

    
402
        if (this.minimumOccurrences != other.minimumOccurrences) {
403
            return false;
404
        }
405

    
406
        if (this.geometryType != other.geometryType) {
407
            return false;
408
        }
409

    
410
        if (this.geometrySubType != other.geometrySubType) {
411
            return false;
412
        }
413

    
414
        if (!compareObject(this.evaluator, other.evaluator)) {
415
            return false;
416
        }
417

    
418
        if (!compareObject(this.SRS, other.SRS)) {
419
            return false;
420
        }
421

    
422
        if (!compareObject(this.dateFormat, other.dateFormat)) {
423
            return false;
424
        }
425

    
426
        if (!compareObject(this.objectClass, other.objectClass)) {
427
            return false;
428
        }
429

    
430
        return true;
431
    }
432

    
433
    @Override
434
    public void loadFromState(PersistentState state)
435
            throws PersistenceException {
436
        allowNull = state.getBoolean("allowNull");
437
        dataType
438
                = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
439
        // FIXME how persist dateFormat ???
440
        // dateFormat;
441
        defaultValue = state.get("defaultValue");
442

    
443
        index = state.getInt("index");
444
        maximumOccurrences = state.getInt("maximumOccurrences");
445
        minimumOccurrences = state.getInt("minimumOccurrences");
446
        size = state.getInt("size");
447
        name = state.getString("name");
448
        try {
449
            objectClass = Class.forName(state.getString("objectClass"));
450
        } catch (ClassNotFoundException e) {
451
            throw new PersistenceException(e);
452
        }
453
        precision = state.getInt("precision");
454
        evaluator = (Evaluator) state.get("evaluator");
455
        primaryKey = state.getBoolean("primaryKey");
456
        readOnly = state.getBoolean("readOnly");
457
        String srsId = state.getString("srsId");
458
        if (srsId != null) {
459
            SRS = CRSFactory.getCRS(srsId);
460
        }
461
        geometryType = state.getInt("geometryType");
462
        geometrySubType = state.getInt("geometrySubType");
463
        additionalInfo = (Map) state.get("aditionalInfo");
464
        isAutomatic = state.getBoolean("isAutomatic");
465
    }
466

    
467
    @Override
468
    public void saveToState(PersistentState state) throws PersistenceException {
469
        state.set("allowNull", allowNull);
470
        state.set("dataType", dataType);
471
        // FIXME how persist dateFormat ???
472
        // dateFormat;
473

    
474
        defaultValue = state.get("defaultValue");
475

    
476
        index = state.getInt("index");
477
        maximumOccurrences = state.getInt("maximumOccurrences");
478
        minimumOccurrences = state.getInt("minimumOccurrences");
479
        size = state.getInt("size");
480
        name = state.getString("name");
481
        try {
482
            objectClass = Class.forName(state.getString("objectClass"));
483
        } catch (ClassNotFoundException e) {
484
            throw new PersistenceException(e);
485
        }
486
        precision = state.getInt("precision");
487
        evaluator = (Evaluator) state.get("evaluator");
488
        primaryKey = state.getBoolean("primaryKey");
489
        readOnly = state.getBoolean("readOnly");
490
        String srsId = state.getString("srsId");
491
        if (srsId != null) {
492
            SRS = CRSFactory.getCRS(srsId);
493
        }
494
        geometryType = state.getInt("geometryType");
495
        geometrySubType = state.getInt("geometrySubType");
496
        additionalInfo = (Map) state.get("aditionalInfo");
497
        isAutomatic = state.getBoolean("isAutomatic");
498
    }
499

    
500
    /*
501
     * Start of DynField interface Implementation
502
     *
503
     */
504

    
505
    public Tags getTags() {
506
        return tags;
507
    }
508

    
509
    @Override
510
    public DynObjectValueItem[] getAvailableValues() {
511
        return this.availableValues;
512
    }
513

    
514
    @Override
515
    public String getDescription() {
516
        if( this.description == null ) {
517
            return getName();
518
        }
519
        return this.description;
520
    }
521

    
522
    @Override
523
    public Object getMaxValue() {
524
        return this.maxValue;
525
    }
526

    
527
    @Override
528
    public Object getMinValue() {
529
        return this.minValue;
530
    }
531

    
532
    @Override
533
    public int getTheTypeOfAvailableValues() {
534
        return 1;
535
    }
536

    
537
    @Override
538
    public int getType() {
539
        if (featureAttributeGetter != null) {
540
            return featureAttributeGetter.getDataType().getType();
541
        }
542
        return getDataType().getType();
543
    }
544

    
545
    @Override
546
    public boolean isMandatory() {
547
        return !allowNull() || isPrimaryKey();
548
    }
549

    
550
    @Override
551
    public boolean isPersistent() {
552
        return false;
553
    }
554

    
555
    @Override
556
    public DynField setAvailableValues(DynObjectValueItem[] values) {
557
        if ( ArrayUtils.isEmpty(values) ) {
558
            this.availableValues = null;
559
        } else {
560
            this.availableValues = values;
561
        }
562
        return this;
563
    }
564

    
565
    @Override
566
    public DynField setDescription(String description) {
567
        this.description = description;
568
        return this;
569
    }
570

    
571
    @Override
572
    public DynField setMandatory(boolean mandatory) {
573
        throw new UnsupportedOperationException();
574
    }
575

    
576
    @Override
577
    public DynField setMaxValue(Object maxValue) {
578
        try {
579
            this.maxValue = this.coerce(maxValue);
580
        } catch (CoercionException e) {
581
            throw new IllegalArgumentException(e);
582
        }
583
        return this;
584
    }
585

    
586
    @Override
587
    public DynField setMinValue(Object minValue) {
588
        try {
589
            this.maxValue = this.coerce(minValue);
590
        } catch (CoercionException e) {
591
            throw new IllegalArgumentException(e);
592
        }
593
        return this;
594
    }
595

    
596
    @Override
597
    public DynField setPersistent(boolean persistent) {
598
        throw new UnsupportedOperationException();
599
    }
600

    
601
    @Override
602
    public DynField setTheTypeOfAvailableValues(int type) {
603
        throw new UnsupportedOperationException();
604
    }
605

    
606
    @Override
607
    public DynField setType(int type) {
608
        throw new UnsupportedOperationException();
609
    }
610

    
611
    @Override
612
    public DynField setDefaultDynValue(Object defaultValue) {
613
        throw new UnsupportedOperationException();
614
    }
615

    
616
    @Override
617
    public Class getClassOfValue() {
618
        return null;
619
    }
620

    
621
    @Override
622
    public DynField getElementsType() {
623
        return null;
624
    }
625

    
626
    @Override
627
    public DynField setClassOfValue(Class theClass)
628
            throws DynFieldIsNotAContainerException {
629
        throw new UnsupportedOperationException();
630
    }
631

    
632
    @Override
633
    public DynField setElementsType(DynStruct type)
634
            throws DynFieldIsNotAContainerException {
635
        throw new UnsupportedOperationException();
636
    }
637

    
638
    @Override
639
    public DynField setElementsType(int type)
640
            throws DynFieldIsNotAContainerException {
641
        throw new UnsupportedOperationException();
642
    }
643

    
644
    @Override
645
    public DynField setSubtype(String subtype) {
646
        throw new UnsupportedOperationException();
647
    }
648

    
649
    @Override
650
    public void validate(Object value) throws DynFieldValidateException {
651

    
652
        if (value == null && !this.allowNull()) {
653
            throw new DynFieldValidateException(value, this, null);
654
        }
655

    
656
        try {
657
            this.dataType.coerce(value);
658
        } catch (CoercionException e) {
659
            throw new DynFieldValidateException(value, this, e);
660
        }
661

    
662
        /*
663
         * Other checks will be needed
664
         */
665
    }
666

    
667
    @Override
668
    public String getSubtype() {
669
        if (featureAttributeGetter != null) {
670
            return featureAttributeGetter.getDataType().getSubtype();
671
        }
672
        return this.dataType.getSubtype();
673
    }
674

    
675
    @Override
676
    public Object coerce(Object value) throws CoercionException {
677
        if ( value == null ) {
678
            return value; // O debe devolver this.defaultValue
679
        }
680
        try {
681
            return this.getDataType().coerce(value);
682
        } catch(Exception ex){
683
            throw new RuntimeException(ex);
684
        }
685
    }
686

    
687
    @Override
688
    public DynField setAvailableValues(List values) {
689
        if (  values == null || values.isEmpty() ) {
690
            this.availableValues = null;
691
        } else {
692
            this.availableValues = (DynObjectValueItem[]) values.toArray(
693
                new DynObjectValueItem[values.size()]
694
            );
695
        }
696
        return this;
697
    }
698

    
699
    @Override
700
    public String getGroup() {
701
        return this.groupName;
702
    }
703

    
704
    @Override
705
    public int getOder() {
706
        return this.order;
707
    }
708

    
709
    @Override
710
    public String getLabel() {
711
        if( this.label == null ) {
712
            return this.getName();
713
        }
714
        return this.label;
715
    }
716

    
717
    @Override
718
    public DynField setLabel(String label) {
719
        this.label = label;
720
        return this;
721
    }
722

    
723
    @Override
724
    public DynField setGroup(String groupName) {
725
        this.groupName = groupName;
726
        return this;
727
    }
728

    
729
    @Override
730
    public DynField setOrder(int order) {
731
        this.order = order;
732
        return this;
733
    }
734

    
735
    @Override
736
    public DynField setHidden(boolean hidden) {
737
        this.hidden = hidden;
738
        return this;
739
    }
740

    
741
    @Override
742
    public boolean isHidden() {
743
        return this.hidden;
744
    }
745

    
746
    @Override
747
    public DynField setReadOnly(boolean arg0) {
748
        throw new UnsupportedOperationException();
749
    }
750

    
751
    @Override
752
    public boolean isContainer() {
753
        return false;
754
    }
755

    
756
    @Override
757
    public Class getClassOfItems() {
758
        return null;
759
    }
760

    
761
    @Override
762
    public DynField setDefaultFieldValue(Object defaultValue) {
763
        throw new UnsupportedOperationException();
764
    }
765

    
766
    @Override
767
    public DynField setClassOfItems(Class theClass) {
768
        throw new UnsupportedOperationException();
769
    }
770

    
771
    @Override
772
    public DynField setType(DataType type) {
773
        throw new UnsupportedOperationException();
774
    }
775

    
776
    @Override
777
    public boolean isTime() {
778
        return isTime;
779
    }
780

    
781
    @Override
782
    public FeatureAttributeGetter getFeatureAttributeGetter() {
783
        return featureAttributeGetter;
784
    }
785

    
786
    @Override
787
    public void setFeatureAttributeGetter(
788
            FeatureAttributeGetter featureAttributeTransform) {
789
        this.featureAttributeGetter = featureAttributeTransform;
790
    }
791

    
792
    @Override
793
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
794
        return this.featureAttributeEmulator;
795
    }
796

    
797
    @Override
798
    public boolean isIndexed() {
799
        return this.indexed;
800
    }
801

    
802
    @Override
803
    public boolean allowIndexDuplicateds() {
804
        return this.allowIndexDuplicateds;
805
    }
806

    
807
    @Override
808
    public boolean isIndexAscending() {
809
        return this.isIndexAscending;
810
    }
811

    
812
    @Override
813
    public DynField setClassOfValue(DynStruct dynStrct) {
814
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
815
    }
816

    
817
    @Override
818
    public DynField setClassOfValue(String theClassNameOfValue) {
819
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
820
    }
821

    
822
    @Override
823
    public String getClassNameOfValue() {
824
        return null;
825
    }
826

    
827
    @Override
828
    public DynStruct getDynClassOfValue() {
829
        return null;
830
    }
831

    
832
    @Override
833
    public DynField setTypeOfItems(int type) {
834
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
835
    }
836

    
837
    @Override
838
    public int getTypeOfItems() {
839
        return DataTypes.INVALID;
840
    }
841

    
842
    @Override
843
    public DynField setClassOfItems(DynStruct dynStrct) {
844
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
845
    }
846

    
847
    @Override
848
    public DynField setClassOfItems(String theClassNameOfValue) {
849
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
850
    }
851

    
852
    @Override
853
    public String getClassNameOfItems() {
854
        return null;
855
    }
856

    
857
    @Override
858
    public DynStruct getDynClassOfItems() {
859
        return null;
860
    }
861

    
862
    @Override
863
    public DynField setRelationType(int relationType) {
864
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
865
    }
866

    
867
    @Override
868
    public int getRelationType() {
869
        return RELATION_TYPE_NONE;
870
    }
871

    
872
    @Override
873
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
874
        this.availableValuesMethod = availableValuesMethod;
875
        return this;
876
    }
877

    
878
    @Override
879
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
880
        if( this.availableValuesMethod != null ) {
881
            DynObjectValueItem[] values;
882
            try {
883
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
884
            } catch (DynMethodException ex) {
885
                return this.availableValues;
886
            }
887
            if( values != null ) {
888
                return values;
889
            }
890
        }
891
        return this.availableValues;
892
    }
893

    
894
    @Override
895
    public DynMethod getAvailableValuesMethod() {
896
        return this.availableValuesMethod;
897
    }
898

    
899
    @Override
900
    public boolean isAvailableValuesCalculated() {
901
        return this.availableValuesMethod!=null;
902
    }
903

    
904
    @Override
905
    public DynMethod getCalculateMethod() {
906
        return this.calculateMethod;
907
    }
908

    
909
    @Override
910
    public DynField setCalculateMethod(DynMethod method) {
911
        this.calculateMethod = method;
912
        return this;
913
    }
914
    
915
    @Override
916
    public boolean isCalculated() {
917
        return this.calculateMethod != null;
918
    }
919
    
920
    @Override
921
    public Object getCalculatedValue(DynObject self) {
922
        try {
923
            return this.calculateMethod.invoke(self, new Object[] { this });
924
        } catch (DynMethodException ex) {
925
            throw new RuntimeException(ex);
926
        }
927
    }
928

    
929
    @Override
930
    public DynField setValidateElements(boolean validate) {
931
        return this;
932
    }
933

    
934
    @Override
935
    public boolean getValidateElements() {
936
        return false;
937
    }
938

    
939
    private class ConstantValueEvaluator extends AbstractEvaluator {
940

    
941
        @Override
942
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
943
            return defaultValue;
944
        }
945

    
946
        @Override
947
        public String getName() {
948
            return "Constant attribute " + name;
949
        }
950
    }
951

    
952
    public void setConstantValue(boolean isConstantValue) {
953
        if (isConstantValue) {
954
            /* Cuando un attributo tiene asociado un evaluador, este se interpreta
955
             * como que no debe cargarse de la fuente de datos subyacente, siendo
956
             * el evaluador el que se encarga de proporcionar su valor.
957
             * Nos limitamos a asignar un evaluador que retorna simpre el valor
958
             * por defecto para ese attributo.
959
             */
960
            this.evaluator = new ConstantValueEvaluator();
961
        } else {
962
            this.evaluator = null;
963
        }
964
    }
965

    
966
    public boolean isComputed() {
967
        return featureAttributeEmulator!=null || evaluator!=null;
968
    }
969
}