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

History | View | Annotate | Download (26.6 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
    }
128

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
339
    }
340

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
428
        return true;
429
    }
430

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

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

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

    
472
        defaultValue = state.get("defaultValue");
473

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

    
498
    /*
499
     * Start of DynField interface Implementation
500
     *
501
     */
502

    
503
    public Tags getTags() {
504
        return tags;
505
    }
506

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

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

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

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

    
530
    @Override
531
    public int getTheTypeOfAvailableValues() {
532
        return 1;
533
    }
534

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

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

    
548
    @Override
549
    public boolean isPersistent() {
550
        return false;
551
    }
552

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

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

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

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

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

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

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

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

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

    
614
    @Override
615
    public Class getClassOfValue() {
616
        return null;
617
    }
618

    
619
    @Override
620
    public DynField getElementsType() {
621
        return null;
622
    }
623

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

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

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

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

    
647
    @Override
648
    public void validate(Object value) throws DynFieldValidateException {
649

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

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

    
660
        /*
661
         * Other checks will be needed
662
         */
663
    }
664

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

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

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

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

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

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

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

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

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

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

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

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

    
749
    @Override
750
    public boolean isContainer() {
751
        return false;
752
    }
753

    
754
    @Override
755
    public Class getClassOfItems() {
756
        return null;
757
    }
758

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

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

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

    
774
    @Override
775
    public boolean isTime() {
776
        return isTime;
777
    }
778

    
779
    @Override
780
    public FeatureAttributeGetter getFeatureAttributeGetter() {
781
        return featureAttributeGetter;
782
    }
783

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

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

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

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

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

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

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

    
820
    @Override
821
    public String getClassNameOfValue() {
822
        return null;
823
    }
824

    
825
    @Override
826
    public DynStruct getDynClassOfValue() {
827
        return null;
828
    }
829

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

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

    
840
    @Override
841
    public DynField setClassOfItems(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 setClassOfItems(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 getClassNameOfItems() {
852
        return null;
853
    }
854

    
855
    @Override
856
    public DynStruct getDynClassOfItems() {
857
        return null;
858
    }
859

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

    
865
    @Override
866
    public int getRelationType() {
867
        return RELATION_TYPE_NONE;
868
    }
869

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

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

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

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

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

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

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

    
932
    @Override
933
    public boolean getValidateElements() {
934
        return false;
935
    }
936

    
937
    private class ConstantValueEvaluator extends AbstractEvaluator {
938

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

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

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

    
964
}