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

History | View | Annotate | Download (28.4 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.EditableFeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
38
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
39
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureType;
42
import org.gvsig.fmap.geom.Geometry;
43
import org.gvsig.fmap.geom.GeometryException;
44
import org.gvsig.fmap.geom.GeometryLocator;
45
import org.gvsig.fmap.geom.type.GeometryType;
46
import org.gvsig.tools.ToolsLocator;
47
import org.gvsig.tools.dataTypes.CoercionException;
48
import org.gvsig.tools.dataTypes.DataType;
49
import org.gvsig.tools.dataTypes.DataTypes;
50
import org.gvsig.tools.dynobject.DynField;
51
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
52
import org.gvsig.tools.dynobject.DynField_v2;
53
import org.gvsig.tools.dynobject.DynMethod;
54
import org.gvsig.tools.dynobject.DynObject;
55
import org.gvsig.tools.dynobject.DynObjectValueItem;
56
import org.gvsig.tools.dynobject.DynStruct;
57
import org.gvsig.tools.dynobject.Tags;
58
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
59
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
60
import org.gvsig.tools.dynobject.exception.DynMethodException;
61
import org.gvsig.tools.dynobject.impl.DefaultTags;
62
import org.gvsig.tools.evaluator.AbstractEvaluator;
63
import org.gvsig.tools.evaluator.Evaluator;
64
import org.gvsig.tools.evaluator.EvaluatorData;
65
import org.gvsig.tools.evaluator.EvaluatorException;
66
import org.gvsig.tools.persistence.Persistent;
67
import org.gvsig.tools.persistence.PersistentState;
68
import org.gvsig.tools.persistence.exception.PersistenceException;
69

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
318
    public IProjection getSRS(WeakReference storeRef) {
319
        if( this.SRS==null ) {
320
            FeatureStore store = (FeatureStore) storeRef.get();
321
            this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
322
        }
323
        return this.SRS;
324
    }
325

    
326

    
327
    @Override
328
    public int getSize() {
329
        return this.size;
330
    }
331

    
332
    @Override
333
    public boolean isPrimaryKey() {
334
        return this.primaryKey;
335
    }
336

    
337
    @Override
338
    public boolean isReadOnly() {
339
        if (this.readOnly) {
340
            return true;
341
        }
342
        if (this.getEvaluator() != null) {
343
            return true;
344
        }
345
        if (this.featureAttributeEmulator != null) {
346
            return !this.featureAttributeEmulator.allowSetting();
347
        }
348
        return false;
349
    }
350

    
351
    @Override
352
    public Object getAdditionalInfo(String infoName) {
353
        if (this.additionalInfo == null) {
354
            return null;
355
        }
356
        return this.additionalInfo.get(infoName);
357
    }
358

    
359
    @Override
360
    public boolean isAutomatic() {
361
        return this.isAutomatic;
362
    }
363

    
364
    private boolean compareObject(Object a, Object b) {
365
        if (a != b) {
366
            if (a == null) {
367
                return false;
368
            }
369
            return a.equals(b);
370
        }
371
        return true;
372

    
373
    }
374

    
375
    @Override
376
    public boolean equals(Object obj) {
377
        if (this == obj) {
378
            return true;
379
        }
380
        if (!(obj instanceof DefaultFeatureAttributeDescriptor)) {
381
            return false;
382
        }
383
        DefaultFeatureAttributeDescriptor other
384
                = (DefaultFeatureAttributeDescriptor) obj;
385

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

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

    
394
        if (!compareObject(this.name, other.name)) {
395
            return false;
396
        }
397

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

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

    
406
        if (!compareObject(this.defaultValue, other.defaultValue)) {
407
            return false;
408
        }
409

    
410
        if (!compareObject(this.defaultValue, other.defaultValue)) {
411
            return false;
412
        }
413

    
414
        if (this.primaryKey != other.primaryKey) {
415
            return false;
416
        }
417

    
418
        if (this.isAutomatic != other.isAutomatic) {
419
            return false;
420
        }
421

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

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

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

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

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

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

    
446
        if (!compareObject(this.evaluator, other.evaluator)) {
447
            return false;
448
        }
449

    
450
        if (!compareObject(this.SRS, other.SRS)) {
451
            return false;
452
        }
453

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

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

    
462
        return true;
463
    }
464

    
465
    @Override
466
    public void loadFromState(PersistentState state)
467
            throws PersistenceException {
468
        allowNull = state.getBoolean("allowNull");
469
        dataType
470
                = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
471
        // FIXME how persist dateFormat ???
472
        // dateFormat;
473
        defaultValue = state.get("defaultValue");
474

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

    
499
    @Override
500
    public void saveToState(PersistentState state) throws PersistenceException {
501
        state.set("allowNull", allowNull);
502
        state.set("dataType", dataType);
503
        // FIXME how persist dateFormat ???
504
        // dateFormat;
505

    
506
        defaultValue = state.get("defaultValue");
507

    
508
        index = state.getInt("index");
509
        maximumOccurrences = state.getInt("maximumOccurrences");
510
        minimumOccurrences = state.getInt("minimumOccurrences");
511
        size = state.getInt("size");
512
        name = state.getString("name");
513
        try {
514
            objectClass = Class.forName(state.getString("objectClass"));
515
        } catch (ClassNotFoundException e) {
516
            throw new PersistenceException(e);
517
        }
518
        precision = state.getInt("precision");
519
        evaluator = (Evaluator) state.get("evaluator");
520
        primaryKey = state.getBoolean("primaryKey");
521
        readOnly = state.getBoolean("readOnly");
522
        String srsId = state.getString("srsId");
523
        if (srsId != null) {
524
            SRS = CRSFactory.getCRS(srsId);
525
        }
526
        geometryType = state.getInt("geometryType");
527
        geometrySubType = state.getInt("geometrySubType");
528
        additionalInfo = (Map) state.get("aditionalInfo");
529
        isAutomatic = state.getBoolean("isAutomatic");
530
    }
531

    
532
    /*
533
     * Start of DynField interface Implementation
534
     *
535
     */
536

    
537
    @Override
538
    public Tags getTags() {
539
        return tags;
540
    }
541

    
542
    @Override
543
    public DynObjectValueItem[] getAvailableValues() {
544
        return this.availableValues;
545
    }
546

    
547
    @Override
548
    public String getDescription() {
549
        if( this.description == null ) {
550
            return getName();
551
        }
552
        return this.description;
553
    }
554

    
555
    @Override
556
    public Object getMaxValue() {
557
        return this.maxValue;
558
    }
559

    
560
    @Override
561
    public Object getMinValue() {
562
        return this.minValue;
563
    }
564

    
565
    @Override
566
    public int getTheTypeOfAvailableValues() {
567
        return 1;
568
    }
569

    
570
    @Override
571
    public int getType() {
572
        if (featureAttributeGetter != null) {
573
            return featureAttributeGetter.getDataType().getType();
574
        }
575
        return getDataType().getType();
576
    }
577

    
578
    @Override
579
    public boolean isMandatory() {
580
        return !allowNull() || isPrimaryKey();
581
    }
582

    
583
    @Override
584
    public boolean isPersistent() {
585
        return false;
586
    }
587

    
588
    @Override
589
    public DynField setAvailableValues(DynObjectValueItem[] values) {
590
        if ( ArrayUtils.isEmpty(values) ) {
591
            this.availableValues = null;
592
        } else {
593
            this.availableValues = values;
594
        }
595
        return this;
596
    }
597

    
598
    @Override
599
    public DynField setDescription(String description) {
600
        this.description = description;
601
        return this;
602
    }
603

    
604
    @Override
605
    public DynField setMandatory(boolean mandatory) {
606
        throw new UnsupportedOperationException();
607
    }
608

    
609
    @Override
610
    public DynField setMaxValue(Object maxValue) {
611
        try {
612
            this.maxValue = this.coerce(maxValue);
613
        } catch (CoercionException e) {
614
            throw new IllegalArgumentException(e);
615
        }
616
        return this;
617
    }
618

    
619
    @Override
620
    public DynField setMinValue(Object minValue) {
621
        try {
622
            this.maxValue = this.coerce(minValue);
623
        } catch (CoercionException e) {
624
            throw new IllegalArgumentException(e);
625
        }
626
        return this;
627
    }
628

    
629
    @Override
630
    public DynField setPersistent(boolean persistent) {
631
        throw new UnsupportedOperationException();
632
    }
633

    
634
    @Override
635
    public DynField setTheTypeOfAvailableValues(int type) {
636
        throw new UnsupportedOperationException();
637
    }
638

    
639
    @Override
640
    public DynField setType(int type) {
641
        throw new UnsupportedOperationException();
642
    }
643

    
644
    @Override
645
    public DynField setDefaultDynValue(Object defaultValue) {
646
        throw new UnsupportedOperationException();
647
    }
648

    
649
    @Override
650
    public Class getClassOfValue() {
651
        return null;
652
    }
653

    
654
    @Override
655
    public DynField getElementsType() {
656
        return null;
657
    }
658

    
659
    @Override
660
    public DynField setClassOfValue(Class theClass)
661
            throws DynFieldIsNotAContainerException {
662
        throw new UnsupportedOperationException();
663
    }
664

    
665
    @Override
666
    public DynField setElementsType(DynStruct type)
667
            throws DynFieldIsNotAContainerException {
668
        throw new UnsupportedOperationException();
669
    }
670

    
671
    @Override
672
    public DynField setElementsType(int type)
673
            throws DynFieldIsNotAContainerException {
674
        throw new UnsupportedOperationException();
675
    }
676

    
677
    @Override
678
    public DynField setSubtype(String subtype) {
679
        throw new UnsupportedOperationException();
680
    }
681

    
682
    @Override
683
    public void validate(Object value) throws DynFieldValidateException {
684

    
685
        if (value == null && !this.allowNull()) {
686
            throw new DynFieldValidateException(value, this, null);
687
        }
688

    
689
        try {
690
            this.dataType.coerce(value);
691
        } catch (CoercionException e) {
692
            throw new DynFieldValidateException(value, this, e);
693
        }
694

    
695
        /*
696
         * Other checks will be needed
697
         */
698
    }
699

    
700
    @Override
701
    public String getSubtype() {
702
        if (featureAttributeGetter != null) {
703
            return featureAttributeGetter.getDataType().getSubtype();
704
        }
705
        return this.dataType.getSubtype();
706
    }
707

    
708
    @Override
709
    public Object coerce(Object value) throws CoercionException {
710
        if ( value == null ) {
711
            return value; // O debe devolver this.defaultValue
712
        }
713
        try {
714
            return this.getDataType().coerce(value);
715
        } catch(Exception ex){
716
            throw new RuntimeException(ex);
717
        }
718
    }
719

    
720
    @Override
721
    public DynField setAvailableValues(List values) {
722
        if (  values == null || values.isEmpty() ) {
723
            this.availableValues = null;
724
        } else {
725
            this.availableValues = (DynObjectValueItem[]) values.toArray(
726
                new DynObjectValueItem[values.size()]
727
            );
728
        }
729
        return this;
730
    }
731

    
732
    @Override
733
    public String getGroup() {
734
        return this.groupName;
735
    }
736

    
737
    @Override
738
    public int getOder() {
739
        return this.order;
740
    }
741

    
742
    @Override
743
    public String getLabel() {
744
        if( this.label == null ) {
745
            return this.getName();
746
        }
747
        return this.label;
748
    }
749

    
750
    @Override
751
    public DynField setLabel(String label) {
752
        this.label = label;
753
        return this;
754
    }
755

    
756
    @Override
757
    public DynField setGroup(String groupName) {
758
        this.groupName = groupName;
759
        return this;
760
    }
761

    
762
    @Override
763
    public DynField setOrder(int order) {
764
        this.order = order;
765
        return this;
766
    }
767

    
768
    @Override
769
    public DynField setHidden(boolean hidden) {
770
        this.hidden = hidden;
771
        return this;
772
    }
773

    
774
    @Override
775
    public boolean isHidden() {
776
        return this.hidden;
777
    }
778

    
779
    @Override
780
    public DynField setReadOnly(boolean arg0) {
781
        throw new UnsupportedOperationException();
782
    }
783

    
784
    @Override
785
    public boolean isContainer() {
786
        return false;
787
    }
788

    
789
    @Override
790
    public Class getClassOfItems() {
791
        return null;
792
    }
793

    
794
    @Override
795
    public DynField setDefaultFieldValue(Object defaultValue) {
796
        throw new UnsupportedOperationException();
797
    }
798

    
799
    @Override
800
    public DynField setClassOfItems(Class theClass) {
801
        throw new UnsupportedOperationException();
802
    }
803

    
804
    @Override
805
    public DynField setType(DataType type) {
806
        throw new UnsupportedOperationException();
807
    }
808

    
809
    @Override
810
    public boolean isTime() {
811
        return isTime;
812
    }
813

    
814
    @Override
815
    public FeatureAttributeGetter getFeatureAttributeGetter() {
816
        return featureAttributeGetter;
817
    }
818

    
819
    @Override
820
    public void setFeatureAttributeGetter(
821
            FeatureAttributeGetter featureAttributeTransform) {
822
        this.featureAttributeGetter = featureAttributeTransform;
823
    }
824

    
825
    @Override
826
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
827
        return this.featureAttributeEmulator;
828
    }
829

    
830
    public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
831
        this.featureAttributeEmulator = featureAttributeEmulator;
832
        return this;
833
    }
