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

History | View | Annotate | Download (40.5 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 44128 jjdelcerro
import java.util.Objects;
33 42563 jjdelcerro
import org.apache.commons.lang3.ArrayUtils;
34 44190 jjdelcerro
import org.apache.commons.lang3.StringUtils;
35 40435 jjdelcerro
import org.cresques.cts.IProjection;
36 44022 jjdelcerro
import org.gvsig.fmap.dal.DataStore;
37 44083 jjdelcerro
import org.gvsig.fmap.dal.DataTypes;
38 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
39 42563 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
40 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeGetter;
41 43739 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
42
import org.gvsig.fmap.dal.feature.FeatureType;
43 44262 jjdelcerro
import org.gvsig.fmap.dal.feature.ForeingKey;
44 40435 jjdelcerro
import org.gvsig.fmap.geom.Geometry;
45
import org.gvsig.fmap.geom.GeometryException;
46
import org.gvsig.fmap.geom.GeometryLocator;
47 44190 jjdelcerro
import org.gvsig.fmap.geom.GeometryUtils;
48 40435 jjdelcerro
import org.gvsig.fmap.geom.type.GeometryType;
49 44077 jjdelcerro
import org.gvsig.timesupport.Interval;
50 44190 jjdelcerro
import org.gvsig.timesupport.RelativeInterval;
51 44077 jjdelcerro
import org.gvsig.timesupport.TimeSupportLocator;
52 40435 jjdelcerro
import org.gvsig.tools.ToolsLocator;
53
import org.gvsig.tools.dataTypes.CoercionException;
54
import org.gvsig.tools.dataTypes.DataType;
55
import org.gvsig.tools.dynobject.DynField;
56 41323 jjdelcerro
import org.gvsig.tools.dynobject.DynField_LabelAttribute;
57 42563 jjdelcerro
import org.gvsig.tools.dynobject.DynField_v2;
58 42775 jjdelcerro
import org.gvsig.tools.dynobject.DynMethod;
59 42606 jjdelcerro
import org.gvsig.tools.dynobject.DynObject;
60 40435 jjdelcerro
import org.gvsig.tools.dynobject.DynObjectValueItem;
61
import org.gvsig.tools.dynobject.DynStruct;
62 42563 jjdelcerro
import org.gvsig.tools.dynobject.Tags;
63 40435 jjdelcerro
import org.gvsig.tools.dynobject.exception.DynFieldIsNotAContainerException;
64
import org.gvsig.tools.dynobject.exception.DynFieldValidateException;
65 42775 jjdelcerro
import org.gvsig.tools.dynobject.exception.DynMethodException;
66 42563 jjdelcerro
import org.gvsig.tools.dynobject.impl.DefaultTags;
67 41212 jjdelcerro
import org.gvsig.tools.evaluator.AbstractEvaluator;
68 40435 jjdelcerro
import org.gvsig.tools.evaluator.Evaluator;
69 41212 jjdelcerro
import org.gvsig.tools.evaluator.EvaluatorData;
70
import org.gvsig.tools.evaluator.EvaluatorException;
71 44338 jjdelcerro
import org.gvsig.tools.i18n.I18nManager;
72 44190 jjdelcerro
import org.gvsig.tools.persistence.PersistenceManager;
73 40435 jjdelcerro
import org.gvsig.tools.persistence.Persistent;
74
import org.gvsig.tools.persistence.PersistentState;
75
import org.gvsig.tools.persistence.exception.PersistenceException;
76 44190 jjdelcerro
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
78 40435 jjdelcerro
79 44259 jjdelcerro
@SuppressWarnings("UseSpecificCatch")
80 40435 jjdelcerro
public class DefaultFeatureAttributeDescriptor implements
81 42563 jjdelcerro
        FeatureAttributeDescriptor, Persistent, DynField_v2, DynField_LabelAttribute {
82 40435 jjdelcerro
83 44190 jjdelcerro
    protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureAttributeDescriptor.class);
84
85 40435 jjdelcerro
    protected boolean allowNull;
86
    protected DataType dataType;
87 44128 jjdelcerro
    protected String dataProfile;
88 40435 jjdelcerro
    protected DateFormat dateFormat;
89
    protected Object defaultValue;
90
    protected int index;
91
    protected int maximumOccurrences;
92
    protected int minimumOccurrences;
93
    protected int size;
94
    protected String name;
95
    protected Class objectClass;
96
    protected int precision;
97
    protected Evaluator evaluator;
98
    protected boolean primaryKey;
99
    protected boolean readOnly;
100
    protected IProjection SRS;
101
    protected GeometryType geomType;
102
    protected int geometryType;
103
    protected int geometrySubType;
104
    protected Map additionalInfo;
105
    protected boolean isAutomatic;
106 41335 jjdelcerro
    protected boolean isTime = false;
107 44077 jjdelcerro
    protected Interval interval;
108 41335 jjdelcerro
    protected FeatureAttributeGetter featureAttributeGetter = null;
109
    protected FeatureAttributeEmulator featureAttributeEmulator = null;
110 41638 jjdelcerro
    protected boolean indexed = false;
111
    protected boolean isIndexAscending = true;
112
    protected boolean allowIndexDuplicateds = true;
113 40435 jjdelcerro
114 42563 jjdelcerro
    protected DynObjectValueItem[] availableValues;
115
    protected String description;
116
    protected Object minValue;
117
    protected Object maxValue;
118
    protected String label;
119 44337 jjdelcerro
    protected String shortLabel;
120 42563 jjdelcerro
    protected int order;
121
    protected boolean hidden;
122
    protected String groupName;
123
    protected Tags tags = new DefaultTags();
124 42775 jjdelcerro
    private DynMethod availableValuesMethod;
125
    private DynMethod calculateMethod;
126 43739 jjdelcerro
    private WeakReference typeRef;
127 44262 jjdelcerro
    protected DefaultForeingKey foreingKey = null;
128 44253 jjdelcerro
129
    private int relationType = RELATION_TYPE_NONE;
130 42563 jjdelcerro
131 44190 jjdelcerro
    public DefaultFeatureAttributeDescriptor() {
132
        // Usada en la persistencia
133
    }
134
135 43739 jjdelcerro
    protected DefaultFeatureAttributeDescriptor(FeatureType type) {
136 44259 jjdelcerro
        this();
137
//        LOGGER.info(String.format("Created FeatureAttributeDescriptor [%08x].", this.hashCode()));
138 44190 jjdelcerro
        setFeatureType(type);
139 40435 jjdelcerro
        this.allowNull = true;
140
        this.dataType = null;
141
        this.dateFormat = null;
142
        this.defaultValue = null;
143
        this.index = -1;
144
        this.maximumOccurrences = 0;
145
        this.minimumOccurrences = 0;
146
        this.size = 0;
147
        this.name = null;
148
        this.objectClass = null;
149
        this.precision = 0;
150
        this.evaluator = null;
151
        this.primaryKey = false;
152
        this.readOnly = false;
153
        this.SRS = null;
154
        this.geometryType = Geometry.TYPES.NULL;
155
        this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
156
        this.additionalInfo = null;
157
        this.isAutomatic = false;
158 43362 jjdelcerro
        this.hidden = false;
159 44253 jjdelcerro
        this.relationType = RELATION_TYPE_NONE;
160 40435 jjdelcerro
    }
161
162
    protected DefaultFeatureAttributeDescriptor(
163 43739 jjdelcerro
            DefaultFeatureAttributeDescriptor other
164
        ) {
165 44259 jjdelcerro
        this();
166 42775 jjdelcerro
        copyFrom(other);
167 44259 jjdelcerro
//        LOGGER.info(String.format("Created FeatureAttributeDescriptor [%08x] [%s] (copy).", this.hashCode(), this.name));
168 42775 jjdelcerro
    }
169
170
    @Override
171
    public void copyFrom(DynField other1) {
172
        if( !(other1 instanceof DefaultFeatureAttributeDescriptor) ) {
173
            throw new IllegalArgumentException("Can't copy from a non DefaultFeatureAttributeDescriptor");
174
        }
175
        DefaultFeatureAttributeDescriptor other = (DefaultFeatureAttributeDescriptor) other1;
176 43739 jjdelcerro
        this.typeRef = other.typeRef;
177 40435 jjdelcerro
        this.allowNull = other.allowNull;
178
        this.dataType = other.dataType;
179
        this.dateFormat = other.dateFormat;
180
        this.defaultValue = other.defaultValue;
181
        this.index = other.index;
182
        this.maximumOccurrences = other.maximumOccurrences;
183
        this.minimumOccurrences = other.minimumOccurrences;
184
        this.size = other.size;
185
        this.name = other.name;
186
        this.objectClass = other.objectClass;
187
        this.precision = other.precision;
188
        this.evaluator = other.evaluator;
189
        this.primaryKey = other.primaryKey;
190
        this.readOnly = other.readOnly;
191
        this.SRS = other.SRS;
192
        this.geometryType = other.geometryType;
193
        this.geometrySubType = other.geometrySubType;
194
        this.geomType = other.geomType;
195
        if (other.additionalInfo != null) {
196
            Iterator iter = other.additionalInfo.entrySet().iterator();
197
            Map.Entry entry;
198
            this.additionalInfo = new HashMap();
199
            while (iter.hasNext()) {
200
                entry = (Entry) iter.next();
201
                this.additionalInfo.put(entry.getKey(), entry.getValue());
202
            }
203
        } else {
204
            this.additionalInfo = null;
205
        }
206
        this.isAutomatic = other.isAutomatic;
207 41335 jjdelcerro
        this.isTime = other.isTime;
208
        this.featureAttributeEmulator = other.featureAttributeEmulator;
209 41638 jjdelcerro
        this.indexed = other.indexed;
210
        this.isIndexAscending = other.isIndexAscending;
211
        this.allowIndexDuplicateds = other.allowIndexDuplicateds;
212 43362 jjdelcerro
        this.hidden = other.hidden;
213 44188 jjdelcerro
        this.dataProfile = other.dataProfile;
214 44202 jjdelcerro
215
        this.availableValues = other.availableValues;
216
        this.description = other.description;
217
        this.minValue = other.minValue;
218
        this.maxValue = other.maxValue;
219
        this.label = other.label;
220
        this.order = other.order;
221
        this.groupName = other.groupName;
222
        if( other.tags==null ) {
223
            this.tags = null;
224
        } else {
225
            try {
226
                this.tags = (Tags) other.tags.clone();
227
            } catch (Exception ex) {
228
            }
229
        }
230 44262 jjdelcerro
        this.foreingKey = null;
231
        if( other.foreingKey!=null ) {
232
            try {
233
                this.foreingKey = (DefaultForeingKey) other.foreingKey.clone();
234
            } catch (CloneNotSupportedException ex) {
235
            }
236
        }
237
        if( this.foreingKey!=null ) {
238
            this.foreingKey.setDescriptor(this);
239
        }
240
241 44202 jjdelcerro
        // TODO: ? Habria que clonarlos ?
242
        this.availableValuesMethod = other.availableValuesMethod;
243
        this.calculateMethod = other.calculateMethod;
244 44253 jjdelcerro
        this.relationType = other.relationType;
245 40435 jjdelcerro
    }
246 42775 jjdelcerro
247 44190 jjdelcerro
    public void setFeatureType(FeatureType type) {
248
        // Usada en la persistencia
249
        if( type == null ) {
250
            this.typeRef = null;
251
        } else {
252
            this.typeRef = new WeakReference(type);
253 44259 jjdelcerro
//            LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] set FeatureType [%08x], ref [%08x].", this.hashCode(), type.hashCode(), typeRef.hashCode()));
254 44190 jjdelcerro
        }
255
    }
256
257 42561 jjdelcerro
    @Override
258 40435 jjdelcerro
    public String getDataTypeName() {
259 42561 jjdelcerro
        if (this.getDataType() == null) {
260 40435 jjdelcerro
            return "(unknow)";
261
        }
262 42561 jjdelcerro
        return this.getDataType().getName();
263 40435 jjdelcerro
    }
264
265 42561 jjdelcerro
    @Override
266 44318 jjdelcerro
    public DefaultFeatureAttributeDescriptor getCopy() {
267 40435 jjdelcerro
        return new DefaultFeatureAttributeDescriptor(this);
268
    }
269
270 42561 jjdelcerro
    @Override
271 42775 jjdelcerro
    public Object clone() throws CloneNotSupportedException {
272
        return new DefaultFeatureAttributeDescriptor(this);
273
    }
274
275
    @Override
276 40435 jjdelcerro
    public boolean allowNull() {
277
        return allowNull;
278
    }
279
280 42561 jjdelcerro
    @Override
281 40435 jjdelcerro
    public DataType getDataType() {
282 42561 jjdelcerro
        if (featureAttributeGetter != null) {
283
            return featureAttributeGetter.getDataType();
284
        }
285 40435 jjdelcerro
        return this.dataType;
286
    }
287
288 43954 jjdelcerro
    public FeatureAttributeDescriptor setDataType(int type) {
289
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
290
        return this;
291
    }
292
293 42561 jjdelcerro
    @Override
294 40435 jjdelcerro
    public DateFormat getDateFormat() {
295
        return this.dateFormat;
296
    }
297
298 42561 jjdelcerro
    @Override
299 40435 jjdelcerro
    public Object getDefaultValue() {
300
        return this.defaultValue;
301
    }
302
303 42561 jjdelcerro
    @Override
304 40435 jjdelcerro
    public Evaluator getEvaluator() {
305
        return this.evaluator;
306
    }
307
308 42561 jjdelcerro
    @Override
309 40435 jjdelcerro
    public int getGeometryType() {
310 44083 jjdelcerro
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
311
            return Geometry.TYPES.UNKNOWN;
312
        }
313 40435 jjdelcerro
        return this.geometryType;
314
    }
