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 @ 44858
History | View | Annotate | Download (20.7 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl; |
25 | |||
26 | 44669 | jjdelcerro | import java.math.BigDecimal; |
27 | 41483 | jjdelcerro | import java.text.DateFormat; |
28 | 40435 | jjdelcerro | import java.util.HashMap; |
29 | 44669 | jjdelcerro | import java.util.Locale; |
30 | 44189 | jjdelcerro | import java.util.Objects; |
31 | 44084 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
32 | 40435 | jjdelcerro | |
33 | import org.cresques.cts.IProjection; |
||
34 | 44253 | jjdelcerro | 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 | 44337 | jjdelcerro | import org.gvsig.fmap.dal.DataTypeUtils; |
39 | 44253 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
40 | import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
||
41 | 40964 | jldominguez | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; |
||
43 | 40435 | jjdelcerro | |
44 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
45 | 44262 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableForeingKey; |
46 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
47 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
48 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
49 | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
||
50 | 42303 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
51 | 44253 | jjdelcerro | import org.gvsig.fmap.geom.GeometryUtils; |
52 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.type.GeometryType; |
53 | 44077 | jjdelcerro | import org.gvsig.timesupport.Interval; |
54 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
55 | 44189 | jjdelcerro | import org.gvsig.tools.dataTypes.DataType; |
56 | 44740 | jjdelcerro | import org.gvsig.tools.dynobject.DynField; |
57 | 40435 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
58 | |||
59 | public class DefaultEditableFeatureAttributeDescriptor extends |
||
60 | DefaultFeatureAttributeDescriptor implements
|
||
61 | EditableFeatureAttributeDescriptor { |
||
62 | 40964 | jldominguez | |
63 | private static Logger logger = LoggerFactory.getLogger( |
||
64 | DefaultEditableFeatureAttributeDescriptor.class); |
||
65 | 40435 | jjdelcerro | |
66 | 44094 | jjdelcerro | private final DefaultFeatureAttributeDescriptor source; |
67 | 40435 | jjdelcerro | 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 | 44190 | jjdelcerro | public DefaultEditableFeatureAttributeDescriptor(FeatureType type, boolean strongChanges) { |
85 | 43739 | jjdelcerro | super(type);
|
86 | 40435 | jjdelcerro | this.source = null; |
87 | 44190 | jjdelcerro | hasStrongChanges = strongChanges; |
88 | 40435 | jjdelcerro | } |
89 | |||
90 | public DefaultFeatureAttributeDescriptor getSource() {
|
||
91 | return this.source; |
||
92 | } |
||
93 | 44094 | jjdelcerro | |
94 | 40435 | jjdelcerro | public void fixAll() { |
95 | 44094 | jjdelcerro | super.fixAll();
|
96 | 40435 | jjdelcerro | } |
97 | 44094 | jjdelcerro | |
98 | 40435 | jjdelcerro | 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 | 40964 | jldominguez | 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 | 40435 | jjdelcerro | |
112 | if (ex.size() > 0) { |
||
113 | throw ex;
|
||
114 | } |
||
115 | } |
||
116 | |||
117 | public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
||
118 | 44189 | jjdelcerro | updateStrongChanges(this.allowNull, allowNull);
|
119 | 40435 | jjdelcerro | this.allowNull = allowNull;
|
120 | return this; |
||
121 | } |
||
122 | 44262 | jjdelcerro | |
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 | 40435 | jjdelcerro | |
132 | 44669 | jjdelcerro | public EditableFeatureAttributeDescriptor setDataType(DataType dataType) {
|
133 | updateStrongChanges(this.dataType, dataType);
|
||
134 | this.dataType = dataType;
|
||
135 | return this; |
||
136 | } |
||
137 | |||
138 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setDataType(int type) { |
139 | 44189 | jjdelcerro | updateStrongChanges(this.dataType, type);
|
140 | 40435 | jjdelcerro | this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
141 | return this; |
||
142 | } |
||
143 | |||
144 | public EditableFeatureAttributeDescriptor setDefaultValue(
|
||
145 | Object defaultValue) {
|
||
146 | 44189 | jjdelcerro | updateStrongChanges(this.defaultValue, defaultValue);
|
147 | 40435 | jjdelcerro | this.defaultValue = defaultValue;
|
148 | return this; |
||
149 | } |
||
150 | |||
151 | public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
|
||
152 | 44189 | jjdelcerro | updateStrongChanges(this.evaluator, evaluator);
|
153 | 40435 | jjdelcerro | this.evaluator = evaluator;
|
154 | return this; |
||
155 | } |
||
156 | |||
157 | 44253 | jjdelcerro | @Override
|
158 | 41335 | jjdelcerro | public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
159 | this.featureAttributeEmulator = featureAttributeEmulator;
|
||
160 | return this; |
||
161 | } |
||
162 | 44253 | jjdelcerro | |
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 | 41335 | jjdelcerro | |
185 | 44253 | jjdelcerro | @Override
|
186 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
187 | this.geometryType = type;
|
||
188 | 42303 | jjdelcerro | if( this.geometrySubType == Geometry.SUBTYPES.UNKNOWN ) { |
189 | this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
||
190 | } |
||
191 | 40435 | jjdelcerro | 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 | 44189 | jjdelcerro | updateStrongChanges(this.geomType, geometryType);
|
204 | 40435 | jjdelcerro | this.geomType = geometryType;
|
205 | this.geometryType = this.geomType.getType(); |
||
206 | this.geometrySubType = this.geomType.getSubType(); |
||
207 | return this; |
||
208 | } |
||
209 | |||
210 | 42716 | jjdelcerro | @Override
|
211 | 44253 | jjdelcerro | 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 | 42716 | jjdelcerro | 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 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
242 | boolean isPrimaryKey) {
|
||
243 | 44189 | jjdelcerro | updateStrongChanges(this.primaryKey, primaryKey);
|
244 | 40435 | jjdelcerro | this.primaryKey = isPrimaryKey;
|
245 | return this; |
||
246 | } |
||
247 | |||
248 | public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
||
249 | 44189 | jjdelcerro | updateStrongChanges(this.readOnly, readOnly);
|
250 | 40435 | jjdelcerro | this.readOnly = isReadOnly;
|
251 | return this; |
||
252 | } |
||
253 | |||
254 | public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
||
255 | int maximumOccurrences) {
|
||
256 | 44189 | jjdelcerro | updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
|
257 | 40435 | jjdelcerro | this.maximumOccurrences = maximumOccurrences;
|
258 | return this; |
||
259 | } |
||
260 | |||
261 | public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
||
262 | int minimumOccurrences) {
|
||
263 | 44189 | jjdelcerro | updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
|
264 | 40435 | jjdelcerro | this.minimumOccurrences = minimumOccurrences;
|
265 | return this; |
||
266 | } |
||
267 | |||
268 | 43967 | jjdelcerro | @Override
|
269 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setName(String name) { |
270 | 44084 | jjdelcerro | if( StringUtils.equalsIgnoreCase(this.name, name) ) { |
271 | return this; |
||
272 | } |
||
273 | 40435 | jjdelcerro | if (originalName == null) { |
274 | originalName = this.name;
|
||
275 | 43967 | jjdelcerro | if (!isComputed()) {
|
276 | hasStrongChanges = true;
|
||
277 | } |
||
278 | 40435 | jjdelcerro | } |
279 | 44259 | jjdelcerro | super.setName(name);
|
280 | 43135 | jjdelcerro | if (!isComputed()) {
|
281 | 40435 | jjdelcerro | hasStrongChanges = true;
|
282 | } |
||
283 | return this; |
||
284 | } |
||
285 | |||
286 | public String getOriginalName() { |
||
287 | return originalName;
|
||
288 | } |
||
289 | |||
290 | public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
||
291 | 44189 | jjdelcerro | updateStrongChanges(this.objectClass, theClass);
|
292 | 40435 | jjdelcerro | this.objectClass = theClass;
|
293 | return this; |
||
294 | } |
||
295 | |||
296 | 44669 | jjdelcerro | @Override
|
297 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
298 | 44189 | jjdelcerro | updateStrongChanges(this.precision, precision);
|
299 | 40435 | jjdelcerro | this.precision = precision;
|
300 | return this; |
||
301 | } |
||
302 | |||
303 | 44253 | jjdelcerro | @Override
|
304 | 44669 | jjdelcerro | 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 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
314 | 44189 | jjdelcerro | updateStrongChanges(this.SRS, SRS);
|
315 | 40435 | jjdelcerro | this.SRS = SRS;
|
316 | return this; |
||
317 | } |
||
318 | |||
319 | 44253 | jjdelcerro | @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 | 44077 | jjdelcerro | public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
|
331 | 44189 | jjdelcerro | updateStrongChanges(this.getInterval(), interval);
|
332 | 44094 | jjdelcerro | super.setInterval(interval);
|
333 | 44077 | jjdelcerro | return this; |
334 | } |
||
335 | |||
336 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setSize(int size) { |
337 | 44189 | jjdelcerro | updateStrongChanges(this.size, size);
|
338 | 40435 | jjdelcerro | 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 | 43362 | jjdelcerro | if( isAutomatic ) {
|
358 | 44456 | jjdelcerro | this.setReadOnly(true); |
359 | 43362 | jjdelcerro | } |
360 | 40435 | jjdelcerro | return this; |
361 | } |
||
362 | |||
363 | 41483 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
364 | 44189 | jjdelcerro | updateStrongChanges(this.isTime, isTime);
|
365 | 43135 | jjdelcerro | this.isTime = isTime;
|
366 | return this; |
||
367 | 41483 | jjdelcerro | } |
368 | |||
369 | public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
||
370 | this.dateFormat = dateFormat;
|
||
371 | return this; |
||
372 | } |
||
373 | 41638 | jjdelcerro | |
374 | public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
||
375 | 44189 | jjdelcerro | updateStrongChanges(this.indexed, isIndexed);
|
376 | 41638 | jjdelcerro | this.indexed = isIndexed;
|
377 | return this; |
||
378 | } |
||
379 | 41483 | jjdelcerro | |
380 | 41638 | jjdelcerro | public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
381 | 44189 | jjdelcerro | updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
|
382 | 41638 | jjdelcerro | this.allowIndexDuplicateds = allowDuplicateds;
|
383 | return this; |
||
384 | } |
||
385 | |||
386 | public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
||
387 | 44189 | jjdelcerro | updateStrongChanges(this.isIndexAscending, ascending);
|
388 | 41638 | jjdelcerro | this.isIndexAscending = ascending;
|
389 | return this; |
||
390 | } |
||
391 | 44128 | jjdelcerro | |
392 | @Override
|
||
393 | public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
||
394 | super.setDataProfileName(dataProfile);
|
||
395 | return this; |
||
396 | } |
||
397 | 44189 | jjdelcerro | |
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 | 44337 | jjdelcerro | |
440 | 44673 | jjdelcerro | @Override
|
441 | 44669 | jjdelcerro | 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 | 44337 | jjdelcerro | |
452 | 44669 | jjdelcerro | 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 | 44673 | jjdelcerro | @Override
|
467 | 44669 | jjdelcerro | 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 | 44337 | jjdelcerro | 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 | 44338 | jjdelcerro | case "isreadonly": |
494 | case "readonly": |
||
495 | 44337 | jjdelcerro | 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 | 44669 | jjdelcerro | 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 | 44337 | jjdelcerro | 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 | 44338 | jjdelcerro | case "foreingkey.closedlist": |
563 | this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false)); |
||
564 | 44337 | jjdelcerro | 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 | 44740 | jjdelcerro | case "relation": |
579 | this.setRelationType(toRelation(value));
|
||
580 | break;
|
||
581 | 44337 | jjdelcerro | default:
|
582 | throw new IllegalArgumentException("Name attribute '"+name+"' not valid."); |
||
583 | } |
||
584 | return this; |
||
585 | } |
||
586 | 44673 | jjdelcerro | |
587 | 44740 | jjdelcerro | private int toRelation(Object value) { |
588 | if (value == null) { |
||
589 | return DynField.RELATION_TYPE_NONE;
|
||
590 | } |
||
591 | 44745 | jjdelcerro | Integer x = (Integer) DataTypeUtils.coerce(DataTypes.INT,value, null); |
592 | 44740 | jjdelcerro | 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 | 44844 | jjdelcerro | |
615 | @Override
|
||
616 | public EditableFeatureAttributeDescriptor setRequiredBytes(int size) { |
||
617 | this.requiredBytes = size;
|
||
618 | return this; |
||
619 | } |
||
620 | 40435 | jjdelcerro | } |