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 / DefaultEditableFeatureAttributeDescriptor.java

History | View | Annotate | Download (27.2 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 40435 jjdelcerro
package org.gvsig.fmap.dal.feature.impl;
25
26 44669 jjdelcerro
import java.math.BigDecimal;
27 41483 jjdelcerro
import java.text.DateFormat;
28 40435 jjdelcerro
import java.util.HashMap;
29 44669 jjdelcerro
import java.util.Locale;
30 44189 jjdelcerro
import java.util.Objects;
31 45425 jjdelcerro
import javax.json.JsonObject;
32 44084 jjdelcerro
import org.apache.commons.lang3.StringUtils;
33 40435 jjdelcerro
34
import org.cresques.cts.IProjection;
35 44253 jjdelcerro
import org.gvsig.expressionevaluator.Expression;
36
import org.gvsig.expressionevaluator.ExpressionUtils;
37
import org.gvsig.fmap.crs.CRSFactory;
38
import org.gvsig.fmap.dal.DALLocator;
39 44337 jjdelcerro
import org.gvsig.fmap.dal.DataTypeUtils;
40 44253 jjdelcerro
import org.gvsig.fmap.dal.DataTypes;
41
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression;
42 40964 jldominguez
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44 40435 jjdelcerro
45
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
46 44262 jjdelcerro
import org.gvsig.fmap.dal.feature.EditableForeingKey;
47 41335 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator;
48 43739 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureType;
49 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException;
50
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException;
51 42303 jjdelcerro
import org.gvsig.fmap.geom.Geometry;
52 44253 jjdelcerro
import org.gvsig.fmap.geom.GeometryUtils;
53 40435 jjdelcerro
import org.gvsig.fmap.geom.type.GeometryType;
54 45425 jjdelcerro
import org.gvsig.json.Json;
55
import org.gvsig.json.JsonManager;
56
import org.gvsig.json.JsonObjectBuilder;
57
import org.gvsig.json.SupportToJson;
58 44077 jjdelcerro
import org.gvsig.timesupport.Interval;
59 40435 jjdelcerro
import org.gvsig.tools.ToolsLocator;
60 44189 jjdelcerro
import org.gvsig.tools.dataTypes.DataType;
61 44740 jjdelcerro
import org.gvsig.tools.dynobject.DynField;
62 40435 jjdelcerro
import org.gvsig.tools.evaluator.Evaluator;
63
64
public class DefaultEditableFeatureAttributeDescriptor extends
65 45739 jjdelcerro
        DefaultFeatureAttributeDescriptor implements
66
        EditableFeatureAttributeDescriptor {
67
68 40964 jldominguez
    private static Logger logger = LoggerFactory.getLogger(
69 45739 jjdelcerro
            DefaultEditableFeatureAttributeDescriptor.class);
70 40435 jjdelcerro
71 44094 jjdelcerro
    private final DefaultFeatureAttributeDescriptor source;
72 40435 jjdelcerro
    private boolean hasStrongChanges;
73
    private String originalName = null;
74
75
    protected DefaultEditableFeatureAttributeDescriptor(
76 45739 jjdelcerro
            DefaultFeatureAttributeDescriptor other) {
77 40435 jjdelcerro
        super(other);
78
        if (other instanceof DefaultEditableFeatureAttributeDescriptor) {
79 45739 jjdelcerro
            DefaultEditableFeatureAttributeDescriptor other_edi
80
                    = (DefaultEditableFeatureAttributeDescriptor) other;
81 40435 jjdelcerro
            originalName = other_edi.getOriginalName();
82
            this.source = other_edi.getSource();
83
        } else {
84
            this.source = other;
85
        }
86
        hasStrongChanges = false;
87
    }
88
89 44190 jjdelcerro
    public DefaultEditableFeatureAttributeDescriptor(FeatureType type, boolean strongChanges) {
90 43739 jjdelcerro
        super(type);
91 40435 jjdelcerro
        this.source = null;
92 44190 jjdelcerro
        hasStrongChanges = strongChanges;
93 40435 jjdelcerro
    }
94
95
    public DefaultFeatureAttributeDescriptor getSource() {
96
        return this.source;
97
    }
98 45739 jjdelcerro
99 40435 jjdelcerro
    public void fixAll() {
100 44094 jjdelcerro
        super.fixAll();
101 40435 jjdelcerro
    }
102 45739 jjdelcerro
103 40435 jjdelcerro
    public void checkIntegrity() throws AttributeFeatureTypeIntegrityException {
104 45739 jjdelcerro
        AttributeFeatureTypeIntegrityException ex
105
                = new AttributeFeatureTypeIntegrityException(getName());
106 40435 jjdelcerro
        if (this.size < 0) {
107
            ex.add(new AttributeFeatureTypeSizeException(this.size));
108
        }
109
110 45739 jjdelcerro
        if (this.dataType.isObject() && this.objectClass == null) {
111 40964 jldominguez
            logger.warn("Incorrect data type object, objectClass is null.");
112
            ex.add(new AttributeFeatureTypeIntegrityException(this.name));
113
        }
114 45739 jjdelcerro
115 40964 jldominguez
        // TODO: Add other integrity checks...
116 40435 jjdelcerro
        if (ex.size() > 0) {
117
            throw ex;
118
        }
119
    }
120
121
    public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) {
122 44189 jjdelcerro
        updateStrongChanges(this.allowNull, allowNull);
123 40435 jjdelcerro
        this.allowNull = allowNull;
124 47436 fdiaz
        this.setFixed(false);
125 40435 jjdelcerro
        return this;
126
    }
127 45739 jjdelcerro
128 44262 jjdelcerro
    @Override
129
    public EditableForeingKey getForeingKey() {
130 45739 jjdelcerro
        if (this.foreingKey == null) {
131 44262 jjdelcerro
            this.foreingKey = new DefaultForeingKey();
132
            this.foreingKey.setDescriptor(this);
133
        }
134
        return this.foreingKey;
135
    }
136 40435 jjdelcerro
137 44669 jjdelcerro
    public EditableFeatureAttributeDescriptor setDataType(DataType dataType) {
138
        updateStrongChanges(this.dataType, dataType);
139
        this.dataType = dataType;
140 47436 fdiaz
        this.setFixed(false);
141 44669 jjdelcerro
        return this;
142
    }
143 45739 jjdelcerro
144 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setDataType(int type) {
145 44189 jjdelcerro
        updateStrongChanges(this.dataType, type);
146 40435 jjdelcerro
        this.dataType = ToolsLocator.getDataTypesManager().get(type);
147 47436 fdiaz
        this.setFixed(false);
148 40435 jjdelcerro
        return this;
149
    }
150
151
    public EditableFeatureAttributeDescriptor setDefaultValue(
152 45739 jjdelcerro
            Object defaultValue) {
153 44189 jjdelcerro
        updateStrongChanges(this.defaultValue, defaultValue);
154 40435 jjdelcerro
        this.defaultValue = defaultValue;
155 47436 fdiaz
        this.setFixed(false);
156 40435 jjdelcerro
        return this;
157
    }
158
159 46433 fdiaz
    @Override
160
    public EditableFeatureAttributeDescriptor setDefaultFieldValue(
161
            Object defaultValue) {
162
        return setDefaultValue(defaultValue);
163
    }
164
165 45135 jjdelcerro
    public EditableFeatureAttributeDescriptor setAvoidCachingAvailableValues(boolean avoidCachingAvailableValues) {
166
        this.avoidCachingAvailableValues = avoidCachingAvailableValues;
167 47436 fdiaz
        this.setFixed(false);
168 45135 jjdelcerro
        return this;
169
    }
170 45739 jjdelcerro
171 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
172 44189 jjdelcerro
        updateStrongChanges(this.evaluator, evaluator);
173 40435 jjdelcerro
        this.evaluator = evaluator;
174 47436 fdiaz
        this.setFixed(false);
175 40435 jjdelcerro
        return this;
176
    }