315
316 42561 jjdelcerro
    @Override
317 40435 jjdelcerro
    public int getGeometrySubType() {
318 44083 jjdelcerro
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
319
            return Geometry.SUBTYPES.UNKNOWN;
320
        }
321 40435 jjdelcerro
        return this.geometrySubType;
322
    }
323
324 42561 jjdelcerro
    @Override
325 40435 jjdelcerro
    public GeometryType getGeomType() {
326 44083 jjdelcerro
        if( this.dataType.getType()!=DataTypes.GEOMETRY ) {
327
            return null;
328
        }
329 40435 jjdelcerro
        if (this.geomType == null) {
330
            try {
331 42561 jjdelcerro
                this.geomType
332
                        = GeometryLocator.getGeometryManager().getGeometryType(
333
                                this.geometryType, this.geometrySubType);
334 40435 jjdelcerro
            } catch (GeometryException e) {
335
                throw new RuntimeException(
336 42561 jjdelcerro
                        "Error getting geometry type with type = "
337 40435 jjdelcerro
                        + this.geometryType + ", subtype = "
338
                        + this.geometrySubType, e);
339
            }
340
        }
341
        return this.geomType;
342
    }
343
344 42561 jjdelcerro
    @Override
345 40435 jjdelcerro
    public int getIndex() {
346
        return this.index;
347
    }
