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 @ 45921
History | View | Annotate | Download (25.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 |
return this; |
125 |
} |
126 |
|
127 |
@Override
|
128 |
public EditableForeingKey getForeingKey() {
|
129 |
if (this.foreingKey == null) { |
130 |
this.foreingKey = new DefaultForeingKey(); |
131 |
this.foreingKey.setDescriptor(this); |
132 |
} |
133 |
return this.foreingKey; |
134 |
} |
135 |
|
136 |
public EditableFeatureAttributeDescriptor setDataType(DataType dataType) {
|
137 |
updateStrongChanges(this.dataType, dataType);
|
138 |
this.dataType = dataType;
|
139 |
return this; |
140 |
} |
141 |
|
142 |
public EditableFeatureAttributeDescriptor setDataType(int type) { |
143 |
updateStrongChanges(this.dataType, type);
|
144 |
this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
145 |
return this; |
146 |
} |
147 |
|
148 |
public EditableFeatureAttributeDescriptor setDefaultValue(
|
149 |
Object defaultValue) {
|
150 |
updateStrongChanges(this.defaultValue, defaultValue);
|
151 |
this.defaultValue = defaultValue;
|
152 |
return this; |
153 |
} |
154 |
|
155 |
public EditableFeatureAttributeDescriptor setAvoidCachingAvailableValues(boolean avoidCachingAvailableValues) { |
156 |
this.avoidCachingAvailableValues = avoidCachingAvailableValues;
|
157 |
return this; |
158 |
} |
159 |
|
160 |
public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
|
161 |
updateStrongChanges(this.evaluator, evaluator);
|
162 |
this.evaluator = evaluator;
|
163 |
return this; |
164 |
} |
165 |
|
166 |
@Override
|
167 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
168 |
this.featureAttributeEmulator = featureAttributeEmulator;
|
169 |
return this; |
170 |
} |
171 |
|
172 |
@Override
|
173 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(Expression expression) { |
174 |
if (ExpressionUtils.isPhraseEmpty(expression)) {
|
175 |
this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null); |
176 |
return this; |
177 |
} |
178 |
FeatureAttributeEmulatorExpression emulator = DALLocator.getDataManager().createFeatureAttributeEmulatorExpression( |
179 |
this.getFeatureType(),
|
180 |
expression |
181 |
); |
182 |
return this.setFeatureAttributeEmulator(emulator); |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(String expression) { |
187 |
if (StringUtils.isBlank(expression)) {
|
188 |
this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null); |
189 |
return this; |
190 |
} |
191 |
return this.setFeatureAttributeEmulator(ExpressionUtils.createExpression(expression)); |
192 |
} |
193 |
|
194 |
@Override
|
195 |
public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
196 |
this.geometryType = type;
|
197 |
if (this.geometrySubType == Geometry.SUBTYPES.UNKNOWN) { |
198 |
this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
199 |
} |
200 |
this.geomType = null; |
201 |
return this; |
202 |
} |
203 |
|
204 |
public EditableFeatureAttributeDescriptor setGeometrySubType(int subType) { |
205 |
this.geometrySubType = subType;
|
206 |
this.geomType = null; |
207 |
return this; |
208 |
} |
209 |
|
210 |
public EditableFeatureAttributeDescriptor setGeometryType(
|
211 |
GeometryType geometryType) { |
212 |
updateStrongChanges(this.geomType, geometryType);
|
213 |
this.geomType = geometryType;
|
214 |
this.geometryType = this.geomType.getType(); |
215 |
this.geometrySubType = this.geomType.getSubType(); |
216 |
return this; |
217 |
} |
218 |
|
219 |
@Override
|
220 |
public EditableFeatureAttributeDescriptor setGeometryType(String geometryType) { |
221 |
if (StringUtils.isBlank(geometryType)) {
|
222 |
throw new IllegalArgumentException("Invalid geometry type (null)"); |
223 |
} |
224 |
String separators = ":/-!;#@"; |
225 |
Character sep = null; |
226 |
for (char ch : separators.toCharArray()) { |
227 |
if (geometryType.indexOf(ch) >= 0) { |
228 |
sep = ch; |
229 |
break;
|
230 |
} |
231 |
} |
232 |
if (sep == null) { |
233 |
throw new IllegalArgumentException("Invalid geometry type (" + geometryType + ") can't find separator, format can be GEOMETRYTYPE[" + separators + "]GEOMETRYSUBTYPE"); |
234 |
} |
235 |
String[] xx = geometryType.split("[" + sep + "]"); |
236 |
int theGeomType = GeometryUtils.getGeometryType(xx[0]); |
237 |
int theGeomSubtype = GeometryUtils.getGeometrySubtype(xx[1]); |
238 |
this.setGeometryType(theGeomType, theGeomSubtype);
|
239 |
return this; |
240 |
} |
241 |
|
242 |
@Override
|
243 |
public EditableFeatureAttributeDescriptor setGeometryType(int type, int subType) { |
244 |
this.geometryType = type;
|
245 |
this.geometrySubType = subType;
|
246 |
this.geomType = null; |
247 |
return this; |
248 |
} |
249 |
|
250 |
public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
251 |
boolean isPrimaryKey) {
|
252 |
updateStrongChanges(this.primaryKey, primaryKey);
|
253 |
this.primaryKey = isPrimaryKey;
|
254 |
return this; |
255 |
} |
256 |
|
257 |
public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
258 |
updateStrongChanges(this.readOnly, readOnly);
|
259 |
this.readOnly = isReadOnly;
|
260 |
return this; |
261 |
} |
262 |
|
263 |
public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
264 |
int maximumOccurrences) {
|
265 |
updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
|
266 |
this.maximumOccurrences = maximumOccurrences;
|
267 |
return this; |
268 |
} |
269 |
|
270 |
public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
271 |
int minimumOccurrences) {
|
272 |
updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
|
273 |
this.minimumOccurrences = minimumOccurrences;
|
274 |
return this; |
275 |
} |
276 |
|
277 |
@Override
|
278 |
public EditableFeatureAttributeDescriptor setName(String name) { |
279 |
if (StringUtils.equals(this.name, name)) { |
280 |
return this; |
281 |
} |
282 |
if (originalName == null) { |
283 |
originalName = this.name;
|
284 |
if (!isComputed()) {
|
285 |
hasStrongChanges = true;
|
286 |
} |
287 |
} |
288 |
super.setName(name);
|
289 |
if (!isComputed()) {
|
290 |
hasStrongChanges = true;
|
291 |
} |
292 |
return this; |
293 |
} |
294 |
|
295 |
public String getOriginalName() { |
296 |
return originalName;
|
297 |
} |
298 |
|
299 |
public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
300 |
updateStrongChanges(this.objectClass, theClass);
|
301 |
this.objectClass = theClass;
|
302 |
return this; |
303 |
} |
304 |
|
305 |
@Override
|
306 |
public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
307 |
updateStrongChanges(this.precision, precision);
|
308 |
this.precision = precision;
|
309 |
return this; |
310 |
} |
311 |
|
312 |
@Override
|
313 |
public EditableFeatureAttributeDescriptor setScale(int scale) { |
314 |
updateStrongChanges(this.scale, scale);
|
315 |
this.scale = scale;
|
316 |
this.coerceContext = null; |
317 |
this.mathContext = null; |
318 |
return this; |
319 |
} |
320 |
|
321 |
@Override
|
322 |
public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
323 |
updateStrongChanges(this.SRS, SRS);
|
324 |
this.SRS = SRS;
|
325 |
return this; |
326 |
} |
327 |
|
328 |
@Override
|
329 |
public EditableFeatureAttributeDescriptor setSRS(String SRS) { |
330 |
if (StringUtils.isBlank(SRS)) {
|
331 |
this.setSRS((IProjection) null); |
332 |
return this; |
333 |
} |
334 |
SRS = SRS.replace('@', ':'); |
335 |
IProjection proj = CRSFactory.getCRS(SRS); |
336 |
this.setSRS(proj);
|
337 |
return this; |
338 |
} |
339 |
|
340 |
public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
|
341 |
updateStrongChanges(this.getInterval(), interval);
|
342 |
super.setInterval(interval);
|
343 |
return this; |
344 |
} |
345 |
|
346 |
public EditableFeatureAttributeDescriptor setSize(int size) { |
347 |
updateStrongChanges(this.size, size);
|
348 |
this.size = size;
|
349 |
return this; |
350 |
} |
351 |
|
352 |
public boolean hasStrongChanges() { |
353 |
return hasStrongChanges;
|
354 |
} |
355 |
|
356 |
@Override
|
357 |
public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
358 |
String infoName, Object value) { |
359 |
return this.setAdditionalInfo(infoName, Objects.toString(value, "")); |
360 |
} |
361 |
|
362 |
public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
363 |
String infoName, String value) { |
364 |
if (this.additionalInfo == null) { |
365 |
this.additionalInfo = new HashMap(); |
366 |
} |
367 |
this.additionalInfo.put(infoName, value);
|
368 |
return this; |
369 |
} |
370 |
|
371 |
public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) { |
372 |
this.isAutomatic = isAutomatic;
|
373 |
// if (isAutomatic) {
|
374 |
// this.setReadOnly(true);
|
375 |
// }
|
376 |
return this; |
377 |
} |
378 |
|
379 |
public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
380 |
updateStrongChanges(this.isTime, isTime);
|
381 |
this.isTime = isTime;
|
382 |
return this; |
383 |
} |
384 |
|
385 |
public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
386 |
this.dateFormat = dateFormat;
|
387 |
return this; |
388 |
} |
389 |
|
390 |
public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
391 |
updateStrongChanges(this.indexed, isIndexed);
|
392 |
this.indexed = isIndexed;
|
393 |
return this; |
394 |
} |
395 |
|
396 |
public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
397 |
updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
|
398 |
this.allowIndexDuplicateds = allowDuplicateds;
|
399 |
return this; |
400 |
} |
401 |
|
402 |
public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
403 |
updateStrongChanges(this.isIndexAscending, ascending);
|
404 |
this.isIndexAscending = ascending;
|
405 |
return this; |
406 |
} |
407 |
|
408 |
@Override
|
409 |
public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
410 |
super.setDataProfileName(dataProfile);
|
411 |
return this; |
412 |
} |
413 |
|
414 |
private void updateStrongChanges(int previous, int newvalue) { |
415 |
if (isComputed()) {
|
416 |
return;
|
417 |
} |
418 |
if (previous == newvalue) {
|
419 |
return;
|
420 |
} |
421 |
this.hasStrongChanges = true; |
422 |
} |
423 |
|
424 |
private void updateStrongChanges(DataType previous, int newvalue) { |
425 |
if (isComputed()) {
|
426 |
return;
|
427 |
} |
428 |
if (previous != null) { |
429 |
if (previous.getType() == newvalue) {
|
430 |
return;
|
431 |
} |
432 |
} |
433 |
this.hasStrongChanges = true; |
434 |
} |
435 |
|
436 |
private void updateStrongChanges(boolean previous, boolean newvalue) { |
437 |
if (isComputed()) {
|
438 |
return;
|
439 |
} |
440 |
if (previous == newvalue) {
|
441 |
return;
|
442 |
} |
443 |
this.hasStrongChanges = true; |
444 |
} |
445 |
|
446 |
private void updateStrongChanges(Object previous, Object newvalue) { |
447 |
if (isComputed()) {
|
448 |
return;
|
449 |
} |
450 |
if (Objects.equals(newvalue, previous)) {
|
451 |
return;
|
452 |
} |
453 |
this.hasStrongChanges = true; |
454 |
} |
455 |
|
456 |
@Override
|
457 |
public EditableFeatureAttributeDescriptor setLocale(Locale locale) { |
458 |
if (locale == null) { |
459 |
this.locale = Locale.ENGLISH; |
460 |
} else {
|
461 |
this.locale = locale;
|
462 |
} |
463 |
this.coerceContext = null; |
464 |
this.mathContext = null; |
465 |
return this; |
466 |
} |
467 |
|
468 |
public EditableFeatureAttributeDescriptor setLocale(String locale) { |
469 |
Locale l;
|
470 |
try {
|
471 |
String s = DataTypeUtils.toString(locale, null); |
472 |
if (StringUtils.isBlank(s)) {
|
473 |
return this.setLocale((Locale) null); |
474 |
} |
475 |
l = new Locale(s); |
476 |
return this.setLocale(l); |
477 |
} catch (Exception ex) { |
478 |
return this.setLocale((Locale) null); |
479 |
} |
480 |
} |
481 |
|
482 |
@Override
|
483 |
public EditableFeatureAttributeDescriptor setRoundMode(int roundMode) { |
484 |
switch (roundMode) {
|
485 |
case BigDecimal.ROUND_UP: |
486 |
case BigDecimal.ROUND_DOWN: |
487 |
case BigDecimal.ROUND_CEILING: |
488 |
case BigDecimal.ROUND_FLOOR: |
489 |
case BigDecimal.ROUND_HALF_UP: |
490 |
case BigDecimal.ROUND_HALF_DOWN: |
491 |
case BigDecimal.ROUND_HALF_EVEN: |
492 |
case BigDecimal.ROUND_UNNECESSARY: |
493 |
this.roundMode = roundMode;
|
494 |
this.coerceContext = null; |
495 |
this.mathContext = null; |
496 |
break;
|
497 |
default:
|
498 |
throw new IllegalArgumentException("round mode '" + roundMode + "' not valid."); |
499 |
} |
500 |
return this; |
501 |
} |
502 |
|
503 |
@Override
|
504 |
public EditableFeatureAttributeDescriptor set(String name, Object value) { |
505 |
if (StringUtils.isBlank(name)) {
|
506 |
throw new IllegalArgumentException("Name can't be empty"); |
507 |
} |
508 |
String ss;
|
509 |
switch (name.trim().toLowerCase()) {
|
510 |
case "isavoidcachingavailablevalues": |
511 |
case "avoidcachingavailablevalues": |
512 |
case "nocachingavailablevalues": |
513 |
this.setAvoidCachingAvailableValues(DataTypeUtils.toBoolean(value, false)); |
514 |
break;
|
515 |
case "availablevalues": |
516 |
this.setAvailableValuesExpression(DataTypeUtils.toString(value, null)); |
517 |
break;
|
518 |
case "isreadonly": |
519 |
case "readonly": |
520 |
this.setIsReadOnly(DataTypeUtils.toBoolean(value, false)); |
521 |
break;
|
522 |
case "mandatory": |
523 |
this.setMandatory(DataTypeUtils.toBoolean(value, false)); |
524 |
break;
|
525 |
case "hidden": |
526 |
this.setHidden(DataTypeUtils.toBoolean(value, false)); |
527 |
break;
|
528 |
case "allownull": |
529 |
this.setAllowNull(DataTypeUtils.toBoolean(value, false)); |
530 |
break;
|
531 |
case "indexed": |
532 |
case "isindexed": |
533 |
this.setIsIndexed(DataTypeUtils.toBoolean(value, false)); |
534 |
break;
|
535 |
case "pk": |
536 |
case "ispk": |
537 |
case "primarykey": |
538 |
case "isprimarykey": |
539 |
this.setIsPrimaryKey(DataTypeUtils.toBoolean(value, false)); |
540 |
break;
|
541 |
case "allowindexduplicateds": |
542 |
this.setAllowIndexDuplicateds(DataTypeUtils.toBoolean(value, false)); |
543 |
break;
|
544 |
case "isautomatic": |
545 |
case "automatic": |
546 |
this.setIsAutomatic(DataTypeUtils.toBoolean(value, false)); |
547 |
break;
|
548 |
case "time": |
549 |
case "istime": |
550 |
this.setIsTime(DataTypeUtils.toBoolean(value, false)); |
551 |
break;
|
552 |
case "profile": |
553 |
this.setDataProfileName(DataTypeUtils.toString(value, null)); |
554 |
break;
|
555 |
case "group": |
556 |
this.setGroup(DataTypeUtils.toString(value, null)); |
557 |
break;
|
558 |
case "description": |
559 |
this.setDescription(DataTypeUtils.toString(value, null)); |
560 |
break;
|
561 |
case "label": |
562 |
this.setLabel(DataTypeUtils.toString(value, null)); |
563 |
break;
|
564 |
case "shortlabel": |
565 |
this.setShortLabel(DataTypeUtils.toString(value, null)); |
566 |
break;
|
567 |
case "expression": |
568 |
this.setFeatureAttributeEmulator(DataTypeUtils.toString(value, null)); |
569 |
break;
|
570 |
case "size": |
571 |
this.setSize(DataTypeUtils.toInteger(value, 50)); |
572 |
break;
|
573 |
case "precision": |
574 |
this.setPrecision(DataTypeUtils.toInteger(value, 10)); |
575 |
break;
|
576 |
case "scale": |
577 |
this.setScale(DataTypeUtils.toInteger(value, 10)); |
578 |
break;
|
579 |
case "roundmode": |
580 |
this.setRoundMode(DataTypeUtils.toInteger(value, BigDecimal.ROUND_UNNECESSARY)); |
581 |
break;
|
582 |
case "locale": |
583 |
this.setLocale(DataTypeUtils.toString(value, null)); |
584 |
break;
|
585 |
case "order": |
586 |
this.setOrder(DataTypeUtils.toInteger(value, 0)); |
587 |
break;
|
588 |
case "fk": |
589 |
case "foreingkey": |
590 |
this.getForeingKey().setForeingKey(DataTypeUtils.toBoolean(value, false)); |
591 |
break;
|
592 |
case "fk_code": |
593 |
case "foreingkey_code": |
594 |
case "foreingkey.code": |
595 |
this.getForeingKey().setCodeName(DataTypeUtils.toString(value, "")); |
596 |
break;
|
597 |
case "fk_label": |
598 |
case "foreingkey_label": |
599 |
case "foreingkey.label": |
600 |
this.getForeingKey().setLabelFormula(DataTypeUtils.toString(value, "")); |
601 |
break;
|
602 |
case "fk_closed": |
603 |
case "fk_closedlist": |
604 |
case "fk.closedlist": |
605 |
case "foreingkey_closedlist": |
606 |
case "foreingkey.closedlist": |
607 |
this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false)); |
608 |
break;
|
609 |
case "fk_table": |
610 |
case "foreingkey_table": |
611 |
case "foreingkey.table": |
612 |
this.getForeingKey().setTableName(DataTypeUtils.toString(value, null)); |
613 |
break;
|
614 |
case "interval": |
615 |
this.setInterval(DataTypeUtils.toInterval(value, null)); |
616 |
break;
|
617 |
case "geomtype": |
618 |
case "geometrytype": |
619 |
this.setGeometryType(DataTypeUtils.toString(value, null)); |
620 |
break;
|
621 |
case "srs": |
622 |
this.setSRS(DataTypeUtils.toString(value, null)); |
623 |
break;
|
624 |
case "relation": |
625 |
this.setRelationType(toRelation(value));
|
626 |
break;
|
627 |
case "name": |
628 |
this.setName(DataTypeUtils.toString(value, null)); |
629 |
break;
|
630 |
case "type": |
631 |
case "datatype": |
632 |
ss = DataTypeUtils.toString(value, null);
|
633 |
if (!StringUtils.isBlank(ss)) {
|
634 |
this.setDataType(ToolsLocator.getDataTypesManager().getType(ss));
|
635 |
} |
636 |
break;
|
637 |
case "defaultvalue": |
638 |
this.setDefaultValue(value);
|
639 |
break;
|
640 |
case "availablevaluesfilter": |
641 |
this.setAvailableValuesFilter(DataTypeUtils.toString(value, null)); |
642 |
break;
|
643 |
default:
|
644 |
throw new IllegalArgumentException("Name attribute '" + name + "' not valid."); |
645 |
} |
646 |
return this; |
647 |
} |
648 |
|
649 |
private int toRelation(Object value) { |
650 |
if (value == null) { |
651 |
return DynField.RELATION_TYPE_NONE;
|
652 |
} |
653 |
Integer x = (Integer) DataTypeUtils.coerce(DataTypes.INT, value, null); |
654 |
if (x != null) { |
655 |
return x;
|
656 |
} |
657 |
try {
|
658 |
String s = value.toString().toUpperCase();
|
659 |
switch (s) {
|
660 |
case "NONE": |
661 |
default:
|
662 |
return DynField.RELATION_TYPE_NONE;
|
663 |
case "IDENTITY": |
664 |
return DynField.RELATION_TYPE_IDENTITY;
|
665 |
case "COLLABORATION": |
666 |
return DynField.RELATION_TYPE_COLLABORATION;
|
667 |
case "COMPOSITION": |
668 |
return DynField.RELATION_TYPE_COMPOSITION;
|
669 |
case "AGGREGATE": |
670 |
return DynField.RELATION_TYPE_AGGREGATE;
|
671 |
} |
672 |
} catch (Exception ex) { |
673 |
return DynField.RELATION_TYPE_NONE;
|
674 |
} |
675 |
} |
676 |
|
677 |
@Override
|
678 |
public EditableFeatureAttributeDescriptor setDisplaySize(int size) { |
679 |
this.displaySize = size;
|
680 |
return this; |
681 |
} |
682 |
|
683 |
@Override
|
684 |
public EditableFeatureAttributeDescriptor setAvailableValuesFilter(Expression filter) { |
685 |
super.setAvailableValuesFilter(filter);
|
686 |
return this; |
687 |
} |
688 |
|
689 |
@Override
|
690 |
public EditableFeatureAttributeDescriptor setAvailableValuesFilter(String filter) { |
691 |
super.setAvailableValuesFilter(filter);
|
692 |
return this; |
693 |
} |
694 |
|
695 |
private static class TheJsonSerializer implements JsonManager.JsonSerializer { |
696 |
|
697 |
public TheJsonSerializer() {
|
698 |
} |
699 |
|
700 |
@Override
|
701 |
public Class getObjectClass() { |
702 |
return DefaultEditableFeatureAttributeDescriptor.class;
|
703 |
} |
704 |
|
705 |
@Override
|
706 |
public Object toObject(JsonObject json) { |
707 |
DefaultFeatureAttributeDescriptor o = new DefaultFeatureAttributeDescriptor();
|
708 |
o.fromJson(json); |
709 |
return o;
|
710 |
} |
711 |
|
712 |
@Override
|
713 |
public JsonObjectBuilder toJsonBuilder(Object value) { |
714 |
return ((SupportToJson) value).toJsonBuilder();
|
715 |
} |
716 |
|
717 |
} |
718 |
|
719 |
@Override
|
720 |
public EditableFeatureAttributeDescriptor setForeingkey(
|
721 |
boolean isForeingkey,
|
722 |
boolean isClosedList,
|
723 |
String tableName,
|
724 |
String codeName,
|
725 |
String labelFormula
|
726 |
) { |
727 |
if (isForeingkey) {
|
728 |
EditableForeingKey fk = this.getForeingKey();
|
729 |
fk.setForeingKey(isForeingkey); |
730 |
fk.setClosedList(isClosedList); |
731 |
fk.setTableName(tableName); |
732 |
fk.setCodeName(codeName); |
733 |
fk.setLabelFormula(labelFormula); |
734 |
} else {
|
735 |
this.foreingKey = null; |
736 |
} |
737 |
return this; |
738 |
} |
739 |
|
740 |
@Override
|
741 |
public EditableFeatureAttributeDescriptor setTag(String name, Object value) { |
742 |
this.getTags().set(name, value);
|
743 |
return this; |
744 |
} |
745 |
|
746 |
public static void selfRegister() { |
747 |
Json.registerSerializer(new TheJsonSerializer());
|
748 |
} |
749 |
|
750 |
} |