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

History | View | Annotate | Download (30.1 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 java.util.Objects;
33
import org.apache.commons.lang3.ArrayUtils;
34
import org.cresques.cts.IProjection;
35
import org.gvsig.fmap.crs.CRSFactory;
36
import org.gvsig.fmap.dal.DataStore;
37
import org.gvsig.fmap.dal.DataTypes;
38
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
40
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
41
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
42
import org.gvsig.fmap.dal.feature.FeatureStore;
43
import org.gvsig.fmap.dal.feature.FeatureType;
44
import org.gvsig.fmap.geom.Geometry;
45
import org.gvsig.fmap.geom.GeometryException;
46
import org.gvsig.fmap.geom.GeometryLocator;
47
import org.gvsig.fmap.geom.type.GeometryType;
48
import org.gvsig.timesupport.Interval;
49
import org.gvsig.timesupport.TimeSupportLocator;
50
import org.gvsig.tools.ToolsLocator;
51
import org.gvsig.tools.dataTypes.CoercionException;
52
import org.gvsig.tools.dataTypes.DataType;
53
import org.gvsig.tools.dynobject.DynField;
54
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
55
import org.gvsig.tools.dynobject.DynField_v2;
56
import org.gvsig.tools.dynobject.DynMethod;
57
import org.gvsig.tools.dynobject.DynObject;
58
import org.gvsig.tools.dynobject.DynObjectValueItem;
59
import org.gvsig.tools.dynobject.DynStruct;
60
import org.gvsig.tools.dynobject.Tags;
61
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
62
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
63
import org.gvsig.tools.dynobject.exception.DynMethodException;
64
import org.gvsig.tools.dynobject.impl.DefaultTags;
65
import org.gvsig.tools.evaluator.AbstractEvaluator;
66
import org.gvsig.tools.evaluator.Evaluator;
67
import org.gvsig.tools.evaluator.EvaluatorData;
68
import org.gvsig.tools.evaluator.EvaluatorException;
69
import org.gvsig.tools.persistence.Persistent;
70
import org.gvsig.tools.persistence.PersistentState;
71
import org.gvsig.tools.persistence.exception.PersistenceException;
72

    
73
public class DefaultFeatureAttributeDescriptor implements
74
        FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute {
75

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

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

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

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

    
205
    @Override
206
    public FeatureAttributeDescriptor getCopy() {
207
        return new DefaultFeatureAttributeDescriptor(this);
208
    }
209

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

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

    
228
    public FeatureAttributeDescriptor setDataType(int type) {
229
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
230
        return this;
231
    }
232

    
233
    @Override
234
    public DateFormat getDateFormat() {
235
        return this.dateFormat;
236
    }
237

    
238
    @Override
239
    public Object getDefaultValue() {
240
        return this.defaultValue;
241
    }
242

    
243
    @Override
244
    public Evaluator getEvaluator() {
245
        return this.evaluator;
246
    }
247

    
248
    @Override
249
    public int getGeometryType() {
250
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
251
            return Geometry.TYPES.UNKNOWN;
252
        }
253
        return this.geometryType;
254
    }
255

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

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

    
284
    @Override
285
    public int getIndex() {
286
        return this.index;
287
    }
288

    
289
    protected FeatureAttributeDescriptor setIndex(int index) {
290
        this.index = index;
291
        return this;
292
    }
293

    
294
    @Override
295
    public int getMaximumOccurrences() {
296
        return this.maximumOccurrences;
297
    }
298

    
299
    @Override
300
    public int getMinimumOccurrences() {
301
        return this.minimumOccurrences;
302
    }
303

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

    
322
    @Override
323
    public int getPrecision() {
324
        return this.precision;
325
    }
326

    
327
    @Override
328
    public IProjection getSRS() {
329
        return this.SRS;
330
    }
331

    
332
    @Override
333
    public Interval getInterval() {
334
        return this.interval;
335
    }
336

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

    
345

    
346
    @Override
347
    public int getSize() {
348
        return this.size;
349
    }
350

    
351
    @Override
352
    public boolean isPrimaryKey() {
353
        return this.primaryKey;
354
    }
355

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

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

    
378
    @Override
379
    public boolean isAutomatic() {
380
        return this.isAutomatic;
381
    }
382

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

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

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

    
402
        if (!Objects.equals(this.name, other.name)) {
403
            return false;
404
        }
405

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

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

    
414
        if (!Objects.equals(this.defaultValue, other.defaultValue)) {
415
            return false;
416
        }
417

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

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

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

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

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

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

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

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

    
450
        if (!Objects.equals(this.evaluator, other.evaluator)) {
451
            return false;
452
        }
453

    
454
        if (!Objects.equals(this.featureAttributeEmulator, other.featureAttributeEmulator)) {
455
            return false;
456
        }
457

    
458
        if (!Objects.equals(this.SRS, other.SRS)) {
459
            return false;
460
        }
461

    
462
        if (!Objects.equals(this.dateFormat, other.dateFormat)) {
463
            return false;
464
        }
465

    
466
        if (!Objects.equals(this.objectClass, other.objectClass)) {
467
            return false;
468
        }
469

    
470
        if (!Objects.equals(this.dataProfile, other.dataProfile)) {
471
            return false;
472
        }
473

    
474
        return true;
475
    }