348
349
    protected FeatureAttributeDescriptor setIndex(int index) {
350
        this.index = index;
351
        return this;
352
    }
353
354 42561 jjdelcerro
    @Override
355 40435 jjdelcerro
    public int getMaximumOccurrences() {
356
        return this.maximumOccurrences;
357
    }
358
359 42561 jjdelcerro
    @Override
360 40435 jjdelcerro
    public int getMinimumOccurrences() {
361
        return this.minimumOccurrences;
362
    }
363
364 42561 jjdelcerro
    @Override
365 40435 jjdelcerro
    public String getName() {
366
        return this.name;
367
    }
368 43954 jjdelcerro
369
    public FeatureAttributeDescriptor setName(String name) {
370 44259 jjdelcerro
//        LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] set name [%s].", this.hashCode(), name));
371 43954 jjdelcerro
        this.name = name;
372
        return this;
373
    }
374
375 42561 jjdelcerro
    @Override
376 40435 jjdelcerro
    public Class getObjectClass() {
377 42561 jjdelcerro
        if (getDataType().getType() == DataTypes.OBJECT) {
378 40435 jjdelcerro
            return objectClass;
379
        }
380 42561 jjdelcerro
        return getDataType().getDefaultClass();
381 40435 jjdelcerro
    }
382
383 42561 jjdelcerro
    @Override
384 40435 jjdelcerro
    public int getPrecision() {
385
        return this.precision;
386
    }
387
388 42561 jjdelcerro
    @Override
389 40435 jjdelcerro
    public IProjection getSRS() {
390
        return this.SRS;
391
    }
392
393 44077 jjdelcerro
    @Override
394
    public Interval getInterval() {
395
        return this.interval;
396
    }
397
398 44022 jjdelcerro
    public IProjection getSRS(WeakReference storeRef) {
399
        if( this.SRS==null ) {
400
            FeatureStore store = (FeatureStore) storeRef.get();
401
            this.SRS = (IProjection) store.getDynValue(DataStore.METADATA_CRS);
402
        }
403
        return this.SRS;
404
    }
405
406
407 42561 jjdelcerro
    @Override
408 40435 jjdelcerro
    public int getSize() {
409
        return this.size;
410
    }
411
412 42561 jjdelcerro
    @Override
413 40435 jjdelcerro
    public boolean isPrimaryKey() {
414
        return this.primaryKey;
415
    }
416
417 42561 jjdelcerro
    @Override
418 40435 jjdelcerro
    public boolean isReadOnly() {
419 42561 jjdelcerro
        if (this.readOnly) {
420 41335 jjdelcerro
            return true;
421
        }
422 42561 jjdelcerro
        if (this.getEvaluator() != null) {
423 41335 jjdelcerro
            return true;
424
        }
425 42561 jjdelcerro
        if (this.featureAttributeEmulator != null) {
426 41335 jjdelcerro
            return !this.featureAttributeEmulator.allowSetting();
427
        }
428
        return false;
429 40435 jjdelcerro
    }
430
431 42561 jjdelcerro
    @Override
432 40435 jjdelcerro
    public Object getAdditionalInfo(String infoName) {
433
        if (this.additionalInfo == null) {
434
            return null;
435
        }
436
        return this.additionalInfo.get(infoName);
437
    }
438
439 42561 jjdelcerro
    @Override
440 40435 jjdelcerro
    public boolean isAutomatic() {
441
        return this.isAutomatic;
442
    }
443
444 42561 jjdelcerro
    @Override
445 40435 jjdelcerro
    public boolean equals(Object obj) {
446
        if (this == obj) {
447
            return true;
448
        }
449
        if (!(obj instanceof DefaultFeatureAttributeDescriptor)) {
450
            return false;
451
        }
452 42561 jjdelcerro
        DefaultFeatureAttributeDescriptor other
453
                = (DefaultFeatureAttributeDescriptor) obj;
454 40435 jjdelcerro
455
        if (this.allowNull != other.allowNull) {
456
            return false;
457
        }
458
459
        if (this.index != other.index) {
460
            return false;
461
        }
462
463 44128 jjdelcerro
        if (!Objects.equals(this.name, other.name)) {
464 40435 jjdelcerro
            return false;
465
        }
466
467 42561 jjdelcerro
        if (this.getDataType() != other.getDataType()) {
468 40435 jjdelcerro
            return false;
469
        }
470
471
        if (this.size != other.size) {
472
            return false;
473
        }
474
475 44128 jjdelcerro
        if (!Objects.equals(this.defaultValue, other.defaultValue)) {
476 40435 jjdelcerro
            return false;
477
        }
478
479
        if (this.primaryKey != other.primaryKey) {
480
            return false;
481
        }
482
483
        if (this.isAutomatic != other.isAutomatic) {
484
            return false;
485
        }
486
487
        if (this.readOnly != other.readOnly) {
488
            return false;
489
        }
490
491
        if (this.precision != other.precision) {
492
            return false;
493
        }
494
495
        if (this.maximumOccurrences != other.maximumOccurrences) {
496
            return false;
497
        }
498
499
        if (this.minimumOccurrences != other.minimumOccurrences) {
500
            return false;
501
        }
502
503
        if (this.geometryType != other.geometryType) {
504
            return false;
505
        }
506
507
        if (this.geometrySubType != other.geometrySubType) {
508
            return false;
509
        }
510
511 44128 jjdelcerro
        if (!Objects.equals(this.evaluator, other.evaluator)) {
512 40435 jjdelcerro
            return false;
513
        }
514
515 44128 jjdelcerro
        if (!Objects.equals(this.featureAttributeEmulator, other.featureAttributeEmulator)) {
516 40435 jjdelcerro
            return false;
517
        }
518
519 44128 jjdelcerro
        if (!Objects.equals(this.SRS, other.SRS)) {
520 40435 jjdelcerro
            return false;
521
        }
522
523 44128 jjdelcerro
        if (!Objects.equals(this.dateFormat, other.dateFormat)) {
524 40435 jjdelcerro
            return false;
525
        }
526
527 44128 jjdelcerro
        if (!Objects.equals(this.objectClass, other.objectClass)) {
528
            return false;
529
        }
530
531
        if (!Objects.equals(this.dataProfile, other.dataProfile)) {
532
            return false;
533
        }
534
535 40435 jjdelcerro
        return true;
536
    }