177
178 44253 jjdelcerro
    @Override
179 41335 jjdelcerro
    public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
180
        this.featureAttributeEmulator = featureAttributeEmulator;
181 47436 fdiaz
        this.setFixed(false);
182 41335 jjdelcerro
        return this;
183
    }
184 45739 jjdelcerro
185 44253 jjdelcerro
    @Override
186
    public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(Expression expression) {
187 45739 jjdelcerro
        if (ExpressionUtils.isPhraseEmpty(expression)) {
188
            this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null);
189 44253 jjdelcerro
            return this;
190 45739 jjdelcerro
        }
191 44253 jjdelcerro
        FeatureAttributeEmulatorExpression emulator = DALLocator.getDataManager().createFeatureAttributeEmulatorExpression(
192
                this.getFeatureType(),
193
                expression
194
        );
195
        return this.setFeatureAttributeEmulator(emulator);
196
    }
197
198
    @Override
199
    public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(String expression) {
200 45739 jjdelcerro
        if (StringUtils.isBlank(expression)) {
201
            this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null);
202 44253 jjdelcerro
            return this;
203 45739 jjdelcerro
        }
204 44253 jjdelcerro
        return this.setFeatureAttributeEmulator(ExpressionUtils.createExpression(expression));
205
    }
206 45739 jjdelcerro
207 44253 jjdelcerro
    @Override
