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

History | View | Annotate | Download (28.4 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6 42561 jjdelcerro
 * 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 40559 jjdelcerro
 *
11 42561 jjdelcerro
 * 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 40559 jjdelcerro
 *
16 42561 jjdelcerro
 * 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 40559 jjdelcerro
 *
20 42561 jjdelcerro
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22 40559 jjdelcerro
 */
23 40435 jjdelcerro
package org.gvsig.fmap.dal.feature.impl;
24
25 43739 jjdelcerro
import java.lang.ref.WeakReference;
26 40435 jjdelcerro
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 42563 jjdelcerro
import org.apache.commons.lang3.ArrayUtils;
33 40435 jjdelcerro
import org.cresques.cts.IProjection;
34
import org.gvsig.fmap.crs.CRSFactory;
35 44022 jjdelcerro
import org.gvsig.fmap.dal.DataStore;
36 43954 jjdelcerro
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
37 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
38 42563 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
39 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
40 43739 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureType;
42 40435 jjdelcerro
import org.gvsig.fmap.geom.Geometry;
43
import org.gvsig.fmap.geom.GeometryException;
44
import org.gvsig.fmap.geom.GeometryLocator;
45
import org.gvsig.fmap.geom.type.GeometryType;
46
import org.gvsig.tools.ToolsLocator;
47
import org.gvsig.tools.dataTypes.CoercionException;
48
import org.gvsig.tools.dataTypes.DataType;
49
import org.gvsig.tools.dataTypes.DataTypes;
50
import org.gvsig.tools.dynobject.DynField;
51 41323 jjdelcerro
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
52 42563 jjdelcerro
import org.gvsig.tools.dynobject.DynField_v2;
53 42775 jjdelcerro
import org.gvsig.tools.dynobject.DynMethod;
54 42606 jjdelcerro
import org.gvsig.tools.dynobject.DynObject;
55 40435 jjdelcerro
import org.gvsig.tools.dynobject.DynObjectValueItem;
56
import org.gvsig.tools.dynobject.DynStruct;
57 42563 jjdelcerro
import org.gvsig.tools.dynobject.Tags;
58 40435 jjdelcerro
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
59
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
60 42775 jjdelcerro
import org.gvsig.tools.dynobject.exception.DynMethodException;
61 42563 jjdelcerro
import org.gvsig.tools.dynobject.impl.DefaultTags;
62 41212 jjdelcerro
import org.gvsig.tools.evaluator.AbstractEvaluator;
63 40435 jjdelcerro
import org.gvsig.tools.evaluator.Evaluator;
64 41212 jjdelcerro
import org.gvsig.tools.evaluator.EvaluatorData;
65
import org.gvsig.tools.evaluator.EvaluatorException;
66 40435 jjdelcerro
import org.gvsig.tools.persistence.Persistent;
67
import org.gvsig.tools.persistence.PersistentState;
68
import org.gvsig.tools.persistence.exception.PersistenceException;
69
70
public class DefaultFeatureAttributeDescriptor implements
71 42563 jjdelcerro
        FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute {
72 40435 jjdelcerro
73
    protected boolean allowNull;
74
    protected DataType dataType;
75
    protected DateFormat dateFormat;
76
    protected Object defaultValue;
77
    protected int index;
78
    protected int maximumOccurrences;
79
    protected int minimumOccurrences;
80
    protected int size;
81
    protected String name;
82
    protected Class objectClass;
83
    protected int precision;
84
    protected Evaluator evaluator;
85
    protected boolean primaryKey;
86
    protected boolean readOnly;
87
    protected IProjection SRS;
88
    protected GeometryType geomType;
89
    protected int geometryType;
90
    protected int geometrySubType;
91
    protected Map additionalInfo;
92
    protected boolean isAutomatic;
93 41335 jjdelcerro
    protected boolean isTime = false;
94
    protected FeatureAttributeGetter featureAttributeGetter = null;
95
    protected FeatureAttributeEmulator featureAttributeEmulator = null;
96 41638 jjdelcerro
    protected boolean indexed = false;
97
    protected boolean isIndexAscending = true;
98
    protected boolean allowIndexDuplicateds = true;
99 40435 jjdelcerro
100 42563 jjdelcerro
    protected DynObjectValueItem[] availableValues;
101
    protected String description;
102
    protected Object minValue;
103
    protected Object maxValue;
104
    protected String label;
105
    protected int order;
106
    protected boolean hidden;
107
    protected String groupName;
108
    protected Tags tags = new DefaultTags();
109 42775 jjdelcerro
    private DynMethod availableValuesMethod;
110
    private DynMethod calculateMethod;
111 43739 jjdelcerro
    private WeakReference typeRef;
112 42563 jjdelcerro
113 43739 jjdelcerro
    protected DefaultFeatureAttributeDescriptor(FeatureType type) {
114
        if( type == null ) {
115
            this.typeRef = null;
116
        } else {
117
            this.typeRef = new WeakReference(type);
118
        }
119 40435 jjdelcerro
        this.allowNull = true;
120
        this.dataType = null;
121
        this.dateFormat = null;
122
        this.defaultValue = null;
123
        this.index = -1;
124
        this.maximumOccurrences = 0;
125
        this.minimumOccurrences = 0;
126
        this.size = 0;
127
        this.name = null;
128
        this.objectClass = null;
129
        this.precision = 0;
130
        this.evaluator = null;
131
        this.primaryKey = false;
132
        this.readOnly = false;
133
        this.SRS = null;
134
        this.geometryType = Geometry.TYPES.NULL;
135
        this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
136
        this.additionalInfo = null;
137
        this.isAutomatic = false;
138 43362 jjdelcerro
        this.hidden = false;
139 40435 jjdelcerro
    }
140
141
    protected DefaultFeatureAttributeDescriptor(
142 43739 jjdelcerro
            DefaultFeatureAttributeDescriptor other
143
        ) {
144 42775 jjdelcerro
        copyFrom(other);
145
    }
146
147
    @Override
148
    public void copyFrom(DynField other1) {
149
        if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) {
150
            throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor");
151
        }
152
        DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1;
153 43739 jjdelcerro
        this.typeRef = other.typeRef;
154 40435 jjdelcerro
        this.allowNull = other.allowNull;
155
        this.dataType = other.dataType;
156
        this.dateFormat = other.dateFormat;
157
        this.defaultValue = other.defaultValue;
158
        this.index = other.index;
159
        this.maximumOccurrences = other.maximumOccurrences;
160
        this.minimumOccurrences = other.minimumOccurrences;
161
        this.size = other.size;
162
        this.name = other.name;
163
        this.objectClass = other.objectClass;
164
        this.precision = other.precision;
165
        this.evaluator = other.evaluator;
166
        this.primaryKey = other.primaryKey;
167
        this.readOnly = other.readOnly;
168
        this.SRS = other.SRS;
169
        this.geometryType = other.geometryType;
170
        this.geometrySubType = other.geometrySubType;
171
        this.geomType = other.geomType;
172
        if (other.additionalInfo != null) {
173
            Iterator iter = other.additionalInfo.entrySet().iterator();
174
            Map.Entry entry;
175
            this.additionalInfo = new HashMap();
176
            while (iter.hasNext()) {
177
                entry = (Entry) iter.next();
178
                this.additionalInfo.put(entry.getKey(), entry.getValue());
179
            }
180
        } else {
181
            this.additionalInfo = null;
182
        }
183
        this.isAutomatic = other.isAutomatic;
184 41335 jjdelcerro
        this.isTime = other.isTime;
185
        this.featureAttributeEmulator = other.featureAttributeEmulator;
186 41638 jjdelcerro
        this.indexed = other.indexed;
187
        this.isIndexAscending = other.isIndexAscending;
188
        this.allowIndexDuplicateds = other.allowIndexDuplicateds;
189 43362 jjdelcerro
        this.hidden = other.hidden;
190 40435 jjdelcerro
    }
191 42775 jjdelcerro
192 42561 jjdelcerro
    @Override
193 40435 jjdelcerro
    public String getDataTypeName() {
194 42561 jjdelcerro
        if (this.getDataType() == null) {
195 40435 jjdelcerro
            return "(unknow)";
196
        }
197 42561 jjdelcerro
        return this.getDataType().getName();
198 40435 jjdelcerro
    }
199
200 42561 jjdelcerro
    @Override
201 40435 jjdelcerro
    public FeatureAttributeDescriptor getCopy() {
202
        return new DefaultFeatureAttributeDescriptor(this);
203
    }
204
205 42561 jjdelcerro
    @Override
206 42775 jjdelcerro
    public Object clone() throws CloneNotSupportedException {
207
        return new DefaultFeatureAttributeDescriptor(this);
208
    }
209
210
    @Override
211 40435 jjdelcerro
    public boolean allowNull() {
212
        return allowNull;
213
    }
214
215 42561 jjdelcerro
    @Override
216 40435 jjdelcerro
    public DataType getDataType() {
217 42561 jjdelcerro
        if (featureAttributeGetter != null) {
218
            return featureAttributeGetter.getDataType();
219
        }
220 40435 jjdelcerro
        return this.dataType;
221
    }
222
223 43954 jjdelcerro
    public FeatureAttributeDescriptor setDataType(int type) {
224
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
225
        return this;
226
    }
227
228 42561 jjdelcerro
    @Override
229 40435 jjdelcerro
    public DateFormat getDateFormat() {
230
        return this.dateFormat;
231
    }
232
233 42561 jjdelcerro
    @Override
234 40435 jjdelcerro
    public Object getDefaultValue() {
235
        return this.defaultValue;
236
    }
237
238 42561 jjdelcerro
    @Override
239 40435 jjdelcerro
    public Evaluator getEvaluator() {
240
        return this.evaluator;
241
    }
242
243 42561 jjdelcerro
    @Override
244 40435 jjdelcerro
    public int getGeometryType() {
245
        return this.geometryType;
246
    }
247
248 42561 jjdelcerro
    @Override
249 40435 jjdelcerro
    public int getGeometrySubType() {
250
        return this.geometrySubType;
251
    }
252
253 42561 jjdelcerro
    @Override
254 40435 jjdelcerro
    public GeometryType getGeomType() {
255
        if (this.geomType == null) {
256
            try {
257 42561 jjdelcerro
                this.geomType
258
                        = GeometryLocator.getGeometryManager().getGeometryType(
259
                                this.geometryType, this.geometrySubType);
260 40435 jjdelcerro
            } catch (GeometryException e) {
261
                throw new RuntimeException(
262 42561 jjdelcerro
                        "Error getting geometry type with type = "
263 40435 jjdelcerro
                        + this.geometryType + ", subtype = "
264
                        + this.geometrySubType, e);
265
            }
266
        }
267
        return this.geomType;
268
    }
269
270 42561 jjdelcerro
    @Override
271 40435 jjdelcerro
    public int getIndex() {
272
        return this.index;
273
    }
274
275
    protected FeatureAttributeDescriptor setIndex(int index) {
276
        this.index = index;
277
        return this;
278
    }
279
280 42561 jjdelcerro
    @Override
281 40435 jjdelcerro
    public int getMaximumOccurrences() {
282
        return this.maximumOccurrences;
283
    }
284
285 42561 jjdelcerro
    @Override
286 40435 jjdelcerro
    public int getMinimumOccurrences() {
287
        return this.minimumOccurrences;
288
    }
289
290 42561 jjdelcerro
    @Override
291 40435 jjdelcerro
    public String getName() {
292
        return this.name;
293
    }
294 43954 jjdelcerro
295
    public FeatureAttributeDescriptor setName(String name) {
296
        this.name = name;
297
        return this;
298
    }
299
300 42561 jjdelcerro
    @Override
301 40435 jjdelcerro
    public Class getObjectClass() {
302 42561 jjdelcerro
        if (getDataType().getType() == DataTypes.OBJECT) {
303 40435 jjdelcerro
            return objectClass;
304
        }
305 42561 jjdelcerro
        return getDataType().getDefaultClass();
306 40435 jjdelcerro
    }
307
308 42561 jjdelcerro
    @Override
309 40435 jjdelcerro
    public int getPrecision() {
310
        return this.precision;
311
    }
312
313 42561 jjdelcerro
    @Override
314 40435 jjdelcerro
    public IProjection getSRS() {
315
        return this.SRS;
316
    }
317
318 44022 jjdelcerro
    public IProjection getSRS(WeakReference storeRef) {
319
        if( this.SRS==null ) {
320
            FeatureStore store = (FeatureStore) storeRef.get();
321
            this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
322
        }
323
        return this.SRS;
324
    }
325
326
327 42561 jjdelcerro
    @Override
328 40435 jjdelcerro
    public int getSize() {
329
        return this.size;
330
    }
331
332 42561 jjdelcerro
    @Override
333 40435 jjdelcerro
    public boolean isPrimaryKey() {
334
        return this.primaryKey;
335
    }
336
337 42561 jjdelcerro
    @Override
338 40435 jjdelcerro
    public boolean isReadOnly() {
339 42561 jjdelcerro
        if (this.readOnly) {
340 41335 jjdelcerro
            return true;
341
        }
342 42561 jjdelcerro
        if (this.getEvaluator() != null) {
343 41335 jjdelcerro
            return true;
344
        }
345 42561 jjdelcerro
        if (this.featureAttributeEmulator != null) {
346 41335 jjdelcerro
            return !this.featureAttributeEmulator.allowSetting();
347
        }
348
        return false;
349 40435 jjdelcerro
    }
350
351 42561 jjdelcerro
    @Override
352 40435 jjdelcerro
    public Object getAdditionalInfo(String infoName) {
353
        if (this.additionalInfo == null) {
354
            return null;
355
        }
356
        return this.additionalInfo.get(infoName);
357
    }
358
359 42561 jjdelcerro
    @Override
360 40435 jjdelcerro
    public boolean isAutomatic() {
361
        return this.isAutomatic;
362
    }
363
364
    private boolean compareObject(Object a, Object b) {
365
        if (a != b) {
366
            if (a == null) {
367
                return false;
368
            }
369
            return a.equals(b);
370
        }
371
        return true;
372
373
    }
374
375 42561 jjdelcerro
    @Override
376 40435 jjdelcerro
    public boolean equals(Object obj) {
377
        if (this == obj) {
378
            return true;
379
        }
380
        if (!(obj instanceof DefaultFeatureAttributeDescriptor)) {
381
            return false;
382
        }
383 42561 jjdelcerro
        DefaultFeatureAttributeDescriptor other
384
                = (DefaultFeatureAttributeDescriptor) obj;
385 40435 jjdelcerro
386
        if (this.allowNull != other.allowNull) {
387
            return false;
388
        }
389
390
        if (this.index != other.index) {
391
            return false;
392
        }
393
394
        if (!compareObject(this.name, other.name)) {
395
            return false;
396
        }
397
398 42561 jjdelcerro
        if (this.getDataType() != other.getDataType()) {
399 40435 jjdelcerro
            return false;
400
        }
401
402
        if (this.size != other.size) {
403
            return false;
404
        }
405
406
        if (!compareObject(this.defaultValue, other.defaultValue)) {
407
            return false;
408
        }
409
410
        if (!compareObject(this.defaultValue, other.defaultValue)) {
411
            return false;
412
        }
413
414
        if (this.primaryKey != other.primaryKey) {
415
            return false;
416
        }
417
418
        if (this.isAutomatic != other.isAutomatic) {
419
            return false;
420
        }
421
422
        if (this.readOnly != other.readOnly) {
423
            return false;
424
        }
425
426
        if (this.precision != other.precision) {
427
            return false;
428
        }
429
430
        if (this.maximumOccurrences != other.maximumOccurrences) {
431
            return false;
432
        }
433
434
        if (this.minimumOccurrences != other.minimumOccurrences) {
435
            return false;
436
        }
437
438
        if (this.geometryType != other.geometryType) {
439
            return false;
440
        }
441
442
        if (this.geometrySubType != other.geometrySubType) {
443
            return false;
444
        }
445
446
        if (!compareObject(this.evaluator, other.evaluator)) {
447
            return false;
448
        }
449
450
        if (!compareObject(this.SRS, other.SRS)) {
451
            return false;
452
        }
453
454
        if (!compareObject(this.dateFormat, other.dateFormat)) {
455
            return false;
456
        }
457
458
        if (!compareObject(this.objectClass, other.objectClass)) {
459
            return false;
460
        }
461
462
        return true;
463
    }
464
465 42561 jjdelcerro
    @Override
466 40435 jjdelcerro
    public void loadFromState(PersistentState state)
467 42561 jjdelcerro
            throws PersistenceException {
468 40435 jjdelcerro
        allowNull = state.getBoolean("allowNull");
469 42561 jjdelcerro
        dataType
470
                = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
471 40435 jjdelcerro
        // FIXME how persist dateFormat ???
472
        // dateFormat;
473
        defaultValue = state.get("defaultValue");
474
475
        index = state.getInt("index");
476
        maximumOccurrences = state.getInt("maximumOccurrences");
477
        minimumOccurrences = state.getInt("minimumOccurrences");
478
        size = state.getInt("size");
479
        name = state.getString("name");
480
        try {
481
            objectClass = Class.forName(state.getString("objectClass"));
482
        } catch (ClassNotFoundException e) {
483
            throw new PersistenceException(e);
484
        }
485
        precision = state.getInt("precision");
486
        evaluator = (Evaluator) state.get("evaluator");
487
        primaryKey = state.getBoolean("primaryKey");
488
        readOnly = state.getBoolean("readOnly");
489
        String srsId = state.getString("srsId");
490
        if (srsId != null) {
491
            SRS = CRSFactory.getCRS(srsId);
492
        }
493
        geometryType = state.getInt("geometryType");
494
        geometrySubType = state.getInt("geometrySubType");
495
        additionalInfo = (Map) state.get("aditionalInfo");
496
        isAutomatic = state.getBoolean("isAutomatic");
497
    }
498
499 42561 jjdelcerro
    @Override
500 40435 jjdelcerro
    public void saveToState(PersistentState state) throws PersistenceException {
501
        state.set("allowNull", allowNull);
502
        state.set("dataType", dataType);
503
        // FIXME how persist dateFormat ???
504
        // dateFormat;
505
506
        defaultValue = state.get("defaultValue");
507
508
        index = state.getInt("index");
509
        maximumOccurrences = state.getInt("maximumOccurrences");
510
        minimumOccurrences = state.getInt("minimumOccurrences");
511
        size = state.getInt("size");
512
        name = state.getString("name");
513
        try {
514
            objectClass = Class.forName(state.getString("objectClass"));
515
        } catch (ClassNotFoundException e) {
516
            throw new PersistenceException(e);
517
        }
518
        precision = state.getInt("precision");
519
        evaluator = (Evaluator) state.get("evaluator");
520
        primaryKey = state.getBoolean("primaryKey");
521
        readOnly = state.getBoolean("readOnly");
522
        String srsId = state.getString("srsId");
523
        if (srsId != null) {
524
            SRS = CRSFactory.getCRS(srsId);
525
        }
526
        geometryType = state.getInt("geometryType");
527
        geometrySubType = state.getInt("geometrySubType");
528
        additionalInfo = (Map) state.get("aditionalInfo");
529
        isAutomatic = state.getBoolean("isAutomatic");
530
    }
531
532 42563 jjdelcerro
    /*
533 40435 jjdelcerro
     * Start of DynField interface Implementation
534 42561 jjdelcerro
     *
535 40435 jjdelcerro
     */
536 42634 fdiaz
537 43739 jjdelcerro
    @Override
538 42563 jjdelcerro
    public Tags getTags() {
539
        return tags;
540
    }
541 42634 fdiaz
542 42561 jjdelcerro
    @Override
543 40435 jjdelcerro
    public DynObjectValueItem[] getAvailableValues() {
544 42563 jjdelcerro
        return this.availableValues;
545 40435 jjdelcerro
    }
546
547 42561 jjdelcerro
    @Override
548 40435 jjdelcerro
    public String getDescription() {
549 42563 jjdelcerro
        if( this.description == null ) {
550
            return getName();
551
        }
552
        return this.description;
553 40435 jjdelcerro
    }
554
555 42561 jjdelcerro
    @Override
556 40435 jjdelcerro
    public Object getMaxValue() {
557 42563 jjdelcerro
        return this.maxValue;
558 40435 jjdelcerro
    }
559
560 42561 jjdelcerro
    @Override
561 40435 jjdelcerro
    public Object getMinValue() {
562 42563 jjdelcerro
        return this.minValue;
563 40435 jjdelcerro
    }
564
565 42561 jjdelcerro
    @Override
566 40435 jjdelcerro
    public int getTheTypeOfAvailableValues() {
567 42563 jjdelcerro
        return 1;
568 40435 jjdelcerro
    }
569
570 42561 jjdelcerro
    @Override
571 40435 jjdelcerro
    public int getType() {
572 42561 jjdelcerro
        if (featureAttributeGetter != null) {
573 40435 jjdelcerro
            return featureAttributeGetter.getDataType().getType();
574
        }
575
        return getDataType().getType();
576
    }
577
578 42561 jjdelcerro
    @Override
579 40435 jjdelcerro
    public boolean isMandatory() {
580
        return !allowNull() || isPrimaryKey();
581
    }
582
583 42561 jjdelcerro
    @Override
584 40435 jjdelcerro
    public boolean isPersistent() {
585
        return false;
586
    }
587
588 42561 jjdelcerro
    @Override
589 40435 jjdelcerro
    public DynField setAvailableValues(DynObjectValueItem[] values) {
590 42563 jjdelcerro
        if ( ArrayUtils.isEmpty(values) ) {
591
            this.availableValues = null;
592
        } else {
593
            this.availableValues = values;
594
        }
595
        return this;
596 40435 jjdelcerro
    }
597
598 42561 jjdelcerro
    @Override
599 40435 jjdelcerro
    public DynField setDescription(String description) {
600 42563 jjdelcerro
        this.description = description;
601
        return this;
602 40435 jjdelcerro
    }
603
604 42561 jjdelcerro
    @Override
605 40435 jjdelcerro
    public DynField setMandatory(boolean mandatory) {
606
        throw new UnsupportedOperationException();
607
    }
608
609 42561 jjdelcerro
    @Override
610 40435 jjdelcerro
    public DynField setMaxValue(Object maxValue) {
611 42563 jjdelcerro
        try {
612
            this.maxValue = this.coerce(maxValue);
613
        } catch (CoercionException e) {
614
            throw new IllegalArgumentException(e);
615
        }
616
        return this;
617 40435 jjdelcerro
    }
618
619 42561 jjdelcerro
    @Override
620 40435 jjdelcerro
    public DynField setMinValue(Object minValue) {
621 42563 jjdelcerro
        try {
622
            this.maxValue = this.coerce(minValue);
623
        } catch (CoercionException e) {
624
            throw new IllegalArgumentException(e);
625
        }
626
        return this;
627 40435 jjdelcerro
    }
628
629 42561 jjdelcerro
    @Override
630 40435 jjdelcerro
    public DynField setPersistent(boolean persistent) {
631
        throw new UnsupportedOperationException();
632
    }
633
634 42561 jjdelcerro
    @Override
635 40435 jjdelcerro
    public DynField setTheTypeOfAvailableValues(int type) {
636
        throw new UnsupportedOperationException();
637
    }
638
639 42561 jjdelcerro
    @Override
640 40435 jjdelcerro
    public DynField setType(int type) {
641
        throw new UnsupportedOperationException();
642
    }
643
644 42561 jjdelcerro
    @Override
645 40435 jjdelcerro
    public DynField setDefaultDynValue(Object defaultValue) {
646
        throw new UnsupportedOperationException();
647
    }
648
649 42561 jjdelcerro
    @Override
650 40435 jjdelcerro
    public Class getClassOfValue() {
651
        return null;
652
    }
653
654 42561 jjdelcerro
    @Override
655 40435 jjdelcerro
    public DynField getElementsType() {
656
        return null;
657
    }
658
659 42561 jjdelcerro
    @Override
660 40435 jjdelcerro
    public DynField setClassOfValue(Class theClass)
661 42561 jjdelcerro
            throws DynFieldIsNotAContainerException {
662 40435 jjdelcerro
        throw new UnsupportedOperationException();
663
    }
664
665 42561 jjdelcerro
    @Override
666 40435 jjdelcerro
    public DynField setElementsType(DynStruct type)
667 42561 jjdelcerro
            throws DynFieldIsNotAContainerException {
668 40435 jjdelcerro
        throw new UnsupportedOperationException();
669
    }
670
671 42561 jjdelcerro
    @Override
672 40435 jjdelcerro
    public DynField setElementsType(int type)
673 42561 jjdelcerro
            throws DynFieldIsNotAContainerException {
674 40435 jjdelcerro
        throw new UnsupportedOperationException();
675
    }
676
677 42561 jjdelcerro
    @Override
678 40435 jjdelcerro
    public DynField setSubtype(String subtype) {
679
        throw new UnsupportedOperationException();
680
    }
681
682 42561 jjdelcerro
    @Override
683 40435 jjdelcerro
    public void validate(Object value) throws DynFieldValidateException {
684 42561 jjdelcerro
685 40435 jjdelcerro
        if (value == null && !this.allowNull()) {
686
            throw new DynFieldValidateException(value, this, null);
687
        }
688 42561 jjdelcerro
689 40435 jjdelcerro
        try {
690
            this.dataType.coerce(value);
691
        } catch (CoercionException e) {
692
            throw new DynFieldValidateException(value, this, e);
693
        }
694 42561 jjdelcerro
695 40435 jjdelcerro
        /*
696
         * Other checks will be needed
697
         */
698
    }
699
700 42561 jjdelcerro
    @Override
701 40435 jjdelcerro
    public String getSubtype() {
702 42561 jjdelcerro
        if (featureAttributeGetter != null) {
703 40435 jjdelcerro
            return featureAttributeGetter.getDataType().getSubtype();
704 42561 jjdelcerro
        }
705 40435 jjdelcerro
        return this.dataType.getSubtype();
706
    }
707
708 42561 jjdelcerro
    @Override
709 42563 jjdelcerro
    public Object coerce(Object value) throws CoercionException {
710
        if ( value == null ) {
711
            return value; // O debe devolver this.defaultValue
712
        }
713
        try {
714
            return this.getDataType().coerce(value);
715
        } catch(Exception ex){
716
            throw new RuntimeException(ex);
717
        }
718 40435 jjdelcerro
    }
719
720 42561 jjdelcerro
    @Override
721 40435 jjdelcerro
    public DynField setAvailableValues(List values) {
722 42563 jjdelcerro
        if (  values == null || values.isEmpty() ) {
723
            this.availableValues = null;
724
        } else {
725
            this.availableValues = (DynObjectValueItem[]) values.toArray(
726
                new DynObjectValueItem[values.size()]
727
            );
728
        }
729
        return this;
730 40435 jjdelcerro
    }
731
732 42561 jjdelcerro
    @Override
733 40435 jjdelcerro
    public String getGroup() {
734 42563 jjdelcerro
        return this.groupName;
735 40435 jjdelcerro
    }
736
737 42561 jjdelcerro
    @Override
738 40435 jjdelcerro
    public int getOder() {
739 42563 jjdelcerro
        return this.order;
740 40435 jjdelcerro
    }
741
742 42561 jjdelcerro
    @Override
743 41323 jjdelcerro
    public String getLabel() {
744 42563 jjdelcerro
        if( this.label == null ) {
745
            return this.getName();
746
        }
747
        return this.label;
748 41323 jjdelcerro
    }
749
750 42561 jjdelcerro
    @Override
751 41323 jjdelcerro
    public DynField setLabel(String label) {
752 42563 jjdelcerro
        this.label = label;
753
        return this;
754 41323 jjdelcerro
    }
755
756 42561 jjdelcerro
    @Override
757 40435 jjdelcerro
    public DynField setGroup(String groupName) {
758 42563 jjdelcerro
        this.groupName = groupName;
759
        return this;
760 40435 jjdelcerro
    }
761
762 42561 jjdelcerro
    @Override
763 40435 jjdelcerro
    public DynField setOrder(int order) {
764 42563 jjdelcerro
        this.order = order;
765
        return this;
766 40435 jjdelcerro
    }
767
768 42561 jjdelcerro
    @Override
769 40435 jjdelcerro
    public DynField setHidden(boolean hidden) {
770 42563 jjdelcerro
        this.hidden = hidden;
771
        return this;
772 40435 jjdelcerro
    }
773
774 42561 jjdelcerro
    @Override
775 40435 jjdelcerro
    public boolean isHidden() {
776 42563 jjdelcerro
        return this.hidden;
777 40435 jjdelcerro
    }
778
779 42561 jjdelcerro
    @Override
780 40435 jjdelcerro
    public DynField setReadOnly(boolean arg0) {
781
        throw new UnsupportedOperationException();
782
    }
783
784 42561 jjdelcerro
    @Override
785 40435 jjdelcerro
    public boolean isContainer() {
786
        return false;
787
    }
788
789 42561 jjdelcerro
    @Override
790 40435 jjdelcerro
    public Class getClassOfItems() {
791
        return null;
792
    }
793
794 42561 jjdelcerro
    @Override
795 40435 jjdelcerro
    public DynField setDefaultFieldValue(Object defaultValue) {
796
        throw new UnsupportedOperationException();
797
    }
798
799 42561 jjdelcerro
    @Override
800 40435 jjdelcerro
    public DynField setClassOfItems(Class theClass) {
801
        throw new UnsupportedOperationException();
802
    }
803
804 42561 jjdelcerro
    @Override
805 40435 jjdelcerro
    public DynField setType(DataType type) {
806
        throw new UnsupportedOperationException();
807
    }
808
809 42561 jjdelcerro
    @Override
810
    public boolean isTime() {
811
        return isTime;
812
    }
813 40435 jjdelcerro
814 42561 jjdelcerro
    @Override
815 40435 jjdelcerro
    public FeatureAttributeGetter getFeatureAttributeGetter() {
816 42561 jjdelcerro
        return featureAttributeGetter;
817 40435 jjdelcerro
    }
818
819 42561 jjdelcerro
    @Override
820 40435 jjdelcerro
    public void setFeatureAttributeGetter(
821 42561 jjdelcerro
            FeatureAttributeGetter featureAttributeTransform) {
822
        this.featureAttributeGetter = featureAttributeTransform;
823
    }
824 41335 jjdelcerro
825 42561 jjdelcerro
    @Override
826 41335 jjdelcerro
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
827
        return this.featureAttributeEmulator;
828
    }