537
538 42561 jjdelcerro
    @Override
539 40435 jjdelcerro
    public void loadFromState(PersistentState state)
540 42561 jjdelcerro
            throws PersistenceException {
541 40435 jjdelcerro
        allowNull = state.getBoolean("allowNull");
542 44077 jjdelcerro
        dataType = ToolsLocator.getDataTypesManager().get(state.getInt("dataType"));
543 44190 jjdelcerro
        dataProfile = state.getString("dataProfile");
544
545
//        FIXME: dateFormat;
546
        try {
547
            defaultValue = dataType.coerce(state.get("defaultValue"));
548
        } catch (CoercionException ex) {
549
        }
550 40435 jjdelcerro
551
        index = state.getInt("index");
552
        maximumOccurrences = state.getInt("maximumOccurrences");
553
        minimumOccurrences = state.getInt("minimumOccurrences");
554
        size = state.getInt("size");
555
        name = state.getString("name");
556
        try {
557 44190 jjdelcerro
            String objectClassName = state.getString("objectClass");
558
            if( !StringUtils.isBlank(objectClassName) ) {
559
                objectClass = Class.forName(objectClassName);
560
            }
561
        } catch (Throwable e) {
562
            LOGGER.warn("Can't restore the objectClass of the FeatureAttributreDescriptor", e);
563 40435 jjdelcerro
        }
564
        precision = state.getInt("precision");
565
        evaluator = (Evaluator) state.get("evaluator");
566
        primaryKey = state.getBoolean("primaryKey");
567
        readOnly = state.getBoolean("readOnly");
568 44190 jjdelcerro
        SRS = (IProjection) state.get("SRS");
569 40435 jjdelcerro
        geometryType = state.getInt("geometryType");
570
        geometrySubType = state.getInt("geometrySubType");
571 44190 jjdelcerro
        if( geometryType!=Geometry.TYPES.UNKNOWN &&
572
                geometrySubType!=Geometry.SUBTYPES.UNKNOWN ) {
573
            geomType = GeometryUtils.getGeometryType(
574
                    geometryType,
575
                    geometrySubType
576
            );
577
        }
578
//        additionalInfo = (Map) state.get("aditionalInfo");
579 40435 jjdelcerro
        isAutomatic = state.getBoolean("isAutomatic");
580 44077 jjdelcerro
        isTime = state.getBoolean("isTime");
581
        if( state.hasValue("intervalStart") ) {
582 44190 jjdelcerro
            long intervalStart = state.getLong("interval_start");
583
            long intervalEnd = state.getLong("interval_end");
584 44077 jjdelcerro
            interval = TimeSupportLocator.getManager().createRelativeInterval(intervalStart, intervalEnd);
585
        } else {
586
            interval = null;
587
        }
588 44190 jjdelcerro
        featureAttributeEmulator = (FeatureAttributeEmulator) state.get("featureAttributeEmulator");
589
        indexed = state.getBoolean("indexed");
590
        isIndexAscending = state.getBoolean("isIndexAscending");
591
        allowIndexDuplicateds = state.getBoolean("allowIndexDuplicateds");
592
593 44202 jjdelcerro
        Map<String,Object> values = state.getMap("availableValues");
594
        if( values == null || values.isEmpty()  ) {
595
            this.availableValues = null;
596
        } else {
597
            this.availableValues = new DynObjectValueItem[values.size()];
598
            int n = 0;
599
            for (Entry<String, Object> entry : values.entrySet()) {
600
                this.availableValues[n++] = new DynObjectValueItem(entry.getValue(), entry.getKey());
601
            }
602
        }
603
604 44190 jjdelcerro
        description = state.getString("description");
605
        minValue = state.get("minValue");
606
        maxValue = state.get("maxValue");
607
        label = state.getString("label");
608
        order = state.getInt("order");
609
        hidden = state.getBoolean("hidden");
610
        groupName = state.getString("groupName");
611 44253 jjdelcerro
        relationType = state.getInt("relationType");
612 44262 jjdelcerro
613
        foreingKey = (DefaultForeingKey) state.get("foreingKey");
614
        if( foreingKey!=null ) {
615
            this.foreingKey.setDescriptor(this);
616
        }
617
        tags = (Tags) state.get("tags");
618
        if( tags == null ) {
619
            this.tags = new DefaultTags();
620
        }
621 40435 jjdelcerro
    }
622
623 42561 jjdelcerro
    @Override