208 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setGeometryType(int type) {
209
        this.geometryType = type;
210 45739 jjdelcerro
        if (this.geometrySubType == Geometry.SUBTYPES.UNKNOWN) {
211 42303 jjdelcerro
            this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
212
        }
213 40435 jjdelcerro
        this.geomType = null;
214 47436 fdiaz
        this.setFixed(false);
215 40435 jjdelcerro
        return this;
216
    }
217
218
    public EditableFeatureAttributeDescriptor setGeometrySubType(int subType) {
219
        this.geometrySubType = subType;
220
        this.geomType = null;
221 47436 fdiaz
        this.setFixed(false);
222 40435 jjdelcerro
        return this;
223
    }
224
225
    public EditableFeatureAttributeDescriptor setGeometryType(
226 45739 jjdelcerro
            GeometryType geometryType) {
227 44189 jjdelcerro
        updateStrongChanges(this.geomType, geometryType);
228 40435 jjdelcerro
        this.geomType = geometryType;
229
        this.geometryType = this.geomType.getType();
230
        this.geometrySubType = this.geomType.getSubType();
231 47436 fdiaz
        this.setFixed(false);
232 40435 jjdelcerro
        return this;
233
    }
234
235 42716 jjdelcerro
    @Override
236 44253 jjdelcerro
    public EditableFeatureAttributeDescriptor setGeometryType(String geometryType) {
237 45739 jjdelcerro
        if (StringUtils.isBlank(geometryType)) {
238 44253 jjdelcerro
            throw new IllegalArgumentException("Invalid geometry type (null)");
239
        }
240
        String separators = ":/-!;#@";
241
        Character sep = null;
242
        for (char ch : separators.toCharArray()) {
243 45739 jjdelcerro
            if (geometryType.indexOf(ch) >= 0) {
244 44253 jjdelcerro
                sep = ch;
245
                break;
246
            }
247
        }
248 45739 jjdelcerro
        if (sep == null) {
249
            throw new IllegalArgumentException("Invalid geometry type (" + geometryType + ") can't find separator, format can be GEOMETRYTYPE[" + separators + "]GEOMETRYSUBTYPE");
250 44253 jjdelcerro
        }
251 45739 jjdelcerro
        String[] xx = geometryType.split("[" + sep + "]");
252 44253 jjdelcerro
        int theGeomType = GeometryUtils.getGeometryType(xx[0]);
253
        int theGeomSubtype = GeometryUtils.getGeometrySubtype(xx[1]);
254
        this.setGeometryType(theGeomType, theGeomSubtype);
255 47436 fdiaz
        this.setFixed(false);
256 44253 jjdelcerro
        return this;
257
    }
258 45739 jjdelcerro
259 44253 jjdelcerro
    @Override
260 42716 jjdelcerro
    public EditableFeatureAttributeDescriptor setGeometryType(int type, int subType) {
261
        this.geometryType = type;
262
        this.geometrySubType = subType;
263
        this.geomType = null;
264 47436 fdiaz
        this.setFixed(false);
265 42716 jjdelcerro
        return this;
266
    }
267
268 46097 jjdelcerro
    @Override
269 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setIsPrimaryKey(
270 45739 jjdelcerro
            boolean isPrimaryKey) {
271 46097 jjdelcerro
        updateStrongChanges(this.primaryKey, isPrimaryKey);
272 40435 jjdelcerro
        this.primaryKey = isPrimaryKey;
273 47436 fdiaz
        this.setFixed(false);
274 40435 jjdelcerro
        return this;
275
    }
276
277 46097 jjdelcerro
    @Override
278 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) {
279 46097 jjdelcerro
        updateStrongChanges(this.readOnly, isReadOnly);
280 40435 jjdelcerro
        this.readOnly = isReadOnly;
281 47436 fdiaz
        this.setFixed(false);
282 40435 jjdelcerro
        return this;
283
    }
284
285
    public EditableFeatureAttributeDescriptor setMaximumOccurrences(
286 45739 jjdelcerro
            int maximumOccurrences) {
287 44189 jjdelcerro
        updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
288 40435 jjdelcerro
        this.maximumOccurrences = maximumOccurrences;
289 47436 fdiaz
        this.setFixed(false);
290 40435 jjdelcerro
        return this;
291
    }
