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 @ 44744
History | View | Annotate | Download (20.5 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 org.apache.commons.lang3.StringUtils; |
32 |
|
33 |
import org.cresques.cts.IProjection; |
34 |
import org.gvsig.expressionevaluator.Expression; |
35 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
36 |
import org.gvsig.fmap.crs.CRSFactory; |
37 |
import org.gvsig.fmap.dal.DALLocator; |
38 |
import org.gvsig.fmap.dal.DataTypeUtils; |
39 |
import org.gvsig.fmap.dal.DataTypes; |
40 |
import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
41 |
import org.slf4j.Logger; |
42 |
import org.slf4j.LoggerFactory; |
43 |
|
44 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
45 |
import org.gvsig.fmap.dal.feature.EditableForeingKey; |
46 |
import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
47 |
import org.gvsig.fmap.dal.feature.FeatureType; |
48 |
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
49 |
import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
50 |
import org.gvsig.fmap.geom.Geometry; |
51 |
import org.gvsig.fmap.geom.GeometryUtils; |
52 |
import org.gvsig.fmap.geom.type.GeometryType; |
53 |
import org.gvsig.timesupport.Interval; |
54 |
import org.gvsig.tools.ToolsLocator; |
55 |
import org.gvsig.tools.dataTypes.DataType; |
56 |
import org.gvsig.tools.dynobject.DynField; |
57 |
import org.gvsig.tools.evaluator.Evaluator; |
58 |
|
59 |
public class DefaultEditableFeatureAttributeDescriptor extends |
60 |
DefaultFeatureAttributeDescriptor implements
|
61 |
EditableFeatureAttributeDescriptor { |
62 |
|
63 |
private static Logger logger = LoggerFactory.getLogger( |
64 |
DefaultEditableFeatureAttributeDescriptor.class); |
65 |
|
66 |
private final DefaultFeatureAttributeDescriptor source; |
67 |
private boolean hasStrongChanges; |
68 |
private String originalName = null; |
69 |
|
70 |
protected DefaultEditableFeatureAttributeDescriptor(
|
71 |
DefaultFeatureAttributeDescriptor other) { |
72 |
super(other);
|
73 |
if (other instanceof DefaultEditableFeatureAttributeDescriptor) { |
74 |
DefaultEditableFeatureAttributeDescriptor other_edi = |
75 |
(DefaultEditableFeatureAttributeDescriptor) other; |
76 |
originalName = other_edi.getOriginalName(); |
77 |
this.source = other_edi.getSource();
|
78 |
} else {
|
79 |
this.source = other;
|
80 |
} |
81 |
hasStrongChanges = false;
|
82 |
} |
83 |
|
84 |
public DefaultEditableFeatureAttributeDescriptor(FeatureType type, boolean strongChanges) { |
85 |
super(type);
|
86 |
this.source = null; |
87 |
hasStrongChanges = strongChanges; |
88 |
} |
89 |
|
90 |
public DefaultFeatureAttributeDescriptor getSource() {
|
91 |
return this.source; |
92 |
} |
93 |
|
94 |
public void fixAll() { |
95 |
super.fixAll();
|
96 |
} |
97 |
|
98 |
public void checkIntegrity() throws AttributeFeatureTypeIntegrityException { |
99 |
AttributeFeatureTypeIntegrityException ex = |
100 |
new AttributeFeatureTypeIntegrityException(getName());
|
101 |
if (this.size < 0) { |
102 |
ex.add(new AttributeFeatureTypeSizeException(this.size)); |
103 |
} |
104 |
|
105 |
if( this.dataType.isObject() && this.objectClass == null ) { |
106 |
logger.warn("Incorrect data type object, objectClass is null.");
|
107 |
ex.add(new AttributeFeatureTypeIntegrityException(this.name)); |
108 |
} |
109 |
|
110 |
// TODO: Add other integrity checks...
|
111 |
|
112 |
if (ex.size() > 0) { |
113 |
throw ex;
|
114 |
} |
115 |
} |
116 |
|
117 |
public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
118 |
updateStrongChanges(this.allowNull, allowNull);
|
119 |
this.allowNull = allowNull;
|
120 |
return this; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public EditableForeingKey getForeingKey() {
|
125 |
if( this.foreingKey==null ) { |
126 |
this.foreingKey = new DefaultForeingKey(); |
127 |
this.foreingKey.setDescriptor(this); |
128 |
} |
129 |
return this.foreingKey; |
130 |
} |
131 |
|
132 |
public EditableFeatureAttributeDescriptor setDataType(DataType dataType) {
|
133 |
updateStrongChanges(this.dataType, dataType);
|
134 |
this.dataType = dataType;
|
135 |
return this; |
136 |
} |
137 |
|
138 |
public EditableFeatureAttributeDescriptor setDataType(int type) { |
139 |
updateStrongChanges(this.dataType, type);
|
140 |
this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
141 |
return this; |
142 |
} |
143 |
|
144 |
public EditableFeatureAttributeDescriptor setDefaultValue(
|
145 |
Object defaultValue) {
|
146 |
updateStrongChanges(this.defaultValue, defaultValue);
|
147 |
this.defaultValue = defaultValue;
|
148 |
return this; |
149 |
} |
150 |
|
151 |
public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
|
152 |
updateStrongChanges(this.evaluator, evaluator);
|
153 |
this.evaluator = evaluator;
|
154 |
return this; |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
159 |
this.featureAttributeEmulator = featureAttributeEmulator;
|
160 |
return this; |
161 |
} |
162 |
|
163 |
@Override
|
164 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(Expression expression) { |
165 |
if( ExpressionUtils.isPhraseEmpty(expression) ) {
|
166 |
this.setFeatureAttributeEmulator((FeatureAttributeEmulator)null); |
167 |
return this; |
168 |
} |
169 |
FeatureAttributeEmulatorExpression emulator = DALLocator.getDataManager().createFeatureAttributeEmulatorExpression( |
170 |
this.getFeatureType(),
|
171 |
expression |
172 |
); |
173 |
return this.setFeatureAttributeEmulator(emulator); |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(String expression) { |
178 |
if( StringUtils.isBlank(expression) ) {
|
179 |
this.setFeatureAttributeEmulator((FeatureAttributeEmulator)null); |
180 |
return this; |
181 |
} |
182 |
return this.setFeatureAttributeEmulator(ExpressionUtils.createExpression(expression)); |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
187 |
this.geometryType = type;
|
188 |
if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) { |
189 |
this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
190 |
} |
191 |
this.geomType = null; |
192 |
return this; |
193 |
} |
194 |
|
195 |
public EditableFeatureAttributeDescriptor setGeometrySubType(int subType) { |
196 |
this.geometrySubType = subType;
|
197 |
this.geomType = null; |
198 |
return this; |
199 |
} |
200 |
|
201 |
public EditableFeatureAttributeDescriptor setGeometryType(
|
202 |
GeometryType geometryType) { |
203 |
updateStrongChanges(this.geomType, geometryType);
|
204 |
this.geomType = geometryType;
|
205 |
this.geometryType = this.geomType.getType(); |
206 |
this.geometrySubType = this.geomType.getSubType(); |
207 |
return this; |
208 |
} |
209 |
|
210 |
@Override
|
211 |
public EditableFeatureAttributeDescriptor setGeometryType(String geometryType) { |
212 |
if( StringUtils.isBlank(geometryType) ) {
|
213 |
throw new IllegalArgumentException("Invalid geometry type (null)"); |
214 |
} |
215 |
String separators = ":/-!;#@"; |
216 |
Character sep = null; |
217 |
for (char ch : separators.toCharArray()) { |
218 |
if( geometryType.indexOf(ch)>=0 ) { |
219 |
sep = ch; |
220 |
break;
|
221 |
} |
222 |
} |
223 |
if( sep == null ) { |
224 |
throw new IllegalArgumentException("Invalid geometry type ("+geometryType+") can't find separator, format can be GEOMETRYTYPE["+separators+"]GEOMETRYSUBTYPE"); |
225 |
} |
226 |
String[] xx = geometryType.split("["+sep+"]"); |
227 |
int theGeomType = GeometryUtils.getGeometryType(xx[0]); |
228 |
int theGeomSubtype = GeometryUtils.getGeometrySubtype(xx[1]); |
229 |
this.setGeometryType(theGeomType, theGeomSubtype);
|
230 |
return this; |
231 |
} |
232 |
|
233 |
@Override
|
234 |
public EditableFeatureAttributeDescriptor setGeometryType(int type, int subType) { |
235 |
this.geometryType = type;
|
236 |
this.geometrySubType = subType;
|
237 |
this.geomType = null; |
238 |
return this; |
239 |
} |
240 |
|
241 |
public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
242 |
boolean isPrimaryKey) {
|
243 |
updateStrongChanges(this.primaryKey, primaryKey);
|
244 |
this.primaryKey = isPrimaryKey;
|
245 |
return this; |
246 |
} |
247 |
|
248 |
public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
249 |
updateStrongChanges(this.readOnly, readOnly);
|
250 |
this.readOnly = isReadOnly;
|
251 |
return this; |
252 |
} |
253 |
|
254 |
public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
255 |
int maximumOccurrences) {
|
256 |
updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
|
257 |
this.maximumOccurrences = maximumOccurrences;
|
258 |
return this; |
259 |
} |
260 |
|
261 |
public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
262 |
int minimumOccurrences) {
|
263 |
updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
|
264 |
this.minimumOccurrences = minimumOccurrences;
|
265 |
return this; |
266 |
} |
267 |
|
268 |
@Override
|
269 |
public EditableFeatureAttributeDescriptor setName(String name) { |
270 |
if( StringUtils.equalsIgnoreCase(this.name, name) ) { |
271 |
return this; |
272 |
} |
273 |
if (originalName == null) { |
274 |
originalName = this.name;
|
275 |
if (!isComputed()) {
|
276 |
hasStrongChanges = true;
|
277 |
} |
278 |
} |
279 |
super.setName(name);
|
280 |
if (!isComputed()) {
|
281 |
hasStrongChanges = true;
|
282 |
} |
283 |
return this; |
284 |
} |
285 |
|
286 |
public String getOriginalName() { |
287 |
return originalName;
|
288 |
} |
289 |
|
290 |
public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
291 |
updateStrongChanges(this.objectClass, theClass);
|
292 |
this.objectClass = theClass;
|
293 |
return this; |
294 |
} |
295 |
|
296 |
@Override
|
297 |
public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
298 |
updateStrongChanges(this.precision, precision);
|
299 |
this.precision = precision;
|
300 |
return this; |
301 |
} |
302 |
|
303 |
@Override
|
304 |
public EditableFeatureAttributeDescriptor setScale(int scale) { |
305 |
updateStrongChanges(this.scale, scale);
|
306 |
this.scale = scale;
|
307 |
this.coerceContext = null; |
308 |
this.mathContext = null; |
309 |
return this; |
310 |
} |
311 |
|
312 |
@Override
|
313 |
public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
314 |
updateStrongChanges(this.SRS, SRS);
|
315 |
this.SRS = SRS;
|
316 |
return this; |
317 |
} |
318 |
|
319 |
@Override
|
320 |
public EditableFeatureAttributeDescriptor setSRS(String SRS) { |
321 |
if( StringUtils.isBlank(SRS) ) {
|
322 |
this.setSRS((IProjection)null); |
323 |
return this; |
324 |
} |
325 |
IProjection proj = CRSFactory.getCRS(SRS); |
326 |
this.setSRS(proj);
|
327 |
return this; |
328 |
} |
329 |
|
330 |
public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
|
331 |
updateStrongChanges(this.getInterval(), interval);
|
332 |
super.setInterval(interval);
|
333 |
return this; |
334 |
} |
335 |
|
336 |
public EditableFeatureAttributeDescriptor setSize(int size) { |
337 |
updateStrongChanges(this.size, size);
|
338 |
this.size = size;
|
339 |
return this; |
340 |
} |
341 |
|
342 |
public boolean hasStrongChanges() { |
343 |
return hasStrongChanges;
|
344 |
} |
345 |
|
346 |
public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
347 |
String infoName, Object value) { |
348 |
if (this.additionalInfo == null) { |
349 |
this.additionalInfo = new HashMap(); |
350 |
} |
351 |
this.additionalInfo.put(infoName, value);
|
352 |
return this; |
353 |
} |
354 |
|
355 |
public EditableFeatureAttributeDescriptor setIsAutomatic(boolean isAutomatic) { |
356 |
this.isAutomatic = isAutomatic;
|
357 |
if( isAutomatic ) {
|
358 |
this.setReadOnly(true); |
359 |
} |
360 |
return this; |
361 |
} |
362 |
|
363 |
public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
364 |
updateStrongChanges(this.isTime, isTime);
|
365 |
this.isTime = isTime;
|
366 |
return this; |
367 |
} |
368 |
|
369 |
public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
370 |
this.dateFormat = dateFormat;
|
371 |
return this; |
372 |
} |
373 |
|
374 |
public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
375 |
updateStrongChanges(this.indexed, isIndexed);
|
376 |
this.indexed = isIndexed;
|
377 |
return this; |
378 |
} |
379 |
|
380 |
public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
381 |
updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
|
382 |
this.allowIndexDuplicateds = allowDuplicateds;
|
383 |
return this; |
384 |
} |
385 |
|
386 |
public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
387 |
updateStrongChanges(this.isIndexAscending, ascending);
|
388 |
this.isIndexAscending = ascending;
|
389 |
return this; |
390 |
} |
391 |
|
392 |
@Override
|
393 |
public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
394 |
super.setDataProfileName(dataProfile);
|
395 |
return this; |
396 |
} |
397 |
|
398 |
private void updateStrongChanges(int previous, int newvalue) { |
399 |
if( isComputed() ) {
|
400 |
return;
|
401 |
} |
402 |
if( previous == newvalue ) {
|
403 |
return;
|
404 |
} |
405 |
this.hasStrongChanges = true; |
406 |
} |
407 |
|
408 |
private void updateStrongChanges(DataType previous, int newvalue) { |
409 |
if( isComputed() ) {
|
410 |
return;
|
411 |
} |
412 |
if( previous!=null ) { |
413 |
if( previous.getType() == newvalue ) {
|
414 |
return;
|
415 |
} |
416 |
} |
417 |
this.hasStrongChanges = true; |
418 |
} |
419 |
|
420 |
private void updateStrongChanges(boolean previous, boolean newvalue) { |
421 |
if( isComputed() ) {
|
422 |
return;
|
423 |
} |
424 |
if( previous == newvalue ) {
|
425 |
return;
|
426 |
} |
427 |
this.hasStrongChanges = true; |
428 |
} |
429 |
|
430 |
private void updateStrongChanges(Object previous, Object newvalue) { |
431 |
if( isComputed() ) {
|
432 |
return;
|
433 |
} |
434 |
if( Objects.equals(newvalue, previous) ) {
|
435 |
return;
|
436 |
} |
437 |
this.hasStrongChanges = true; |
438 |
} |
439 |
|
440 |
@Override
|
441 |
public EditableFeatureAttributeDescriptor setLocale(Locale locale) { |
442 |
if( locale == null ) { |
443 |
this.locale = Locale.ENGLISH; |
444 |
} else {
|
445 |
this.locale = locale;
|
446 |
} |
447 |
this.coerceContext = null; |
448 |
this.mathContext = null; |
449 |
return this; |
450 |
} |
451 |
|
452 |
public EditableFeatureAttributeDescriptor setLocale(String locale) { |
453 |
Locale l;
|
454 |
try {
|
455 |
String s = DataTypeUtils.toString(locale, null); |
456 |
if( StringUtils.isBlank(s) ) {
|
457 |
return this.setLocale((Locale)null); |
458 |
} |
459 |
l = new Locale(s); |
460 |
return this.setLocale(l); |
461 |
} catch(Exception ex) { |
462 |
return this.setLocale((Locale)null); |
463 |
} |
464 |
} |
465 |
|
466 |
@Override
|
467 |
public EditableFeatureAttributeDescriptor setRoundMode(int roundMode) { |
468 |
switch(roundMode) {
|
469 |
case BigDecimal.ROUND_UP: |
470 |
case BigDecimal.ROUND_DOWN: |
471 |
case BigDecimal.ROUND_CEILING: |
472 |
case BigDecimal.ROUND_FLOOR: |
473 |
case BigDecimal.ROUND_HALF_UP: |
474 |
case BigDecimal.ROUND_HALF_DOWN: |
475 |
case BigDecimal.ROUND_HALF_EVEN: |
476 |
case BigDecimal.ROUND_UNNECESSARY: |
477 |
this.roundMode = roundMode;
|
478 |
this.coerceContext = null; |
479 |
this.mathContext = null; |
480 |
break;
|
481 |
default:
|
482 |
throw new IllegalArgumentException("round mode '"+roundMode+"' not valid."); |
483 |
} |
484 |
return this; |
485 |
} |
486 |
|
487 |
@Override
|
488 |
public EditableFeatureAttributeDescriptor set(String name, Object value) { |
489 |
if( StringUtils.isBlank(name)) {
|
490 |
throw new IllegalArgumentException("Name can't be empty"); |
491 |
} |
492 |
switch(name.toLowerCase()) {
|
493 |
case "isreadonly": |
494 |
case "readonly": |
495 |
this.setIsReadOnly(DataTypeUtils.toBoolean(value, false)); |
496 |
break;
|
497 |
case "hidden": |
498 |
this.setHidden(DataTypeUtils.toBoolean(value, false)); |
499 |
break;
|
500 |
case "allownull": |
501 |
this.setAllowNull(DataTypeUtils.toBoolean(value, false)); |
502 |
break;
|
503 |
case "pk": |
504 |
case "ispk": |
505 |
case "primarykey": |
506 |
case "isprimarykey": |
507 |
this.setIsPrimaryKey(DataTypeUtils.toBoolean(value, false)); |
508 |
break;
|
509 |
case "isautomatic": |
510 |
case "automatic": |
511 |
this.setIsAutomatic(DataTypeUtils.toBoolean(value, false)); |
512 |
break;
|
513 |
case "time": |
514 |
case "istime": |
515 |
this.setIsTime(DataTypeUtils.toBoolean(value, false)); |
516 |
break;
|
517 |
case "profile": |
518 |
this.setDataProfileName(DataTypeUtils.toString(value, null)); |
519 |
break;
|
520 |
case "group": |
521 |
this.setGroup(DataTypeUtils.toString(value, null)); |
522 |
break;
|
523 |
case "description": |
524 |
this.setDescription(DataTypeUtils.toString(value, null)); |
525 |
break;
|
526 |
case "label": |
527 |
this.setLabel(DataTypeUtils.toString(value, null)); |
528 |
break;
|
529 |
case "shortlabel": |
530 |
this.setShortLabel(DataTypeUtils.toString(value, null)); |
531 |
break;
|
532 |
case "expression": |
533 |
this.setFeatureAttributeEmulator(DataTypeUtils.toString(value, null)); |
534 |
break;
|
535 |
case "size": |
536 |
this.setSize(DataTypeUtils.toInteger(value, 50)); |
537 |
break;
|
538 |
case "precision": |
539 |
this.setPrecision(DataTypeUtils.toInteger(value, 10)); |
540 |
break;
|
541 |
case "scale": |
542 |
this.setScale(DataTypeUtils.toInteger(value, 10)); |
543 |
break;
|
544 |
case "roundmode": |
545 |
this.setRoundMode(DataTypeUtils.toInteger(value, BigDecimal.ROUND_UNNECESSARY)); |
546 |
break;
|
547 |
case "locale": |
548 |
this.setLocale(DataTypeUtils.toString(value, null)); |
549 |
break;
|
550 |
case "order": |
551 |
this.setOrder(DataTypeUtils.toInteger(value, 0)); |
552 |
break;
|
553 |
case "foreingkey": |
554 |
this.getForeingKey().setForeingKey(DataTypeUtils.toBoolean(value, false)); |
555 |
break;
|
556 |
case "foreingkey.code": |
557 |
this.getForeingKey().setCodeName(DataTypeUtils.toString(value, "")); |
558 |
break;
|
559 |
case "foreingkey.label": |
560 |
this.getForeingKey().setLabelFormula(DataTypeUtils.toString(value, "")); |
561 |
break;
|
562 |
case "foreingkey.closedlist": |
563 |
this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false)); |
564 |
break;
|
565 |
case "foreingkey.table": |
566 |
this.getForeingKey().setTableName(DataTypeUtils.toString(value, null)); |
567 |
break;
|
568 |
case "interval": |
569 |
this.setInterval(DataTypeUtils.toInterval(value, null)); |
570 |
break;
|
571 |
case "geomtype": |
572 |
case "geometrytype": |
573 |
this.setGeometryType(DataTypeUtils.toString(value, null)); |
574 |
break;
|
575 |
case "srs": |
576 |
this.setSRS(DataTypeUtils.toProjection(value, null)); |
577 |
break;
|
578 |
case "relation": |
579 |
this.setRelationType(toRelation(value));
|
580 |
break;
|
581 |
default:
|
582 |
throw new IllegalArgumentException("Name attribute '"+name+"' not valid."); |
583 |
} |
584 |
return this; |
585 |
} |
586 |
|
587 |
private int toRelation(Object value) { |
588 |
if (value == null) { |
589 |
return DynField.RELATION_TYPE_NONE;
|
590 |
} |
591 |
Integer x = DataTypeUtils.toInteger(value, null); |
592 |
if (x != null) { |
593 |
return x;
|
594 |
} |
595 |
try {
|
596 |
String s = value.toString().toUpperCase();
|
597 |
switch (s) {
|
598 |
case "NONE": |
599 |
default:
|
600 |
return DynField.RELATION_TYPE_NONE;
|
601 |
case "IDENTITY": |
602 |
return DynField.RELATION_TYPE_IDENTITY;
|
603 |
case "COLLABORATION": |
604 |
return DynField.RELATION_TYPE_COLLABORATION;
|
605 |
case "COMPOSITION": |
606 |
return DynField.RELATION_TYPE_COMPOSITION;
|
607 |
case "AGGREGATE": |
608 |
return DynField.RELATION_TYPE_AGGREGATE;
|
609 |
} |
610 |
} catch(Exception ex) { |
611 |
return DynField.RELATION_TYPE_NONE;
|
612 |
} |
613 |
} |
614 |
} |