624 40435 jjdelcerro
    public void saveToState(PersistentState state) throws PersistenceException {
625
        state.set("allowNull", allowNull);
626 44190 jjdelcerro
        state.set("dataType", dataType.getType());
627
        state.set("dataProfile", dataProfile);
628
629
//        FIXME: dateFormat;
630 40435 jjdelcerro
631 44190 jjdelcerro
        state.set("defaultValue", Objects.toString(defaultValue));
632 40435 jjdelcerro
633 44190 jjdelcerro
        state.set("index", index);
634
        state.set("maximumOccurrences", maximumOccurrences);
635
        state.set("minimumOccurrences", minimumOccurrences);
636
        state.set("size", size);
637
        state.set("name", name);
638
        state.set("objectClass", objectClass==null? null:objectClass.getName());
639
        state.set("precision", precision);
640
        state.set("evaluator", evaluator);
641
642
        state.set("primaryKey", primaryKey);
643
        state.set("readOnly", readOnly);
644
        state.set("SRS", SRS);
645
        GeometryType theGeomType = this.getGeomType();
646
        if( theGeomType==null ) {
647
            state.set("geometryType", Geometry.TYPES.UNKNOWN);
648
            state.set("geometrySubType", Geometry.SUBTYPES.UNKNOWN);
649
        } else {
650
            state.set("geometryType", theGeomType.getType());
651
            state.set("geometrySubType", theGeomType.getSubType());
652 40435 jjdelcerro
        }
653 44190 jjdelcerro
654
//      FIXME: additionalInfo
655
656
        state.set("isAutomatic", isAutomatic);
657
        state.set("isTime", isTime);
658
        if( this.interval==null ) {
659
            state.setNull("interval_start");
660
            state.setNull("interval_end");
661
        } else {
662
            state.set("interval_start", ((RelativeInterval)interval).getStart().toMillis());
663
            state.set("interval_end", ((RelativeInterval)interval).getEnd().toMillis());
664 40435 jjdelcerro
        }
665 44190 jjdelcerro
        state.set("SRS", SRS);
666
667
//      FIXME: featureAttributeGetter
668
669
        if( featureAttributeEmulator instanceof Persistent ) {
670
            state.set("featureAttributeEmulator", featureAttributeEmulator);
671
        } else {
672
            state.setNull("featureAttributeEmulator");
673
        }
674
675
        state.set("indexed", indexed);
676
        state.set("isIndexAscending", isIndexAscending);
677
        state.set("allowIndexDuplicateds", allowIndexDuplicateds);
678
679 44202 jjdelcerro
        if( this.availableValues==null ) {
680
            state.setNull("availableValues");
681
        } else {
682
            Map<String,Object> values = new HashMap<>();
683
            for (DynObjectValueItem value : availableValues) {
684
                values.put(value.getLabel(),value.getValue());
685
            }
686
            state.set("availableValues", values);
687
        }
688 44190 jjdelcerro
        state.set("description", description);
689
        state.set("minValue", minValue);
690
        state.set("maxValue", maxValue);
691
        state.set("label", label);
692
        state.set("order", order);
693
        state.set("hidden", hidden);
694
        state.set("groupName", groupName);
695 44253 jjdelcerro
        state.set("relationType",relationType);
696 44262 jjdelcerro
697
        state.set("foreingKey" ,this.foreingKey);
698
        state.set("tags" ,this.tags);
699 44190 jjdelcerro
700 40435 jjdelcerro
    }
701 44190 jjdelcerro
702
    private static final String FEATATTRDESC_PERSISTENCE_DEFINITION_NAME = "FeatureAttributeDescriptor";
703 40435 jjdelcerro
704 44190 jjdelcerro
    public static void registerPersistenceDefinition() {
705
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
706
707
708
        if (manager.getDefinition(FEATATTRDESC_PERSISTENCE_DEFINITION_NAME)
709
                == null) {
710
            DynStruct definition = manager.addDefinition(DefaultFeatureAttributeDescriptor.class,
711
                    FEATATTRDESC_PERSISTENCE_DEFINITION_NAME,
712
                    FEATATTRDESC_PERSISTENCE_DEFINITION_NAME
713
                        + " persistent definition",
714
                    null,
715
                    null
716
            );
717
            definition.addDynFieldBoolean("allowNull");
718
            definition.addDynFieldInt("dataType");
719
            definition.addDynFieldString("dataProfile");
720
//            definition.addDynFieldString("dateFormat");
721
            definition.addDynFieldString("defaultValue");
722
            definition.addDynFieldInt("index");
723
            definition.addDynFieldInt("maximumOccurrences");
724
            definition.addDynFieldInt("minimumOccurrences");
725
            definition.addDynFieldInt("size");
726
            definition.addDynFieldString("name");
727
            definition.addDynFieldString("objectClass");
728
            definition.addDynFieldInt("precision");
729
            definition.addDynFieldObject("evaluator")
730
                    .setClassOfValue(Evaluator.class);
731
            definition.addDynFieldBoolean("primaryKey");
732
            definition.addDynFieldBoolean("readOnly");
733
            definition.addDynFieldObject("SRS")
734
                    .setClassOfValue(IProjection.class);
735
            definition.addDynFieldInt("geometryType");
736
            definition.addDynFieldInt("geometrySubType");
737
//            definition.addDynFieldMap("additionalInfo");
738
            definition.addDynFieldBoolean("isAutomatic");
739
            definition.addDynFieldBoolean("isTime");
740
            definition.addDynFieldLong("interval_start");
741
            definition.addDynFieldLong("interval_end");
742
            definition.addDynFieldObject("featureAttributeEmulator")
743
                    .setClassOfValue(FeatureAttributeEmulator.class);
744
            definition.addDynFieldBoolean("indexed");
745
            definition.addDynFieldBoolean("isIndexAscending");
746
            definition.addDynFieldBoolean("allowIndexDuplicateds");
747 44202 jjdelcerro
            definition.addDynFieldMap("availableValues");
748
            definition.addDynFieldString("description");
749
            definition.addDynFieldObject("minValue");
750
            definition.addDynFieldObject("maxValue");
751
            definition.addDynFieldString("label");
752 44190 jjdelcerro
            definition.addDynFieldInt("order");
753
            definition.addDynFieldBoolean("hidden");
754 44202 jjdelcerro
            definition.addDynFieldString("groupName");
755 44253 jjdelcerro
            definition.addDynFieldInt("relationType");
756 44262 jjdelcerro
757
            definition.addDynFieldObject("foreingKey")
758
                    .setClassOfValue(DefaultForeingKey.class);
759
760
            definition.addDynFieldObject("tags")
761
                    .setClassOfValue(Tags.class);
762
763 44190 jjdelcerro
        }
764
    }
765
766
767 42563 jjdelcerro
    /*
768 40435 jjdelcerro
     * Start of DynField interface Implementation
769 42561 jjdelcerro
     *
770 40435 jjdelcerro
     */
771 42634 fdiaz
772 43739 jjdelcerro
    @Override
773 42563 jjdelcerro
    public Tags getTags() {
774
        return tags;
775
    }
776 42634 fdiaz
777 42561 jjdelcerro
    @Override
778 40435 jjdelcerro
    public DynObjectValueItem[] getAvailableValues() {
779 44259 jjdelcerro
        if( this.availableValues == null ) {
780 44338 jjdelcerro
            if( this.isForeingKey() && this.foreingKey.isClosedList() ) {
781
                return this.foreingKey.getAvailableValues(null);
782 44259 jjdelcerro
            }
783
        }
784 42563 jjdelcerro
        return this.availableValues;
785 40435 jjdelcerro
    }
786
787 42561 jjdelcerro
    @Override
788 40435 jjdelcerro
    public String getDescription() {
789 42563 jjdelcerro
        if( this.description == null ) {
790
            return getName();
791
        }
792
        return this.description;
793 40435 jjdelcerro
    }
794
795 42561 jjdelcerro
    @Override
796 40435 jjdelcerro
    public Object getMaxValue() {
797 42563 jjdelcerro
        return this.maxValue;
798 40435 jjdelcerro
    }
799
800 42561 jjdelcerro
    @Override
801 40435 jjdelcerro
    public Object getMinValue() {
802 42563 jjdelcerro
        return this.minValue;
803 40435 jjdelcerro
    }
804
805 42561 jjdelcerro
    @Override