292
293
    public EditableFeatureAttributeDescriptor setMinimumOccurrences(
294 45739 jjdelcerro
            int minimumOccurrences) {
295 44189 jjdelcerro
        updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
296 40435 jjdelcerro
        this.minimumOccurrences = minimumOccurrences;
297 47436 fdiaz
        this.setFixed(false);
298 40435 jjdelcerro
        return this;
299
    }
300
301 43967 jjdelcerro
    @Override
302 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setName(String name) {
303 45739 jjdelcerro
        if (StringUtils.equals(this.name, name)) {
304 44084 jjdelcerro
            return this;
305
        }
306 40435 jjdelcerro
        if (originalName == null) {
307
            originalName = this.name;
308 43967 jjdelcerro
            if (!isComputed()) {
309
                hasStrongChanges = true;
310
            }
311 40435 jjdelcerro
        }
312 44259 jjdelcerro
        super.setName(name);
313 43135 jjdelcerro
        if (!isComputed()) {
314 40435 jjdelcerro
            hasStrongChanges = true;
315
        }
316 47436 fdiaz
        this.setFixed(false);
317 40435 jjdelcerro
        return this;
318
    }
319 45739 jjdelcerro
320 40435 jjdelcerro
    public String getOriginalName() {
321
        return originalName;
322
    }
323
324
    public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) {
325 44189 jjdelcerro
        updateStrongChanges(this.objectClass, theClass);
326 40435 jjdelcerro
        this.objectClass = theClass;
327 47436 fdiaz
        this.setFixed(false);
328 40435 jjdelcerro
        return this;
329
    }
330
331 44669 jjdelcerro
    @Override
332 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setPrecision(int precision) {
333 44189 jjdelcerro
        updateStrongChanges(this.precision, precision);
334 40435 jjdelcerro
        this.precision = precision;
335 47436 fdiaz
        this.setFixed(false);
336 40435 jjdelcerro
        return this;
337
    }
338
339 44253 jjdelcerro
    @Override
340 44669 jjdelcerro
    public EditableFeatureAttributeDescriptor setScale(int scale) {
341
        updateStrongChanges(this.scale, scale);
342
        this.scale = scale;
343
        this.coerceContext = null;
344
        this.mathContext = null;
345 47436 fdiaz
        this.setFixed(false);
346 44669 jjdelcerro
        return this;
347
    }
348
349
    @Override
350 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
351 44189 jjdelcerro
        updateStrongChanges(this.SRS, SRS);
352 40435 jjdelcerro
        this.SRS = SRS;
353 47436 fdiaz
        this.setFixed(false);
354 40435 jjdelcerro
        return this;
355
    }
356
357 44253 jjdelcerro
    @Override
358
    public EditableFeatureAttributeDescriptor setSRS(String SRS) {
359 45739 jjdelcerro
        if (StringUtils.isBlank(SRS)) {
360
            this.setSRS((IProjection) null);
361 44253 jjdelcerro
            return this;
362
        }
363 45135 jjdelcerro
        SRS = SRS.replace('@', ':');
364 44253 jjdelcerro
        IProjection proj = CRSFactory.getCRS(SRS);
365
        this.setSRS(proj);
366 47436 fdiaz
        this.setFixed(false);
367 44253 jjdelcerro
        return this;
368
    }
369 45739 jjdelcerro
370 44077 jjdelcerro
    public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
371 44189 jjdelcerro
        updateStrongChanges(this.getInterval(), interval);
372 44094 jjdelcerro
        super.setInterval(interval);
373 47436 fdiaz
        this.setFixed(false);
374 44077 jjdelcerro
        return this;
375
    }
376
377 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setSize(int size) {
378 44189 jjdelcerro
        updateStrongChanges(this.size, size);
379 40435 jjdelcerro
        this.size = size;
380 47436 fdiaz
        this.setFixed(false);
381 40435 jjdelcerro
        return this;
382
    }
383
384
    public boolean hasStrongChanges() {
385
        return hasStrongChanges;
386
    }
387
388 45154 jjdelcerro
    @Override
389 40435 jjdelcerro
    public EditableFeatureAttributeDescriptor setAdditionalInfo(
390 45739 jjdelcerro
            String infoName, Object value) {
391 45154 jjdelcerro
        return this.setAdditionalInfo(infoName, Objects.toString(value, ""));
392
    }