476

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

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

    
518
    @Override
519
    public void saveToState(PersistentState state) throws PersistenceException {
520
        state.set("allowNull", allowNull);
521
        state.set("dataType", dataType);
522
        // FIXME how persist dateFormat ???
523
        // dateFormat;
524

    
525
        defaultValue = state.get("defaultValue");
526

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

    
551
    /*
552
     * Start of DynField interface Implementation
553
     *
554
     */
555

    
556
    @Override
557
    public Tags getTags() {
558
        return tags;
559
    }
560

    
561
    @Override
562
    public DynObjectValueItem[] getAvailableValues() {
563
        return this.availableValues;
564
    }
565

    
566
    @Override
567
    public String getDescription() {
568
        if( this.description == null ) {
569
            return getName();
570
        }
571
        return this.description;
572
    }
573

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

    
579
    @Override
580
    public Object getMinValue() {
581
        return this.minValue;
582
    }
583

    
584
    @Override
585
    public int getTheTypeOfAvailableValues() {
586
        return 1;
587
    }
588

    
589
    @Override
590
    public int getType() {
591
        if (featureAttributeGetter != null) {
592
            return featureAttributeGetter.getDataType().getType();
593
        }
594
        return getDataType().getType();
595
    }
596

    
597
    @Override
598
    public boolean isMandatory() {
599
        return !allowNull() || isPrimaryKey();
600
    }
601

    
602
    @Override
603
    public boolean isPersistent() {
604
        return false;
605
    }
606

    
607
    @Override
608
    public DynField setAvailableValues(DynObjectValueItem[] values) {
609
        if ( ArrayUtils.isEmpty(values) ) {
610
            this.availableValues = null;
611
        } else {
612
            this.availableValues = values;
613
        }
614
        return this;
615
    }
616

    
617
    @Override
618
    public DynField setDescription(String description) {
619
        this.description = description;
620
        return this;
621
    }
622

    
623
    @Override
624
    public DynField setMandatory(boolean mandatory) {
625
        throw new UnsupportedOperationException();
626
    }
627

    
628
    @Override
629
    public DynField setMaxValue(Object maxValue) {
630
        try {
631
            this.maxValue = this.coerce(maxValue);
632
        } catch (CoercionException e) {
633
            throw new IllegalArgumentException(e);
634
        }
635
        return this;
636
    }
637

    
638
    @Override
639
    public DynField setMinValue(Object minValue) {
640
        try {
641
            this.maxValue = this.coerce(minValue);
642
        } catch (CoercionException e) {
643
            throw new IllegalArgumentException(e);
644
        }
645
        return this;
646
    }
647

    
648
    @Override
649
    public DynField setPersistent(boolean persistent) {
650
        throw new UnsupportedOperationException();
651
    }
652

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

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

    
663
    @Override
664
    public DynField setDefaultDynValue(Object defaultValue) {
665
        throw new UnsupportedOperationException();
666
    }
667

    
668
    @Override
669
    public Class getClassOfValue() {
670
        return null;
671
    }
672

    
673
    @Override
674
    public DynField getElementsType() {
675
        return null;
676
    }
677

    
678
    @Override
679
    public DynField setClassOfValue(Class theClass)
680
            throws DynFieldIsNotAContainerException {
681
        throw new UnsupportedOperationException();
682
    }
683

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

    
690
    @Override
691
    public DynField setElementsType(int type)
692
            throws DynFieldIsNotAContainerException {
693
        throw new UnsupportedOperationException();
694
    }
695

    
696
    public FeatureAttributeDescriptor setDataProfileName(String dataProfile) {
697
        this.dataProfile = dataProfile;
698
        return this;
699
    }
700

    
701
    @Override
702
    public String getDataProfileName() {
703
        return dataProfile;
704
    }
705

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
833
    @Override
834
    public DynField setSubtype(String subtype) {
835
        throw new UnsupportedOperationException();
836
    }
837

    
838
    @Override
839
    public boolean isTime() {
840
        return isTime;
841
    }
842

    
843
    @Override
844
    public FeatureAttributeGetter getFeatureAttributeGetter() {
845
        return featureAttributeGetter;
846
    }
847

    
848
    @Override
849
    public void setFeatureAttributeGetter(
850
            FeatureAttributeGetter featureAttributeTransform) {
851
        this.featureAttributeGetter = featureAttributeTransform;
852
    }
853

    
854
    @Override
855
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
856
        return this.featureAttributeEmulator;
857
    }
