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

History | View | Annotate | Download (29.2 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.DataTypes;
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.timesupport.Interval;
47
import org.gvsig.timesupport.TimeSupportLocator;
48
import org.gvsig.tools.ToolsLocator;
49
import org.gvsig.tools.dataTypes.CoercionException;
50
import org.gvsig.tools.dataTypes.DataType;
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
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
248
            return Geometry.TYPES.UNKNOWN;
249
        }
250
        return this.geometryType;
251
    }
252

    
253
    @Override
254
    public int getGeometrySubType() {
255
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
256
            return Geometry.SUBTYPES.UNKNOWN;
257
        }
258
        return this.geometrySubType;
259
    }
260

    
261
    @Override
262
    public GeometryType getGeomType() {
263
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
264
            return null;
265
        }
266
        if (this.geomType == null) {
267
            try {
268
                this.geomType
269
                        = GeometryLocator.getGeometryManager().getGeometryType(
270
                                this.geometryType, this.geometrySubType);
271
            } catch (GeometryException e) {
272
                throw new RuntimeException(
273
                        "Error getting geometry type with type = "
274
                        + this.geometryType + ", subtype = "
275
                        + this.geometrySubType, e);
276
            }
277
        }
278
        return this.geomType;
279
    }
280

    
281
    @Override
282
    public int getIndex() {
283
        return this.index;
284
    }
285

    
286
    protected FeatureAttributeDescriptor setIndex(int index) {
287
        this.index = index;
288
        return this;
289
    }
290

    
291
    @Override
292
    public int getMaximumOccurrences() {
293
        return this.maximumOccurrences;
294
    }
295

    
296
    @Override
297
    public int getMinimumOccurrences() {
298
        return this.minimumOccurrences;
299
    }
300

    
301
    @Override
302
    public String getName() {
303
        return this.name;
304
    }
305
    
306
    public FeatureAttributeDescriptor setName(String name) {
307
        this.name = name;
308
        return this;
309
    }
310
    
311
    @Override
312
    public Class getObjectClass() {
313
        if (getDataType().getType() == DataTypes.OBJECT) {
314
            return objectClass;
315
        }
316
        return getDataType().getDefaultClass();
317
    }
318

    
319
    @Override
320
    public int getPrecision() {
321
        return this.precision;
322
    }
323

    
324
    @Override
325
    public IProjection getSRS() {
326
        return this.SRS;
327
    }
328

    
329
    @Override
330
    public Interval getInterval() {
331
        return this.interval;
332
    }
333

    
334
    public IProjection getSRS(WeakReference storeRef) {
335
        if( this.SRS==null ) {
336
            FeatureStore store = (FeatureStore) storeRef.get();
337
            this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
338
        }
339
        return this.SRS;
340
    }
341

    
342

    
343
    @Override
344
    public int getSize() {
345
        return this.size;
346
    }
347

    
348
    @Override
349
    public boolean isPrimaryKey() {
350
        return this.primaryKey;
351
    }
352

    
353
    @Override
354
    public boolean isReadOnly() {
355
        if (this.readOnly) {
356
            return true;
357
        }
358
        if (this.getEvaluator() != null) {
359
            return true;
360
        }
361
        if (this.featureAttributeEmulator != null) {
362
            return !this.featureAttributeEmulator.allowSetting();
363
        }
364
        return false;
365
    }
366

    
367
    @Override
368
    public Object getAdditionalInfo(String infoName) {
369
        if (this.additionalInfo == null) {
370
            return null;
371
        }
372
        return this.additionalInfo.get(infoName);
373
    }
374

    
375
    @Override
376
    public boolean isAutomatic() {
377
        return this.isAutomatic;
378
    }
379

    
380
    private boolean compareObject(Object a, Object b) {
381
        if (a != b) {
382
            if (a == null) {
383
                return false;
384
            }
385
            return a.equals(b);
386
        }
387
        return true;
388

    
389
    }
390

    
391
    @Override
392
    public boolean equals(Object obj) {
393
        if (this == obj) {
394
            return true;
395
        }
396
        if (!(obj instanceof DefaultFeatureAttributeDescriptor)) {
397
            return false;
398
        }
399
        DefaultFeatureAttributeDescriptor other
400
                = (DefaultFeatureAttributeDescriptor) obj;
401

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

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

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

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

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

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

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

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

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

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

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

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

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

    
454
        if (this.geometryType != other.geometryType) {
455
            return false;
456
        }
457

    
458
        if (this.geometrySubType != other.geometrySubType) {
459
            return false;
460
        }
461

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

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

    
470
        if (!compareObject(this.dateFormat, other.dateFormat)) {
471
            return false;
472
        }
473

    
474
        if (!compareObject(this.objectClass, other.objectClass)) {
475
            return false;
476
        }
477

    
478
        return true;
479
    }
