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

History | View | Annotate | Download (28.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.feature.impl;
24

    
25
import java.lang.ref.WeakReference;
26
import java.text.DateFormat;
27
import java.util.HashMap;
28
import java.util.Iterator;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.Map.Entry;
32
import org.apache.commons.lang3.ArrayUtils;
33
import org.cresques.cts.IProjection;
34
import org.gvsig.fmap.crs.CRSFactory;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
38
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.dal.feature.FeatureType;
41
import org.gvsig.fmap.geom.Geometry;
42
import org.gvsig.fmap.geom.GeometryException;
43
import org.gvsig.fmap.geom.GeometryLocator;
44
import org.gvsig.fmap.geom.type.GeometryType;
45
import org.gvsig.timesupport.Interval;
46
import org.gvsig.timesupport.TimeSupportLocator;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dataTypes.CoercionException;
49
import org.gvsig.tools.dataTypes.DataType;
50
import org.gvsig.tools.dataTypes.DataTypes;
51
import org.gvsig.tools.dynobject.DynField;
52
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
53
import org.gvsig.tools.dynobject.DynField_v2;
54
import org.gvsig.tools.dynobject.DynMethod;
55
import org.gvsig.tools.dynobject.DynObject;
56
import org.gvsig.tools.dynobject.DynObjectValueItem;
57
import org.gvsig.tools.dynobject.DynStruct;
58
import org.gvsig.tools.dynobject.Tags;
59
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
60
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
61
import org.gvsig.tools.dynobject.exception.DynMethodException;
62
import org.gvsig.tools.dynobject.impl.DefaultTags;
63
import org.gvsig.tools.evaluator.AbstractEvaluator;
64
import org.gvsig.tools.evaluator.Evaluator;
65
import org.gvsig.tools.evaluator.EvaluatorData;
66
import org.gvsig.tools.evaluator.EvaluatorException;
67
import org.gvsig.tools.persistence.Persistent;
68
import org.gvsig.tools.persistence.PersistentState;
69
import org.gvsig.tools.persistence.exception.PersistenceException;
70

    
71
public class DefaultFeatureAttributeDescriptor implements
72
        FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute {
73

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

    
102
    protected DynObjectValueItem[] availableValues;
103
    protected String description;
104
    protected Object minValue;
105
    protected Object maxValue;
106
    protected String label;
107
    protected int order;
108
    protected boolean hidden;
109
    protected String groupName;
110
    protected Tags tags = new DefaultTags();
111
    private DynMethod availableValuesMethod;
112
    private DynMethod calculateMethod;
113
    private WeakReference typeRef;
114

    
115
    protected DefaultFeatureAttributeDescriptor(FeatureType type) {
116
        if( type == null ) {
117
            this.typeRef = null;
118
        } else {
119
            this.typeRef = new WeakReference(type);
120
        }
121
        this.allowNull = true;
122
        this.dataType = null;
123
        this.dateFormat = null;
124
        this.defaultValue = null;
125
        this.index = -1;
126
        this.maximumOccurrences = 0;
127
        this.minimumOccurrences = 0;
128
        this.size = 0;
129
        this.name = null;
130
        this.objectClass = null;
131
        this.precision = 0;
132
        this.evaluator = null;
133
        this.primaryKey = false;
134
        this.readOnly = false;
135
        this.SRS = null;
136
        this.geometryType = Geometry.TYPES.NULL;
137
        this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
138
        this.additionalInfo = null;
139
        this.isAutomatic = false;
140
        this.hidden = false;
141
    }
142

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

    
202
    @Override
203
    public FeatureAttributeDescriptor getCopy() {
204
        return new DefaultFeatureAttributeDescriptor(this);
205
    }
206

    
207
    @Override
208
    public Object clone() throws CloneNotSupportedException {
209
        return new DefaultFeatureAttributeDescriptor(this);
210
    }
211
    
212
    @Override
213
    public boolean allowNull() {
214
        return allowNull;
215
    }
216

    
217
    @Override
218
    public DataType getDataType() {
219
        if (featureAttributeGetter != null) {
220
            return featureAttributeGetter.getDataType();
221
        }
222
        return this.dataType;
223
    }
224

    
225
    public FeatureAttributeDescriptor setDataType(int type) {
226
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
227
        return this;
228
    }
229

    
230
    @Override
231
    public DateFormat getDateFormat() {
232
        return this.dateFormat;
233
    }
234

    
235
    @Override
236
    public Object getDefaultValue() {
237
        return this.defaultValue;
238
    }
239

    
240
    @Override
241
    public Evaluator getEvaluator() {
242
        return this.evaluator;
243
    }
244

    
245
    @Override
246
    public int getGeometryType() {
247
        return this.geometryType;
248
    }
249

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

    
255
    @Override
256
    public GeometryType getGeomType() {
257
        if (this.geomType == null) {
258
            try {
259
                this.geomType
260
                        = GeometryLocator.getGeometryManager().getGeometryType(
261
                                this.geometryType, this.geometrySubType);
262
            } catch (GeometryException e) {
263
                throw new RuntimeException(
264
                        "Error getting geometry type with type = "
265
                        + this.geometryType + ", subtype = "
266
                        + this.geometrySubType, e);
267
            }
268
        }
269
        return this.geomType;
270
    }
271

    
272
    @Override
273
    public int getIndex() {
274
        return this.index;
275
    }
276

    
277
    protected FeatureAttributeDescriptor setIndex(int index) {
278
        this.index = index;
279
        return this;
280
    }
281

    
282
    @Override
283
    public int getMaximumOccurrences() {
284
        return this.maximumOccurrences;
285
    }
286

    
287
    @Override
288
    public int getMinimumOccurrences() {
289
        return this.minimumOccurrences;
290
    }
291

    
292
    @Override
293
    public String getName() {
294
        return this.name;
295
    }
296
    
297
    public FeatureAttributeDescriptor setName(String name) {
298
        this.name = name;
299
        return this;
300
    }
301
    
302
    @Override
303
    public Class getObjectClass() {
304
        if (getDataType().getType() == DataTypes.OBJECT) {
305
            return objectClass;
306
        }
307
        return getDataType().getDefaultClass();
308
    }
309

    
310
    @Override
311
    public int getPrecision() {
312
        return this.precision;
313
    }
314

    
315
    @Override
316
    public IProjection getSRS() {
317
        return this.SRS;
318
    }
319

    
320
    @Override
321
    public Interval getInterval() {
322
        return this.interval;
323
    }
324

    
325
    public IProjection getSRS(WeakReference storeRef) {
326
        if( this.SRS==null ) {
327
            FeatureStore store = (FeatureStore) storeRef.get();
328
            this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
329
        }
330
        return this.SRS;
331
    }
332

    
333

    
334
    @Override
335
    public int getSize() {
336
        return this.size;
337
    }
338

    
339
    @Override
340
    public boolean isPrimaryKey() {
341
        return this.primaryKey;
342
    }
343

    
344
    @Override
345
    public boolean isReadOnly() {
346
        if (this.readOnly) {
347
            return true;
348
        }
349
        if (this.getEvaluator() != null) {
350
            return true;
351
        }
352
        if (this.featureAttributeEmulator != null) {
353
            return !this.featureAttributeEmulator.allowSetting();
354
        }
355
        return false;
356
    }
357

    
358
    @Override
359
    public Object getAdditionalInfo(String infoName) {
360
        if (this.additionalInfo == null) {
361
            return null;
362
        }
363
        return this.additionalInfo.get(infoName);
364
    }
365

    
366
    @Override
367
    public boolean isAutomatic() {
368
        return this.isAutomatic;
369
    }
370

    
371
    private boolean compareObject(Object a, Object b) {
372
        if (a != b) {
373
            if (a == null) {
374
                return false;
375
            }
376
            return a.equals(b);
377
        }
378
        return true;
379

    
380
    }
381

    
382
    @Override
383
    public boolean equals(Object obj) {
384
        if (this == obj) {
385
            return true;
386
        }
387
        if (!(obj instanceof DefaultFeatureAttributeDescriptor)) {
388
            return false;
389
        }
390
        DefaultFeatureAttributeDescriptor other
391
                = (DefaultFeatureAttributeDescriptor) obj;
392

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

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

    
401
        if (!compareObject(this.name, other.name)) {
402
            return false;
403
        }
404

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

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

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

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

    
421
        if (this.primaryKey != other.primaryKey) {
422
            return false;
423
        }
424

    
425
        if (this.isAutomatic != other.isAutomatic) {
426
            return false;
427
        }
428

    
429
        if (this.readOnly != other.readOnly) {
430
            return false;
431
        }
432

    
433
        if (this.precision != other.precision) {
434
            return false;
435
        }
436

    
437
        if (this.maximumOccurrences != other.maximumOccurrences) {
438
            return false;
439
        }
440

    
441
        if (this.minimumOccurrences != other.minimumOccurrences) {
442
            return false;
443
        }
444

    
445
        if (this.geometryType != other.geometryType) {
446
            return false;
447
        }
448

    
449
        if (this.geometrySubType != other.geometrySubType) {
450
            return false;
451
        }
452

    
453
        if (!compareObject(this.evaluator, other.evaluator)) {
454
            return false;
455
        }
456

    
457
        if (!compareObject(this.SRS, other.SRS)) {
458
            return false;
459
        }
460

    
461
        if (!compareObject(this.dateFormat, other.dateFormat)) {
462
            return false;
463
        }
464

    
465
        if (!compareObject(this.objectClass, other.objectClass)) {
466
            return false;
467
        }
468

    
469
        return true;
470
    }
471

    
472
    @Override
473
    public void loadFromState(PersistentState state)
474
            throws PersistenceException {
475
        allowNull = state.getBoolean("allowNull");
476
        dataType = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
477
        // FIXME how persist dateFormat ???
478
        // dateFormat;
479
        defaultValue = state.get("defaultValue");
480

    
481
        index = state.getInt("index");
482
        maximumOccurrences = state.getInt("maximumOccurrences");
483
        minimumOccurrences = state.getInt("minimumOccurrences");
484
        size = state.getInt("size");
485
        name = state.getString("name");
486
        try {
487
            objectClass = Class.forName(state.getString("objectClass"));
488
        } catch (ClassNotFoundException e) {
489
            throw new PersistenceException(e);
490
        }
491
        precision = state.getInt("precision");
492
        evaluator = (Evaluator) state.get("evaluator");
493
        primaryKey = state.getBoolean("primaryKey");
494
        readOnly = state.getBoolean("readOnly");
495
        String srsId = state.getString("srsId");
496
        if (srsId != null) {
497
            SRS = CRSFactory.getCRS(srsId);
498
        }
499
        geometryType = state.getInt("geometryType");
500
        geometrySubType = state.getInt("geometrySubType");
501
        additionalInfo = (Map) state.get("aditionalInfo");
502
        isAutomatic = state.getBoolean("isAutomatic");
503
        isTime = state.getBoolean("isTime");
504
        if( state.hasValue("intervalStart") ) {
505
            long intervalStart = state.getLong("intervalStart");
506
            long intervalEnd = state.getLong("intervalEnd");
507
            interval = TimeSupportLocator.getManager().createRelativeInterval(intervalStart, intervalEnd);
508
        } else {
509
            interval = null;
510
        }
511
    }
512

    
513
    @Override
514
    public void saveToState(PersistentState state) throws PersistenceException {
515
        state.set("allowNull", allowNull);
516
        state.set("dataType", dataType);
517
        // FIXME how persist dateFormat ???
518
        // dateFormat;
519

    
520
        defaultValue = state.get("defaultValue");
521

    
522
        index = state.getInt("index");
523
        maximumOccurrences = state.getInt("maximumOccurrences");
524
        minimumOccurrences = state.getInt("minimumOccurrences");
525
        size = state.getInt("size");
526
        name = state.getString("name");
527
        try {
528
            objectClass = Class.forName(state.getString("objectClass"));
529
        } catch (ClassNotFoundException e) {
530
            throw new PersistenceException(e);
531
        }
532
        precision = state.getInt("precision");
533
        evaluator = (Evaluator) state.get("evaluator");
534
        primaryKey = state.getBoolean("primaryKey");
535
        readOnly = state.getBoolean("readOnly");
536
        String srsId = state.getString("srsId");
537
        if (srsId != null) {
538
            SRS = CRSFactory.getCRS(srsId);
539
        }
540
        geometryType = state.getInt("geometryType");
541
        geometrySubType = state.getInt("geometrySubType");
542
        additionalInfo = (Map) state.get("aditionalInfo");
543
        isAutomatic = state.getBoolean("isAutomatic");
544
    }
545

    
546
    /*
547
     * Start of DynField interface Implementation
548
     *
549
     */
550

    
551
    @Override
552
    public Tags getTags() {
553
        return tags;
554
    }
555

    
556
    @Override
557
    public DynObjectValueItem[] getAvailableValues() {
558
        return this.availableValues;
559
    }
560

    
561
    @Override
562
    public String getDescription() {
563
        if( this.description == null ) {
564
            return getName();
565
        }
566
        return this.description;
567
    }
568

    
569
    @Override
570
    public Object getMaxValue() {
571
        return this.maxValue;
572
    }
573

    
574
    @Override
575
    public Object getMinValue() {
576
        return this.minValue;
577
    }
578

    
579
    @Override
580
    public int getTheTypeOfAvailableValues() {
581
        return 1;
582
    }
583

    
584
    @Override
585
    public int getType() {
586
        if (featureAttributeGetter != null) {
587
            return featureAttributeGetter.getDataType().getType();
588
        }
589
        return getDataType().getType();
590
    }
591

    
592
    @Override
593
    public boolean isMandatory() {
594
        return !allowNull() || isPrimaryKey();
595
    }
596

    
597
    @Override
598
    public boolean isPersistent() {
599
        return false;
600
    }
601

    
602
    @Override
603
    public DynField setAvailableValues(DynObjectValueItem[] values) {
604
        if ( ArrayUtils.isEmpty(values) ) {
605
            this.availableValues = null;
606
        } else {
607
            this.availableValues = values;
608
        }
609
        return this;
610
    }
611

    
612
    @Override
613
    public DynField setDescription(String description) {
614
        this.description = description;
615
        return this;
616
    }
617

    
618
    @Override
619
    public DynField setMandatory(boolean mandatory) {
620
        throw new UnsupportedOperationException();
621
    }
622

    
623
    @Override
624
    public DynField setMaxValue(Object maxValue) {
625
        try {
626
            this.maxValue = this.coerce(maxValue);
627
        } catch (CoercionException e) {
628
            throw new IllegalArgumentException(e);
629
        }
630
        return this;
631
    }
632

    
633
    @Override
634
    public DynField setMinValue(Object minValue) {
635
        try {
636
            this.maxValue = this.coerce(minValue);
637
        } catch (CoercionException e) {
638
            throw new IllegalArgumentException(e);
639
        }
640
        return this;
641
    }
642

    
643
    @Override
644
    public DynField setPersistent(boolean persistent) {
645
        throw new UnsupportedOperationException();
646
    }
647

    
648
    @Override
649
    public DynField setTheTypeOfAvailableValues(int type) {
650
        throw new UnsupportedOperationException();
651
    }
652

    
653
    @Override
654
    public DynField setType(int type) {
655
        throw new UnsupportedOperationException();
656
    }
657

    
658
    @Override
659
    public DynField setDefaultDynValue(Object defaultValue) {
660
        throw new UnsupportedOperationException();
661
    }
662

    
663
    @Override
664
    public Class getClassOfValue() {
665
        return null;
666
    }
667

    
668
    @Override
669
    public DynField getElementsType() {
670
        return null;
671
    }
672

    
673
    @Override
674
    public DynField setClassOfValue(Class theClass)
675
            throws DynFieldIsNotAContainerException {
676
        throw new UnsupportedOperationException();
677
    }
678

    
679
    @Override
680
    public DynField setElementsType(DynStruct type)
681
            throws DynFieldIsNotAContainerException {
682
        throw new UnsupportedOperationException();
683
    }
684

    
685
    @Override
686
    public DynField setElementsType(int type)
687
            throws DynFieldIsNotAContainerException {
688
        throw new UnsupportedOperationException();
689
    }
690

    
691
    @Override
692
    public DynField setSubtype(String subtype) {
693
        throw new UnsupportedOperationException();
694
    }
695

    
696
    @Override
697
    public void validate(Object value) throws DynFieldValidateException {
698

    
699
        if (value == null && !this.allowNull()) {
700
            throw new DynFieldValidateException(value, this, null);
701
        }
702

    
703
        try {
704
            this.dataType.coerce(value);
705
        } catch (CoercionException e) {
706
            throw new DynFieldValidateException(value, this, e);
707
        }
708

    
709
        /*
710
         * Other checks will be needed
711
         */
712
    }
713

    
714
    @Override
715
    public String getSubtype() {
716
        if (featureAttributeGetter != null) {
717
            return featureAttributeGetter.getDataType().getSubtype();
718
        }
719
        return this.dataType.getSubtype();
720
    }
721

    
722
    @Override
723
    public Object coerce(Object value) throws CoercionException {
724
        if ( value == null ) {
725
            return value; // O debe devolver this.defaultValue
726
        }
727
        try {
728
            return this.getDataType().coerce(value);
729
        } catch(Exception ex){
730
            throw new RuntimeException(ex);
731
        }
732
    }
733

    
734
    @Override
735
    public DynField setAvailableValues(List values) {
736
        if (  values == null || values.isEmpty() ) {
737
            this.availableValues = null;
738
        } else {
739
            this.availableValues = (DynObjectValueItem[]) values.toArray(
740
                new DynObjectValueItem[values.size()]
741
            );
742
        }
743
        return this;
744
    }
745

    
746
    @Override
747
    public String getGroup() {
748
        return this.groupName;
749
    }
750

    
751
    @Override
752
    public int getOder() {
753
        return this.order;
754
    }
755

    
756
    @Override
757
    public String getLabel() {
758
        if( this.label == null ) {
759
            return this.getName();
760
        }
761
        return this.label;
762
    }
763

    
764
    @Override
765
    public DynField setLabel(String label) {
766
        this.label = label;
767
        return this;
768
    }
769

    
770
    @Override
771
    public DynField setGroup(String groupName) {
772
        this.groupName = groupName;
773
        return this;
774
    }
775

    
776
    @Override
777
    public DynField setOrder(int order) {
778
        this.order = order;
779
        return this;
780
    }
781

    
782
    @Override
783
    public DynField setHidden(boolean hidden) {
784
        this.hidden = hidden;
785
        return this;
786
    }
787

    
788
    @Override
789
    public boolean isHidden() {
790
        return this.hidden;
791
    }
792

    
793
    @Override
794
    public DynField setReadOnly(boolean arg0) {
795
        throw new UnsupportedOperationException();
796
    }
797

    
798
    @Override
799
    public boolean isContainer() {
800
        return false;
801
    }
802

    
803
    @Override
804
    public Class getClassOfItems() {
805
        return null;
806
    }
807

    
808
    @Override
809
    public DynField setDefaultFieldValue(Object defaultValue) {
810
        throw new UnsupportedOperationException();
811
    }
812

    
813
    @Override
814
    public DynField setClassOfItems(Class theClass) {
815
        throw new UnsupportedOperationException();
816
    }
817

    
818
    @Override
819
    public DynField setType(DataType type) {
820
        throw new UnsupportedOperationException();
821
    }
822

    
823
    @Override
824
    public boolean isTime() {
825
        return isTime;
826
    }
827

    
828
    @Override
829
    public FeatureAttributeGetter getFeatureAttributeGetter() {
830
        return featureAttributeGetter;
831
    }
832

    
833
    @Override
834
    public void setFeatureAttributeGetter(
835
            FeatureAttributeGetter featureAttributeTransform) {
836
        this.featureAttributeGetter = featureAttributeTransform;
837
    }
838

    
839
    @Override
840
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
841
        return this.featureAttributeEmulator;
842
    }
843

    
844
    public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
845
        this.featureAttributeEmulator = featureAttributeEmulator;
846
        return this;
847
    }