829
830 43954 jjdelcerro
    public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
831
        this.featureAttributeEmulator = featureAttributeEmulator;
832
        return this;
833
    }
834
835 42561 jjdelcerro
    @Override
836 41638 jjdelcerro
    public boolean isIndexed() {
837
        return this.indexed;
838
    }
839
840 42561 jjdelcerro
    @Override
841 41638 jjdelcerro
    public boolean allowIndexDuplicateds() {
842
        return this.allowIndexDuplicateds;
843
    }
844
845 42561 jjdelcerro
    @Override
846 41638 jjdelcerro
    public boolean isIndexAscending() {
847
        return this.isIndexAscending;
848
    }
849
850 42563 jjdelcerro
    @Override
851
    public DynField setClassOfValue(DynStruct dynStrct) {
852
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
853
    }
854
855
    @Override
856
    public DynField setClassOfValue(String theClassNameOfValue) {
857
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
858
    }
859
860
    @Override
861
    public String getClassNameOfValue() {
862 42634 fdiaz
        return null;
863 42563 jjdelcerro
    }
864
865
    @Override
866
    public DynStruct getDynClassOfValue() {
867 42634 fdiaz
        return null;
868 42563 jjdelcerro
    }
869
870
    @Override
871
    public DynField setTypeOfItems(int type) {
872
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
873
    }