393 45739 jjdelcerro
394 45154 jjdelcerro
    public EditableFeatureAttributeDescriptor setAdditionalInfo(
395 45739 jjdelcerro
            String infoName, String value) {
396 40435 jjdelcerro
        if (this.additionalInfo == null) {
397
            this.additionalInfo = new HashMap();
398
        }
399
        this.additionalInfo.put(infoName, value);
400 47436 fdiaz
        this.setFixed(false);
401 40435 jjdelcerro
        return this;
402
    }
403
404
    public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) {
405
        this.isAutomatic = isAutomatic;
406 45921 jjdelcerro
//        if (isAutomatic) {
407
//            this.setReadOnly(true);
408
//        }
409 47436 fdiaz
        this.setFixed(false);
410 40435 jjdelcerro
        return this;
411
    }
412 45739 jjdelcerro
413 41483 jjdelcerro
    public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) {
414 44189 jjdelcerro
        updateStrongChanges(this.isTime, isTime);
415 43135 jjdelcerro
        this.isTime = isTime;
416 47436 fdiaz
        this.setFixed(false);
417 43135 jjdelcerro
        return this;
418 41483 jjdelcerro
    }
419
420
    public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) {
421
        this.dateFormat = dateFormat;
422 47436 fdiaz
        this.setFixed(false);
423 41483 jjdelcerro
        return this;
424
    }
425 41638 jjdelcerro
426
    public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) {
427 44189 jjdelcerro
        updateStrongChanges(this.indexed, isIndexed);
428 41638 jjdelcerro
        this.indexed = isIndexed;
429 47436 fdiaz
        this.setFixed(false);
430 41638 jjdelcerro
        return this;
431
    }
432 45739 jjdelcerro
433 41638 jjdelcerro
    public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) {
434 44189 jjdelcerro
        updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
435 41638 jjdelcerro
        this.allowIndexDuplicateds = allowDuplicateds;
436 47436 fdiaz
        this.setFixed(false);
437 41638 jjdelcerro
        return this;
438
    }
439
440
    public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) {
441 44189 jjdelcerro
        updateStrongChanges(this.isIndexAscending, ascending);
442 41638 jjdelcerro
        this.isIndexAscending = ascending;
443 47436 fdiaz
        this.setFixed(false);
444 41638 jjdelcerro
        return this;
445
    }
446 44128 jjdelcerro
447
    @Override
448
    public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) {
449
        super.setDataProfileName(dataProfile);
450 47436 fdiaz
        this.setFixed(false);
451 44128 jjdelcerro
        return this;
452
    }
453 44189 jjdelcerro
454
    private void updateStrongChanges(int previous, int newvalue) {
455 45739 jjdelcerro
        if (isComputed()) {
456 44189 jjdelcerro
            return;
457
        }
458 45739 jjdelcerro
        if (previous == newvalue) {
459 44189 jjdelcerro
            return;
460
        }
461
        this.hasStrongChanges = true;
462
    }
463
464
    private void updateStrongChanges(DataType previous, int newvalue) {
465 45739 jjdelcerro
        if (isComputed()) {
466 44189 jjdelcerro
            return;
467
        }
468 45739 jjdelcerro
        if (previous != null) {
469
            if (previous.getType() == newvalue) {
470 44189 jjdelcerro
                return;
471
            }
472
        }
473
        this.hasStrongChanges = true;
474
    }
475
476
    private void updateStrongChanges(boolean previous, boolean newvalue) {
477 45739 jjdelcerro
        if (isComputed()) {
478 44189 jjdelcerro
            return;
479
        }
480 45739 jjdelcerro
        if (previous == newvalue) {
481 44189 jjdelcerro
            return;
482
        }
483
        this.hasStrongChanges = true;
484
    }
485
486
    private void updateStrongChanges(Object previous, Object newvalue) {
487 45739 jjdelcerro
        if (isComputed()) {
488 44189 jjdelcerro
            return;
489
        }
490 45739 jjdelcerro
        if (Objects.equals(newvalue, previous)) {
491 44189 jjdelcerro
            return;
492
        }
493
        this.hasStrongChanges = true;
494
    }
495 44337 jjdelcerro
496 44673 jjdelcerro
    @Override
497 44669 jjdelcerro
    public EditableFeatureAttributeDescriptor setLocale(Locale locale) {
498 45739 jjdelcerro
        if (locale == null) {
499
            this.locale = Locale.ENGLISH;
500
        } else {
501
            this.locale = locale;
502
        }
503
        this.coerceContext = null;
504
        this.mathContext = null;
505 47436 fdiaz
        this.setFixed(false);
506 45739 jjdelcerro
        return this;
507 44669 jjdelcerro
    }