480

    
481
    @Override
482
    public void loadFromState(PersistentState state)
483
            throws PersistenceException {
484
        allowNull = state.getBoolean("allowNull");
485
        dataType = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
486
        // FIXME how persist dateFormat ???
487
        // dateFormat;
488
        defaultValue = state.get("defaultValue");
489

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

    
522
    @Override
523
    public void saveToState(PersistentState state) throws PersistenceException {
524
        state.set("allowNull", allowNull);
525
        state.set("dataType", dataType);
526
        // FIXME how persist dateFormat ???
527
        // dateFormat;
528

    
529
        defaultValue = state.get("defaultValue");
530

    
531
        index = state.getInt("index");
532
        maximumOccurrences = state.getInt("maximumOccurrences");
533
        minimumOccurrences = state.getInt("minimumOccurrences");
534
        size = state.getInt("size");
535
        name = state.getString("name");
536
        try {
537
            objectClass = Class.forName(state.getString("objectClass"));
538
        } catch (ClassNotFoundException e) {
539
            throw new PersistenceException(e);
540
        }
541
        precision = state.getInt("precision");
542
        evaluator = (Evaluator) state.get("evaluator");
543
        primaryKey = state.getBoolean("primaryKey");
544
        readOnly = state.getBoolean("readOnly");
545
        String srsId = state.getString("srsId");
546
        if (srsId != null) {
547
            SRS = CRSFactory.getCRS(srsId);
548
        }
549
        geometryType = state.getInt("geometryType");
550
        geometrySubType = state.getInt("geometrySubType");
551
        additionalInfo = (Map) state.get("aditionalInfo");
552
        isAutomatic = state.getBoolean("isAutomatic");
553
    }
554

    
555
    /*
556
     * Start of DynField interface Implementation
557
     *
558
     */
559

    
560
    @Override
561
    public Tags getTags() {
562
        return tags;
563
    }
564

    
565
    @Override
566
    public DynObjectValueItem[] getAvailableValues() {
567
        return this.availableValues;
568
    }
569

    
570
    @Override
571
    public String getDescription() {
572
        if( this.description == null ) {
573
            return getName();
574
        }
575
        return this.description;
576
    }
577

    
578
    @Override
579
    public Object getMaxValue() {
580
        return this.maxValue;
581
    }
582

    
583
    @Override
584
    public Object getMinValue() {
585
        return this.minValue;
586
    }
587

    
588
    @Override
589
    public int getTheTypeOfAvailableValues() {
590
        return 1;
591
    }
592

    
593
    @Override
594
    public int getType() {
595
        if (featureAttributeGetter != null) {
596
            return featureAttributeGetter.getDataType().getType();
597
        }
598
        return getDataType().getType();
599
    }
600

    
601
    @Override
602
    public boolean isMandatory() {
603
        return !allowNull() || isPrimaryKey();
604
    }
605

    
606
    @Override
607
    public boolean isPersistent() {
608
        return false;
609
    }
610

    
611
    @Override
612
    public DynField setAvailableValues(DynObjectValueItem[] values) {
613
        if ( ArrayUtils.isEmpty(values) ) {
614
            this.availableValues = null;
615
        } else {
616
            this.availableValues = values;
617
        }
618
        return this;
619
    }
620

    
621
    @Override
622
    public DynField setDescription(String description) {
623
        this.description = description;
624
        return this;
625
    }
626

    
627
    @Override
628
    public DynField setMandatory(boolean mandatory) {
629
        throw new UnsupportedOperationException();
630
    }
631

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

    
642
    @Override
643
    public DynField setMinValue(Object minValue) {
644
        try {
645
            this.maxValue = this.coerce(minValue);
646
        } catch (CoercionException e) {
647
            throw new IllegalArgumentException(e);
648
        }
649
        return this;
650
    }
651

    
652
    @Override
653
    public DynField setPersistent(boolean persistent) {
654
        throw new UnsupportedOperationException();
655
    }
656

    
657
    @Override
658
    public DynField setTheTypeOfAvailableValues(int type) {
659
        throw new UnsupportedOperationException();
660
    }
661

    
662
    @Override
663
    public DynField setType(int type) {
664
        throw new UnsupportedOperationException();
665
    }
666

    
667
    @Override
668
    public DynField setDefaultDynValue(Object defaultValue) {
669
        throw new UnsupportedOperationException();
670
    }
671

    
672
    @Override
673
    public Class getClassOfValue() {
674
        return null;
675
    }
676

    
677
    @Override
678
    public DynField getElementsType() {
679
        return null;
680
    }
681

    
682
    @Override
683
    public DynField setClassOfValue(Class theClass)
684
            throws DynFieldIsNotAContainerException {
685
        throw new UnsupportedOperationException();
686
    }
687

    
688
    @Override
689
    public DynField setElementsType(DynStruct type)
690
            throws DynFieldIsNotAContainerException {
691
        throw new UnsupportedOperationException();
692
    }
693

    
694
    @Override
695
    public DynField setElementsType(int type)
696
            throws DynFieldIsNotAContainerException {
697
        throw new UnsupportedOperationException();
698
    }
699

    
700
    @Override
701
    public DynField setSubtype(String subtype) {
702
        throw new UnsupportedOperationException();
703
    }
704

    
705
    @Override
706
    public void validate(Object value) throws DynFieldValidateException {
707

    
708
        if (value == null && !this.allowNull()) {
709
            throw new DynFieldValidateException(value, this, null);
710
        }
711

    
712
        try {
713
            this.dataType.coerce(value);
714
        } catch (CoercionException e) {
715
            throw new DynFieldValidateException(value, this, e);
716
        }
717

    
718
        /*
719
         * Other checks will be needed
720
         */
721
    }
722

    
723
    @Override
724
    public String getSubtype() {
725
        if (featureAttributeGetter != null) {
726
            return featureAttributeGetter.getDataType().getSubtype();
727
        }
728
        return this.dataType.getSubtype();
729
    }
730

    
731
    @Override
732
    public Object coerce(Object value) throws CoercionException {
733
        if ( value == null ) {
734
            return value; // O debe devolver this.defaultValue
735
        }
736
        try {
737
            return this.getDataType().coerce(value);
738
        } catch(Exception ex){
739
            throw new RuntimeException(ex);
740
        }
741
    }
742

    
743
    @Override
744
    public DynField setAvailableValues(List values) {
745
        if (  values == null || values.isEmpty() ) {
746
            this.availableValues = null;
747
        } else {
748
            this.availableValues = (DynObjectValueItem[]) values.toArray(
749
                new DynObjectValueItem[values.size()]
750
            );
751
        }
752
        return this;
753
    }
754

    
755
    @Override
756
    public String getGroup() {
757
        return this.groupName;
758
    }
759

    
760
    @Override
761
    public int getOder() {
762
        return this.order;
763
    }
764

    
765
    @Override
766
    public String getLabel() {
767
        if( this.label == null ) {
768
            return this.getName();
769
        }
770
        return this.label;
771
    }
772

    
773
    @Override
774
    public DynField setLabel(String label) {
775
        this.label = label;
776
        return this;
777
    }
778

    
779
    @Override
780
    public DynField setGroup(String groupName) {
781
        this.groupName = groupName;
782
        return this;
783
    }
784

    
785
    @Override
786
    public DynField setOrder(int order) {
787
        this.order = order;
788
        return this;
789
    }
790

    
791
    @Override
792
    public DynField setHidden(boolean hidden) {
793
        this.hidden = hidden;
794
        return this;
795
    }
796

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

    
802
    @Override
803
    public DynField setReadOnly(boolean arg0) {
804
        throw new UnsupportedOperationException();
805
    }
806

    
807
    @Override
808
    public boolean isContainer() {
809
        return false;
810
    }
811

    
812
    @Override
813
    public Class getClassOfItems() {
814
        return null;
815
    }
816

    
817
    @Override
818
    public DynField setDefaultFieldValue(Object defaultValue) {
819
        throw new UnsupportedOperationException();
820
    }
821

    
822
    @Override
823
    public DynField setClassOfItems(Class theClass) {
824
        throw new UnsupportedOperationException();
825
    }
826

    
827
    @Override
828
    public DynField setType(DataType type) {
829
        throw new UnsupportedOperationException();
830
    }
831

    
832
    @Override
833
    public boolean isTime() {
834
        return isTime;
835
    }
836

    
837
    @Override
838
    public FeatureAttributeGetter getFeatureAttributeGetter() {
839
        return featureAttributeGetter;
840
    }
841

    
842
    @Override
843
    public void setFeatureAttributeGetter(
844
            FeatureAttributeGetter featureAttributeTransform) {
845
        this.featureAttributeGetter = featureAttributeTransform;
846
    }
847

    
848
    @Override
849
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
850
        return this.featureAttributeEmulator;
851
    }