806 40435 jjdelcerro
    public int getTheTypeOfAvailableValues() {
807 42563 jjdelcerro
        return 1;
808 40435 jjdelcerro
    }
809
810 42561 jjdelcerro
    @Override
811 40435 jjdelcerro
    public int getType() {
812 42561 jjdelcerro
        if (featureAttributeGetter != null) {
813 40435 jjdelcerro
            return featureAttributeGetter.getDataType().getType();
814
        }
815
        return getDataType().getType();
816
    }
817
818 42561 jjdelcerro
    @Override
819 40435 jjdelcerro
    public boolean isMandatory() {
820
        return !allowNull() || isPrimaryKey();
821
    }
822
823 42561 jjdelcerro
    @Override
824 40435 jjdelcerro
    public boolean isPersistent() {
825
        return false;
826
    }
827
828 42561 jjdelcerro
    @Override
829 40435 jjdelcerro
    public DynField setAvailableValues(DynObjectValueItem[] values) {
830 42563 jjdelcerro
        if ( ArrayUtils.isEmpty(values) ) {
831
            this.availableValues = null;
832
        } else {
833
            this.availableValues = values;
834
        }
835
        return this;
836 40435 jjdelcerro
    }
837
838 42561 jjdelcerro
    @Override
839 40435 jjdelcerro
    public DynField setDescription(String description) {
840 42563 jjdelcerro
        this.description = description;
841
        return this;
842 40435 jjdelcerro
    }
843
844 42561 jjdelcerro
    @Override
845 40435 jjdelcerro
    public DynField setMandatory(boolean mandatory) {
846
        throw new UnsupportedOperationException();
847
    }
848
849 42561 jjdelcerro
    @Override
850 40435 jjdelcerro
    public DynField setMaxValue(Object maxValue) {
851 42563 jjdelcerro
        try {
852
            this.maxValue = this.coerce(maxValue);
853
        } catch (CoercionException e) {
854
            throw new IllegalArgumentException(e);
855
        }
856
        return this;
857 40435 jjdelcerro
    }
858
859 42561 jjdelcerro
    @Override
860 40435 jjdelcerro
    public DynField setMinValue(Object minValue) {
861 42563 jjdelcerro
        try {
862
            this.maxValue = this.coerce(minValue);
863
        } catch (CoercionException e) {
864
            throw new IllegalArgumentException(e);
865
        }
866
        return this;
867 40435 jjdelcerro
    }
868
869 42561 jjdelcerro
    @Override
870 40435 jjdelcerro
    public DynField setPersistent(boolean persistent) {
871
        throw new UnsupportedOperationException();
872
    }
873
874 42561 jjdelcerro
    @Override
875 40435 jjdelcerro
    public DynField setTheTypeOfAvailableValues(int type) {
876
        throw new UnsupportedOperationException();
877
    }
878
879 42561 jjdelcerro
    @Override
880 40435 jjdelcerro
    public DynField setType(int type) {
881
        throw new UnsupportedOperationException();
882
    }
883
884 42561 jjdelcerro
    @Override
885 40435 jjdelcerro
    public DynField setDefaultDynValue(Object defaultValue) {
886
        throw new UnsupportedOperationException();
887
    }
888
889 42561 jjdelcerro
    @Override
890 40435 jjdelcerro
    public Class getClassOfValue() {
891
        return null;
892
    }
893
894 42561 jjdelcerro
    @Override
895 40435 jjdelcerro
    public DynField getElementsType() {
896
        return null;
897
    }
898
899 42561 jjdelcerro
    @Override
900 40435 jjdelcerro
    public DynField setClassOfValue(Class theClass)
901 42561 jjdelcerro
            throws DynFieldIsNotAContainerException {
902 40435 jjdelcerro
        throw new UnsupportedOperationException();
903
    }
904
905 42561 jjdelcerro
    @Override
906 40435 jjdelcerro
    public DynField setElementsType(DynStruct type)
907 42561 jjdelcerro
            throws DynFieldIsNotAContainerException {
908 40435 jjdelcerro
        throw new UnsupportedOperationException();
909
    }
910
911 42561 jjdelcerro
    @Override
912 40435 jjdelcerro
    public DynField setElementsType(int type)
913 42561 jjdelcerro
            throws DynFieldIsNotAContainerException {
914 40435 jjdelcerro
        throw new UnsupportedOperationException();
915
    }
916
917 44128 jjdelcerro
    public FeatureAttributeDescriptor setDataProfileName(String dataProfile) {
918
        this.dataProfile = dataProfile;
919
        return this;
920
    }
921
922 42561 jjdelcerro
    @Override
923 44128 jjdelcerro
    public String getDataProfileName() {
924
        return dataProfile;
925 40435 jjdelcerro
    }
926
927 42561 jjdelcerro
    @Override
928 40435 jjdelcerro
    public void validate(Object value) throws DynFieldValidateException {
929 42561 jjdelcerro
930 40435 jjdelcerro
        if (value == null && !this.allowNull()) {
931
            throw new DynFieldValidateException(value, this, null);
932
        }
933 42561 jjdelcerro
934 40435 jjdelcerro
        try {
935
            this.dataType.coerce(value);
936
        } catch (CoercionException e) {
937
            throw new DynFieldValidateException(value, this, e);
938
        }
939 42561 jjdelcerro
940 40435 jjdelcerro
        /*
941
         * Other checks will be needed
942
         */
943
    }
944
945 42561 jjdelcerro
    @Override
946 40435 jjdelcerro
    public String getSubtype() {
947 42561 jjdelcerro
        if (featureAttributeGetter != null) {
948 40435 jjdelcerro
            return featureAttributeGetter.getDataType().getSubtype();
949 42561 jjdelcerro
        }
950 40435 jjdelcerro
        return this.dataType.getSubtype();
951
    }
952
953 42561 jjdelcerro
    @Override
954 42563 jjdelcerro
    public Object coerce(Object value) throws CoercionException {
955
        if ( value == null ) {
956
            return value; // O debe devolver this.defaultValue
957
        }
958
        try {
959
            return this.getDataType().coerce(value);
960
        } catch(Exception ex){
961
            throw new RuntimeException(ex);
962
        }
963 40435 jjdelcerro
    }
964
965 42561 jjdelcerro
    @Override
966 40435 jjdelcerro
    public DynField setAvailableValues(List values) {
967 42563 jjdelcerro
        if (  values == null || values.isEmpty() ) {
968
            this.availableValues = null;
969
        } else {
970
            this.availableValues = (DynObjectValueItem[]) values.toArray(
971
                new DynObjectValueItem[values.size()]
972
            );
973
        }
974
        return this;
975 40435 jjdelcerro
    }
976
977 42561 jjdelcerro
    @Override
978 40435 jjdelcerro
    public String getGroup() {
979 42563 jjdelcerro
        return this.groupName;
980 40435 jjdelcerro
    }
