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

History | View | Annotate | Download (30.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 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
        this.dataProfile = other.dataProfile;
196
    }
197
    
198
    @Override
199
    public String getDataTypeName() {
200
        if (this.getDataType() == null) {
201
            return "(unknow)";
202
        }
203
        return this.getDataType().getName();
204
    }
205

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
346

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
475
        return true;
476
    }
477

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
880
    @Override
881
    public DynField setClassOfValue(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 setClassOfValue(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 getClassNameOfValue() {
892
        return null;
893
    }
894

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1007
    private class ConstantValueEvaluator extends AbstractEvaluator {
1008

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

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

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

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

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

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

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

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

    
1082
}