848
        
849
    @Override
850
    public boolean isIndexed() {
851
        return this.indexed;
852
    }
853

    
854
    @Override
855
    public boolean allowIndexDuplicateds() {
856
        return this.allowIndexDuplicateds;
857
    }
858

    
859
    @Override
860
    public boolean isIndexAscending() {
861
        return this.isIndexAscending;
862
    }
863

    
864
    @Override
865
    public DynField setClassOfValue(DynStruct dynStrct) {
866
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
867
    }
868

    
869
    @Override
870
    public DynField setClassOfValue(String theClassNameOfValue) {
871
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
872
    }
873

    
874
    @Override
875
    public String getClassNameOfValue() {
876
        return null;
877
    }
878

    
879
    @Override
880
    public DynStruct getDynClassOfValue() {
881
        return null;
882
    }
883

    
884
    @Override
885
    public DynField setTypeOfItems(int type) {
886
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
887
    }
888

    
889
    @Override
890
    public int getTypeOfItems() {
891
        return DataTypes.INVALID;
892
    }
893

    
894
    @Override
895
    public DynField setClassOfItems(DynStruct dynStrct) {
896
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
897
    }
898

    
899
    @Override
900
    public DynField setClassOfItems(String theClassNameOfValue) {
901
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
902
    }
903

    
904
    @Override