981
982 42561 jjdelcerro
    @Override
983 40435 jjdelcerro
    public int getOder() {
984 42563 jjdelcerro
        return this.order;
985 40435 jjdelcerro
    }
986
987 42561 jjdelcerro
    @Override
988 41323 jjdelcerro
    public String getLabel() {
989 42563 jjdelcerro
        if( this.label == null ) {
990
            return this.getName();
991
        }
992
        return this.label;
993 41323 jjdelcerro
    }
994 44338 jjdelcerro
995
    @Override
996
    public String getLocalizedLabel() {
997
        if( StringUtils.isBlank(this.label) ) {
998
            return this.getName();
999
        }
1000
        I18nManager i18n = ToolsLocator.getI18nManager();
1001
        return i18n.getTranslation(this.label);
1002
    }
1003 41323 jjdelcerro
1004 42561 jjdelcerro
    @Override
1005 41323 jjdelcerro
    public DynField setLabel(String label) {
1006 42563 jjdelcerro
        this.label = label;
1007
        return this;
1008 41323 jjdelcerro
    }
1009
1010 42561 jjdelcerro
    @Override
1011 44337 jjdelcerro
    public DynField setShortLabel(String shortLabel) {
1012
        this.shortLabel = shortLabel;
1013
        return this;
1014
    }
1015
1016
    @Override
1017
    public String getShortLabel() {
1018
        return StringUtils.isBlank(shortLabel) ? getLabel() : shortLabel;
1019
    }
1020
1021
    @Override
1022 44338 jjdelcerro
    public String getLocalizedShortLabel() {
1023
        if( StringUtils.isBlank(shortLabel) ) {
1024
            return this.getLocalizedLabel();
1025
        }
1026
        I18nManager i18n = ToolsLocator.getI18nManager();
1027
        return i18n.getTranslation(shortLabel);
1028
    }
1029
1030
    @Override
1031 40435 jjdelcerro
    public DynField setGroup(String groupName) {
1032 42563 jjdelcerro
        this.groupName = groupName;
1033
        return this;
1034 40435 jjdelcerro
    }
1035
1036 42561 jjdelcerro
    @Override
1037 40435 jjdelcerro
    public DynField setOrder(int order) {
1038 42563 jjdelcerro
        this.order = order;
1039
        return this;
1040 40435 jjdelcerro
    }
1041
1042 42561 jjdelcerro
    @Override
1043 40435 jjdelcerro
    public DynField setHidden(boolean hidden) {
1044 42563 jjdelcerro
        this.hidden = hidden;
1045
        return this;
1046 40435 jjdelcerro
    }
1047
1048 42561 jjdelcerro
    @Override
1049 40435 jjdelcerro
    public boolean isHidden() {
1050 42563 jjdelcerro
        return this.hidden;
1051 40435 jjdelcerro
    }
1052
1053 42561 jjdelcerro
    @Override
1054 44325 jjdelcerro
    public DynField setReadOnly(boolean readOnly) {
1055
        this.readOnly = readOnly;
1056
        return this;
1057 40435 jjdelcerro
    }
1058
1059 42561 jjdelcerro
    @Override
1060 40435 jjdelcerro
    public boolean isContainer() {
1061
        return false;
1062
    }
1063
1064 42561 jjdelcerro
    @Override
1065 40435 jjdelcerro
    public Class getClassOfItems() {
1066
        return null;
1067
    }
1068
1069 42561 jjdelcerro
    @Override
1070 40435 jjdelcerro
    public DynField setDefaultFieldValue(Object defaultValue) {
1071
        throw new UnsupportedOperationException();
1072
    }
1073
1074 42561 jjdelcerro
    @Override
1075 40435 jjdelcerro
    public DynField setClassOfItems(Class theClass) {
1076
        throw new UnsupportedOperationException();
1077
    }
1078
1079 42561 jjdelcerro
    @Override
1080 40435 jjdelcerro
    public DynField setType(DataType type) {
1081
        throw new UnsupportedOperationException();
1082
    }
1083
1084 42561 jjdelcerro
    @Override
1085 44128 jjdelcerro
    public DynField setSubtype(String subtype) {
1086
        throw new UnsupportedOperationException();
1087
    }
1088
1089
    @Override
1090 42561 jjdelcerro
    public boolean isTime() {
1091
        return isTime;
1092
    }
1093 40435 jjdelcerro
1094 42561 jjdelcerro
    @Override
1095 40435 jjdelcerro
    public FeatureAttributeGetter getFeatureAttributeGetter() {
1096 42561 jjdelcerro
        return featureAttributeGetter;
1097 40435 jjdelcerro
    }
1098
1099 42561 jjdelcerro
    @Override
1100 40435 jjdelcerro
    public void setFeatureAttributeGetter(
1101 42561 jjdelcerro
            FeatureAttributeGetter featureAttributeTransform) {
1102
        this.featureAttributeGetter = featureAttributeTransform;
1103
    }
1104 41335 jjdelcerro
1105 42561 jjdelcerro
    @Override
1106 41335 jjdelcerro
    public FeatureAttributeEmulator getFeatureAttributeEmulator() {
1107
        return this.featureAttributeEmulator;
1108
    }
1109
1110 43954 jjdelcerro
    public FeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
1111
        this.featureAttributeEmulator = featureAttributeEmulator;
1112
        return this;
1113
    }
1114
1115 42561 jjdelcerro
    @Override
1116 41638 jjdelcerro
    public boolean isIndexed() {
1117
        return this.indexed;
1118
    }
1119 44262 jjdelcerro
1120
    public boolean isForeingKey() {
1121
        return this.foreingKey!=null && this.foreingKey.isForeingKey();
1122
    }
1123
1124
    public ForeingKey getForeingKey() {
1125
        return this.foreingKey;
1126
    }
1127 41638 jjdelcerro
1128 42561 jjdelcerro
    @Override
1129 41638 jjdelcerro
    public boolean allowIndexDuplicateds() {
1130
        return this.allowIndexDuplicateds;
1131
    }
1132
1133 42561 jjdelcerro
    @Override
1134 41638 jjdelcerro
    public boolean isIndexAscending() {
1135
        return this.isIndexAscending;
1136
    }
1137
1138 42563 jjdelcerro
    @Override
1139
    public DynField setClassOfValue(DynStruct dynStrct) {
1140
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1141
    }
1142
1143
    @Override
1144
    public DynField setClassOfValue(String theClassNameOfValue) {
1145
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1146
    }
1147
1148
    @Override
1149
    public String getClassNameOfValue() {
1150 42634 fdiaz
        return null;
1151 42563 jjdelcerro
    }
1152
1153
    @Override
1154
    public DynStruct getDynClassOfValue() {
1155 42634 fdiaz
        return null;
1156 42563 jjdelcerro
    }
1157
1158
    @Override
1159
    public DynField setTypeOfItems(int type) {
1160
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1161
    }