834
        
835
    @Override
836
    public boolean isIndexed() {
837
        return this.indexed;
838
    }
839

    
840
    @Override
841
    public boolean allowIndexDuplicateds() {
842
        return this.allowIndexDuplicateds;
843
    }
844

    
845
    @Override
846
    public boolean isIndexAscending() {
847
        return this.isIndexAscending;
848
    }
849

    
850
    @Override
851
    public DynField setClassOfValue(DynStruct dynStrct) {
852
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
853
    }
854

    
855
    @Override
856
    public DynField setClassOfValue(String theClassNameOfValue) {
857
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
858
    }
859

    
860
    @Override
861
    public String getClassNameOfValue() {
862
        return null;
863
    }
864

    
865
    @Override
866
    public DynStruct getDynClassOfValue() {
867
        return null;
868
    }
869

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

    
875
    @Override
876
    public int getTypeOfItems() {
877
        return DataTypes.INVALID;
878
    }
879

    
880
    @Override
881
    public DynField setClassOfItems(DynStruct dynStrct) {
882
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
883
    }
884

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

    
890
    @Override
891
    public String getClassNameOfItems() {
892
        return null;
893
    }
894

    
895
    @Override
896
    public DynStruct getDynClassOfItems() {
897
        return null;
898
    }
899

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

    
905
    @Override
