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 / DefaultFeature.java @ 45693
History | View | Annotate | Download (46.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 | import java.lang.ref.WeakReference; |
||
27 | 44669 | jjdelcerro | import java.math.BigDecimal; |
28 | 45023 | fdiaz | import java.time.LocalDateTime; |
29 | import java.time.ZoneId; |
||
30 | 44655 | jjdelcerro | import java.time.format.DateTimeFormatter; |
31 | 43550 | jjdelcerro | import java.util.ArrayList; |
32 | 40435 | jjdelcerro | import java.util.Date; |
33 | 44858 | jjdelcerro | import java.util.HashMap; |
34 | 40435 | jjdelcerro | import java.util.Iterator; |
35 | import java.util.List; |
||
36 | 43550 | jjdelcerro | import java.util.Map; |
37 | 44655 | jjdelcerro | import java.util.Objects; |
38 | import javax.json.JsonObject; |
||
39 | 44779 | omartinez | import org.apache.commons.lang3.ArrayUtils; |
40 | 44128 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
41 | 40435 | jjdelcerro | import org.cresques.cts.IProjection; |
42 | 44818 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionUtils; |
43 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
44 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
45 | import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException; |
||
46 | import org.gvsig.fmap.dal.exception.DataException; |
||
47 | 44128 | jjdelcerro | import org.gvsig.fmap.dal.feature.DataProfile; |
48 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeature; |
49 | 44773 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
50 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
51 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
52 | 41335 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureAttributeEmulator; |
53 | import org.gvsig.fmap.dal.feature.FeatureAttributeGetter; |
||
54 | 45581 | fdiaz | import org.gvsig.fmap.dal.feature.FeatureExtraColumns; |
55 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureReference; |
56 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
57 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
58 | import org.gvsig.fmap.dal.feature.exception.IllegalValueException; |
||
59 | import org.gvsig.fmap.dal.feature.exception.SetReadOnlyAttributeException; |
||
60 | 42775 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectFeatureFacade; |
61 | 45647 | fdiaz | import org.gvsig.fmap.dal.feature.impl.featurereference.FeatureReferenceFactory; |
62 | 43729 | fdiaz | import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
63 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
64 | import org.gvsig.fmap.geom.Geometry; |
||
65 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
66 | 45581 | fdiaz | import org.gvsig.json.Json; |
67 | import org.gvsig.json.JsonObjectBuilder; |
||
68 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
69 | 44799 | jjdelcerro | import org.gvsig.tools.dataTypes.Coercion; |
70 | 40435 | jjdelcerro | import org.gvsig.tools.dataTypes.CoercionException; |
71 | 45581 | fdiaz | import org.gvsig.tools.dataTypes.DataType; |
72 | 40435 | jjdelcerro | import org.gvsig.tools.dataTypes.DataTypesManager; |
73 | 45581 | fdiaz | import org.gvsig.tools.dataTypes.impl.coercion.CoerceToString; |
74 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
75 | import org.gvsig.tools.evaluator.Evaluator; |
||
76 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
77 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
78 | import org.gvsig.tools.exception.BaseException; |
||
79 | import org.gvsig.tools.exception.BaseRuntimeException; |
||
80 | 40876 | jjdelcerro | import org.gvsig.tools.lang.Cloneable; |
81 | 45581 | fdiaz | import org.slf4j.Logger; |
82 | import org.slf4j.LoggerFactory; |
||
83 | 40435 | jjdelcerro | |
84 | 44799 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
85 | 40876 | jjdelcerro | public class DefaultFeature implements Feature, EvaluatorData, Cloneable { |
86 | 40435 | jjdelcerro | |
87 | 45581 | fdiaz | private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFeature.class); |
88 | 43729 | fdiaz | |
89 | 45581 | fdiaz | private static DataTypesManager dataTypesManager = null; |
90 | protected FeatureProvider data;
|
||
91 | protected FeatureReference reference;
|
||
92 | private WeakReference storeRef; |
||
93 | 40435 | jjdelcerro | |
94 | 45581 | fdiaz | private boolean inserted = false; |
95 | private Object[] extraValuesData; |
||
96 | private Map<String, Object> extraValues; // not persistent |
||
97 | |||
98 | 40435 | jjdelcerro | /*
|
99 | * Usar con mucha precaucion o mejor no usar. Lo precisa el
|
||
100 | * DefaultFeatureSet en la ordenacion.
|
||
101 | 45581 | fdiaz | */
|
102 | public DefaultFeature(FeatureStore store) {
|
||
103 | this.storeRef = new WeakReference(store); |
||
104 | this.reference = null; |
||
105 | } |
||
106 | 40435 | jjdelcerro | |
107 | 45581 | fdiaz | public DefaultFeature(FeatureStore store, FeatureProvider data) {
|
108 | this.data = data;
|
||
109 | this.extraValuesData = null; |
||
110 | this.storeRef = new WeakReference(store); |
||
111 | this.reference = null; |
||
112 | this.inserted = !data.isNew();
|
||
113 | } |
||
114 | 40435 | jjdelcerro | |
115 | 45581 | fdiaz | DefaultFeature(DefaultFeature feature) { |
116 | this.data = feature.data.getCopy();
|
||
117 | this.extraValuesData = ArrayUtils.clone(feature.extraValuesData);
|
||
118 | this.storeRef = feature.storeRef;
|
||
119 | this.reference = feature.reference;
|
||
120 | this.inserted = feature.isInserted();
|
||
121 | } |
||
122 | 40435 | jjdelcerro | |
123 | 43729 | fdiaz | public DefaultFeature(FeatureType targetType, Feature sourceFeature) {
|
124 | 45581 | fdiaz | DefaultFeature defaultFeature = (DefaultFeature) sourceFeature; |
125 | this.data = new DefaultFeatureProvider(targetType, (DefaultFeatureProvider) defaultFeature.getData()); |
||
126 | 44779 | omartinez | this.extraValuesData = null; |
127 | 43729 | fdiaz | this.storeRef = defaultFeature.storeRef;
|
128 | this.reference = defaultFeature.reference;
|
||
129 | this.inserted = defaultFeature.isInserted();
|
||
130 | |||
131 | FeatureType sourceType = sourceFeature.getType(); |
||
132 | |||
133 | for (FeatureAttributeDescriptor targetAttrDescriptor : targetType) {
|
||
134 | 45581 | fdiaz | if (targetAttrDescriptor.isComputed()) {
|
135 | continue;
|
||
136 | 43729 | fdiaz | } |
137 | int sourceIndex = sourceType.getIndex(targetAttrDescriptor.getName());
|
||
138 | 45581 | fdiaz | if (sourceIndex < 0) { |
139 | 43729 | fdiaz | continue;
|
140 | } |
||
141 | Object value = sourceFeature.get(sourceIndex);
|
||
142 | if (value == null && !targetAttrDescriptor.allowNull()) { |
||
143 | continue;
|
||
144 | } |
||
145 | 45581 | fdiaz | this.setforced(targetAttrDescriptor.getIndex(), targetAttrDescriptor, value);
|
146 | 43729 | fdiaz | } |
147 | } |
||
148 | |||
149 | 45581 | fdiaz | public void setData(FeatureProvider data) { |
150 | this.data = data;
|
||
151 | this.extraValuesData = null; |
||
152 | this.reference = null; |
||
153 | this.inserted = true; |
||
154 | } |
||
155 | 40435 | jjdelcerro | |
156 | 45581 | fdiaz | public FeatureProvider getData() {
|
157 | return this.data; |
||
158 | } |
||
159 | 40435 | jjdelcerro | |
160 | 45581 | fdiaz | protected DataTypesManager getDataTypesManager() {
|
161 | if (dataTypesManager == null) { |
||
162 | dataTypesManager = ToolsLocator.getDataTypesManager(); |
||
163 | } |
||
164 | return dataTypesManager;
|
||
165 | } |
||
166 | 40435 | jjdelcerro | |
167 | 44641 | jjdelcerro | protected void set(FeatureAttributeDescriptor attribute, Object value) { |
168 | 41335 | jjdelcerro | int i = attribute.getIndex();
|
169 | 40435 | jjdelcerro | |
170 | 45581 | fdiaz | if (attribute.isReadOnly()) {
|
171 | 41823 | jjdelcerro | throw new SetReadOnlyAttributeException(attribute.getName(), this.getType()); |
172 | 41335 | jjdelcerro | } |
173 | FeatureAttributeEmulator emulator = attribute.getFeatureAttributeEmulator(); |
||
174 | 45581 | fdiaz | if (emulator != null) { |
175 | emulator.set((EditableFeature) this, value);
|
||
176 | 41335 | jjdelcerro | return;
|
177 | } |
||
178 | 43729 | fdiaz | |
179 | 45581 | fdiaz | if (value == null) { |
180 | if (!attribute.allowNull()) {
|
||
181 | if (!attribute.isAutomatic()) {
|
||
182 | 41335 | jjdelcerro | throw new IllegalValueException(attribute, value); |
183 | } |
||
184 | } |
||
185 | this.data.set(i, null); |
||
186 | return;
|
||
187 | 40435 | jjdelcerro | |
188 | 41335 | jjdelcerro | } |
189 | 40435 | jjdelcerro | |
190 | 45581 | fdiaz | if (attribute.getFeatureAttributeGetter() != null) { |
191 | 41335 | jjdelcerro | value = attribute.getFeatureAttributeGetter().setter(value); |
192 | 40435 | jjdelcerro | } |
193 | 44641 | jjdelcerro | this.setforced(i, attribute, value);
|
194 | } |
||
195 | 41335 | jjdelcerro | |
196 | 44641 | jjdelcerro | private void setforced(int i, FeatureAttributeDescriptor attribute, Object value) { |
197 | |||
198 | 42218 | jjdelcerro | Class objectClass = attribute.getObjectClass();
|
199 | 45581 | fdiaz | if (objectClass != null) { |
200 | if (objectClass.isInstance(value)) {
|
||
201 | if (attribute.getType() == DataTypes.DECIMAL) {
|
||
202 | BigDecimal d = (BigDecimal) value; |
||
203 | if (d.scale() == attribute.getScale() && d.precision() <= attribute.getPrecision()) {
|
||
204 | this.data.set(i, value);
|
||
205 | return;
|
||
206 | } |
||
207 | 45693 | fdiaz | } else if (attribute.getType() == DataTypes.GEOMETRY) { |
208 | if (!attribute.getGeomType().equals(((Geometry) value).getGeometryType())) {
|
||
209 | try {
|
||
210 | Coercion coercer = attribute.getDataType().getCoercion(); |
||
211 | value = coercer.coerce(value, attribute.getCoercionContext()); |
||
212 | } catch (CoercionException e) {
|
||
213 | throw new IllegalArgumentException("Can't convert to " |
||
214 | + attribute.getDataType().getName() |
||
215 | + " from '"
|
||
216 | + value == null ? "NULL" : value.getClass().getName() |
||
217 | + "' with value '"
|
||
218 | + Objects.toString(value) |
||
219 | + "' and context '"
|
||
220 | + attribute.getCoercionContext() |
||
221 | + "'.");
|
||
222 | } |
||
223 | } |
||
224 | this.data.set(i, value);
|
||
225 | return;
|
||
226 | 45581 | fdiaz | } else {
|
227 | 44799 | jjdelcerro | this.data.set(i, value);
|
228 | return;
|
||
229 | } |
||
230 | } |
||
231 | DataProfile dataProfile = attribute.getDataProfile(); |
||
232 | 45581 | fdiaz | if (dataProfile != null) { |
233 | 42218 | jjdelcerro | try {
|
234 | 44799 | jjdelcerro | value = dataProfile.coerce( |
235 | attribute.getDataType(), |
||
236 | 45581 | fdiaz | value, |
237 | 44799 | jjdelcerro | attribute.getTags() |
238 | ); |
||
239 | 42218 | jjdelcerro | } catch (CoercionException e) {
|
240 | 44799 | jjdelcerro | |
241 | 42218 | jjdelcerro | } |
242 | 45581 | fdiaz | } |
243 | 44799 | jjdelcerro | try {
|
244 | Coercion coercer = attribute.getDataType().getCoercion(); |
||
245 | 45581 | fdiaz | if (attribute.getType() == DataTypes.STRING && value instanceof Boolean) { |
246 | 45131 | fdiaz | value = coercer.coerce(value, attribute.getCoercionContext()); |
247 | value = StringUtils.left((String) value, attribute.getSize());
|
||
248 | } else {
|
||
249 | 45581 | fdiaz | value = coercer.coerce(value, attribute.getCoercionContext()); |
250 | 45131 | fdiaz | } |
251 | 44799 | jjdelcerro | } catch (CoercionException e) {
|
252 | throw new IllegalArgumentException("Can't convert to " |
||
253 | + attribute.getDataType().getName() |
||
254 | + " from '"
|
||
255 | 45581 | fdiaz | + value == null ? "NULL" : value.getClass().getName() |
256 | + "' with value '"
|
||
257 | + Objects.toString(value) |
||
258 | + "' and context '"
|
||
259 | + attribute.getCoercionContext() |
||
260 | + "'.");
|
||
261 | 40435 | jjdelcerro | } |
262 | 41335 | jjdelcerro | } |
263 | 40435 | jjdelcerro | this.data.set(i, value);
|
264 | } |
||
265 | 43729 | fdiaz | |
266 | 45581 | fdiaz | private Object get(int index, Class theClass, int type) { |
267 | 40435 | jjdelcerro | Object value = this.get(index); |
268 | 45581 | fdiaz | if (theClass.isInstance(value)) {
|
269 | 40435 | jjdelcerro | return value;
|
270 | } |
||
271 | try {
|
||
272 | return this.getDataTypesManager().coerce(type, value); |
||
273 | } catch (CoercionException e) {
|
||
274 | 43729 | fdiaz | |
275 | 40435 | jjdelcerro | if (value == null) { |
276 | return null; |
||
277 | } |
||
278 | throw new IllegalArgumentException( |
||
279 | 45581 | fdiaz | "Can't convert to " + theClass.getName()
|
280 | + " from '" + value.getClass().getName()
|
||
281 | + "' with value '" + value.toString() + "'."); |
||
282 | 40435 | jjdelcerro | } |
283 | } |
||
284 | 43729 | fdiaz | |
285 | 40435 | jjdelcerro | public void initializeValues() { |
286 | FeatureType type = this.getType();
|
||
287 | 44297 | jjdelcerro | for (FeatureAttributeDescriptor attribute : type) {
|
288 | 40435 | jjdelcerro | if (attribute.isAutomatic() || attribute.isReadOnly()
|
289 | 45581 | fdiaz | || attribute.isComputed()) { |
290 | 40435 | jjdelcerro | continue;
|
291 | } |
||
292 | if (attribute.getDefaultValue() == null && !attribute.allowNull()) { |
||
293 | continue;
|
||
294 | } |
||
295 | 45581 | fdiaz | Object value = attribute.getDefaultValue();
|
296 | if (value instanceof CharSequence) { |
||
297 | String s = ((CharSequence) value).toString(); |
||
298 | if (ExpressionUtils.isDynamicText(s)) {
|
||
299 | try {
|
||
300 | value = ExpressionUtils.evaluateDynamicText(s); |
||
301 | } catch (Throwable th) { |
||
302 | value = null;
|
||
303 | } |
||
304 | 44818 | jjdelcerro | } |
305 | } |
||
306 | this.set(attribute, value);
|
||
307 | 40435 | jjdelcerro | } |
308 | } |
||
309 | |||
310 | public void clear() { |
||
311 | initializeValues(); |
||
312 | } |
||
313 | |||
314 | public void initializeValues(Feature feature) { |
||
315 | 45581 | fdiaz | FeatureType myType = this.getType();
|
316 | FeatureType type = feature.getType(); |
||
317 | 44779 | omartinez | extraValuesData = null;
|
318 | 44297 | jjdelcerro | for (FeatureAttributeDescriptor attribute : type) {
|
319 | 45581 | fdiaz | FeatureAttributeDescriptor myAttribute = myType.getAttributeDescriptor(attribute.getName()); |
320 | 40435 | jjdelcerro | if (myAttribute != null) { |
321 | this.set(myAttribute, feature.get(attribute.getIndex()));
|
||
322 | } |
||
323 | } |
||
324 | } |
||
325 | |||
326 | 44297 | jjdelcerro | @Override
|
327 | 40435 | jjdelcerro | public FeatureStore getStore() {
|
328 | return (FeatureStore) this.storeRef.get(); |
||
329 | } |
||
330 | |||
331 | 44297 | jjdelcerro | @Override
|
332 | 40435 | jjdelcerro | public FeatureType getType() {
|
333 | return this.data.getType(); |
||
334 | } |
||
335 | |||
336 | 44297 | jjdelcerro | @Override
|
337 | 40435 | jjdelcerro | public EditableFeature getEditable() {
|
338 | return new DefaultEditableFeature(this); |
||
339 | } |
||
340 | |||
341 | 44297 | jjdelcerro | @Override
|
342 | 40435 | jjdelcerro | public Feature getCopy() {
|
343 | return new DefaultFeature(this); |
||
344 | } |
||
345 | 43729 | fdiaz | |
346 | 44297 | jjdelcerro | @Override
|
347 | @SuppressWarnings("CloneDoesntCallSuperClone") |
||
348 | 40876 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
349 | return new DefaultFeature(this); |
||
350 | } |
||
351 | 40435 | jjdelcerro | |
352 | 44297 | jjdelcerro | @Override
|
353 | 40435 | jjdelcerro | public FeatureReference getReference() {
|
354 | if (this.reference == null) { |
||
355 | if (!isInserted()) {
|
||
356 | return null; |
||
357 | } |
||
358 | 45647 | fdiaz | reference = FeatureReferenceFactory.createFromFeature(this);
|
359 | 40435 | jjdelcerro | } |
360 | return this.reference; |
||
361 | } |
||
362 | |||
363 | 44331 | jjdelcerro | @Override
|
364 | public Object getOrDefault(String name, Object defaultValue) { |
||
365 | int index = this.data.getType().getIndex(name); |
||
366 | 45581 | fdiaz | if (index < 0) { |
367 | 44331 | jjdelcerro | return defaultValue;
|
368 | } |
||
369 | return this.get(index); |
||
370 | } |
||
371 | |||
372 | @Override
|
||
373 | public String getStringOrDefault(String name, String defaultValue) { |
||
374 | int index = this.data.getType().getIndex(name); |
||
375 | 45581 | fdiaz | if (index < 0) { |
376 | 44331 | jjdelcerro | return defaultValue;
|
377 | } |
||
378 | try {
|
||
379 | return (String) this.get(index); |
||
380 | 45581 | fdiaz | } catch (Throwable th) { |
381 | 44331 | jjdelcerro | return defaultValue;
|
382 | } |
||
383 | } |
||
384 | |||
385 | @Override
|
||
386 | 45540 | jjdelcerro | public boolean getBooleanOrDefault(String name, boolean defaultValue) { |
387 | int index = this.data.getType().getIndex(name); |
||
388 | 45581 | fdiaz | if (index < 0) { |
389 | 45540 | jjdelcerro | return defaultValue;
|
390 | } |
||
391 | try {
|
||
392 | return this.getBoolean(index); |
||
393 | 45581 | fdiaz | } catch (Throwable th) { |
394 | 45540 | jjdelcerro | return defaultValue;
|
395 | } |
||
396 | } |
||
397 | |||
398 | @Override
|
||
399 | 44331 | jjdelcerro | public int getIntOrDefault(String name, int defaultValue) { |
400 | int index = this.data.getType().getIndex(name); |
||
401 | 45581 | fdiaz | if (index < 0) { |
402 | 44331 | jjdelcerro | return defaultValue;
|
403 | } |
||
404 | try {
|
||
405 | 45540 | jjdelcerro | return this.getInt(index); |
406 | 45581 | fdiaz | } catch (Throwable th) { |
407 | 44331 | jjdelcerro | return defaultValue;
|
408 | } |
||
409 | } |
||
410 | |||
411 | @Override
|
||
412 | public long getLongOrDefault(String name, long defaultValue) { |
||
413 | int index = this.data.getType().getIndex(name); |
||
414 | 45581 | fdiaz | if (index < 0) { |
415 | 44331 | jjdelcerro | return defaultValue;
|
416 | } |
||
417 | try {
|
||
418 | 45540 | jjdelcerro | return this.getLong(index); |
419 | 45581 | fdiaz | } catch (Throwable th) { |
420 | 44331 | jjdelcerro | return defaultValue;
|
421 | } |
||
422 | } |
||
423 | |||
424 | @Override
|
||
425 | public float getFloatOrDefault(String name, float defaultValue) { |
||
426 | int index = this.data.getType().getIndex(name); |
||
427 | 45581 | fdiaz | if (index < 0) { |
428 | 44331 | jjdelcerro | return defaultValue;
|
429 | } |
||
430 | try {
|
||
431 | 45540 | jjdelcerro | return this.getFloat(index); |
432 | 45581 | fdiaz | } catch (Throwable th) { |
433 | 44331 | jjdelcerro | return defaultValue;
|
434 | } |
||
435 | } |
||
436 | |||
437 | @Override
|
||
438 | public double getDoubleOrDefault(String name, double defaultValue) { |
||
439 | int index = this.data.getType().getIndex(name); |
||
440 | 45581 | fdiaz | if (index < 0) { |
441 | 44331 | jjdelcerro | return defaultValue;
|
442 | } |
||
443 | try {
|
||
444 | 45540 | jjdelcerro | return this.getDouble(index); |
445 | 45581 | fdiaz | } catch (Throwable th) { |
446 | 44331 | jjdelcerro | return defaultValue;
|
447 | } |
||
448 | } |
||
449 | |||
450 | @Override
|
||
451 | 44669 | jjdelcerro | public BigDecimal getDecimalOrDefault(String name, BigDecimal defaultValue) { |
452 | int index = this.data.getType().getIndex(name); |
||
453 | 45581 | fdiaz | if (index < 0) { |
454 | 44669 | jjdelcerro | return defaultValue;
|
455 | } |
||
456 | try {
|
||
457 | 45540 | jjdelcerro | return this.getDecimal(index); |
458 | 45581 | fdiaz | } catch (Throwable th) { |
459 | 44669 | jjdelcerro | return defaultValue;
|
460 | } |
||
461 | } |
||
462 | |||
463 | @Override
|
||
464 | 44331 | jjdelcerro | public Date getDateOrDefault(String name, Date defaultValue) { |
465 | int index = this.data.getType().getIndex(name); |
||
466 | 45581 | fdiaz | if (index < 0) { |
467 | 44331 | jjdelcerro | return defaultValue;
|
468 | } |
||
469 | try {
|
||
470 | 45540 | jjdelcerro | return this.getDate(index); |
471 | 45581 | fdiaz | } catch (Throwable th) { |
472 | 44331 | jjdelcerro | return defaultValue;
|
473 | } |
||
474 | } |
||
475 | |||
476 | @Override
|
||
477 | public Object getOrDefault(int index, Object defaultValue) { |
||
478 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
479 | 44331 | jjdelcerro | return defaultValue;
|
480 | } |
||
481 | try {
|
||
482 | return this.get(index); |
||
483 | 45581 | fdiaz | } catch (Throwable th) { |
484 | 44331 | jjdelcerro | return defaultValue;
|
485 | } |
||
486 | } |
||
487 | |||
488 | @Override
|
||
489 | public String getStringOrDefault(int index, String defaultValue) { |
||
490 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
491 | 44331 | jjdelcerro | return defaultValue;
|
492 | } |
||
493 | try {
|
||
494 | 45540 | jjdelcerro | return this.getString(index); |
495 | 45581 | fdiaz | } catch (Throwable th) { |
496 | 44331 | jjdelcerro | return defaultValue;
|
497 | } |
||
498 | } |
||
499 | |||
500 | @Override
|
||
501 | 45540 | jjdelcerro | public boolean getBooleanOrDefault(int index, boolean defaultValue) { |
502 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
503 | 45540 | jjdelcerro | return defaultValue;
|
504 | } |
||
505 | try {
|
||
506 | return this.getBoolean(index); |
||
507 | 45581 | fdiaz | } catch (Throwable th) { |
508 | 45540 | jjdelcerro | return defaultValue;
|
509 | } |
||
510 | } |
||
511 | |||
512 | @Override
|
||
513 | 44331 | jjdelcerro | public int getIntOrDefault(int index, int defaultValue) { |
514 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
515 | 44331 | jjdelcerro | return defaultValue;
|
516 | } |
||
517 | try {
|
||
518 | 45540 | jjdelcerro | return this.getInt(index); |
519 | 45581 | fdiaz | } catch (Throwable th) { |
520 | 44331 | jjdelcerro | return defaultValue;
|
521 | } |
||
522 | } |
||
523 | |||
524 | @Override
|
||
525 | public long getLongOrDefault(int index, long defaultValue) { |
||
526 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
527 | 44331 | jjdelcerro | return defaultValue;
|
528 | } |
||
529 | try {
|
||
530 | 45540 | jjdelcerro | return this.getLong(index); |
531 | 45581 | fdiaz | } catch (Throwable th) { |
532 | 44331 | jjdelcerro | return defaultValue;
|
533 | } |
||
534 | } |
||
535 | |||
536 | @Override
|
||
537 | public float getFloatOrDefault(int index, float defaultValue) { |
||
538 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
539 | 44331 | jjdelcerro | return defaultValue;
|
540 | } |
||
541 | try {
|
||
542 | 45540 | jjdelcerro | return this.getFloat(index); |
543 | 45581 | fdiaz | } catch (Throwable th) { |
544 | 44331 | jjdelcerro | return defaultValue;
|
545 | } |
||
546 | } |
||
547 | |||
548 | @Override
|
||
549 | public double getDoubleOrDefault(int index, double defaultValue) { |
||
550 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
551 | 44331 | jjdelcerro | return defaultValue;
|
552 | } |
||
553 | try {
|
||
554 | 45540 | jjdelcerro | return this.getDouble(index); |
555 | 45581 | fdiaz | } catch (Throwable th) { |
556 | 44331 | jjdelcerro | return defaultValue;
|
557 | } |
||
558 | } |
||
559 | |||
560 | @Override
|
||
561 | 44669 | jjdelcerro | public BigDecimal getDecimalOrDefault(int index, BigDecimal defaultValue) { |
562 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
563 | 44669 | jjdelcerro | return defaultValue;
|
564 | } |
||
565 | try {
|
||
566 | 45540 | jjdelcerro | return this.getDecimal(index); |
567 | 45581 | fdiaz | } catch (Throwable th) { |
568 | 44669 | jjdelcerro | return defaultValue;
|
569 | } |
||
570 | } |
||
571 | |||
572 | @Override
|
||
573 | 44331 | jjdelcerro | public Date getDateOrDefault(int index, Date defaultValue) { |
574 | 45581 | fdiaz | if (index < 0 || index >= this.data.getType().size()) { |
575 | 44331 | jjdelcerro | return defaultValue;
|
576 | } |
||
577 | try {
|
||
578 | 45540 | jjdelcerro | return this.getDate(index); |
579 | 45581 | fdiaz | } catch (Throwable th) { |
580 | 44331 | jjdelcerro | return defaultValue;
|
581 | } |
||
582 | } |
||
583 | |||
584 | 40435 | jjdelcerro | class UnableToGetReferenceException extends BaseRuntimeException { |
585 | |||
586 | /**
|
||
587 | 43729 | fdiaz | *
|
588 | 40435 | jjdelcerro | */
|
589 | private static final long serialVersionUID = 1812805035204824163L; |
||
590 | |||
591 | /**
|
||
592 | * @param exception
|
||
593 | */
|
||
594 | 44799 | jjdelcerro | @SuppressWarnings("OverridableMethodCallInConstructor") |
595 | 40435 | jjdelcerro | public UnableToGetReferenceException(BaseException exception) {
|
596 | super("Unable to get reference", "_UnableToGetReferenceException", |
||
597 | 45581 | fdiaz | serialVersionUID); |
598 | 40435 | jjdelcerro | this.initCause(exception);
|
599 | 43729 | fdiaz | |
600 | 40435 | jjdelcerro | } |
601 | 43729 | fdiaz | |
602 | 40435 | jjdelcerro | } |
603 | 43729 | fdiaz | |
604 | 44297 | jjdelcerro | @Override
|
605 | 45581 | fdiaz | public void validate(int mode) throws DataException { |
606 | 40435 | jjdelcerro | ((DefaultFeatureType) this.data.getType()).validateFeature(this, mode); |
607 | } |
||
608 | |||
609 | 44297 | jjdelcerro | @Override
|
610 | 40435 | jjdelcerro | public List getSRSs() { |
611 | // TODO Auto-generated method stub
|
||
612 | return null; |
||
613 | } |
||
614 | |||
615 | 44297 | jjdelcerro | @Override
|
616 | 40435 | jjdelcerro | public Envelope getDefaultEnvelope() {
|
617 | 41342 | jjdelcerro | Envelope envelope = this.data.getDefaultEnvelope();
|
618 | 45581 | fdiaz | if (envelope == null) { |
619 | 44618 | jjdelcerro | int i = this.data.getType().getDefaultGeometryAttributeIndex(); |
620 | 45581 | fdiaz | if (i < 0) { |
621 | 44618 | jjdelcerro | return null; |
622 | } |
||
623 | 41342 | jjdelcerro | Geometry geom = this.getDefaultGeometry();
|
624 | 45581 | fdiaz | if (geom != null) { |
625 | 41348 | jjdelcerro | envelope = geom.getEnvelope(); |
626 | } |
||
627 | 41342 | jjdelcerro | } |
628 | return envelope;
|
||
629 | 40435 | jjdelcerro | } |
630 | |||
631 | 44022 | jjdelcerro | @Override
|
632 | 40435 | jjdelcerro | public Geometry getDefaultGeometry() {
|
633 | 45581 | fdiaz | Geometry geom = this.data.getDefaultGeometry();
|
634 | if (geom == null) { |
||
635 | 44022 | jjdelcerro | int i = this.data.getType().getDefaultGeometryAttributeIndex(); |
636 | 45581 | fdiaz | if (i < 0) { |
637 | 44618 | jjdelcerro | return null; |
638 | } |
||
639 | 44022 | jjdelcerro | Object x = this.get(i); |
640 | 45581 | fdiaz | if (x instanceof Geometry) { |
641 | 44022 | jjdelcerro | geom = (Geometry) x; |
642 | } else {
|
||
643 | geom = this.getGeometry(i);
|
||
644 | } |
||
645 | 43420 | jjdelcerro | } |
646 | 45581 | fdiaz | if (geom != null) { |
647 | if (geom.getProjection() == null) { |
||
648 | 44022 | jjdelcerro | FeatureType type = this.getType();
|
649 | DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex()); |
||
650 | IProjection proj = attrdesc.getSRS(this.storeRef);
|
||
651 | geom.setProjection(proj); |
||
652 | } |
||
653 | } |
||
654 | return geom;
|
||
655 | 40435 | jjdelcerro | } |
656 | |||
657 | 44767 | jjdelcerro | // @Override
|
658 | // public Time getDefaultTime() {
|
||
659 | // Time time = this.data.getDefaultTime();
|
||
660 | // if( time == null ) {
|
||
661 | // int i = this.data.getType().getDefaultTimeAttributeIndex();
|
||
662 | // Object x = this.get(i);
|
||
663 | // if( x instanceof Time ) {
|
||
664 | // time = (Time) x;
|
||
665 | // } else {
|
||
666 | // time = this.getTime(i);
|
||
667 | // }
|
||
668 | // }
|
||
669 | // return time;
|
||
670 | // }
|
||
671 | //
|
||
672 | 44086 | jjdelcerro | @Override
|
673 | 40435 | jjdelcerro | public IProjection getDefaultSRS() {
|
674 | 44022 | jjdelcerro | IProjection srs = this.data.getType().getDefaultSRS();
|
675 | 45581 | fdiaz | if (srs == null) { |
676 | 44022 | jjdelcerro | FeatureType type = this.getType();
|
677 | DefaultFeatureAttributeDescriptor attrdesc = (DefaultFeatureAttributeDescriptor) type.get(type.getDefaultGeometryAttributeIndex()); |
||
678 | srs = attrdesc.getSRS(this.storeRef);
|
||
679 | } |
||
680 | return srs;
|
||
681 | 40435 | jjdelcerro | } |
682 | |||
683 | 44297 | jjdelcerro | @Override
|
684 | 40435 | jjdelcerro | public List getGeometries() { |
685 | // TODO Auto-generated method stub
|
||
686 | return null; |
||
687 | } |
||
688 | |||
689 | 44128 | jjdelcerro | @Override
|
690 | public Object getFromProfile(int index) { |
||
691 | FeatureAttributeDescriptor descriptor = this.data.getType().getAttributeDescriptor(index);
|
||
692 | Object value = this.get(index); |
||
693 | String profileName = descriptor.getDataProfileName();
|
||
694 | 45581 | fdiaz | if (StringUtils.isBlank(profileName)) {
|
695 | 44128 | jjdelcerro | return value;
|
696 | } |
||
697 | DataProfile profile = DALLocator.getDataManager().getDataProfile(profileName); |
||
698 | 45581 | fdiaz | if (profile == null) { |
699 | 44128 | jjdelcerro | return value;
|
700 | } |
||
701 | 44253 | jjdelcerro | return profile.createData(value, descriptor.getTags());
|
702 | 44128 | jjdelcerro | } |
703 | |||
704 | @Override
|
||
705 | public Object getFromProfile(String name) { |
||
706 | FeatureAttributeDescriptor descriptor = this.data.getType().getAttributeDescriptor(name);
|
||
707 | return this.getFromProfile(descriptor.getIndex()); |
||
708 | } |
||
709 | |||
710 | 44297 | jjdelcerro | @Override
|
711 | 40435 | jjdelcerro | public Object get(String name) { |
712 | int index = this.data.getType().getIndex(name); |
||
713 | 45581 | fdiaz | if (index < 0) { |
714 | 45155 | omartinez | // buscamos en los extra cols
|
715 | 45581 | fdiaz | if (hasExtraColumnValue(name)) {
|
716 | 45155 | omartinez | return getExtraColumnValue(name);
|
717 | } |
||
718 | if (hasExtraValue(name)) {
|
||
719 | return getExtraValue(name);
|
||
720 | } |
||
721 | // y si esta ahi return
|
||
722 | 45581 | fdiaz | throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature."); |
723 | 40435 | jjdelcerro | } |
724 | return this.get(index); |
||
725 | } |
||
726 | 45581 | fdiaz | |
727 | 44669 | jjdelcerro | @Override
|
728 | public boolean isNull(int index) { |
||
729 | FeatureType type = this.data.getType();
|
||
730 | 45581 | fdiaz | if (index < 0 || index >= type.size()) { |
731 | throw new IllegalArgumentException("Attribute index '" + index + "' out of range (0 to " + this.data.getType().size() + "."); |
||
732 | 44669 | jjdelcerro | } |
733 | FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index); |
||
734 | if (!this.data.getType().hasEvaluators()) { |
||
735 | 45581 | fdiaz | return this.data.get(index) == null; |
736 | 44669 | jjdelcerro | } |
737 | Evaluator eval = attribute.getEvaluator(); |
||
738 | if (eval == null) { |
||
739 | 45581 | fdiaz | return this.data.get(index) == null; |
740 | 44669 | jjdelcerro | } |
741 | Object value = this.data.get(index); |
||
742 | if (value != null) { |
||
743 | return true; |
||
744 | } |
||
745 | try {
|
||
746 | value = eval.evaluate(this);
|
||
747 | } catch (EvaluatorException e) {
|
||
748 | throw new DataEvaluatorRuntimeException(e); |
||
749 | } |
||
750 | this.data.set(index, value);
|
||
751 | 45581 | fdiaz | return value == null; |
752 | 44669 | jjdelcerro | } |
753 | 45581 | fdiaz | |
754 | 44669 | jjdelcerro | @Override
|
755 | public boolean isNull(String name) { |
||
756 | int index = this.data.getType().getIndex(name); |
||
757 | 45581 | fdiaz | if (index < 0) { |
758 | throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature."); |
||
759 | 44669 | jjdelcerro | } |
760 | return this.isNull(index); |
||
761 | } |
||
762 | 43729 | fdiaz | |
763 | 43550 | jjdelcerro | public boolean has_key(String key) { |
764 | Object x = this.getType().get(key); |
||
765 | return x != null; |
||
766 | } |
||
767 | 43729 | fdiaz | |
768 | 43550 | jjdelcerro | public List<String> keys() { |
769 | List<String> ks = new ArrayList<>(); |
||
770 | 45581 | fdiaz | for (FeatureAttributeDescriptor attr : this.getType()) { |
771 | 43550 | jjdelcerro | ks.add(attr.getName()); |
772 | } |
||
773 | return ks;
|
||
774 | } |
||
775 | 43729 | fdiaz | |
776 | 43550 | jjdelcerro | public Iterator<String> iterkeys() { |
777 | final Iterator it = this.getType().iterator(); |
||
778 | return new Iterator<String>() { |
||
779 | @Override
|
||
780 | public boolean hasNext() { |
||
781 | return it.hasNext();
|
||
782 | } |
||
783 | 40435 | jjdelcerro | |
784 | 43550 | jjdelcerro | @Override
|
785 | public String next() { |
||
786 | 45581 | fdiaz | return ((FeatureAttributeDescriptor) it.next()).getName();
|
787 | 43550 | jjdelcerro | } |
788 | 43561 | jjdelcerro | |
789 | @Override
|
||
790 | public void remove() { |
||
791 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
792 | } |
||
793 | 43550 | jjdelcerro | }; |
794 | } |
||
795 | 40435 | jjdelcerro | |
796 | 43550 | jjdelcerro | public Iterator iteritems() { |
797 | final Iterator it = this.getType().iterator(); |
||
798 | return new Iterator<Map.Entry>() { |
||
799 | @Override
|
||
800 | public boolean hasNext() { |
||
801 | return it.hasNext();
|
||
802 | } |
||
803 | |||
804 | @Override
|
||
805 | public Map.Entry next() { |
||
806 | 45581 | fdiaz | final String name = ((FeatureAttributeDescriptor) it.next()).getName(); |
807 | 43550 | jjdelcerro | return new Map.Entry<String, Object>() { |
808 | @Override
|
||
809 | public String getKey() { |
||
810 | return name;
|
||
811 | } |
||
812 | |||
813 | @Override
|
||
814 | public Object getValue() { |
||
815 | return get(name);
|
||
816 | } |
||
817 | |||
818 | @Override
|
||
819 | public Object setValue(Object value) { |
||
820 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
821 | } |
||
822 | 43729 | fdiaz | |
823 | 43550 | jjdelcerro | }; |
824 | } |
||
825 | 43561 | jjdelcerro | |
826 | @Override
|
||
827 | public void remove() { |
||
828 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
||
829 | } |
||
830 | 43729 | fdiaz | }; |
831 | 43550 | jjdelcerro | } |
832 | |||
833 | @Override
|
||
834 | 40435 | jjdelcerro | public Object get(int index) { |
835 | FeatureType type = this.data.getType();
|
||
836 | 45581 | fdiaz | if (index < 0 || index >= type.size()) { |
837 | throw new IllegalArgumentException("Attribute index '" + index + "' out of range (0 to " + this.data.getType().size() + "."); |
||
838 | 40435 | jjdelcerro | } |
839 | 44840 | jjdelcerro | Object value = this.data.get(index); |
840 | 40435 | jjdelcerro | FeatureAttributeDescriptor attribute = type.getAttributeDescriptor(index); |
841 | 44840 | jjdelcerro | if (type.hasEvaluators()) {
|
842 | 45581 | fdiaz | Evaluator eval = attribute.getEvaluator(); |
843 | if (eval != null) { |
||
844 | if (value == null) { // Ya hemos calculado el campo ? |
||
845 | // FIXME: para comprobar si esta calculado usar un array especifico.
|
||
846 | try {
|
||
847 | value = eval.evaluate(this);
|
||
848 | } catch (EvaluatorException e) {
|
||
849 | throw new DataEvaluatorRuntimeException(e); |
||
850 | } |
||
851 | this.data.set(index, value);
|
||
852 | } |
||
853 | } |
||
854 | 43729 | fdiaz | } |
855 | 44840 | jjdelcerro | value = get(attribute, value); |
856 | 45581 | fdiaz | return value;
|
857 | 40435 | jjdelcerro | } |
858 | |||
859 | 45581 | fdiaz | private Object get(FeatureAttributeDescriptor featureAttributeDescriptor, Object value) { |
860 | 41335 | jjdelcerro | FeatureAttributeEmulator emulator = featureAttributeDescriptor.getFeatureAttributeEmulator(); |
861 | 45581 | fdiaz | if (emulator != null) { |
862 | 44226 | jjdelcerro | // int index = featureAttributeDescriptor.getIndex();
|
863 | // value = this.data.get(index);
|
||
864 | // if( value==null ) {
|
||
865 | 45581 | fdiaz | value = emulator.get(this);
|
866 | 44226 | jjdelcerro | // this.data.set(index,value);
|
867 | // }
|
||
868 | 44022 | jjdelcerro | } else {
|
869 | FeatureAttributeGetter getter = featureAttributeDescriptor.getFeatureAttributeGetter(); |
||
870 | 45581 | fdiaz | if (getter != null) { |
871 | 44022 | jjdelcerro | value = getter.getter(value); |
872 | } |
||
873 | 40435 | jjdelcerro | } |
874 | 44951 | omartinez | DataType dataType = featureAttributeDescriptor.getDataType(); |
875 | 45047 | jjdelcerro | Class<? extends DataType> theClass = dataType.getDefaultClass(); |
876 | 45581 | fdiaz | if (theClass != null && !theClass.isInstance(value)) { |
877 | 44951 | omartinez | try {
|
878 | value = this.getDataTypesManager().coerce(dataType.getType(), value);
|
||
879 | } catch (CoercionException e) {
|
||
880 | 45581 | fdiaz | throw new IllegalArgumentException( |
881 | "Can't convert to " + theClass.getSimpleName()
|
||
882 | + " from '" + value.getClass().getSimpleName()
|
||
883 | + "' with value '" + value.toString() + "'."); |
||
884 | 44951 | omartinez | } |
885 | } |
||
886 | 45581 | fdiaz | if (featureAttributeDescriptor.getType() == DataTypes.GEOMETRY) {
|
887 | if (value != null) { |
||
888 | Geometry geom = (Geometry) value; |
||
889 | if (geom.getProjection() == null) { |
||
890 | IProjection proj = ((DefaultFeatureAttributeDescriptor) featureAttributeDescriptor).getSRS(this.storeRef);
|
||
891 | 44022 | jjdelcerro | geom.setProjection(proj); |
892 | } |
||
893 | } |
||
894 | 41335 | jjdelcerro | } |
895 | return value;
|
||
896 | 40435 | jjdelcerro | } |
897 | |||
898 | 44297 | jjdelcerro | @Override
|
899 | public byte[] getByteArray(String name) { |
||
900 | return this.getByteArray(this.data.getType().getIndex(name)); |
||
901 | } |
||
902 | |||
903 | @Override
|
||
904 | public byte[] getByteArray(int index) { |
||
905 | return (byte[]) this.get(index); |
||
906 | } |
||
907 | |||
908 | @Override
|
||
909 | 40435 | jjdelcerro | public Object[] getArray(String name) { |
910 | return this.getArray(this.data.getType().getIndex(name)); |
||
911 | } |
||
912 | |||
913 | 44297 | jjdelcerro | @Override
|
914 | 40435 | jjdelcerro | public Object[] getArray(int index) { |
915 | return (Object[]) this.get(index); |
||
916 | } |
||
917 | |||
918 | 44297 | jjdelcerro | @Override
|
919 | 40435 | jjdelcerro | public boolean getBoolean(String name) { |
920 | return this.getBoolean(this.data.getType().getIndex(name)); |
||
921 | } |
||
922 | |||
923 | 44297 | jjdelcerro | @Override
|
924 | 40435 | jjdelcerro | public boolean getBoolean(int index) { |
925 | 45581 | fdiaz | Boolean value = ((Boolean) this.get(index, Boolean.class, DataTypes.BOOLEAN)); |
926 | 40435 | jjdelcerro | if (value == null) { |
927 | return false; |
||
928 | } |
||
929 | 44297 | jjdelcerro | return value;
|
930 | 40435 | jjdelcerro | } |
931 | |||
932 | 44297 | jjdelcerro | @Override
|
933 | 40435 | jjdelcerro | public byte getByte(String name) { |
934 | return this.getByte(this.data.getType().getIndex(name)); |
||
935 | } |
||
936 | |||
937 | 44297 | jjdelcerro | @Override
|
938 | 40435 | jjdelcerro | public byte getByte(int index) { |
939 | 45581 | fdiaz | Byte value = ((Byte) this.get(index, Byte.class, DataTypes.BYTE)); |
940 | 40435 | jjdelcerro | if (value == null) { |
941 | return 0; |
||
942 | } |
||
943 | 44297 | jjdelcerro | return value;
|
944 | 40435 | jjdelcerro | } |
945 | |||
946 | 44297 | jjdelcerro | @Override
|
947 | 45425 | jjdelcerro | public java.sql.Date getDate(String name) { |
948 | 40435 | jjdelcerro | return this.getDate(this.data.getType().getIndex(name)); |
949 | } |
||
950 | |||
951 | 44297 | jjdelcerro | @Override
|
952 | 45425 | jjdelcerro | public java.sql.Date getDate(int index) { |
953 | 45581 | fdiaz | java.sql.Date value = ((java.sql.Date) this.get(index, java.sql.Date.class, DataTypes.DATE));
|
954 | 44767 | jjdelcerro | return value;
|
955 | } |
||
956 | 40435 | jjdelcerro | |
957 | 44767 | jjdelcerro | @Override
|
958 | 45425 | jjdelcerro | public java.sql.Time getTime(String name) { |
959 | 44767 | jjdelcerro | return this.getTime(this.data.getType().getIndex(name)); |
960 | } |
||
961 | |||
962 | @Override
|
||
963 | 45425 | jjdelcerro | public java.sql.Time getTime(int index) { |
964 | 45581 | fdiaz | java.sql.Time value = ((java.sql.Time) this.get(index, java.sql.Time.class, DataTypes.TIME));
|
965 | 40435 | jjdelcerro | return value;
|
966 | } |
||
967 | |||
968 | 44297 | jjdelcerro | @Override
|
969 | 45425 | jjdelcerro | public java.sql.Timestamp getTimestamp(String name) { |
970 | 44767 | jjdelcerro | return this.getTimestamp(this.data.getType().getIndex(name)); |
971 | } |
||
972 | |||
973 | @Override
|
||
974 | 45425 | jjdelcerro | public java.sql.Timestamp getTimestamp(int index) { |
975 | 45581 | fdiaz | java.sql.Timestamp value = ((java.sql.Timestamp) this.get(index, java.sql.Timestamp.class, DataTypes.TIMESTAMP));
|
976 | 44767 | jjdelcerro | return value;
|
977 | } |
||
978 | |||
979 | @Override
|
||
980 | 40435 | jjdelcerro | public double getDouble(String name) { |
981 | return this.getDouble(this.data.getType().getIndex(name)); |
||
982 | } |
||
983 | |||
984 | 44297 | jjdelcerro | @Override
|
985 | 40435 | jjdelcerro | public double getDouble(int index) { |
986 | 43729 | fdiaz | |
987 | 45581 | fdiaz | Double value = ((Double) this.get(index, Double.class, DataTypes.DOUBLE)); |
988 | 40435 | jjdelcerro | if (value == null) { |
989 | return 0; |
||
990 | } |
||
991 | 44297 | jjdelcerro | return value;
|
992 | 40435 | jjdelcerro | } |
993 | |||
994 | 44297 | jjdelcerro | @Override
|
995 | 44669 | jjdelcerro | public BigDecimal getDecimal(String name) { |
996 | return this.getDecimal(this.data.getType().getIndex(name)); |
||
997 | } |
||
998 | |||
999 | @Override
|
||
1000 | public BigDecimal getDecimal(int index) { |
||
1001 | 45581 | fdiaz | BigDecimal value = ((BigDecimal) this.get(index, BigDecimal.class, DataTypes.DECIMAL)); |
1002 | 44669 | jjdelcerro | return value;
|
1003 | } |
||
1004 | |||
1005 | @Override
|
||
1006 | 40435 | jjdelcerro | public Feature getFeature(String name) { |
1007 | return this.getFeature(this.data.getType().getIndex(name)); |
||
1008 | } |
||
1009 | |||
1010 | 44297 | jjdelcerro | @Override
|
1011 | 40435 | jjdelcerro | public Feature getFeature(int index) { |
1012 | return (Feature) this.get(index); |
||
1013 | } |
||
1014 | |||
1015 | 44297 | jjdelcerro | @Override
|
1016 | 40435 | jjdelcerro | public float getFloat(String name) { |
1017 | return this.getFloat(this.data.getType().getIndex(name)); |
||
1018 | } |
||
1019 | |||
1020 | 44297 | jjdelcerro | @Override
|
1021 | 40435 | jjdelcerro | public float getFloat(int index) { |
1022 | 45581 | fdiaz | Float value = ((Float) this.get(index, Float.class, DataTypes.FLOAT)); |
1023 | 40435 | jjdelcerro | if (value == null) { |
1024 | return 0; |
||
1025 | } |
||
1026 | 44297 | jjdelcerro | return value;
|
1027 | 40435 | jjdelcerro | } |
1028 | |||
1029 | 44297 | jjdelcerro | @Override
|
1030 | 40435 | jjdelcerro | public Geometry getGeometry(String name) { |
1031 | return this.getGeometry(this.data.getType().getIndex(name)); |
||
1032 | } |
||
1033 | |||
1034 | 44297 | jjdelcerro | @Override
|
1035 | 40435 | jjdelcerro | public Geometry getGeometry(int index) { |
1036 | 45581 | fdiaz | return (Geometry) this.get(index, Geometry.class, DataTypes.GEOMETRY); |
1037 | 40435 | jjdelcerro | } |
1038 | |||
1039 | 44297 | jjdelcerro | @Override
|
1040 | 40435 | jjdelcerro | public int getInt(String name) { |
1041 | return this.getInt(this.data.getType().getIndex(name)); |
||
1042 | } |
||
1043 | |||
1044 | 44297 | jjdelcerro | @Override
|
1045 | 40435 | jjdelcerro | public int getInt(int index) { |
1046 | 45581 | fdiaz | Integer value = ((Integer) this.get(index, Integer.class, DataTypes.INT)); |
1047 | 40435 | jjdelcerro | if (value == null) { |
1048 | return 0; |
||
1049 | } |
||
1050 | 44297 | jjdelcerro | return value;
|
1051 | 40435 | jjdelcerro | } |
1052 | |||
1053 | 44297 | jjdelcerro | @Override
|
1054 | 40435 | jjdelcerro | public long getLong(String name) { |
1055 | return this.getLong(this.data.getType().getIndex(name)); |
||
1056 | } |
||
1057 | |||
1058 | 44297 | jjdelcerro | @Override
|
1059 | 40435 | jjdelcerro | public long getLong(int index) { |
1060 | 45581 | fdiaz | Long value = ((Long) this.get(index, Long.class, DataTypes.LONG)); |
1061 | 40435 | jjdelcerro | if (value == null) { |
1062 | return 0; |
||
1063 | } |
||
1064 | 44297 | jjdelcerro | return value;
|
1065 | 40435 | jjdelcerro | } |
1066 | |||
1067 | 44297 | jjdelcerro | @Override
|
1068 | 40435 | jjdelcerro | public String getString(String name) { |
1069 | return this.getString(this.data.getType().getIndex(name)); |
||
1070 | } |
||
1071 | |||
1072 | 44297 | jjdelcerro | @Override
|
1073 | 40435 | jjdelcerro | public String getString(int index) { |
1074 | 45581 | fdiaz | return (String) this.get(index, String.class, DataTypes.STRING); |
1075 | 40435 | jjdelcerro | } |
1076 | |||
1077 | 44297 | jjdelcerro | @Override
|
1078 | 40435 | jjdelcerro | public Object getContextValue(String name) { |
1079 | name = name.toLowerCase(); |
||
1080 | if (name.equals("store")) { |
||
1081 | return this.getStore(); |
||
1082 | } |
||
1083 | |||
1084 | if (name.equals("featuretype")) { |
||
1085 | return this.data.getType(); |
||
1086 | } |
||
1087 | |||
1088 | if (name.equals("feature")) { |
||
1089 | return this; |
||
1090 | } |
||
1091 | |||
1092 | throw new IllegalArgumentException(name); |
||
1093 | } |
||
1094 | |||
1095 | 44297 | jjdelcerro | @Override
|
1096 | 40435 | jjdelcerro | public Iterator getDataNames() { |
1097 | class DataNamesIterator implements Iterator { |
||
1098 | 45581 | fdiaz | |
1099 | 40435 | jjdelcerro | Iterator attributeIteraror;
|
1100 | |||
1101 | DataNamesIterator(DefaultFeature feature) { |
||
1102 | this.attributeIteraror = feature.getType().iterator();
|
||
1103 | } |
||
1104 | |||
1105 | 44297 | jjdelcerro | @Override
|
1106 | 40435 | jjdelcerro | public boolean hasNext() { |
1107 | return this.attributeIteraror.hasNext(); |
||
1108 | } |
||
1109 | |||
1110 | 44297 | jjdelcerro | @Override
|
1111 | 40435 | jjdelcerro | public Object next() { |
1112 | return ((FeatureAttributeDescriptor) this.attributeIteraror |
||
1113 | .next()).getName(); |
||
1114 | } |
||
1115 | |||
1116 | 44297 | jjdelcerro | @Override
|
1117 | 40435 | jjdelcerro | public void remove() { |
1118 | throw new UnsupportedOperationException(); |
||
1119 | } |
||
1120 | |||
1121 | } |
||
1122 | return new DataNamesIterator(this); |
||
1123 | } |
||
1124 | |||
1125 | 44297 | jjdelcerro | @Override
|
1126 | 40435 | jjdelcerro | public Object getDataValue(String name) { |
1127 | name = name.toLowerCase(); |
||
1128 | 41542 | jjdelcerro | try {
|
1129 | return get(name);
|
||
1130 | } catch (IllegalArgumentException ex) { |
||
1131 | 45581 | fdiaz | if ("defaultgeometry".equalsIgnoreCase(name)) { |
1132 | 41542 | jjdelcerro | return this.getDefaultGeometry(); |
1133 | } |
||
1134 | throw ex;
|
||
1135 | } |
||
1136 | 40435 | jjdelcerro | } |
1137 | |||
1138 | 44297 | jjdelcerro | @Override
|
1139 | 40435 | jjdelcerro | public Iterator getDataValues() { |
1140 | class DataValuesIterator implements Iterator { |
||
1141 | 45581 | fdiaz | |
1142 | 40435 | jjdelcerro | DefaultFeature feature; |
1143 | int current = 0; |
||
1144 | |||
1145 | DataValuesIterator(DefaultFeature feature) { |
||
1146 | this.feature = feature;
|
||
1147 | } |
||
1148 | |||
1149 | 44297 | jjdelcerro | @Override
|
1150 | 40435 | jjdelcerro | public boolean hasNext() { |
1151 | return current < feature.getType().size() - 1; |
||
1152 | } |
||
1153 | |||
1154 | 44297 | jjdelcerro | @Override
|
1155 | 40435 | jjdelcerro | public Object next() { |
1156 | return feature.get(current++);
|
||
1157 | } |
||
1158 | |||
1159 | 44297 | jjdelcerro | @Override
|
1160 | 40435 | jjdelcerro | public void remove() { |
1161 | throw new UnsupportedOperationException(); |
||
1162 | } |
||
1163 | |||
1164 | } |
||
1165 | return new DataValuesIterator(this); |
||
1166 | } |
||
1167 | |||
1168 | 44297 | jjdelcerro | @Override
|
1169 | 40435 | jjdelcerro | public boolean hasContextValue(String name) { |
1170 | name = name.toLowerCase(); |
||
1171 | if (name.equals("store")) { |
||
1172 | return true; |
||
1173 | } |
||
1174 | |||
1175 | if (name.equals("featuretype")) { |
||
1176 | return true; |
||
1177 | } |
||
1178 | |||
1179 | 44297 | jjdelcerro | return name.equals("feature"); |
1180 | 40435 | jjdelcerro | } |
1181 | |||
1182 | 44297 | jjdelcerro | @Override
|
1183 | 40435 | jjdelcerro | public boolean hasDataValue(String name) { |
1184 | 45218 | omartinez | return this.hasValue(name); |
1185 | 40435 | jjdelcerro | } |
1186 | 43729 | fdiaz | |
1187 | 44767 | jjdelcerro | // @Override
|
1188 | // public Time getTime(int index) {
|
||
1189 | // return ((Time) this.get(index,Time.class,DataTypes.INSTANT));
|
||
1190 | // }
|
||
1191 | //
|
||
1192 | // @Override
|
||
1193 | // public Time getTime(String name) {
|
||
1194 | // return this.getInstant(this.data.getType().getIndex(name));
|
||
1195 | // }
|
||
1196 | //
|
||
1197 | // @Override
|
||
1198 | // public Instant getInstant(int index) {
|
||
1199 | // return ((Instant) this.get(index,Instant.class,DataTypes.INSTANT));
|
||
1200 | // }
|
||
1201 | //
|
||
1202 | // @Override
|
||
1203 | // public Instant getInstant(String name) {
|
||
1204 | // return this.getInstant(this.data.getType().getIndex(name));
|
||
1205 | // }
|
||
1206 | //
|
||
1207 | // @Override
|
||
1208 | // public Interval getInterval(int index) {
|
||
1209 | // return ((Interval) this.get(index,Interval.class,DataTypes.INTERVAL));
|
||
1210 | // }
|
||
1211 | //
|
||
1212 | // @Override
|
||
1213 | // public Interval getInterval(String name) {
|
||
1214 | // return this.getInterval(this.data.getType().getIndex(name));
|
||
1215 | // }
|
||
1216 | //
|
||
1217 | 44297 | jjdelcerro | @Override
|
1218 | 40435 | jjdelcerro | public DynObject getAsDynObject() {
|
1219 | 42775 | jjdelcerro | DynObjectFeatureFacade facade = new DynObjectFeatureFacade(this); |
1220 | 40435 | jjdelcerro | return facade;
|
1221 | } |
||
1222 | |||
1223 | 44297 | jjdelcerro | @Override
|
1224 | 40435 | jjdelcerro | public String toString() { |
1225 | 45581 | fdiaz | StringBuilder builder = new StringBuilder(); |
1226 | FeatureAttributeDescriptor[] attributeDescriptors
|
||
1227 | = getType().getAttributeDescriptors(); |
||
1228 | 40435 | jjdelcerro | for (int i = 0; i < attributeDescriptors.length; i++) { |
1229 | String name = attributeDescriptors[i].getName();
|
||
1230 | 44607 | jjdelcerro | Object value = get(name);
|
1231 | builder.append(value); |
||
1232 | 40435 | jjdelcerro | if (i < attributeDescriptors.length - 1) { |
1233 | 44297 | jjdelcerro | builder.append(", ");
|
1234 | 40435 | jjdelcerro | } |
1235 | } |
||
1236 | 44297 | jjdelcerro | return builder.toString();
|
1237 | 40435 | jjdelcerro | } |
1238 | 40867 | jbadia | |
1239 | 45581 | fdiaz | /**
|
1240 | 40435 | jjdelcerro | * @return the inserted
|
1241 | */
|
||
1242 | public boolean isInserted() { |
||
1243 | return inserted;
|
||
1244 | } |
||
1245 | |||
1246 | /**
|
||
1247 | * @param inserted the inserted to set
|
||
1248 | */
|
||
1249 | public void setInserted(boolean inserted) { |
||
1250 | this.inserted = inserted;
|
||
1251 | 45640 | jjdelcerro | // this.data.setNew(!inserted);
|
1252 | 40435 | jjdelcerro | } |
1253 | |||
1254 | 45581 | fdiaz | @Override
|
1255 | 40435 | jjdelcerro | public EvaluatorData getEvaluatorData() {
|
1256 | return this; |
||
1257 | } |
||
1258 | 43983 | jjdelcerro | |
1259 | 45013 | jjdelcerro | @Override
|
1260 | 43983 | jjdelcerro | public int size() { |
1261 | return this.data.getType().size(); |
||
1262 | } |
||
1263 | 45581 | fdiaz | |
1264 | 43983 | jjdelcerro | public boolean isEmpty() { |
1265 | return false; |
||
1266 | } |
||
1267 | |||
1268 | public Iterator<String> iterator() { |
||
1269 | final Iterator<FeatureAttributeDescriptor> x = this.data.getType().iterator(); |
||
1270 | return new Iterator<String>() { |
||
1271 | @Override
|
||
1272 | public boolean hasNext() { |
||
1273 | return x.hasNext();
|
||
1274 | } |
||
1275 | |||
1276 | @Override
|
||
1277 | public String next() { |
||
1278 | return x.next().getName();
|
||
1279 | } |
||
1280 | }; |
||
1281 | } |
||
1282 | 45581 | fdiaz | |
1283 | 43983 | jjdelcerro | public boolean containsKey(String key) { |
1284 | 45581 | fdiaz | return this.data.getType().get(key) != null; |
1285 | 43983 | jjdelcerro | } |
1286 | 44346 | jjdelcerro | |
1287 | @Override
|
||
1288 | public String getLabelOfValue(String name) { |
||
1289 | FeatureAttributeDescriptor attrdesc = this.data.getType().getAttributeDescriptor(name);
|
||
1290 | 45581 | fdiaz | if (attrdesc == null) { |
1291 | throw new IllegalArgumentException("Attribute name '" + name + "' not found in the feature."); |
||
1292 | 44346 | jjdelcerro | } |
1293 | Object value = this.get(attrdesc.getIndex()); |
||
1294 | String label = attrdesc.getLabelOfValue(value);
|
||
1295 | return label;
|
||
1296 | } |
||
1297 | 45581 | fdiaz | |
1298 | 44858 | jjdelcerro | @Override
|
1299 | public void setExtraValue(String name, Object value) { |
||
1300 | 45581 | fdiaz | if (this.extraValues == null) { |
1301 | this.extraValues = new HashMap<>(); |
||
1302 | } |
||
1303 | this.extraValues.put(name, value);
|
||
1304 | 44858 | jjdelcerro | } |
1305 | 45581 | fdiaz | |
1306 | 45155 | omartinez | public Object getExtraColumnValue(String name) { |
1307 | 44779 | omartinez | Object value;
|
1308 | 45162 | omartinez | if (this.extraValues != null) { |
1309 | if (this.extraValues.containsKey(name)) { |
||
1310 | return this.extraValues.get(name); |
||
1311 | } |
||
1312 | 44858 | jjdelcerro | } |
1313 | 44829 | omartinez | FeatureExtraColumns columns = this.getType().getExtraColumns();
|
1314 | 44779 | omartinez | int index = columns.getIndexOf(name);
|
1315 | 45162 | omartinez | if (index < 0) { |
1316 | throw new RuntimeException("Not extra column value found"); |
||
1317 | } |
||
1318 | if (extraValuesData == null) { |
||
1319 | 44779 | omartinez | extraValuesData = new Object[columns.size()]; |
1320 | 45162 | omartinez | } |
1321 | EditableFeatureAttributeDescriptor attrdesc = columns.get(index); |
||
1322 | value = extraValuesData[index]; |
||
1323 | 45581 | fdiaz | if (value != null) { |
1324 | 45162 | omartinez | return value;
|
1325 | } |
||
1326 | value = this.getExtraValue(name);
|
||
1327 | extraValuesData[index] = value; |
||
1328 | if (value == null && !this.hasExtraValue(name)) { |
||
1329 | 45581 | fdiaz | if (attrdesc.getFeatureAttributeEmulator() != null) { |
1330 | 45218 | omartinez | value = attrdesc.getFeatureAttributeEmulator().get(this);
|
1331 | extraValuesData[index] = value; |
||
1332 | } |
||
1333 | 44778 | omartinez | } |
1334 | 45162 | omartinez | return value;
|
1335 | 45155 | omartinez | } |
1336 | |||
1337 | @Override
|
||
1338 | public Object getExtraValue(String name) { |
||
1339 | Object value = this.data.getExtraValue(name); |
||
1340 | 44773 | jjdelcerro | return value;
|
1341 | 44376 | jjdelcerro | } |
1342 | 45581 | fdiaz | |
1343 | 44773 | jjdelcerro | @Override
|
1344 | 44738 | jjdelcerro | public boolean hasExtraValue(String name) { |
1345 | 45155 | omartinez | return this.data.hasExtraValue(name); |
1346 | } |
||
1347 | |||
1348 | private boolean hasExtraColumnValue(String name) { |
||
1349 | 45581 | fdiaz | if (this.extraValues != null) { |
1350 | if (this.extraValues.containsKey(name)) { |
||
1351 | return true; |
||
1352 | } |
||
1353 | 44858 | jjdelcerro | } |
1354 | 44829 | omartinez | FeatureExtraColumns columns = this.getType().getExtraColumns();
|
1355 | 44779 | omartinez | int index = columns.getIndexOf(name);
|
1356 | 45581 | fdiaz | if (index >= 0) { |
1357 | return true; |
||
1358 | 44779 | omartinez | } |
1359 | 45155 | omartinez | return false; |
1360 | 44738 | jjdelcerro | } |
1361 | 45581 | fdiaz | |
1362 | 44376 | jjdelcerro | @Override
|
1363 | 45218 | omartinez | public boolean hasValue(String name) { |
1364 | name = name.toLowerCase(); |
||
1365 | 45581 | fdiaz | return this.data.getType().getIndex(name) >= 0 |
1366 | || hasExtraValue(name) |
||
1367 | || hasExtraColumnValue(name); |
||
1368 | 45218 | omartinez | } |
1369 | 45581 | fdiaz | |
1370 | 45218 | omartinez | @Override
|
1371 | 44376 | jjdelcerro | public Object getExtraValue(int index) { |
1372 | return this.data.getExtraValue(index); |
||
1373 | } |
||
1374 | |||
1375 | 45425 | jjdelcerro | @Override
|
1376 | public JsonObject toJson() {
|
||
1377 | JsonObjectBuilder builder = this.toJsonBuilder();
|
||
1378 | return builder.build();
|
||
1379 | } |
||
1380 | 45581 | fdiaz | |
1381 | 45425 | jjdelcerro | @Override
|
1382 | public JsonObjectBuilder toJsonBuilder() {
|
||
1383 | 44655 | jjdelcerro | JsonObjectBuilder builder = Json.createObjectBuilder(); |
1384 | 45425 | jjdelcerro | Date date;
|
1385 | Geometry geom; |
||
1386 | 44655 | jjdelcerro | FeatureType ft = this.getType();
|
1387 | for (FeatureAttributeDescriptor desc : ft) {
|
||
1388 | if (desc.isComputed()) {
|
||
1389 | continue;
|
||
1390 | } |
||
1391 | 45581 | fdiaz | switch (desc.getType()) {
|
1392 | 44655 | jjdelcerro | case DataTypes.GEOMETRY:
|
1393 | 45425 | jjdelcerro | geom = this.getGeometry(desc.getIndex());
|
1394 | 45581 | fdiaz | if (geom != null) { |
1395 | 45425 | jjdelcerro | builder.add(desc.getName(), geom.convertToHexWKBQuietly()); |
1396 | 44655 | jjdelcerro | } |
1397 | break;
|
||
1398 | case DataTypes.BOOLEAN:
|
||
1399 | builder.add(desc.getName(), this.getBoolean(desc.getIndex()));
|
||
1400 | break;
|
||
1401 | case DataTypes.BYTE:
|
||
1402 | builder.add(desc.getName(), this.getByte(desc.getIndex()));
|
||
1403 | break;
|
||
1404 | case DataTypes.INT:
|
||
1405 | builder.add(desc.getName(), this.getInt(desc.getIndex()));
|
||
1406 | break;
|
||
1407 | case DataTypes.LONG:
|
||
1408 | builder.add(desc.getName(), this.getLong(desc.getIndex()));
|
||
1409 | break;
|
||
1410 | case DataTypes.DOUBLE:
|
||
1411 | builder.add(desc.getName(), this.getDouble(desc.getIndex()));
|
||
1412 | break;
|
||
1413 | case DataTypes.FLOAT:
|
||
1414 | builder.add(desc.getName(), this.getFloat(desc.getIndex()));
|
||
1415 | break;
|
||
1416 | case DataTypes.DATE:
|
||
1417 | // Format date as ISO 8601
|
||
1418 | 45425 | jjdelcerro | date = this.getDate(desc.getIndex());
|
1419 | 45581 | fdiaz | if (date == null) { |
1420 | 45003 | jjdelcerro | builder.addNull(desc.getName()); |
1421 | } else {
|
||
1422 | 45023 | fdiaz | LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()); |
1423 | 45425 | jjdelcerro | String value = DateTimeFormatter.ISO_DATE.format(localDateTime);
|
1424 | builder.add(desc.getName(), value); |
||
1425 | } |
||
1426 | break;
|
||
1427 | case DataTypes.TIMESTAMP:
|
||
1428 | // Format date as ISO 8601
|
||
1429 | date = this.getTimestamp(desc.getIndex());
|
||
1430 | 45581 | fdiaz | if (date == null) { |
1431 | 45425 | jjdelcerro | builder.addNull(desc.getName()); |
1432 | } else {
|
||
1433 | LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()); |
||
1434 | 45023 | fdiaz | String value = DateTimeFormatter.ISO_DATE_TIME.format(localDateTime);
|
1435 | 45003 | jjdelcerro | builder.add(desc.getName(), value); |
1436 | } |
||
1437 | 44655 | jjdelcerro | break;
|
1438 | 45425 | jjdelcerro | case DataTypes.TIME:
|
1439 | // Format date as ISO 8601
|
||
1440 | date = this.getTime(desc.getIndex());
|
||
1441 | 45581 | fdiaz | if (date == null) { |
1442 | 45425 | jjdelcerro | builder.addNull(desc.getName()); |
1443 | } else {
|
||
1444 | LocalDateTime localDateTime = LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()); |
||
1445 | String value = DateTimeFormatter.ISO_TIME.format(localDateTime);
|
||
1446 | builder.add(desc.getName(), value); |
||
1447 | } |
||
1448 | break;
|
||
1449 | 44655 | jjdelcerro | default:
|
1450 | 45581 | fdiaz | builder.add(desc.getName(), this.getStringOrDefault(desc.getIndex(), "")); |
1451 | 44655 | jjdelcerro | } |
1452 | 45581 | fdiaz | } |
1453 | 45425 | jjdelcerro | return builder;
|
1454 | 44655 | jjdelcerro | } |
1455 | 44376 | jjdelcerro | |
1456 | 44923 | jjdelcerro | @Override
|
1457 | public List<String> getKeys() { |
||
1458 | 45581 | fdiaz | List<String> l = new ArrayList<>(); |
1459 | for (FeatureAttributeDescriptor descriptor : this.getType()) { |
||
1460 | l.add(descriptor.getName()); |
||
1461 | } |
||
1462 | return l;
|
||
1463 | 44923 | jjdelcerro | } |
1464 | |||
1465 | 40435 | jjdelcerro | } |