874
875
    @Override
876
    public int getTypeOfItems() {
877 42634 fdiaz
        return DataTypes.INVALID;
878 42563 jjdelcerro
    }
879
880
    @Override
881
    public DynField setClassOfItems(DynStruct dynStrct) {
882
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
883
    }
884
885
    @Override
886
    public DynField setClassOfItems(String theClassNameOfValue) {
887
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
888
    }
889
890
    @Override
891
    public String getClassNameOfItems() {
892 42634 fdiaz
        return null;
893 42563 jjdelcerro
    }
894
895
    @Override
896
    public DynStruct getDynClassOfItems() {
897 42634 fdiaz
        return null;
898 42563 jjdelcerro
    }
899
900
    @Override
901
    public DynField setRelationType(int relationType) {
902
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
903
    }
904
905
    @Override
906
    public int getRelationType() {
907
        return RELATION_TYPE_NONE;
908
    }
909
910 42606 jjdelcerro
    @Override
911 42775 jjdelcerro
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
912
        this.availableValuesMethod = availableValuesMethod;
913
        return this;
914 42606 jjdelcerro
    }
915
916
    @Override
917 42775 jjdelcerro
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
918
        if( this.availableValuesMethod != null ) {
919
            DynObjectValueItem[] values;
920
            try {
921
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
922
            } catch (DynMethodException ex) {
923
                return this.availableValues;
924
            }
925 42606 jjdelcerro
            if( values != null ) {
926
                return values;
927
            }
928
        }