906
    public int getRelationType() {
907
        return RELATION_TYPE_NONE;
908
    }
909

    
910
    @Override
911
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
912
        this.availableValuesMethod = availableValuesMethod;
913
        return this;
914
    }
915

    
916
    @Override
917
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
918
        if( this.availableValuesMethod != null ) {
919
            DynObjectValueItem[] values;
920
            try {
921
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
922
            } catch (DynMethodException ex) {
923
                return this.availableValues;
924
            }
925
            if( values != null ) {
926
                return values;
927
            }
928
        }
929
        return this.availableValues;
930
    }
931

    
932
    @Override
933
    public DynMethod getAvailableValuesMethod() {
934
        return this.availableValuesMethod;
935
    }
936

    
937
    @Override
938
    public boolean isAvailableValuesCalculated() {
939
        return this.availableValuesMethod!=null;
940
    }
941

    
942
    @Override
943
    public DynMethod getCalculateMethod() {
944
        return this.calculateMethod;
945
    }
946

    
947
    @Override
948
    public DynField setCalculateMethod(DynMethod method) {
949
        this.calculateMethod = method;
950
        return this;
951
    }
952
    
953
    @Override
954
    public boolean isCalculated() {
955
        return this.calculateMethod != null;
956
    }
957
    
958
    @Override