852

    
853
    public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
854
        this.featureAttributeEmulator = featureAttributeEmulator;
855
        return this;
856
    }
857
        
858
    @Override
859
    public boolean isIndexed() {
860
        return this.indexed;
861
    }
862

    
863
    @Override
864
    public boolean allowIndexDuplicateds() {
865
        return this.allowIndexDuplicateds;
866
    }
867

    
868
    @Override
869
    public boolean isIndexAscending() {
870
        return this.isIndexAscending;
871
    }
872

    
873
    @Override
874
    public DynField setClassOfValue(DynStruct dynStrct) {
875
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
876
    }
877

    
878
    @Override
879
    public DynField setClassOfValue(String theClassNameOfValue) {
880
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
881
    }
882

    
883
    @Override
884
    public String getClassNameOfValue() {
885
        return null;
886
    }
887

    
888
    @Override
889
    public DynStruct getDynClassOfValue() {
890
        return null;
891
    }
892

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

    
898
    @Override
899
    public int getTypeOfItems() {
900
        return DataTypes.INVALID;
901
    }
902

    
903
    @Override
904
    public DynField setClassOfItems(DynStruct dynStrct) {
905
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
906
    }
907

    
908
    @Override
909
    public DynField setClassOfItems(String theClassNameOfValue) {
910
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
911
    }