858

    
859
    public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
860
        this.featureAttributeEmulator = featureAttributeEmulator;
861
        return this;
862
    }
863
        
864
    @Override
865
    public boolean isIndexed() {
866
        return this.indexed;
867
    }
868

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

    
874
    @Override
875
    public boolean isIndexAscending() {
876
        return this.isIndexAscending;
877
    }
878

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

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

    
889
    @Override
890
    public String getClassNameOfValue() {
891
        return null;
892
    }
893

    
894
    @Override
895
    public DynStruct getDynClassOfValue() {
896
        return null;
897
    }
898

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

    
904
    @Override
905
    public int getTypeOfItems() {
906
        return DataTypes.INVALID;
907
    }
908

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

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

    
919
    @Override
920
    public String getClassNameOfItems() {
921
        return null;
922
    }
923

    
924
    @Override
925
    public DynStruct getDynClassOfItems() {
926
        return null;
927
    }
928

    
929
    @Override
930
    public DynField setRelationType(int relationType) {
931
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
932
    }
933

    
934
    @Override
935
    public int getRelationType() {
936
        return RELATION_TYPE_NONE;
937
    }
938

    
939
    @Override
940
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
941
        this.availableValuesMethod = availableValuesMethod;
942
        return this;
943
    }
944

    
945
    @Override
946
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
947
        if( this.availableValuesMethod != null ) {
948
            DynObjectValueItem[] values;
949
            try {
950
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
951
            } catch (DynMethodException ex) {
952
                return this.availableValues;
953
            }
954
            if( values != null ) {
955
                return values;
956
            }
957
        }
958
        return this.availableValues;
959
    }
960

    
961
    @Override
962
    public DynMethod getAvailableValuesMethod() {
963
        return this.availableValuesMethod;
964
    }
965

    
966
    @Override
967
    public boolean isAvailableValuesCalculated() {
968
        return this.availableValuesMethod!=null;
969
    }
970

    
971
    @Override
972
    public DynMethod getCalculateMethod() {
973
        return this.calculateMethod;
974
    }
975

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

    
996
    @Override
997
    public DynField setValidateElements(boolean validate) {
998
        return this;
999
    }
1000

    
1001
    @Override
1002
    public boolean getValidateElements() {
1003
        return false;
1004
    }
1005

    
1006
    private class ConstantValueEvaluator extends AbstractEvaluator {
1007

    
1008
        @Override
1009
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
1010
            return defaultValue;
1011
        }
1012

    
1013
        @Override
1014
        public String getName() {
1015
            return "Constant attribute " + name;
1016
        }
1017
    }
1018

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

    
1033
    @Override
1034
    public boolean isComputed() {
1035
        return featureAttributeEmulator!=null || evaluator!=null;
1036
    }
1037

    
1038
    @Override
1039
    public FeatureStore getStore() {
1040
        FeatureType ftype = this.getFeatureType();
1041
        if( ftype == null ) {
1042
            return null;
1043
        }
1044
        return ftype.getStore();
1045
    }
1046
    
1047
    @Override
1048
    public FeatureType getFeatureType() {
1049
        if( this.typeRef==null ) {
1050
            return null;
1051
        }
1052
        return (FeatureType) this.typeRef.get();
1053
    }
1054

    
1055
    public FeatureAttributeDescriptor setInterval(Interval interval) {
1056
        this.interval = interval;
1057
        return this;
1058
    }
1059

    
1060
    public void fixAll() {
1061
        switch(this.getType()) {
1062
            case DataTypes.INSTANT:
1063
            case DataTypes.INTERVAL:
1064
            case DataTypes.DATE:
1065
                if( this.getInterval()!=null ) {
1066
                    this.isTime = true;
1067
                }
1068
                break;
1069
        }
1070
    }
1071

    
1072
    @Override
1073
    public String[] getRequiredFieldNames() {
1074
        FeatureAttributeEmulator emulator = this.getFeatureAttributeEmulator();
1075
        if( emulator==null ) {
1076
            return null;
1077
        }
1078
        return emulator.getRequiredFieldNames();
1079
    }
1080

    
1081
}