905
    public String getClassNameOfItems() {
906
        return null;
907
    }
908

    
909
    @Override
910
    public DynStruct getDynClassOfItems() {
911
        return null;
912
    }
913

    
914
    @Override
915
    public DynField setRelationType(int relationType) {
916
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
917
    }
918

    
919
    @Override
920
    public int getRelationType() {
921
        return RELATION_TYPE_NONE;
922
    }
923

    
924
    @Override
925
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
926
        this.availableValuesMethod = availableValuesMethod;
927
        return this;
928
    }
929

    
930
    @Override
931
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
932
        if( this.availableValuesMethod != null ) {
933
            DynObjectValueItem[] values;
934
            try {
935
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
936
            } catch (DynMethodException ex) {
937
                return this.availableValues;
938
            }
939
            if( values != null ) {
940
                return values;
941
            }
942
        }
943
        return this.availableValues;
944
    }
945

    
946
    @Override
947
    public DynMethod getAvailableValuesMethod() {
948
        return this.availableValuesMethod;
949
    }
950

    
951
    @Override
952
    public boolean isAvailableValuesCalculated() {
953
        return this.availableValuesMethod!=null;
954
    }
955

    
956
    @Override
957
    public DynMethod getCalculateMethod() {
958
        return this.calculateMethod;
959
    }