508 44337 jjdelcerro
509 44669 jjdelcerro
    public EditableFeatureAttributeDescriptor setLocale(String locale) {
510 45739 jjdelcerro
        Locale l;
511
        try {
512
            String s = DataTypeUtils.toString(locale, null);
513
            if (StringUtils.isBlank(s)) {
514
                return this.setLocale((Locale) null);
515
            }
516
            l = new Locale(s);
517
            return this.setLocale(l);
518
        } catch (Exception ex) {
519
            return this.setLocale((Locale) null);
520 47436 fdiaz
        } finally {
521
            this.setFixed(false);
522 44669 jjdelcerro
        }
523
    }
524 45739 jjdelcerro
525 44673 jjdelcerro
    @Override
526 44669 jjdelcerro
    public EditableFeatureAttributeDescriptor setRoundMode(int roundMode) {
527 45739 jjdelcerro
        switch (roundMode) {
528
            case BigDecimal.ROUND_UP:
529
            case BigDecimal.ROUND_DOWN:
530
            case BigDecimal.ROUND_CEILING:
531
            case BigDecimal.ROUND_FLOOR:
532
            case BigDecimal.ROUND_HALF_UP:
533
            case BigDecimal.ROUND_HALF_DOWN:
534
            case BigDecimal.ROUND_HALF_EVEN:
535
            case BigDecimal.ROUND_UNNECESSARY:
536
                this.roundMode = roundMode;
537
                this.coerceContext = null;
538
                this.mathContext = null;
539
                break;
540
            default:
541
                throw new IllegalArgumentException("round mode '" + roundMode + "' not valid.");
542
        }
543 47436 fdiaz
        this.setFixed(false);
544 45739 jjdelcerro
        return this;
545 44669 jjdelcerro
    }
546
547
    @Override
548 44337 jjdelcerro
    public EditableFeatureAttributeDescriptor set(String name, Object value) {
549 45739 jjdelcerro
        if (StringUtils.isBlank(name)) {
550 44337 jjdelcerro
            throw new IllegalArgumentException("Name can't be empty");
551
        }
552 45739 jjdelcerro
        String ss;
553
        switch (name.trim().toLowerCase()) {
554 45135 jjdelcerro
            case "isavoidcachingavailablevalues":
555
            case "avoidcachingavailablevalues":
556
            case "nocachingavailablevalues":
557
                this.setAvoidCachingAvailableValues(DataTypeUtils.toBoolean(value, false));
558
                break;
559 45042 jjdelcerro
            case "availablevalues":
560
                this.setAvailableValuesExpression(DataTypeUtils.toString(value, null));
561
                break;
562 44338 jjdelcerro
            case "isreadonly":
563
            case "readonly":
564 44337 jjdelcerro
                this.setIsReadOnly(DataTypeUtils.toBoolean(value, false));
565
                break;
566 45068 jjdelcerro
            case "mandatory":
567
                this.setMandatory(DataTypeUtils.toBoolean(value, false));
568
                break;
569 44337 jjdelcerro
            case "hidden":
570
                this.setHidden(DataTypeUtils.toBoolean(value, false));
571
                break;
572
            case "allownull":
573
                this.setAllowNull(DataTypeUtils.toBoolean(value, false));
574
                break;
575 45731 omartinez
            case "indexed":
576
            case "isindexed":
577
                this.setIsIndexed(DataTypeUtils.toBoolean(value, false));
578
                break;
579 47020 jjdelcerro
            case "indexasc":
580
            case "indexascending":
581
            case "isindexascending":
582
                this.setIsIndexAscending(DataTypeUtils.toBoolean(value, false));
583
                break;
584 44337 jjdelcerro
            case "pk":
585
            case "ispk":
586
            case "primarykey":
587
            case "isprimarykey":
588
                this.setIsPrimaryKey(DataTypeUtils.toBoolean(value, false));
589
                break;
590 45865 omartinez
            case "allowindexduplicateds":
591
                this.setAllowIndexDuplicateds(DataTypeUtils.toBoolean(value, false));
592
                break;
593 44337 jjdelcerro
            case "isautomatic":
594
            case "automatic":
595
                this.setIsAutomatic(DataTypeUtils.toBoolean(value, false));
596
                break;
597
            case "time":
598
            case "istime":
599
                this.setIsTime(DataTypeUtils.toBoolean(value, false));
600
                break;
601
            case "profile":
602
                this.setDataProfileName(DataTypeUtils.toString(value, null));
603
                break;
604
            case "group":
605
                this.setGroup(DataTypeUtils.toString(value, null));
606
                break;
607
            case "description":
608
                this.setDescription(DataTypeUtils.toString(value, null));
609
                break;
610
            case "label":
611
                this.setLabel(DataTypeUtils.toString(value, null));
612
                break;
613
            case "shortlabel":
614
                this.setShortLabel(DataTypeUtils.toString(value, null));
615
                break;
616
            case "expression":
617
                this.setFeatureAttributeEmulator(DataTypeUtils.toString(value, null));
618
                break;
619
            case "size":
620
                this.setSize(DataTypeUtils.toInteger(value, 50));
621
                break;
622 47565 jjdelcerro
            case "displaysize":
623
                this.setDisplaySize(DataTypeUtils.toInteger(value, 50));
624
                break;
625 44337 jjdelcerro
            case "precision":
626
                this.setPrecision(DataTypeUtils.toInteger(value, 10));
627
                break;
628 44669 jjdelcerro
            case "scale":
629
                this.setScale(DataTypeUtils.toInteger(value, 10));
630
                break;
631
            case "roundmode":
632 45739 jjdelcerro
                this.setRoundMode(DataTypeUtils.toInteger(value, BigDecimal.ROUND_UNNECESSARY));
633
                break;
634 44669 jjdelcerro
            case "locale":
635 45739 jjdelcerro
                this.setLocale(DataTypeUtils.toString(value, null));
636
                break;
637 44337 jjdelcerro
            case "order":
638
                this.setOrder(DataTypeUtils.toInteger(value, 0));
639
                break;
640 45040 jjdelcerro
            case "fk":
641 44337 jjdelcerro
            case "foreingkey":
642
                this.getForeingKey().setForeingKey(DataTypeUtils.toBoolean(value, false));
643
                break;
644 45040 jjdelcerro
            case "fk_code":
645
            case "foreingkey_code":
646 44337 jjdelcerro
            case "foreingkey.code":
647
                this.getForeingKey().setCodeName(DataTypeUtils.toString(value, ""));
648
                break;
649 45040 jjdelcerro
            case "fk_label":
650
            case "foreingkey_label":
651 44337 jjdelcerro
            case "foreingkey.label":
652
                this.getForeingKey().setLabelFormula(DataTypeUtils.toString(value, ""));
653
                break;
654 45739 jjdelcerro
            case "fk_closed":
655
            case "fk_closedlist":
656 45040 jjdelcerro
            case "fk.closedlist":
657
            case "foreingkey_closedlist":
658 44338 jjdelcerro
            case "foreingkey.closedlist":
659
                this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false));