1162
1163
    @Override
1164
    public int getTypeOfItems() {
1165 42634 fdiaz
        return DataTypes.INVALID;
1166 42563 jjdelcerro
    }
1167
1168
    @Override
1169
    public DynField setClassOfItems(DynStruct dynStrct) {
1170
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1171
    }
1172
1173
    @Override
1174
    public DynField setClassOfItems(String theClassNameOfValue) {
1175
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
1176
    }
1177
1178
    @Override
1179
    public String getClassNameOfItems() {
1180 42634 fdiaz
        return null;
1181 42563 jjdelcerro
    }
1182
1183
    @Override
1184
    public DynStruct getDynClassOfItems() {
1185 42634 fdiaz
        return null;
1186 42563 jjdelcerro
    }
1187
1188
    @Override
1189
    public DynField setRelationType(int relationType) {
1190 44253 jjdelcerro
        this.relationType = relationType;
1191
        return this;
1192 42563 jjdelcerro
    }
1193
1194
    @Override
1195
    public int getRelationType() {
1196 44253 jjdelcerro
        return this.relationType;
1197 42563 jjdelcerro
    }
1198
1199 42606 jjdelcerro
    @Override
1200 42775 jjdelcerro
    public DynField setAvailableValues(DynMethod availableValuesMethod) {
1201
        this.availableValuesMethod = availableValuesMethod;
1202
        return this;
1203 42606 jjdelcerro
    }
1204
1205
    @Override
1206 42775 jjdelcerro
    public DynObjectValueItem[] getAvailableValues(DynObject self) {
1207
        if( this.availableValuesMethod != null ) {
1208
            DynObjectValueItem[] values;
1209
            try {
1210
                values = (DynObjectValueItem[]) this.availableValuesMethod.invoke(self,new Object[] {this});
1211
            } catch (DynMethodException ex) {
1212
                return this.availableValues;
1213
            }
1214 42606 jjdelcerro
            if( values != null ) {
1215
                return values;
1216
            }
1217
        }
1218
        return this.availableValues;
1219
    }
1220
1221 42775 jjdelcerro
    @Override
1222
    public DynMethod getAvailableValuesMethod() {
1223
        return this.availableValuesMethod;
1224
    }
1225
1226
    @Override
1227
    public boolean isAvailableValuesCalculated() {
1228
        return this.availableValuesMethod!=null;
1229
    }
1230
1231
    @Override
1232
    public DynMethod getCalculateMethod() {
1233
        return this.calculateMethod;
1234
    }
1235
1236
    @Override
1237
    public DynField setCalculateMethod(DynMethod method) {
1238
        this.calculateMethod = method;
1239
        return this;
1240
    }
1241
1242
    @Override
1243
    public boolean isCalculated() {
1244
        return this.calculateMethod != null;
1245
    }
1246
1247
    @Override
1248
    public Object getCalculatedValue(DynObject self) {
1249
        try {
1250
            return this.calculateMethod.invoke(self, new Object[] { this });
1251
        } catch (DynMethodException ex) {
1252
            throw new RuntimeException(ex);
1253
        }
1254
    }
1255
1256
    @Override
1257
    public DynField setValidateElements(boolean validate) {
1258
        return this;
1259
    }
1260
1261
    @Override
1262
    public boolean getValidateElements() {
1263
        return false;
1264
    }
1265
1266 41212 jjdelcerro
    private class ConstantValueEvaluator extends AbstractEvaluator {
1267 42561 jjdelcerro
1268
        @Override
1269 41212 jjdelcerro
        public Object evaluate(EvaluatorData data) throws EvaluatorException {
1270
            return defaultValue;
1271
        }
1272 42561 jjdelcerro
1273
        @Override
1274 41212 jjdelcerro
        public String getName() {
1275 42561 jjdelcerro
            return "Constant attribute " + name;
1276 41212 jjdelcerro
        }
1277
    }
1278 41335 jjdelcerro
1279 41212 jjdelcerro
    public void setConstantValue(boolean isConstantValue) {
1280 42561 jjdelcerro
        if (isConstantValue) {
1281 41212 jjdelcerro
            /* Cuando un attributo tiene asociado un evaluador, este se interpreta
1282 42634 fdiaz
             * como que no debe cargarse de la fuente de datos subyacente, siendo
1283 41212 jjdelcerro
             * el evaluador el que se encarga de proporcionar su valor.
1284
             * Nos limitamos a asignar un evaluador que retorna simpre el valor
1285
             * por defecto para ese attributo.
1286
             */
1287
            this.evaluator = new ConstantValueEvaluator();
1288
        } else {
1289
            this.evaluator = null;
1290
        }
1291
    }
1292 42561 jjdelcerro
1293 43739 jjdelcerro
    @Override
1294 43135 jjdelcerro
    public boolean isComputed() {
1295 44190 jjdelcerro
        return featureAttributeEmulator!=null || evaluator!=null || isCalculated();
1296 43135 jjdelcerro
    }
1297 43739 jjdelcerro
1298
    @Override
1299
    public FeatureStore getStore() {
1300
        FeatureType ftype = this.getFeatureType();
1301
        if( ftype == null ) {
1302
            return null;
1303
        }
1304
        return ftype.getStore();
1305
    }
1306
1307
    @Override
1308
    public FeatureType getFeatureType() {
1309
        if( this.typeRef==null ) {
1310
            return null;
1311
        }
1312 44259 jjdelcerro
        FeatureType ftype = (FeatureType) this.typeRef.get();
1313
//        LOGGER.info(String.format("FeatureAttributeDescriptor[%08x] get FeatureType [%08x], ref [%08x].", this.hashCode(), ftype.hashCode(), typeRef.hashCode()));
1314
        return ftype;
1315 43739 jjdelcerro
    }
1316 44094 jjdelcerro
1317
    public FeatureAttributeDescriptor setInterval(Interval interval) {
1318
        this.interval = interval;
1319
        return this;
1320
    }
1321
1322
    public void fixAll() {
1323
        switch(this.getType()) {
1324
            case DataTypes.INSTANT:
1325
            case DataTypes.INTERVAL:
1326
            case DataTypes.DATE:
1327
                if( this.getInterval()!=null ) {
1328
                    this.isTime = true;
1329
                }
1330
                break;
1331
        }
1332
    }
1333
1334 44158 jjdelcerro
    @Override
1335
    public String[] getRequiredFieldNames() {
1336
        FeatureAttributeEmulator emulator = this.getFeatureAttributeEmulator();
1337
        if( emulator==null ) {
1338
            return null;
1339
        }
1340
        return emulator.getRequiredFieldNames();
1341
    }
1342
1343 44262 jjdelcerro
    @Override
1344
    public void recentUsed() {
1345
        DefaultFeatureType.RECENTS_USEDS.add(this);
1346
    }
1347
1348 40435 jjdelcerro
}