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 @ 45739
History | View | Annotate | Download (24.7 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 "isautomatic": |
542 |
case "automatic": |
543 |
this.setIsAutomatic(DataTypeUtils.toBoolean(value, false)); |
544 |
break;
|
545 |
case "time": |
546 |
case "istime": |
547 |
this.setIsTime(DataTypeUtils.toBoolean(value, false)); |
548 |
break;
|
549 |
case "profile": |
550 |
this.setDataProfileName(DataTypeUtils.toString(value, null)); |
551 |
break;
|
552 |
case "group": |
553 |
this.setGroup(DataTypeUtils.toString(value, null)); |
554 |
break;
|
555 |
case "description": |
556 |
this.setDescription(DataTypeUtils.toString(value, null)); |
557 |
break;
|
558 |
case "label": |
559 |
this.setLabel(DataTypeUtils.toString(value, null)); |
560 |
break;
|
561 |
case "shortlabel": |
562 |
this.setShortLabel(DataTypeUtils.toString(value, null)); |
563 |
break;
|
564 |
case "expression": |
565 |
this.setFeatureAttributeEmulator(DataTypeUtils.toString(value, null)); |
566 |
break;
|
567 |
case "size": |
568 |
this.setSize(DataTypeUtils.toInteger(value, 50)); |
569 |
break;
|
570 |
case "precision": |
571 |
this.setPrecision(DataTypeUtils.toInteger(value, 10)); |
572 |
break;
|
573 |
case "scale": |
574 |
this.setScale(DataTypeUtils.toInteger(value, 10)); |
575 |
break;
|
576 |
case "roundmode": |
577 |
this.setRoundMode(DataTypeUtils.toInteger(value, BigDecimal.ROUND_UNNECESSARY)); |
578 |
break;
|
579 |
case "locale": |
580 |
this.setLocale(DataTypeUtils.toString(value, null)); |
581 |
break;
|
582 |
case "order": |
583 |
this.setOrder(DataTypeUtils.toInteger(value, 0)); |
584 |
break;
|
585 |
case "fk": |
586 |
case "foreingkey": |
587 |
this.getForeingKey().setForeingKey(DataTypeUtils.toBoolean(value, false)); |
588 |
break;
|
589 |
case "fk_code": |
590 |
case "foreingkey_code": |
591 |
case "foreingkey.code": |
592 |
this.getForeingKey().setCodeName(DataTypeUtils.toString(value, "")); |
593 |
break;
|
594 |
case "fk_label": |
595 |
case "foreingkey_label": |
596 |
case "foreingkey.label": |
597 |
this.getForeingKey().setLabelFormula(DataTypeUtils.toString(value, "")); |
598 |
break;
|
599 |
case "fk_closed": |
600 |
case "fk_closedlist": |
601 |
case "fk.closedlist": |
602 |
case "foreingkey_closedlist": |
603 |
case "foreingkey.closedlist": |
604 |
this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false)); |
605 |
break;
|
606 |
case "fk_table": |
607 |
case "foreingkey_table": |
608 |
case "foreingkey.table": |
609 |
this.getForeingKey().setTableName(DataTypeUtils.toString(value, null)); |
610 |
break;
|
611 |
case "interval": |
612 |
this.setInterval(DataTypeUtils.toInterval(value, null)); |
613 |
break;
|
614 |
case "geomtype": |
615 |
case "geometrytype": |
616 |
this.setGeometryType(DataTypeUtils.toString(value, null)); |
617 |
break;
|
618 |
case "srs": |
619 |
this.setSRS(DataTypeUtils.toString(value, null)); |
620 |
break;
|
621 |
case "relation": |
622 |
this.setRelationType(toRelation(value));
|
623 |
break;
|
624 |
case "name": |
625 |
this.setName(DataTypeUtils.toString(value, null)); |
626 |
break;
|
627 |
case "type": |
628 |
case "datatype": |
629 |
ss = DataTypeUtils.toString(value, null);
|
630 |
if (!StringUtils.isBlank(ss)) {
|
631 |
this.setDataType(ToolsLocator.getDataTypesManager().getType(ss));
|
632 |
} |
633 |
break;
|
634 |
case "defaultValue": |
635 |
this.defaultValue = value;
|
636 |
break;
|
637 |
default:
|
638 |
throw new IllegalArgumentException("Name attribute '" + name + "' not valid."); |
639 |
} |
640 |
return this; |
641 |
} |
642 |
|
643 |
private int toRelation(Object value) { |
644 |
if (value == null) { |
645 |
return DynField.RELATION_TYPE_NONE;
|
646 |
} |
647 |
Integer x = (Integer) DataTypeUtils.coerce(DataTypes.INT, value, null); |
648 |
if (x != null) { |
649 |
return x;
|
650 |
} |
651 |
try {
|
652 |
String s = value.toString().toUpperCase();
|
653 |
switch (s) {
|
654 |
case "NONE": |
655 |
default:
|
656 |
return DynField.RELATION_TYPE_NONE;
|
657 |
case "IDENTITY": |
658 |
return DynField.RELATION_TYPE_IDENTITY;
|
659 |
case "COLLABORATION": |
660 |
return DynField.RELATION_TYPE_COLLABORATION;
|
661 |
case "COMPOSITION": |
662 |
return DynField.RELATION_TYPE_COMPOSITION;
|
663 |
case "AGGREGATE": |
664 |
return DynField.RELATION_TYPE_AGGREGATE;
|
665 |
} |
666 |
} catch (Exception ex) { |
667 |
return DynField.RELATION_TYPE_NONE;
|
668 |
} |
669 |
} |
670 |
|
671 |
@Override
|
672 |
public EditableFeatureAttributeDescriptor setDisplaySize(int size) { |
673 |
this.displaySize = size;
|
674 |
return this; |
675 |
} |
676 |
|
677 |
@Override
|
678 |
public EditableFeatureAttributeDescriptor setAvailableValuesFilter(Expression filter) { |
679 |
super.setAvailableValuesFilter(filter);
|
680 |
return this; |
681 |
} |
682 |
|
683 |
private static class TheJsonSerializer implements JsonManager.JsonSerializer { |
684 |
|
685 |
public TheJsonSerializer() {
|
686 |
} |
687 |
|
688 |
@Override
|
689 |
public Class getObjectClass() { |
690 |
return DefaultEditableFeatureAttributeDescriptor.class;
|
691 |
} |
692 |
|
693 |
@Override
|
694 |
public Object toObject(JsonObject json) { |
695 |
DefaultFeatureAttributeDescriptor o = new DefaultFeatureAttributeDescriptor();
|
696 |
o.fromJson(json); |
697 |
return o;
|
698 |
} |
699 |
|
700 |
@Override
|
701 |
public JsonObjectBuilder toJsonBuilder(Object value) { |
702 |
return ((SupportToJson) value).toJsonBuilder();
|
703 |
} |
704 |
|
705 |
} |
706 |
|
707 |
@Override
|
708 |
public EditableFeatureAttributeDescriptor setForeingkey(
|
709 |
boolean isForeingkey,
|
710 |
boolean isClosedList,
|
711 |
String tableName,
|
712 |
String codeName,
|
713 |
String labelFormula
|
714 |
) { |
715 |
if (isForeingkey) {
|
716 |
EditableForeingKey fk = this.getForeingKey();
|
717 |
fk.setForeingKey(isForeingkey); |
718 |
fk.setClosedList(isClosedList); |
719 |
fk.setTableName(tableName); |
720 |
fk.setCodeName(codeName); |
721 |
fk.setLabelFormula(labelFormula); |
722 |
} else {
|
723 |
this.foreingKey = null; |
724 |
} |
725 |
return this; |
726 |
} |
727 |
|
728 |
@Override
|
729 |
public EditableFeatureAttributeDescriptor setTag(String name, Object value) { |
730 |
this.getTags().set(name, value);
|
731 |
return this; |
732 |
} |
733 |
|
734 |
public static void selfRegister() { |
735 |
Json.registerSerializer(new TheJsonSerializer());
|
736 |
} |
737 |
|
738 |
} |