660 44337 jjdelcerro
                break;
661 45040 jjdelcerro
            case "fk_table":
662
            case "foreingkey_table":
663 44337 jjdelcerro
            case "foreingkey.table":
664
                this.getForeingKey().setTableName(DataTypeUtils.toString(value, null));
665
                break;
666
            case "interval":
667
                this.setInterval(DataTypeUtils.toInterval(value, null));
668
                break;
669
            case "geomtype":
670
            case "geometrytype":
671
                this.setGeometryType(DataTypeUtils.toString(value, null));
672
                break;
673
            case "srs":
674 45135 jjdelcerro
                this.setSRS(DataTypeUtils.toString(value, null));
675 44337 jjdelcerro
                break;
676 44740 jjdelcerro
            case "relation":
677
                this.setRelationType(toRelation(value));
678
                break;
679 44941 jjdelcerro
            case "name":
680
                this.setName(DataTypeUtils.toString(value, null));
681
                break;
682
            case "type":
683
            case "datatype":
684
                ss = DataTypeUtils.toString(value, null);
685 45739 jjdelcerro
                if (!StringUtils.isBlank(ss)) {
686 44941 jjdelcerro
                    this.setDataType(ToolsLocator.getDataTypesManager().getType(ss));
687
                }
688
                break;
689 45775 jjdelcerro
            case "defaultvalue":
690
                this.setDefaultValue(value);
691 45739 jjdelcerro
                break;
692 45775 jjdelcerro
            case "availablevaluesfilter":
693
                this.setAvailableValuesFilter(DataTypeUtils.toString(value, null));
694
                break;
695 46542 fdiaz
            case "format":
696
            case "defaultformat":
697
                this.setDefaultFormat(DataTypeUtils.toString(value, null));
698 44337 jjdelcerro
            default:
699 45739 jjdelcerro
                throw new IllegalArgumentException("Name attribute '" + name + "' not valid.");
700
        }
701 47436 fdiaz
        this.setFixed(false);
702 44337 jjdelcerro
        return this;
703
    }
