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