929
        return this.availableValues;
930
    }
931
932 42775 jjdelcerro
    @Override
933
    public DynMethod getAvailableValuesMethod() {
934
        return this.availableValuesMethod;
935
    }
936
937
    @Override
938
    public boolean isAvailableValuesCalculated() {
939
        return this.availableValuesMethod!=null;
940
    }
941
942
    @Override
943
    public DynMethod getCalculateMethod() {
944
        return this.calculateMethod;
945
    }
946
947
    @Override
948
    public DynField setCalculateMethod(DynMethod method) {
949
        this.calculateMethod = method;
950
        return this;
951
    }
952
953
    @Override
954
    public boolean isCalculated() {
955
        return this.calculateMethod != null;
956
    }
957
958
    @Override
959
    public Object getCalculatedValue(DynObject self) {
960
        try {
961
            return this.calculateMethod.invoke(self, new Object[] { this });
962
        } catch (DynMethodException ex) {
963
            throw new RuntimeException(ex);
964
        }
965
    }
966
967
    @Override
968
    public DynField setValidateElements(boolean validate) {
969
        return this;
970
    }
971
972
    @Override
973
    public boolean getValidateElements() {
974
        return false;
975
    }
976
977 41212 jjdelcerro
    private class ConstantValueEvaluator extends AbstractEvaluator {
978 42561 jjdelcerro
979
        @Override
980 41212 jjdelcerro
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
981
            return defaultValue;
982
        }
