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