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 | 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 | 45425 | jjdelcerro | import javax.json.JsonObject; |
32 | 44084 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
33 | 40435 | jjdelcerro | |
34 | import org.cresques.cts.IProjection; |
||
35 | 44253 | jjdelcerro | 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 | 44337 | jjdelcerro | import org.gvsig.fmap.dal.DataTypeUtils; |
40 | 44253 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
41 | import org.gvsig.fmap.dal.expressionevaluator.FeatureAttributeEmulatorExpression; |
||
42 | 40964 | jldominguez | import org.slf4j.Logger; |
43 | import org.slf4j.LoggerFactory; |
||
44 | 40435 | jjdelcerro | |
45 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
46 | 44262 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableForeingKey; |
47 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
48 | 43739 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
49 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeIntegrityException; |
50 | import org.gvsig.fmap.dal.feature.exception.AttributeFeatureTypeSizeException; |
||
51 | 42303 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
52 | 44253 | jjdelcerro | import org.gvsig.fmap.geom.GeometryUtils; |
53 | 40435 | jjdelcerro | import org.gvsig.fmap.geom.type.GeometryType; |
54 | 45425 | jjdelcerro | import org.gvsig.json.Json; |
55 | import org.gvsig.json.JsonManager; |
||
56 | import org.gvsig.json.JsonObjectBuilder; |
||
57 | import org.gvsig.json.SupportToJson; |
||
58 | 44077 | jjdelcerro | import org.gvsig.timesupport.Interval; |
59 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
60 | 44189 | jjdelcerro | import org.gvsig.tools.dataTypes.DataType; |
61 | 44740 | jjdelcerro | import org.gvsig.tools.dynobject.DynField; |
62 | 40435 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
63 | |||
64 | public class DefaultEditableFeatureAttributeDescriptor extends |
||
65 | 45739 | jjdelcerro | DefaultFeatureAttributeDescriptor implements
|
66 | EditableFeatureAttributeDescriptor { |
||
67 | |||
68 | 40964 | jldominguez | private static Logger logger = LoggerFactory.getLogger( |
69 | 45739 | jjdelcerro | DefaultEditableFeatureAttributeDescriptor.class); |
70 | 40435 | jjdelcerro | |
71 | 44094 | jjdelcerro | private final DefaultFeatureAttributeDescriptor source; |
72 | 40435 | jjdelcerro | private boolean hasStrongChanges; |
73 | private String originalName = null; |
||
74 | |||
75 | protected DefaultEditableFeatureAttributeDescriptor(
|
||
76 | 45739 | jjdelcerro | DefaultFeatureAttributeDescriptor other) { |
77 | 40435 | jjdelcerro | super(other);
|
78 | if (other instanceof DefaultEditableFeatureAttributeDescriptor) { |
||
79 | 45739 | jjdelcerro | DefaultEditableFeatureAttributeDescriptor other_edi |
80 | = (DefaultEditableFeatureAttributeDescriptor) other; |
||
81 | 40435 | jjdelcerro | originalName = other_edi.getOriginalName(); |
82 | this.source = other_edi.getSource();
|
||
83 | } else {
|
||
84 | this.source = other;
|
||
85 | } |
||
86 | hasStrongChanges = false;
|
||
87 | } |
||
88 | |||
89 | 44190 | jjdelcerro | public DefaultEditableFeatureAttributeDescriptor(FeatureType type, boolean strongChanges) { |
90 | 43739 | jjdelcerro | super(type);
|
91 | 40435 | jjdelcerro | this.source = null; |
92 | 44190 | jjdelcerro | hasStrongChanges = strongChanges; |
93 | 40435 | jjdelcerro | } |
94 | |||
95 | public DefaultFeatureAttributeDescriptor getSource() {
|
||
96 | return this.source; |
||
97 | } |
||
98 | 45739 | jjdelcerro | |
99 | 40435 | jjdelcerro | public void fixAll() { |
100 | 44094 | jjdelcerro | super.fixAll();
|
101 | 40435 | jjdelcerro | } |
102 | 45739 | jjdelcerro | |
103 | 40435 | jjdelcerro | public void checkIntegrity() throws AttributeFeatureTypeIntegrityException { |
104 | 45739 | jjdelcerro | AttributeFeatureTypeIntegrityException ex |
105 | = new AttributeFeatureTypeIntegrityException(getName());
|
||
106 | 40435 | jjdelcerro | if (this.size < 0) { |
107 | ex.add(new AttributeFeatureTypeSizeException(this.size)); |
||
108 | } |
||
109 | |||
110 | 45739 | jjdelcerro | if (this.dataType.isObject() && this.objectClass == null) { |
111 | 40964 | jldominguez | logger.warn("Incorrect data type object, objectClass is null.");
|
112 | ex.add(new AttributeFeatureTypeIntegrityException(this.name)); |
||
113 | } |
||
114 | 45739 | jjdelcerro | |
115 | 40964 | jldominguez | // TODO: Add other integrity checks...
|
116 | 40435 | jjdelcerro | if (ex.size() > 0) { |
117 | throw ex;
|
||
118 | } |
||
119 | } |
||
120 | |||
121 | public EditableFeatureAttributeDescriptor setAllowNull(boolean allowNull) { |
||
122 | 44189 | jjdelcerro | updateStrongChanges(this.allowNull, allowNull);
|
123 | 40435 | jjdelcerro | this.allowNull = allowNull;
|
124 | return this; |
||
125 | } |
||
126 | 45739 | jjdelcerro | |
127 | 44262 | jjdelcerro | @Override
|
128 | public EditableForeingKey getForeingKey() {
|
||
129 | 45739 | jjdelcerro | if (this.foreingKey == null) { |
130 | 44262 | jjdelcerro | this.foreingKey = new DefaultForeingKey(); |
131 | this.foreingKey.setDescriptor(this); |
||
132 | } |
||
133 | return this.foreingKey; |
||
134 | } |
||
135 | 40435 | jjdelcerro | |
136 | 44669 | jjdelcerro | public EditableFeatureAttributeDescriptor setDataType(DataType dataType) {
|
137 | updateStrongChanges(this.dataType, dataType);
|
||
138 | this.dataType = dataType;
|
||
139 | return this; |
||
140 | } |
||
141 | 45739 | jjdelcerro | |
142 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setDataType(int type) { |
143 | 44189 | jjdelcerro | updateStrongChanges(this.dataType, type);
|
144 | 40435 | jjdelcerro | this.dataType = ToolsLocator.getDataTypesManager().get(type);
|
145 | return this; |
||
146 | } |
||
147 | |||
148 | public EditableFeatureAttributeDescriptor setDefaultValue(
|
||
149 | 45739 | jjdelcerro | Object defaultValue) {
|
150 | 44189 | jjdelcerro | updateStrongChanges(this.defaultValue, defaultValue);
|
151 | 40435 | jjdelcerro | this.defaultValue = defaultValue;
|
152 | return this; |
||
153 | } |
||
154 | |||
155 | 46433 | fdiaz | @Override
|
156 | public EditableFeatureAttributeDescriptor setDefaultFieldValue(
|
||
157 | Object defaultValue) {
|
||
158 | return setDefaultValue(defaultValue);
|
||
159 | } |
||
160 | |||
161 | 45135 | jjdelcerro | public EditableFeatureAttributeDescriptor setAvoidCachingAvailableValues(boolean avoidCachingAvailableValues) { |
162 | this.avoidCachingAvailableValues = avoidCachingAvailableValues;
|
||
163 | return this; |
||
164 | } |
||
165 | 45739 | jjdelcerro | |
166 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setEvaluator(Evaluator evaluator) {
|
167 | 44189 | jjdelcerro | updateStrongChanges(this.evaluator, evaluator);
|
168 | 40435 | jjdelcerro | this.evaluator = evaluator;
|
169 | return this; |
||
170 | } |
||
171 | |||
172 | 44253 | jjdelcerro | @Override
|
173 | 41335 | jjdelcerro | public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(FeatureAttributeEmulator featureAttributeEmulator) {
|
174 | this.featureAttributeEmulator = featureAttributeEmulator;
|
||
175 | return this; |
||
176 | } |
||
177 | 45739 | jjdelcerro | |
178 | 44253 | jjdelcerro | @Override
|
179 | public EditableFeatureAttributeDescriptor setFeatureAttributeEmulator(Expression expression) { |
||
180 | 45739 | jjdelcerro | if (ExpressionUtils.isPhraseEmpty(expression)) {
|
181 | this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null); |
||
182 | 44253 | jjdelcerro | return this; |
183 | 45739 | jjdelcerro | } |
184 | 44253 | jjdelcerro | 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 | 45739 | jjdelcerro | if (StringUtils.isBlank(expression)) {
|
194 | this.setFeatureAttributeEmulator((FeatureAttributeEmulator) null); |
||
195 | 44253 | jjdelcerro | return this; |
196 | 45739 | jjdelcerro | } |
197 | 44253 | jjdelcerro | return this.setFeatureAttributeEmulator(ExpressionUtils.createExpression(expression)); |
198 | } |
||
199 | 45739 | jjdelcerro | |
200 | 44253 | jjdelcerro | @Override
|
201 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setGeometryType(int type) { |
202 | this.geometryType = type;
|
||
203 | 45739 | jjdelcerro | if (this.geometrySubType == Geometry.SUBTYPES.UNKNOWN) { |
204 | 42303 | jjdelcerro | this.geometrySubType = Geometry.SUBTYPES.GEOM2D;
|
205 | } |
||
206 | 40435 | jjdelcerro | 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 | 45739 | jjdelcerro | GeometryType geometryType) { |
218 | 44189 | jjdelcerro | updateStrongChanges(this.geomType, geometryType);
|
219 | 40435 | jjdelcerro | this.geomType = geometryType;
|
220 | this.geometryType = this.geomType.getType(); |
||
221 | this.geometrySubType = this.geomType.getSubType(); |
||
222 | return this; |
||
223 | } |
||
224 | |||
225 | 42716 | jjdelcerro | @Override
|
226 | 44253 | jjdelcerro | public EditableFeatureAttributeDescriptor setGeometryType(String geometryType) { |
227 | 45739 | jjdelcerro | if (StringUtils.isBlank(geometryType)) {
|
228 | 44253 | jjdelcerro | throw new IllegalArgumentException("Invalid geometry type (null)"); |
229 | } |
||
230 | String separators = ":/-!;#@"; |
||
231 | Character sep = null; |
||
232 | for (char ch : separators.toCharArray()) { |
||
233 | 45739 | jjdelcerro | if (geometryType.indexOf(ch) >= 0) { |
234 | 44253 | jjdelcerro | sep = ch; |
235 | break;
|
||
236 | } |
||
237 | } |
||
238 | 45739 | jjdelcerro | if (sep == null) { |
239 | throw new IllegalArgumentException("Invalid geometry type (" + geometryType + ") can't find separator, format can be GEOMETRYTYPE[" + separators + "]GEOMETRYSUBTYPE"); |
||
240 | 44253 | jjdelcerro | } |
241 | 45739 | jjdelcerro | String[] xx = geometryType.split("[" + sep + "]"); |
242 | 44253 | jjdelcerro | int theGeomType = GeometryUtils.getGeometryType(xx[0]); |
243 | int theGeomSubtype = GeometryUtils.getGeometrySubtype(xx[1]); |
||
244 | this.setGeometryType(theGeomType, theGeomSubtype);
|
||
245 | return this; |
||
246 | } |
||
247 | 45739 | jjdelcerro | |
248 | 44253 | jjdelcerro | @Override
|
249 | 42716 | jjdelcerro | 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 | 46097 | jjdelcerro | @Override
|
257 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsPrimaryKey(
|
258 | 45739 | jjdelcerro | boolean isPrimaryKey) {
|
259 | 46097 | jjdelcerro | updateStrongChanges(this.primaryKey, isPrimaryKey);
|
260 | 40435 | jjdelcerro | this.primaryKey = isPrimaryKey;
|
261 | return this; |
||
262 | } |
||
263 | |||
264 | 46097 | jjdelcerro | @Override
|
265 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsReadOnly(boolean isReadOnly) { |
266 | 46097 | jjdelcerro | updateStrongChanges(this.readOnly, isReadOnly);
|
267 | 40435 | jjdelcerro | this.readOnly = isReadOnly;
|
268 | return this; |
||
269 | } |
||
270 | |||
271 | public EditableFeatureAttributeDescriptor setMaximumOccurrences(
|
||
272 | 45739 | jjdelcerro | int maximumOccurrences) {
|
273 | 44189 | jjdelcerro | updateStrongChanges(this.maximumOccurrences, maximumOccurrences);
|
274 | 40435 | jjdelcerro | this.maximumOccurrences = maximumOccurrences;
|
275 | return this; |
||
276 | } |
||
277 | |||
278 | public EditableFeatureAttributeDescriptor setMinimumOccurrences(
|
||
279 | 45739 | jjdelcerro | int minimumOccurrences) {
|
280 | 44189 | jjdelcerro | updateStrongChanges(this.minimumOccurrences, minimumOccurrences);
|
281 | 40435 | jjdelcerro | this.minimumOccurrences = minimumOccurrences;
|
282 | return this; |
||
283 | } |
||
284 | |||
285 | 43967 | jjdelcerro | @Override
|
286 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setName(String name) { |
287 | 45739 | jjdelcerro | if (StringUtils.equals(this.name, name)) { |
288 | 44084 | jjdelcerro | return this; |
289 | } |
||
290 | 40435 | jjdelcerro | if (originalName == null) { |
291 | originalName = this.name;
|
||
292 | 43967 | jjdelcerro | if (!isComputed()) {
|
293 | hasStrongChanges = true;
|
||
294 | } |
||
295 | 40435 | jjdelcerro | } |
296 | 44259 | jjdelcerro | super.setName(name);
|
297 | 43135 | jjdelcerro | if (!isComputed()) {
|
298 | 40435 | jjdelcerro | hasStrongChanges = true;
|
299 | } |
||
300 | return this; |
||
301 | } |
||
302 | 45739 | jjdelcerro | |
303 | 40435 | jjdelcerro | public String getOriginalName() { |
304 | return originalName;
|
||
305 | } |
||
306 | |||
307 | public EditableFeatureAttributeDescriptor setObjectClass(Class theClass) { |
||
308 | 44189 | jjdelcerro | updateStrongChanges(this.objectClass, theClass);
|
309 | 40435 | jjdelcerro | this.objectClass = theClass;
|
310 | return this; |
||
311 | } |
||
312 | |||
313 | 44669 | jjdelcerro | @Override
|
314 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setPrecision(int precision) { |
315 | 44189 | jjdelcerro | updateStrongChanges(this.precision, precision);
|
316 | 40435 | jjdelcerro | this.precision = precision;
|
317 | return this; |
||
318 | } |
||
319 | |||
320 | 44253 | jjdelcerro | @Override
|
321 | 44669 | jjdelcerro | 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 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setSRS(IProjection SRS) {
|
331 | 44189 | jjdelcerro | updateStrongChanges(this.SRS, SRS);
|
332 | 40435 | jjdelcerro | this.SRS = SRS;
|
333 | return this; |
||
334 | } |
||
335 | |||
336 | 44253 | jjdelcerro | @Override
|
337 | public EditableFeatureAttributeDescriptor setSRS(String SRS) { |
||
338 | 45739 | jjdelcerro | if (StringUtils.isBlank(SRS)) {
|
339 | this.setSRS((IProjection) null); |
||
340 | 44253 | jjdelcerro | return this; |
341 | } |
||
342 | 45135 | jjdelcerro | SRS = SRS.replace('@', ':'); |
343 | 44253 | jjdelcerro | IProjection proj = CRSFactory.getCRS(SRS); |
344 | this.setSRS(proj);
|
||
345 | return this; |
||
346 | } |
||
347 | 45739 | jjdelcerro | |
348 | 44077 | jjdelcerro | public EditableFeatureAttributeDescriptor setInterval(Interval interval) {
|
349 | 44189 | jjdelcerro | updateStrongChanges(this.getInterval(), interval);
|
350 | 44094 | jjdelcerro | super.setInterval(interval);
|
351 | 44077 | jjdelcerro | return this; |
352 | } |
||
353 | |||
354 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setSize(int size) { |
355 | 44189 | jjdelcerro | updateStrongChanges(this.size, size);
|
356 | 40435 | jjdelcerro | this.size = size;
|
357 | return this; |
||
358 | } |
||
359 | |||
360 | public boolean hasStrongChanges() { |
||
361 | return hasStrongChanges;
|
||
362 | } |
||
363 | |||
364 | 45154 | jjdelcerro | @Override
|
365 | 40435 | jjdelcerro | public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
366 | 45739 | jjdelcerro | String infoName, Object value) { |
367 | 45154 | jjdelcerro | return this.setAdditionalInfo(infoName, Objects.toString(value, "")); |
368 | } |
||
369 | 45739 | jjdelcerro | |
370 | 45154 | jjdelcerro | public EditableFeatureAttributeDescriptor setAdditionalInfo(
|
371 | 45739 | jjdelcerro | String infoName, String value) { |
372 | 40435 | jjdelcerro | 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 | 45921 | jjdelcerro | // if (isAutomatic) {
|
382 | // this.setReadOnly(true);
|
||
383 | // }
|
||
384 | 40435 | jjdelcerro | return this; |
385 | } |
||
386 | 45739 | jjdelcerro | |
387 | 41483 | jjdelcerro | public EditableFeatureAttributeDescriptor setIsTime(boolean isTime) { |
388 | 44189 | jjdelcerro | updateStrongChanges(this.isTime, isTime);
|
389 | 43135 | jjdelcerro | this.isTime = isTime;
|
390 | return this; |
||
391 | 41483 | jjdelcerro | } |
392 | |||
393 | public EditableFeatureAttributeDescriptor setDateFormat(DateFormat dateFormat) { |
||
394 | this.dateFormat = dateFormat;
|
||
395 | return this; |
||
396 | } |
||
397 | 41638 | jjdelcerro | |
398 | public EditableFeatureAttributeDescriptor setIsIndexed(boolean isIndexed) { |
||
399 | 44189 | jjdelcerro | updateStrongChanges(this.indexed, isIndexed);
|
400 | 41638 | jjdelcerro | this.indexed = isIndexed;
|
401 | return this; |
||
402 | } |
||
403 | 45739 | jjdelcerro | |
404 | 41638 | jjdelcerro | public EditableFeatureAttributeDescriptor setAllowIndexDuplicateds(boolean allowDuplicateds) { |
405 | 44189 | jjdelcerro | updateStrongChanges(this.allowIndexDuplicateds, allowDuplicateds);
|
406 | 41638 | jjdelcerro | this.allowIndexDuplicateds = allowDuplicateds;
|
407 | return this; |
||
408 | } |
||
409 | |||
410 | public EditableFeatureAttributeDescriptor setIsIndexAscending(boolean ascending) { |
||
411 | 44189 | jjdelcerro | updateStrongChanges(this.isIndexAscending, ascending);
|
412 | 41638 | jjdelcerro | this.isIndexAscending = ascending;
|
413 | return this; |
||
414 | } |
||
415 | 44128 | jjdelcerro | |
416 | @Override
|
||
417 | public EditableFeatureAttributeDescriptor setDataProfileName(String dataProfile) { |
||
418 | super.setDataProfileName(dataProfile);
|
||
419 | return this; |
||
420 | } |
||
421 | 44189 | jjdelcerro | |
422 | private void updateStrongChanges(int previous, int newvalue) { |
||
423 | 45739 | jjdelcerro | if (isComputed()) {
|
424 | 44189 | jjdelcerro | return;
|
425 | } |
||
426 | 45739 | jjdelcerro | if (previous == newvalue) {
|
427 | 44189 | jjdelcerro | return;
|
428 | } |
||
429 | this.hasStrongChanges = true; |
||
430 | } |
||
431 | |||
432 | private void updateStrongChanges(DataType previous, int newvalue) { |
||
433 | 45739 | jjdelcerro | if (isComputed()) {
|
434 | 44189 | jjdelcerro | return;
|
435 | } |
||
436 | 45739 | jjdelcerro | if (previous != null) { |
437 | if (previous.getType() == newvalue) {
|
||
438 | 44189 | jjdelcerro | return;
|
439 | } |
||
440 | } |
||
441 | this.hasStrongChanges = true; |
||
442 | } |
||
443 | |||
444 | private void updateStrongChanges(boolean previous, boolean newvalue) { |
||
445 | 45739 | jjdelcerro | if (isComputed()) {
|
446 | 44189 | jjdelcerro | return;
|
447 | } |
||
448 | 45739 | jjdelcerro | if (previous == newvalue) {
|
449 | 44189 | jjdelcerro | return;
|
450 | } |
||
451 | this.hasStrongChanges = true; |
||
452 | } |
||
453 | |||
454 | private void updateStrongChanges(Object previous, Object newvalue) { |
||
455 | 45739 | jjdelcerro | if (isComputed()) {
|
456 | 44189 | jjdelcerro | return;
|
457 | } |
||
458 | 45739 | jjdelcerro | if (Objects.equals(newvalue, previous)) {
|
459 | 44189 | jjdelcerro | return;
|
460 | } |
||
461 | this.hasStrongChanges = true; |
||
462 | } |
||
463 | 44337 | jjdelcerro | |
464 | 44673 | jjdelcerro | @Override
|
465 | 44669 | jjdelcerro | public EditableFeatureAttributeDescriptor setLocale(Locale locale) { |
466 | 45739 | jjdelcerro | 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 | 44669 | jjdelcerro | } |
475 | 44337 | jjdelcerro | |
476 | 44669 | jjdelcerro | public EditableFeatureAttributeDescriptor setLocale(String locale) { |
477 | 45739 | jjdelcerro | 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 | 44669 | jjdelcerro | } |
488 | } |
||
489 | 45739 | jjdelcerro | |
490 | 44673 | jjdelcerro | @Override
|
491 | 44669 | jjdelcerro | public EditableFeatureAttributeDescriptor setRoundMode(int roundMode) { |
492 | 45739 | jjdelcerro | 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 | 44669 | jjdelcerro | } |
510 | |||
511 | @Override
|
||
512 | 44337 | jjdelcerro | public EditableFeatureAttributeDescriptor set(String name, Object value) { |
513 | 45739 | jjdelcerro | if (StringUtils.isBlank(name)) {
|
514 | 44337 | jjdelcerro | throw new IllegalArgumentException("Name can't be empty"); |
515 | } |
||
516 | 45739 | jjdelcerro | String ss;
|
517 | switch (name.trim().toLowerCase()) {
|
||
518 | 45135 | jjdelcerro | case "isavoidcachingavailablevalues": |
519 | case "avoidcachingavailablevalues": |
||
520 | case "nocachingavailablevalues": |
||
521 | this.setAvoidCachingAvailableValues(DataTypeUtils.toBoolean(value, false)); |
||
522 | break;
|
||
523 | 45042 | jjdelcerro | case "availablevalues": |
524 | this.setAvailableValuesExpression(DataTypeUtils.toString(value, null)); |
||
525 | break;
|
||
526 | 44338 | jjdelcerro | case "isreadonly": |
527 | case "readonly": |
||
528 | 44337 | jjdelcerro | this.setIsReadOnly(DataTypeUtils.toBoolean(value, false)); |
529 | break;
|
||
530 | 45068 | jjdelcerro | case "mandatory": |
531 | this.setMandatory(DataTypeUtils.toBoolean(value, false)); |
||
532 | break;
|
||
533 | 44337 | jjdelcerro | case "hidden": |
534 | this.setHidden(DataTypeUtils.toBoolean(value, false)); |
||
535 | break;
|
||
536 | case "allownull": |
||
537 | this.setAllowNull(DataTypeUtils.toBoolean(value, false)); |
||
538 | break;
|
||
539 | 45731 | omartinez | case "indexed": |
540 | case "isindexed": |
||
541 | this.setIsIndexed(DataTypeUtils.toBoolean(value, false)); |
||
542 | break;
|
||
543 | 47020 | jjdelcerro | case "indexasc": |
544 | case "indexascending": |
||
545 | case "isindexascending": |
||
546 | this.setIsIndexAscending(DataTypeUtils.toBoolean(value, false)); |
||
547 | break;
|
||
548 | 44337 | jjdelcerro | case "pk": |
549 | case "ispk": |
||
550 | case "primarykey": |
||
551 | case "isprimarykey": |
||
552 | this.setIsPrimaryKey(DataTypeUtils.toBoolean(value, false)); |
||
553 | break;
|
||
554 | 45865 | omartinez | case "allowindexduplicateds": |
555 | this.setAllowIndexDuplicateds(DataTypeUtils.toBoolean(value, false)); |
||
556 | break;
|
||
557 | 44337 | jjdelcerro | 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 | 44669 | jjdelcerro | case "scale": |
590 | this.setScale(DataTypeUtils.toInteger(value, 10)); |
||
591 | break;
|
||
592 | case "roundmode": |
||
593 | 45739 | jjdelcerro | this.setRoundMode(DataTypeUtils.toInteger(value, BigDecimal.ROUND_UNNECESSARY)); |
594 | break;
|
||
595 | 44669 | jjdelcerro | case "locale": |
596 | 45739 | jjdelcerro | this.setLocale(DataTypeUtils.toString(value, null)); |
597 | break;
|
||
598 | 44337 | jjdelcerro | case "order": |
599 | this.setOrder(DataTypeUtils.toInteger(value, 0)); |
||
600 | break;
|
||
601 | 45040 | jjdelcerro | case "fk": |
602 | 44337 | jjdelcerro | case "foreingkey": |
603 | this.getForeingKey().setForeingKey(DataTypeUtils.toBoolean(value, false)); |
||
604 | break;
|
||
605 | 45040 | jjdelcerro | case "fk_code": |
606 | case "foreingkey_code": |
||
607 | 44337 | jjdelcerro | case "foreingkey.code": |
608 | this.getForeingKey().setCodeName(DataTypeUtils.toString(value, "")); |
||
609 | break;
|
||
610 | 45040 | jjdelcerro | case "fk_label": |
611 | case "foreingkey_label": |
||
612 | 44337 | jjdelcerro | case "foreingkey.label": |
613 | this.getForeingKey().setLabelFormula(DataTypeUtils.toString(value, "")); |
||
614 | break;
|
||
615 | 45739 | jjdelcerro | case "fk_closed": |
616 | case "fk_closedlist": |
||
617 | 45040 | jjdelcerro | case "fk.closedlist": |
618 | case "foreingkey_closedlist": |
||
619 | 44338 | jjdelcerro | case "foreingkey.closedlist": |
620 | this.getForeingKey().setClosedList(DataTypeUtils.toBoolean(value, false)); |
||
621 | 44337 | jjdelcerro | break;
|
622 | 45040 | jjdelcerro | case "fk_table": |
623 | case "foreingkey_table": |
||
624 | 44337 | jjdelcerro | 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 | 45135 | jjdelcerro | this.setSRS(DataTypeUtils.toString(value, null)); |
636 | 44337 | jjdelcerro | break;
|
637 | 44740 | jjdelcerro | case "relation": |
638 | this.setRelationType(toRelation(value));
|
||
639 | break;
|
||
640 | 44941 | jjdelcerro | case "name": |
641 | this.setName(DataTypeUtils.toString(value, null)); |
||
642 | break;
|
||
643 | case "type": |
||
644 | case "datatype": |
||
645 | ss = DataTypeUtils.toString(value, null);
|
||
646 | 45739 | jjdelcerro | if (!StringUtils.isBlank(ss)) {
|
647 | 44941 | jjdelcerro | this.setDataType(ToolsLocator.getDataTypesManager().getType(ss));
|
648 | } |
||
649 | break;
|
||
650 | 45775 | jjdelcerro | case "defaultvalue": |
651 | this.setDefaultValue(value);
|
||
652 | 45739 | jjdelcerro | break;
|
653 | 45775 | jjdelcerro | case "availablevaluesfilter": |
654 | this.setAvailableValuesFilter(DataTypeUtils.toString(value, null)); |
||
655 | break;
|
||
656 | 46542 | fdiaz | case "format": |
657 | case "defaultformat": |
||
658 | this.setDefaultFormat(DataTypeUtils.toString(value, null)); |
||
659 | 44337 | jjdelcerro | default:
|
660 | 45739 | jjdelcerro | throw new IllegalArgumentException("Name attribute '" + name + "' not valid."); |
661 | } |
||
662 | 44337 | jjdelcerro | return this; |
663 | } |
||
664 | 45739 | jjdelcerro | |
665 | 44740 | jjdelcerro | private int toRelation(Object value) { |
666 | 45739 | jjdelcerro | if (value == null) { |
667 | 44740 | jjdelcerro | return DynField.RELATION_TYPE_NONE;
|
668 | } |
||
669 | 45739 | jjdelcerro | 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 | 44740 | jjdelcerro | } |
692 | 44844 | jjdelcerro | |
693 | 45739 | jjdelcerro | @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 | 45775 | jjdelcerro | @Override
|
706 | public EditableFeatureAttributeDescriptor setAvailableValuesFilter(String filter) { |
||
707 | super.setAvailableValuesFilter(filter);
|
||
708 | return this; |
||
709 | } |
||
710 | |||
711 | 45425 | jjdelcerro | private static class TheJsonSerializer implements JsonManager.JsonSerializer { |
712 | 45739 | jjdelcerro | |
713 | public TheJsonSerializer() {
|
||
714 | 45425 | jjdelcerro | } |
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 | 45739 | jjdelcerro | return ((SupportToJson) value).toJsonBuilder();
|
731 | 45425 | jjdelcerro | } |
732 | 45739 | jjdelcerro | |
733 | 45425 | jjdelcerro | } |
734 | 45739 | jjdelcerro | |
735 | 45564 | jjdelcerro | @Override
|
736 | public EditableFeatureAttributeDescriptor setForeingkey(
|
||
737 | boolean isForeingkey,
|
||
738 | boolean isClosedList,
|
||
739 | String tableName,
|
||
740 | String codeName,
|
||
741 | String labelFormula
|
||
742 | 45739 | jjdelcerro | ) { |
743 | if (isForeingkey) {
|
||
744 | 45564 | jjdelcerro | 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 | 45739 | jjdelcerro | } |
753 | 45564 | jjdelcerro | return this; |
754 | } |
||
755 | 45425 | jjdelcerro | |
756 | 45564 | jjdelcerro | @Override
|
757 | public EditableFeatureAttributeDescriptor setTag(String name, Object value) { |
||
758 | this.getTags().set(name, value);
|
||
759 | return this; |
||
760 | } |
||
761 | |||
762 | 45425 | jjdelcerro | public static void selfRegister() { |
763 | Json.registerSerializer(new TheJsonSerializer());
|
||
764 | } |
||
765 | 45739 | jjdelcerro | |
766 | 45968 | jjdelcerro | @Override
|
767 | public EditableFeatureAttributeDescriptor setDefaultFormat(String format) { |
||
768 | this.defaultFormat = format;
|
||
769 | return this; |
||
770 | } |
||
771 | |||
772 | |||
773 | 40435 | jjdelcerro | } |