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 @ 47565
History | View | Annotate | Download (27.2 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
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 |
package org.gvsig.fmap.dal.feature.impl; |
25 |
|
26 |
import java.math.BigDecimal; |
27 |
import java.text.DateFormat; |
28 |
import java.util.HashMap; |
29 |
import java.util.Locale; |
30 |
import java.util.Objects; |
31 |
import javax.json.JsonObject; |
32 |
import org.apache.commons.lang3.StringUtils; |
33 |
|
34 |
import org.cresques.cts.IProjection; |
35 |
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 |
import org.gvsig.fmap.dal.DataTypeUtils; |
40 |
import org.gvsig.fmap.dal.DataTypes; |
41 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
46 |
import org.gvsig.fmap.dal.feature.EditableForeingKey; |
47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
48 |
import org.gvsig.fmap.dal.feature.FeatureType; |
49 |
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
50 |
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
51 |
import org.gvsig.fmap.geom.Geometry; |
52 |
import org.gvsig.fmap.geom.GeometryUtils; |
53 |
import org.gvsig.fmap.geom.type.GeometryType; |
54 |
import org.gvsig.json.Json; |
55 |
import org.gvsig.json.JsonManager; |
56 |
import org.gvsig.json.JsonObjectBuilder; |
57 |
import org.gvsig.json.SupportToJson; |
58 |
import org.gvsig.timesupport.Interval; |
59 |
import org.gvsig.tools.ToolsLocator; |
60 |
import org.gvsig.tools.dataTypes.DataType; |
61 |
import org.gvsig.tools.dynobject.DynField; |
62 |
import org.gvsig.tools.evaluator.Evaluator; |
63 |
|
64 |
public class DefaultEditableFeatureAttributeDescriptor extends |
65 |
DefaultFeatureAttributeDescriptor implements
|
66 |
EditableFeatureAttributeDescriptor { |
67 |
|
68 |
private static Logger logger = LoggerFactory.getLogger( |
69 |
DefaultEditableFeatureAttributeDescriptor.class); |
70 |
|
71 |
private final DefaultFeatureAttributeDescriptor source; |
72 |
private boolean hasStrongChanges; |
73 |
private String originalName = null; |
74 |
|
75 |
protected DefaultEditableFeatureAttributeDescriptor(
|
76 |
DefaultFeatureAttributeDescriptor other) { |
77 |
super(other);
|
78 |
if (other instanceof DefaultEditableFeatureAttributeDescriptor) { |
79 |
DefaultEditableFeatureAttributeDescriptor other_edi |
80 |
= (DefaultEditableFeatureAttributeDescriptor) other; |
81 |
originalName = other_edi.getOriginalName(); |
82 |
this.source = other_edi.getSource();
|
83 |
} else {
|
84 |
this.source = other;
|
85 |
} |
86 |
hasStrongChanges = false;
|
87 |
} |
88 |
|
89 |
public DefaultEditableFeatureAttributeDescriptor(FeatureType type, boolean strongChanges) { |
90 |
super(type);
|
91 |
this.source = null; |
92 |
hasStrongChanges = strongChanges; |
93 |
} |
94 |
|
95 |
public DefaultFeatureAttributeDescriptor getSource() {
|
96 |
return this.source; |
97 |
} |
98 |
|
99 |
public void fixAll() { |
100 |
super.fixAll();
|
101 |
} |
102 |
|
103 |
public void checkIntegrity() throws AttributeFeatureTypeIntegrityException { |
104 |
AttributeFeatureTypeIntegrityException ex |
105 |
= new AttributeFeatureTypeIntegrityException(getName());
|
106 |
if (this.size < 0) { |
107 |
ex.add(new AttributeFeatureTypeSizeException(this.size)); |
108 |
} |
109 |
|
110 |
if (this.dataType.isObject() && this.objectClass == null) { |
111 |
logger.warn("Incorrect data type object, objectClass is null.");
|
112 |
ex.add(new AttributeFeatureTypeIntegrityException(this.name)); |
113 |
} |
114 |
|
115 |
// TODO: Add other integrity checks...
|
116 |
if (ex.size() > 0) { |
117 |
throw ex;
|
118 |
} |
119 |
} |
120 |
|
121 |
public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
122 |
updateStrongChanges(this.allowNull, allowNull);
|
123 |
this.allowNull = allowNull;
|
124 |
this.setFixed(false); |
125 |
return this; |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public EditableForeingKey getForeingKey() {
|
130 |
if (this.foreingKey == null) { |
131 |
this.foreingKey = new DefaultForeingKey(); |
132 |
this.foreingKey.setDescriptor(this); |
133 |
} |
134 |
return this.foreingKey; |
135 |
} |
136 |
|
137 |
public EditableFeatureAttributeDescriptor setDataType(DataType dataType) {
|
138 |
updateStrongChanges(this.dataType, dataType);
|
139 |
this.dataType = dataType;
|
140 |
this.setFixed(false); |
141 |
return this; |
142 |
} |
143 |
|
144 |
public EditableFeatureAttributeDescriptor setDataType(int type) { |
145 |
updateStrongChanges(this.dataType, type);
|
146 |
this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
147 |
this.setFixed(false); |
148 |
return this; |
149 |
} |
150 |
|
151 |
public EditableFeatureAttributeDescriptor setDefaultValue(
|
152 |
Object defaultValue) {
|
153 |
updateStrongChanges(this.defaultValue, defaultValue);
|
154 |
this.defaultValue = defaultValue;
|
155 |
this.setFixed(false); |
156 |
return this; |
157 |
} |
158 |
|
159 |
@Override
|
160 |
public EditableFeatureAttributeDescriptor setDefaultFieldValue(
|
161 |
Object defaultValue) {
|
162 |
return setDefaultValue(defaultValue);
|
163 |
} |
164 |
|
165 |
public EditableFeatureAttributeDescriptor setAvoidCachingAvailableValues(boolean avoidCachingAvailableValues) { |
166 |
this.avoidCachingAvailableValues = avoidCachingAvailableValues;
|
167 |
this.setFixed(false); |
168 |
return this; |
169 |
} |
170 |
|
171 |
public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
|
172 |
updateStrongChanges(this.evaluator, evaluator);
|
173 |
this.evaluator = evaluator;
|
174 |
this.setFixed(false); |
175 |
return this; |
176 |
} |
177 |
|
178 |
@Override
|
179 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
180 |
this.featureAttributeEmulator = featureAttributeEmulator;
|
181 |
this.setFixed(false); |
182 |
return this; |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(Expression expression) { |
187 |
if (ExpressionUtils.isPhraseEmpty(expression)) {
|
188 |
this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null); |
189 |
return this; |
190 |
} |
191 |
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 |
if (StringUtils.isBlank(expression)) {
|
201 |
this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null); |
202 |
return this; |
203 |
} |
204 |
return this.setFeatureAttributeEmulator(ExpressionUtils.createExpression(expression)); |
205 |
} |
206 |
|
207 |
@Override
|
208 |
public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
209 |
this.geometryType = type;
|
210 |
if (this.geometrySubType == Geometry.SUBTYPES.UNKNOWN) { |
211 |
this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
212 |
} |
213 |
this.geomType = null; |
214 |
this.setFixed(false); |
215 |
return this; |
216 |
} |
217 |
|
218 |
public EditableFeatureAttributeDescriptor setGeometrySubType(int subType) { |
219 |
this.geometrySubType = subType;
|
220 |
this.geomType = null; |
221 |
this.setFixed(false); |
222 |
return this; |
223 |
} |
224 |
|
225 |
public EditableFeatureAttributeDescriptor setGeometryType(
|
226 |
GeometryType geometryType) { |
227 |
updateStrongChanges(this.geomType, geometryType);
|
228 |
this.geomType = geometryType;
|
229 |
this.geometryType = this.geomType.getType(); |
230 |
this.geometrySubType = this.geomType.getSubType(); |
231 |
this.setFixed(false); |
232 |
return this; |
233 |
} |
234 |
|
235 |
@Override
|
236 |
public EditableFeatureAttributeDescriptor setGeometryType(String geometryType) { |
237 |
if (StringUtils.isBlank(geometryType)) {
|
238 |
throw new IllegalArgumentException("Invalid geometry type (null)"); |
239 |
} |
240 |
String separators = ":/-!;#@"; |
241 |
Character sep = null; |
242 |
for (char ch : separators.toCharArray()) { |
243 |
if (geometryType.indexOf(ch) >= 0) { |
244 |
sep = ch; |
245 |
break;
|
246 |
} |
247 |
} |
248 |
if (sep == null) { |
249 |
throw new IllegalArgumentException("Invalid geometry type (" + geometryType + ") can't find separator, format can be GEOMETRYTYPE[" + separators + "]GEOMETRYSUBTYPE"); |
250 |
} |
251 |
String[] xx = geometryType.split("[" + sep + "]"); |
252 |
int theGeomType = GeometryUtils.getGeometryType(xx[0]); |
253 |
int theGeomSubtype = GeometryUtils.getGeometrySubtype(xx[1]); |
254 |
this.setGeometryType(theGeomType, theGeomSubtype);
|
255 |
this.setFixed(false); |
256 |
return this; |
257 |
} |
258 |
|
259 |
@Override
|
260 |
public EditableFeatureAttributeDescriptor setGeometryType(int type, int subType) { |
261 |
this.geometryType = type;
|
262 |
this.geometrySubType = subType;
|
263 |
this.geomType = null; |
264 |
this.setFixed(false); |
265 |
return this; |
266 |
} |
267 |
|
268 |
@Override
|
269 |
public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
270 |
boolean isPrimaryKey) {
|
271 |
updateStrongChanges(this.primaryKey, isPrimaryKey);
|
272 |
this.primaryKey = isPrimaryKey;
|
273 |
this.setFixed(false); |
274 |
return this; |
275 |
} |
276 |
|
277 |
@Override
|
278 |
public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
279 |
updateStrongChanges(this.readOnly, isReadOnly);
|
280 |
this.readOnly = isReadOnly;
|
281 |
this.setFixed(false); |
282 |
return this; |
283 |
} |
284 |
|
285 |
public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
286 |
int maximumOccurrences) {
|
287 |
updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
|
288 |
this.maximumOccurrences = maximumOccurrences;
|
289 |
this.setFixed(false); |
290 |
return this; |
291 |
} |
292 |
|
293 |
public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
294 |
int minimumOccurrences) {
|
295 |
updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
|
296 |
this.minimumOccurrences = minimumOccurrences;
|
297 |
this.setFixed(false); |
298 |
return this; |
299 |
} |
300 |
|
301 |
@Override
|
302 |
public EditableFeatureAttributeDescriptor setName(String name) { |
303 |
if (StringUtils.equals(this.name, name)) { |
304 |
return this; |
305 |
} |
306 |
if (originalName == null) { |
307 |
originalName = this.name;
|
308 |
if (!isComputed()) {
|
309 |
hasStrongChanges = true;
|
310 |
} |
311 |
} |
312 |
super.setName(name);
|
313 |
if (!isComputed()) {
|
314 |
hasStrongChanges = true;
|
315 |
} |
316 |
this.setFixed(false); |
317 |
return this; |
318 |
} |
319 |
|
320 |
public String getOriginalName() { |
321 |
return originalName;
|
322 |
} |
323 |
|
324 |
public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
325 |
updateStrongChanges(this.objectClass, theClass);
|
326 |
this.objectClass = theClass;
|
327 |
this.setFixed(false); |
328 |
return this; |
329 |
} |
330 |
|
331 |
@Override
|
332 |
public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
333 |
updateStrongChanges(this.precision, precision);
|
334 |
this.precision = precision;
|
335 |
this.setFixed(false); |
336 |
return this; |
337 |
} |
338 |
|
339 |
@Override
|
340 |
public EditableFeatureAttributeDescriptor setScale(int scale) { |
341 |
updateStrongChanges(this.scale, scale);
|
342 |
this.scale = scale;
|
343 |
this.coerceContext = null; |
344 |
this.mathContext = null; |
345 |
this.setFixed(false); |
346 |
return this; |
347 |
} |
348 |
|
349 |
@Override
|
350 |
public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
351 |
updateStrongChanges(this.SRS, SRS);
|
352 |
this.SRS = SRS;
|
353 |
this.setFixed(false); |
354 |
return this; |
355 |
} |
356 |
|
357 |
@Override
|
358 |
public EditableFeatureAttributeDescriptor setSRS(String SRS) { |
359 |
if (StringUtils.isBlank(SRS)) {
|
360 |
this.setSRS((IProjection) null); |
361 |
return this; |
362 |
} |
363 |
SRS = SRS.replace('@', ':'); |
364 |
IProjection proj = CRSFactory.getCRS(SRS); |
365 |
this.setSRS(proj);
|
366 |
this.setFixed(false); |
367 |
return this; |
368 |
} |
369 |
|
370 |
public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
|
371 |
updateStrongChanges(this.getInterval(), interval);
|
372 |
super.setInterval(interval);
|
373 |
this.setFixed(false); |
374 |
return this; |
375 |
} |
376 |
|
377 |
public EditableFeatureAttributeDescriptor setSize(int size) { |
378 |
updateStrongChanges(this.size, size);
|
379 |
this.size = size;
|
380 |
this.setFixed(false); |
381 |
return this; |
382 |
} |
383 |
|
384 |
public boolean hasStrongChanges() { |
385 |
return hasStrongChanges;
|
386 |
} |
387 |
|
388 |
@Override
|
389 |
public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
390 |
String infoName, Object value) { |
391 |
return this.setAdditionalInfo(infoName, Objects.toString(value, "")); |
392 |
} |
393 |
|
394 |
public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
395 |
String infoName, String value) { |
396 |
if (this.additionalInfo == null) { |
397 |
this.additionalInfo = new HashMap(); |
398 |
} |
399 |
this.additionalInfo.put(infoName, value);
|
400 |
this.setFixed(false); |
401 |
return this; |
402 |
} |
403 |
|
404 |
public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) { |
405 |
this.isAutomatic = isAutomatic;
|
406 |
// if (isAutomatic) {
|
407 |
// this.setReadOnly(true);
|
408 |
// }
|
409 |
this.setFixed(false); |
410 |
return this; |
411 |
} |
412 |
|
413 |
public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
414 |
updateStrongChanges(this.isTime, isTime);
|
415 |
this.isTime = isTime;
|
416 |
this.setFixed(false); |
417 |
return this; |
418 |
} |
419 |
|
420 |
public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
421 |
this.dateFormat = dateFormat;
|
422 |
this.setFixed(false); |
423 |
return this; |
424 |
} |
425 |
|
426 |
public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
427 |
updateStrongChanges(this.indexed, isIndexed);
|
428 |
this.indexed = isIndexed;
|
429 |
this.setFixed(false); |
430 |
return this; |
431 |
} |
432 |
|
433 |
public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
434 |
updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
|
435 |
this.allowIndexDuplicateds = allowDuplicateds;
|
436 |
this.setFixed(false); |
437 |
return this; |
438 |
} |
439 |
|
440 |
public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
441 |
updateStrongChanges(this.isIndexAscending, ascending);
|
442 |
this.isIndexAscending = ascending;
|
443 |
this.setFixed(false); |
444 |
return this; |
445 |
} |
446 |
|
447 |
@Override
|
448 |
public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
449 |
super.setDataProfileName(dataProfile);
|
450 |
this.setFixed(false); |
451 |
return this; |
452 |
} |
453 |
|
454 |
private void updateStrongChanges(int previous, int newvalue) { |
455 |
if (isComputed()) {
|
456 |
return;
|
457 |
} |
458 |
if (previous == newvalue) {
|
459 |
return;
|
460 |
} |
461 |
this.hasStrongChanges = true; |
462 |
} |
463 |
|
464 |
private void updateStrongChanges(DataType previous, int newvalue) { |
465 |
if (isComputed()) {
|
466 |
return;
|
467 |
} |
468 |
if (previous != null) { |
469 |
if (previous.getType() == newvalue) {
|
470 |
return;
|
471 |
} |
472 |
} |
473 |
this.hasStrongChanges = true; |
474 |
} |
475 |
|
476 |
private void updateStrongChanges(boolean previous, boolean newvalue) { |
477 |
if (isComputed()) {
|
478 |
return;
|
479 |
} |
480 |
if (previous == newvalue) {
|
481 |
return;
|
482 |
} |
483 |
this.hasStrongChanges = true; |
484 |
} |
485 |
|
486 |
private void updateStrongChanges(Object previous, Object newvalue) { |
487 |
if (isComputed()) {
|
488 |
return;
|
489 |
} |
490 |
if (Objects.equals(newvalue, previous)) {
|
491 |
return;
|
492 |
} |
493 |
this.hasStrongChanges = true; |
494 |
} |
495 |
|
496 |
@Override
|
497 |
public EditableFeatureAttributeDescriptor setLocale(Locale locale) { |
498 |
if (locale == null) { |
499 |
this.locale = Locale.ENGLISH; |
500 |
} else {
|
501 |
this.locale = locale;
|
502 |
} |
503 |
this.coerceContext = null; |
504 |
this.mathContext = null; |
505 |
this.setFixed(false); |
506 |
return this; |
507 |
} |
508 |
|
509 |
public EditableFeatureAttributeDescriptor setLocale(String locale) { |
510 |
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 |
} finally {
|
521 |
this.setFixed(false); |
522 |
} |
523 |
} |
524 |
|
525 |
@Override
|
526 |
public EditableFeatureAttributeDescriptor setRoundMode(int roundMode) { |
527 |
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 |
this.setFixed(false); |
544 |
return this; |
545 |
} |
546 |
|
547 |
@Override
|
548 |
public EditableFeatureAttributeDescriptor set(String name, Object value) { |
549 |
if (StringUtils.isBlank(name)) {
|
550 |
throw new IllegalArgumentException("Name can't be empty"); |
551 |
} |
552 |
String ss;
|
553 |
switch (name.trim().toLowerCase()) {
|
554 |
case "isavoidcachingavailablevalues": |
555 |
case "avoidcachingavailablevalues": |
556 |
case "nocachingavailablevalues": |
557 |
this.setAvoidCachingAvailableValues(DataTypeUtils.toBoolean(value, false)); |
558 |
break;
|
559 |
case "availablevalues": |
560 |
this.setAvailableValuesExpression(DataTypeUtils.toString(value, null)); |
561 |
break;
|
562 |
case "isreadonly": |
563 |
case "readonly": |
564 |
this.setIsReadOnly(DataTypeUtils.toBoolean(value, false)); |
565 |
break;
|
566 |
case "mandatory": |
567 |
this.setMandatory(DataTypeUtils.toBoolean(value, false)); |
568 |
break;
|
569 |
case "hidden": |
570 |
this.setHidden(DataTypeUtils.toBoolean(value, false)); |
571 |
break;
|
572 |
case "allownull": |
573 |
this.setAllowNull(DataTypeUtils.toBoolean(value, false)); |
574 |
break;
|
575 |
case "indexed": |
576 |
case "isindexed": |
577 |
this.setIsIndexed(DataTypeUtils.toBoolean(value, false)); |
578 |
break;
|
579 |
case "indexasc": |
580 |
case "indexascending": |
581 |
case "isindexascending": |
582 |
this.setIsIndexAscending(DataTypeUtils.toBoolean(value, false)); |
583 |
break;
|
584 |
case "pk": |
585 |
case "ispk": |
586 |
case "primarykey": |
587 |
case "isprimarykey": |
588 |
this.setIsPrimaryKey(DataTypeUtils.toBoolean(value, false)); |
589 |
break;
|
590 |
case "allowindexduplicateds": |
591 |
this.setAllowIndexDuplicateds(DataTypeUtils.toBoolean(value, false)); |
592 |
break;
|
593 |
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 |
case "displaysize": |
623 |
this.setDisplaySize(DataTypeUtils.toInteger(value, 50)); |
624 |
break;
|
625 |
case "precision": |
626 |
this.setPrecision(DataTypeUtils.toInteger(value, 10)); |
627 |
break;
|
628 |
case "scale": |
629 |
this.setScale(DataTypeUtils.toInteger(value, 10)); |
630 |
break;
|
631 |
case "roundmode": |
632 |
this.setRoundMode(DataTypeUtils.toInteger(value, BigDecimal.ROUND_UNNECESSARY)); |
633 |
break;
|
634 |
case "locale": |
635 |
this.setLocale(DataTypeUtils.toString(value, null)); |
636 |
break;
|
637 |
case "order": |
638 |
this.setOrder(DataTypeUtils.toInteger(value, 0)); |
639 |
break;
|
640 |
case "fk": |
641 |
case "foreingkey": |
642 |
this.getForeingKey().setForeingKey(DataTypeUtils.toBoolean(value, false)); |
643 |
break;
|
644 |
case "fk_code": |
645 |
case "foreingkey_code": |
646 |
case "foreingkey.code": |
647 |
this.getForeingKey().setCodeName(DataTypeUtils.toString(value, "")); |
648 |
break;
|
649 |
case "fk_label": |
650 |
case "foreingkey_label": |
651 |
case "foreingkey.label": |
652 |
this.getForeingKey().setLabelFormula(DataTypeUtils.toString(value, "")); |
653 |
break;
|
654 |
case "fk_closed": |
655 |
case "fk_closedlist": |
656 |
case "fk.closedlist": |
657 |
case "foreingkey_closedlist": |
658 |
case "foreingkey.closedlist": |
659 |
this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false)); |
660 |
break;
|
661 |
case "fk_table": |
662 |
case "foreingkey_table": |
663 |
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 |
this.setSRS(DataTypeUtils.toString(value, null)); |
675 |
break;
|
676 |
case "relation": |
677 |
this.setRelationType(toRelation(value));
|
678 |
break;
|
679 |
case "name": |
680 |
this.setName(DataTypeUtils.toString(value, null)); |
681 |
break;
|
682 |
case "type": |
683 |
case "datatype": |
684 |
ss = DataTypeUtils.toString(value, null);
|
685 |
if (!StringUtils.isBlank(ss)) {
|
686 |
this.setDataType(ToolsLocator.getDataTypesManager().getType(ss));
|
687 |
} |
688 |
break;
|
689 |
case "defaultvalue": |
690 |
this.setDefaultValue(value);
|
691 |
break;
|
692 |
case "availablevaluesfilter": |
693 |
this.setAvailableValuesFilter(DataTypeUtils.toString(value, null)); |
694 |
break;
|
695 |
case "format": |
696 |
case "defaultformat": |
697 |
this.setDefaultFormat(DataTypeUtils.toString(value, null)); |
698 |
default:
|
699 |
throw new IllegalArgumentException("Name attribute '" + name + "' not valid."); |
700 |
} |
701 |
this.setFixed(false); |
702 |
return this; |
703 |
} |
704 |
|
705 |
private int toRelation(Object value) { |
706 |
if (value == null) { |
707 |
return DynField.RELATION_TYPE_NONE;
|
708 |
} |
709 |
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 |
} |
732 |
|
733 |
@Override
|
734 |
public EditableFeatureAttributeDescriptor setDisplaySize(int size) { |
735 |
this.displaySize = size;
|
736 |
this.setFixed(false); |
737 |
return this; |
738 |
} |
739 |
|
740 |
@Override
|
741 |
public EditableFeatureAttributeDescriptor setAvailableValuesFilter(Expression filter) { |
742 |
super.setAvailableValuesFilter(filter);
|
743 |
return this; |
744 |
} |
745 |
|
746 |
@Override
|
747 |
public EditableFeatureAttributeDescriptor setAvailableValuesFilter(String filter) { |
748 |
super.setAvailableValuesFilter(filter);
|
749 |
return this; |
750 |
} |
751 |
|
752 |
private static class TheJsonSerializer implements JsonManager.JsonSerializer { |
753 |
|
754 |
public TheJsonSerializer() {
|
755 |
} |
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 |
return ((SupportToJson) value).toJsonBuilder();
|
772 |
} |
773 |
|
774 |
} |
775 |
|
776 |
@Override
|
777 |
public EditableFeatureAttributeDescriptor setForeingkey(
|
778 |
boolean isForeingkey,
|
779 |
boolean isClosedList,
|
780 |
String tableName,
|
781 |
String codeName,
|
782 |
String labelFormula
|
783 |
) { |
784 |
if (isForeingkey) {
|
785 |
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 |
} |
794 |
this.setFixed(false); |
795 |
return this; |
796 |
} |
797 |
|
798 |
@Override
|
799 |
public EditableFeatureAttributeDescriptor setTag(String name, Object value) { |
800 |
this.getTags().set(name, value);
|
801 |
this.setFixed(false); |
802 |
return this; |
803 |
} |
804 |
|
805 |
public static void selfRegister() { |
806 |
Json.registerSerializer(new TheJsonSerializer());
|
807 |
} |
808 |
|
809 |
@Override
|
810 |
public EditableFeatureAttributeDescriptor setDefaultFormat(String format) { |
811 |
this.defaultFormat = format;
|
812 |
this.setFixed(false); |
813 |
return this; |
814 |
} |
815 |
|
816 |
|
817 |
} |