960

    
961
    @Override
962
    public DynField setCalculateMethod(DynMethod method) {
963
        this.calculateMethod = method;
964
        return this;
965
    }
966
    
967
    @Override
968
    public boolean isCalculated() {
969
        return this.calculateMethod != null;
970
    }
971
    
972
    @Override
973
    public Object getCalculatedValue(DynObject self) {
974
        try {
975
            return this.calculateMethod.invoke(self, new Object[] { this });
976
        } catch (DynMethodException ex) {
977
            throw new RuntimeException(ex);
978
        }
979
    }
980

    
981
    @Override
982
    public DynField setValidateElements(boolean validate) {
983
        return this;
984
    }
985

    
986
    @Override
987
    public boolean getValidateElements() {
988
        return false;
989
    }
990

    
991
    private class ConstantValueEvaluator extends AbstractEvaluator {
992

    
993
        @Override
994
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
995
            return defaultValue;
996
        }
997

    
998
        @Override
999
        public String getName() {
1000
            return "Constant attribute " + name;
1001
        }
1002
    }
1003

    
1004
    public void setConstantValue(boolean isConstantValue) {
1005
        if (isConstantValue) {
1006
            /* Cuando un attributo tiene asociado un evaluador, este se interpreta
1007
             * como que no debe cargarse de la fuente de datos subyacente, siendo
1008
             * el evaluador el que se encarga de proporcionar su valor.
1009
             * Nos limitamos a asignar un evaluador que retorna simpre el valor
1010
             * por defecto para ese attributo.
1011
             */
1012
            this.evaluator = new ConstantValueEvaluator();
1013
        } else {
1014
            this.evaluator = null;
1015
        }
1016
    }
1017

    
1018
    @Override
1019
    public boolean isComputed() {
1020
        return featureAttributeEmulator!=null || evaluator!=null;
1021
    }
1022

    
1023
    @Override
1024
    public FeatureStore getStore() {
1025
        FeatureType ftype = this.getFeatureType();
1026
        if( ftype == null ) {
1027
            return null;
1028
        }
1029
        return ftype.getStore();
1030
    }
1031
    
1032
    @Override
1033
    public FeatureType getFeatureType() {
1034
        if( this.typeRef==null ) {
1035
            return null;
1036
        }
1037
        return (FeatureType) this.typeRef.get();
1038
    }
1039
}