983 42561 jjdelcerro
984
        @Override
985 41212 jjdelcerro
        public String getName() {
986 42561 jjdelcerro
            return "Constant attribute " + name;
987 41212 jjdelcerro
        }
988
    }
989 41335 jjdelcerro
990 41212 jjdelcerro
    public void setConstantValue(boolean isConstantValue) {
991 42561 jjdelcerro
        if (isConstantValue) {
992 41212 jjdelcerro
            /* Cuando un attributo tiene asociado un evaluador, este se interpreta
993 42634 fdiaz
             * como que no debe cargarse de la fuente de datos subyacente, siendo
994 41212 jjdelcerro
             * el evaluador el que se encarga de proporcionar su valor.
995
             * Nos limitamos a asignar un evaluador que retorna simpre el valor
996
             * por defecto para ese attributo.
997
             */
998
            this.evaluator = new ConstantValueEvaluator();
999
        } else {
1000
            this.evaluator = null;
1001
        }
1002
    }
1003 42561 jjdelcerro
1004 43739 jjdelcerro
    @Override
1005 43135 jjdelcerro
    public boolean isComputed() {
1006
        return featureAttributeEmulator!=null || evaluator!=null;
1007
    }
1008 43739 jjdelcerro
1009
    @Override
1010
    public FeatureStore getStore() {
1011
        FeatureType ftype = this.getFeatureType();
1012
        if( ftype == null ) {
1013
            return null;
1014
        }
1015
        return ftype.getStore();
1016
    }
1017
1018
    @Override
1019
    public FeatureType getFeatureType() {
1020
        if( this.typeRef==null ) {
1021
            return null;
1022
        }
1023
        return (FeatureType) this.typeRef.get();
1024
    }
1025 40435 jjdelcerro
}