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

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