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