959
    public Object getCalculatedValue(DynObject self) {
960
        try {
961
            return this.calculateMethod.invoke(self, new Object[] { this });
962
        } catch (DynMethodException ex) {
963
            throw new RuntimeException(ex);
964
        }
965
    }
966

    
967
    @Override
968
    public DynField setValidateElements(boolean validate) {
969
        return this;
970
    }
971

    
972
    @Override
973
    public boolean getValidateElements() {
974
        return false;
975
    }
976

    
977
    private class ConstantValueEvaluator extends AbstractEvaluator {
978

    
979
        @Override
980
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
981
            return defaultValue;
982
        }
983

    
984
        @Override
985
        public String getName() {
986
            return "Constant attribute " + name;
987
        }
988
    }
989

    
990
    public void setConstantValue(boolean isConstantValue) {
991
        if (isConstantValue) {
992
            /* Cuando un attributo tiene asociado un evaluador, este se interpreta
993
             * como que no debe cargarse de la fuente de datos subyacente, siendo
994
             * el evaluador el que se encarga de proporcionar su valor.
995
             * Nos limitamos a asignar un evaluador que retorna simpre el valor
996
             * por defecto para ese attributo.
997
             */
998
            this.evaluator = new ConstantValueEvaluator();
999
        } else {
1000
            this.evaluator = null;
1001
        }
1002
    }
1003

    
1004
    @Override
1005
    public boolean isComputed() {
1006
        return featureAttributeEmulator!=null || evaluator!=null;
1007
    }
1008

    
1009
    @Override
1010
    public FeatureStore getStore() {
1011
        FeatureType ftype = this.getFeatureType();
1012
        if( ftype == null ) {
1013
            return null;
1014
        }
1015
        return ftype.getStore();
1016
    }
1017
    
1018
    @Override
1019
    public FeatureType getFeatureType() {
1020
        if( this.typeRef==null ) {
1021
            return null;
1022
        }
1023
        return (FeatureType) this.typeRef.get();
1024
    }
1025
}