704 45739 jjdelcerro
705 44740 jjdelcerro
    private int toRelation(Object value) {
706 45739 jjdelcerro
        if (value == null) {
707 44740 jjdelcerro
            return DynField.RELATION_TYPE_NONE;
708
        }
709 45739 jjdelcerro
        Integer x = (Integer) DataTypeUtils.coerce(DataTypes.INT, value, null);
710
        if (x != null) {
711
            return x;
712
        }
713
        try {
714
            String s = value.toString().toUpperCase();
715
            switch (s) {
716
                case "NONE":
717
                default:
718
                    return DynField.RELATION_TYPE_NONE;
719
                case "IDENTITY":
720
                    return DynField.RELATION_TYPE_IDENTITY;
721
                case "COLLABORATION":
722
                    return DynField.RELATION_TYPE_COLLABORATION;
723
                case "COMPOSITION":
724
                    return DynField.RELATION_TYPE_COMPOSITION;
725
                case "AGGREGATE":
726
                    return DynField.RELATION_TYPE_AGGREGATE;
727
            }
728
        } catch (Exception ex) {
729
            return DynField.RELATION_TYPE_NONE;
730
        }
731 44740 jjdelcerro
    }
732 44844 jjdelcerro
733 45739 jjdelcerro
    @Override
734
    public EditableFeatureAttributeDescriptor setDisplaySize(int size) {
735
        this.displaySize = size;
736 47436 fdiaz
        this.setFixed(false);
737 45739 jjdelcerro
        return this;
738
    }
739
740
    @Override
741
    public EditableFeatureAttributeDescriptor setAvailableValuesFilter(Expression filter) {
742
        super.setAvailableValuesFilter(filter);
743
        return this;
744
    }
745
746 45775 jjdelcerro
    @Override
747
    public EditableFeatureAttributeDescriptor setAvailableValuesFilter(String filter) {
748
        super.setAvailableValuesFilter(filter);
749
        return this;
750
    }
751
752 45425 jjdelcerro
    private static class TheJsonSerializer implements JsonManager.JsonSerializer {
753 45739 jjdelcerro
754
        public TheJsonSerializer() {
755 45425 jjdelcerro
        }
756
757
        @Override
758
        public Class getObjectClass() {
759
            return DefaultEditableFeatureAttributeDescriptor.class;
760
        }
761
762
        @Override
763
        public Object toObject(JsonObject json) {
764
            DefaultFeatureAttributeDescriptor o = new DefaultFeatureAttributeDescriptor();
765
            o.fromJson(json);
766
            return o;
767
        }
768
769
        @Override
770
        public JsonObjectBuilder toJsonBuilder(Object value) {
771 45739 jjdelcerro
            return ((SupportToJson) value).toJsonBuilder();
772 45425 jjdelcerro
        }
773 45739 jjdelcerro
774 45425 jjdelcerro
    }
775 45739 jjdelcerro
776 45564 jjdelcerro
    @Override
777
    public EditableFeatureAttributeDescriptor setForeingkey(
778
            boolean isForeingkey,
779
            boolean isClosedList,
780
            String tableName,
781
            String codeName,
782
            String labelFormula
783 45739 jjdelcerro
    ) {
784
        if (isForeingkey) {
785 45564 jjdelcerro
            EditableForeingKey fk = this.getForeingKey();
786
            fk.setForeingKey(isForeingkey);
787
            fk.setClosedList(isClosedList);
788
            fk.setTableName(tableName);
789
            fk.setCodeName(codeName);
790
            fk.setLabelFormula(labelFormula);
791
        } else {
792
            this.foreingKey = null;
793 45739 jjdelcerro
        }
794 47436 fdiaz
        this.setFixed(false);
795 45564 jjdelcerro
        return this;
796
    }
797 45425 jjdelcerro
798 45564 jjdelcerro
    @Override
799
    public EditableFeatureAttributeDescriptor setTag(String name, Object value) {
800
        this.getTags().set(name, value);
801 47436 fdiaz
        this.setFixed(false);
802 45564 jjdelcerro
        return this;
803
    }
804
805 45425 jjdelcerro
    public static void selfRegister() {
806
        Json.registerSerializer(new TheJsonSerializer());
807
    }
808 45739 jjdelcerro
809 45968 jjdelcerro
    @Override
810
    public EditableFeatureAttributeDescriptor setDefaultFormat(String format) {
811
        this.defaultFormat = format;
812 47436 fdiaz
        this.setFixed(false);
813 45968 jjdelcerro
        return this;
814
    }
815
816
817 40435 jjdelcerro
}