912

    
913
    @Override
914
    public String getClassNameOfItems() {
915
        return null;
916
    }
917

    
918
    @Override
919
    public DynStruct getDynClassOfItems() {
920
        return null;
921
    }
922

    
923
    @Override
924
    public DynField setRelationType(int relationType) {
925
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
926
    }
927

    
928
    @Override
929
    public int getRelationType() {
930
        return RELATION_TYPE_NONE;
931
    }
932

    
933
    @Override
934
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
935
        this.availableValuesMethod = availableValuesMethod;
936
        return this;
937
    }
938

    
939
    @Override
940
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
941
        if( this.availableValuesMethod != null ) {
942
            DynObjectValueItem[] values;
943
            try {
944
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
945
            } catch (DynMethodException ex) {
946
                return this.availableValues;
947
            }
948
            if( values != null ) {
949
                return values;
950
            }
951
        }
952
        return this.availableValues;
953
    }
954

    
955
    @Override
956
    public DynMethod getAvailableValuesMethod() {
957
        return this.availableValuesMethod;
958
    }
959

    
960
    @Override
961
    public boolean isAvailableValuesCalculated() {
962
        return this.availableValuesMethod!=null;
963
    }
964

    
965
    @Override
966
    public DynMethod getCalculateMethod() {
967
        return this.calculateMethod;
968
    }
969

    
970
    @Override
971
    public DynField setCalculateMethod(DynMethod method) {
972
        this.calculateMethod = method;
973
        return this;
974
    }
975
    
976
    @Override
977
    public boolean isCalculated() {
978
        return this.calculateMethod != null;
979
    }
980
    
981
    @Override
982
    public Object getCalculatedValue(DynObject self) {
983
        try {
984
            return this.calculateMethod.invoke(self, new Object[] { this });
985
        } catch (DynMethodException ex) {
986
            throw new RuntimeException(ex);
987
        }
988
    }
989

    
990
    @Override
991
    public DynField setValidateElements(boolean validate) {
992
        return this;
993
    }
994

    
995
    @Override
996
    public boolean getValidateElements() {
997
        return false;
998
    }
999

    
1000
    private class ConstantValueEvaluator extends AbstractEvaluator {
1001

    
1002
        @Override
1003
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
1004
            return defaultValue;
1005
        }
1006

    
1007
        @Override
1008
        public String getName() {
1009
            return "Constant attribute " + name;
1010
        }
1011
    }
1012

    
1013
    public void setConstantValue(boolean isConstantValue) {
1014
        if (isConstantValue) {
1015
            /* Cuando un attributo tiene asociado un evaluador, este se interpreta
1016
             * como que no debe cargarse de la fuente de datos subyacente, siendo
1017
             * el evaluador el que se encarga de proporcionar su valor.
1018
             * Nos limitamos a asignar un evaluador que retorna simpre el valor
1019
             * por defecto para ese attributo.
1020
             */
1021
            this.evaluator = new ConstantValueEvaluator();
1022
        } else {
1023
            this.evaluator = null;
1024
        }
1025
    }
1026

    
1027
    @Override
1028
    public boolean isComputed() {
1029
        return featureAttributeEmulator!=null || evaluator!=null;
1030
    }
1031

    
1032
    @Override
1033
    public FeatureStore getStore() {
1034
        FeatureType ftype = this.getFeatureType();
1035
        if( ftype == null ) {
1036
            return null;
1037
        }
1038
        return ftype.getStore();
1039
    }
1040
    
1041
    @Override
1042
    public FeatureType getFeatureType() {
1043
        if( this.typeRef==null ) {
1044
            return null;
1045
        }
1046
        return (FeatureType) this.typeRef.get();
1047
    }
1048
}