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 / DefaultEditableFeature.java @ 45636
History | View | Annotate | Download (19.2 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 | 41805 | jjdelcerro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 40559 | jjdelcerro | * 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 | 41805 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
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 | 45425 | jjdelcerro | import java.time.LocalDate; |
28 | 44655 | jjdelcerro | import java.time.LocalDateTime; |
29 | 45425 | jjdelcerro | import java.time.LocalTime; |
30 | 44655 | jjdelcerro | import java.time.ZoneOffset; |
31 | import java.time.format.DateTimeFormatter; |
||
32 | import java.time.temporal.TemporalAccessor; |
||
33 | 40435 | jjdelcerro | import java.util.Date; |
34 | 45039 | fdiaz | import java.util.Set; |
35 | 45102 | omartinez | import java.util.function.Predicate; |
36 | 44655 | jjdelcerro | import javax.json.JsonNumber; |
37 | import javax.json.JsonObject; |
||
38 | 45425 | jjdelcerro | import javax.json.JsonString; |
39 | import javax.json.JsonValue; |
||
40 | 44655 | jjdelcerro | import org.gvsig.fmap.dal.DataTypes; |
41 | 40435 | jjdelcerro | |
42 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
43 | 44779 | omartinez | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
44 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.Feature; |
45 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
46 | 44815 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
47 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
48 | import org.gvsig.fmap.geom.Geometry; |
||
49 | 44655 | jjdelcerro | import org.gvsig.fmap.geom.GeometryUtils; |
50 | 40435 | jjdelcerro | import org.gvsig.timesupport.Instant; |
51 | import org.gvsig.timesupport.Interval; |
||
52 | 44829 | omartinez | import org.gvsig.fmap.dal.feature.FeatureExtraColumns; |
53 | 45039 | fdiaz | import org.gvsig.fmap.geom.type.GeometryType; |
54 | import org.slf4j.Logger; |
||
55 | import org.slf4j.LoggerFactory; |
||
56 | 40435 | jjdelcerro | |
57 | public class DefaultEditableFeature extends DefaultFeature implements |
||
58 | 41805 | jjdelcerro | EditableFeature { |
59 | 40435 | jjdelcerro | |
60 | 45039 | fdiaz | private static final Logger LOG = LoggerFactory.getLogger(DefaultEditableFeature.class); |
61 | |||
62 | 41805 | jjdelcerro | private DefaultFeature source;
|
63 | 45599 | fdiaz | // private boolean inserted;
|
64 | 40435 | jjdelcerro | |
65 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultFeature feature) {
|
66 | super(feature);
|
||
67 | this.source = feature;
|
||
68 | 45599 | fdiaz | // this.inserted = this.source!=null;
|
69 | 41805 | jjdelcerro | } |
70 | 40435 | jjdelcerro | |
71 | 41805 | jjdelcerro | protected DefaultEditableFeature(DefaultEditableFeature feature) {
|
72 | super(feature);
|
||
73 | this.source = (DefaultFeature) feature.getSource();
|
||
74 | 45599 | fdiaz | // this.inserted = this.source!=null;
|
75 | 41805 | jjdelcerro | } |
76 | 40435 | jjdelcerro | |
77 | 41805 | jjdelcerro | public DefaultEditableFeature(DefaultFeatureStore store, FeatureProvider data) {
|
78 | // Se trata de un editable feature sobre una ya existente
|
||
79 | super(store, data);
|
||
80 | this.source = null; |
||
81 | 45599 | fdiaz | // this.inserted = this.source!=null;
|
82 | 41805 | jjdelcerro | } |
83 | 40435 | jjdelcerro | |
84 | 44829 | omartinez | @Override
|
85 | 41805 | jjdelcerro | public Feature getSource() {
|
86 | return this.source; |
||
87 | } |
||
88 | 40435 | jjdelcerro | |
89 | 44829 | omartinez | @Override
|
90 | 45425 | jjdelcerro | public boolean isUpdatable() { |
91 | 45599 | fdiaz | return super.isInserted(); |
92 | 45425 | jjdelcerro | } |
93 | |||
94 | @Override
|
||
95 | public void setUpdatable(boolean updatable) { |
||
96 | 45599 | fdiaz | super.setInserted(updatable);
|
97 | 45425 | jjdelcerro | } |
98 | |||
99 | @Override
|
||
100 | 41805 | jjdelcerro | public EditableFeature getEditable() {
|
101 | return this; |
||
102 | } |
||
103 | 40435 | jjdelcerro | |
104 | 44829 | omartinez | @Override
|
105 | 41805 | jjdelcerro | public Feature getCopy() {
|
106 | return new DefaultEditableFeature(this); |
||
107 | } |
||
108 | 40435 | jjdelcerro | |
109 | 44829 | omartinez | @Override
|
110 | 41805 | jjdelcerro | public Feature getNotEditableCopy() {
|
111 | return new DefaultFeature(this); |
||
112 | } |
||
113 | 40435 | jjdelcerro | |
114 | 44829 | omartinez | @Override
|
115 | 41805 | jjdelcerro | public void setDefaultGeometry(Geometry geometry) { |
116 | FeatureAttributeDescriptor attribute = this.getType()
|
||
117 | .getAttributeDescriptor( |
||
118 | this.getType().getDefaultGeometryAttributeIndex());
|
||
119 | this.set(attribute, geometry);
|
||
120 | } |
||
121 | 40435 | jjdelcerro | |
122 | 44390 | jjdelcerro | public void __setitem__(String name, Object value) { |
123 | this.set(name, value);
|
||
124 | } |
||
125 | |||
126 | @Override
|
||
127 | 41805 | jjdelcerro | public void set(String name, Object value) { |
128 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
129 | if ( attribute == null ) { |
||
130 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
131 | } |
||
132 | this.set(attribute, value);
|
||
133 | } |
||
134 | 40435 | jjdelcerro | |
135 | 44829 | omartinez | @Override
|
136 | 41805 | jjdelcerro | public void set(int index, Object value) { |
137 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
138 | this.set(attribute, value);
|
||
139 | } |
||
140 | 40435 | jjdelcerro | |
141 | 44829 | omartinez | @Override
|
142 | 41805 | jjdelcerro | public void setArray(String name, Object[] value) { |
143 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
144 | if ( attribute == null ) { |
||
145 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
146 | } |
||
147 | this.set(attribute, value);
|
||
148 | } |
||
149 | 40435 | jjdelcerro | |
150 | 44829 | omartinez | @Override
|
151 | 41805 | jjdelcerro | public void setArray(int index, Object[] value) { |
152 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
153 | this.set(attribute, value);
|
||
154 | } |
||
155 | 40435 | jjdelcerro | |
156 | 44829 | omartinez | @Override
|
157 | 41805 | jjdelcerro | public void setBoolean(String name, boolean value) { |
158 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
159 | if ( attribute == null ) { |
||
160 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
161 | } |
||
162 | this.set(attribute, Boolean.valueOf(value)); |
||
163 | } |
||
164 | 40435 | jjdelcerro | |
165 | 44829 | omartinez | @Override
|
166 | 41805 | jjdelcerro | public void setBoolean(int index, boolean value) { |
167 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
168 | 45039 | fdiaz | this.set(attribute, value);
|
169 | 41805 | jjdelcerro | } |
170 | 40435 | jjdelcerro | |
171 | 44829 | omartinez | @Override
|
172 | 41805 | jjdelcerro | public void setByte(String name, byte value) { |
173 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
174 | if ( attribute == null ) { |
||
175 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
176 | } |
||
177 | 45039 | fdiaz | this.set(attribute, value);
|
178 | 41805 | jjdelcerro | } |
179 | 40435 | jjdelcerro | |
180 | 44829 | omartinez | @Override
|
181 | 41805 | jjdelcerro | public void setByte(int index, byte value) { |
182 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
183 | 45039 | fdiaz | this.set(attribute, value);
|
184 | 41805 | jjdelcerro | } |
185 | 40435 | jjdelcerro | |
186 | 44829 | omartinez | @Override
|
187 | 41805 | jjdelcerro | public void setDate(String name, Date value) { |
188 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
189 | if ( attribute == null ) { |
||
190 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
191 | } |
||
192 | this.set(attribute, value);
|
||
193 | } |
||
194 | 40435 | jjdelcerro | |
195 | 44829 | omartinez | @Override
|
196 | 41805 | jjdelcerro | public void setDate(int index, Date value) { |
197 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
198 | this.set(attribute, value);
|
||
199 | } |
||
200 | 40435 | jjdelcerro | |
201 | 44829 | omartinez | @Override
|
202 | 41805 | jjdelcerro | public void setDouble(String name, double value) { |
203 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
204 | if ( attribute == null ) { |
||
205 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
206 | } |
||
207 | 45039 | fdiaz | this.set(attribute, value);
|
208 | 41805 | jjdelcerro | } |
209 | 40435 | jjdelcerro | |
210 | 44829 | omartinez | @Override
|
211 | 41805 | jjdelcerro | public void setDouble(int index, double value) { |
212 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
213 | 45039 | fdiaz | this.set(attribute, value);
|
214 | 41805 | jjdelcerro | } |
215 | 40435 | jjdelcerro | |
216 | 44669 | jjdelcerro | @Override
|
217 | public void setDecimal(String name, BigDecimal value) { |
||
218 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
219 | if ( attribute == null ) { |
||
220 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
221 | } |
||
222 | this.set(attribute, value);
|
||
223 | } |
||
224 | |||
225 | 44829 | omartinez | @Override
|
226 | 44669 | jjdelcerro | public void setDecimal(int index, BigDecimal value) { |
227 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
228 | this.set(attribute, value);
|
||
229 | } |
||
230 | |||
231 | 44829 | omartinez | @Override
|
232 | 41805 | jjdelcerro | public void setFeature(String name, Feature value) { |
233 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
234 | if ( attribute == null ) { |
||
235 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
236 | } |
||
237 | this.set(attribute, value);
|
||
238 | } |
||
239 | 40435 | jjdelcerro | |
240 | 44829 | omartinez | @Override
|
241 | 41805 | jjdelcerro | public void setFeature(int index, Feature value) { |
242 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
243 | this.set(attribute, value);
|
||
244 | } |
||
245 | 40435 | jjdelcerro | |
246 | 44829 | omartinez | @Override
|
247 | 41805 | jjdelcerro | public void setFloat(String name, float value) { |
248 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
249 | if ( attribute == null ) { |
||
250 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
251 | } |
||
252 | 45039 | fdiaz | this.set(attribute, value);
|
253 | 41805 | jjdelcerro | } |
254 | 40435 | jjdelcerro | |
255 | 44829 | omartinez | @Override
|
256 | 41805 | jjdelcerro | public void setFloat(int index, float value) { |
257 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
258 | 45039 | fdiaz | this.set(attribute, value);
|
259 | 41805 | jjdelcerro | } |
260 | 40435 | jjdelcerro | |
261 | 44829 | omartinez | @Override
|
262 | 41805 | jjdelcerro | public void setGeometry(String name, Geometry value) { |
263 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
264 | if ( attribute == null ) { |
||
265 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
266 | } |
||
267 | this.set(attribute, value);
|
||
268 | } |
||
269 | 40435 | jjdelcerro | |
270 | 44829 | omartinez | @Override
|
271 | 41805 | jjdelcerro | public void setGeometry(int index, Geometry value) { |
272 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
273 | this.set(attribute, value);
|
||
274 | } |
||
275 | 40435 | jjdelcerro | |
276 | 44829 | omartinez | @Override
|
277 | 41805 | jjdelcerro | public void setInt(String name, int value) { |
278 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
279 | if ( attribute == null ) { |
||
280 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
281 | } |
||
282 | 45039 | fdiaz | this.set(attribute, value);
|
283 | 41805 | jjdelcerro | } |
284 | 40435 | jjdelcerro | |
285 | 44829 | omartinez | @Override
|
286 | 41805 | jjdelcerro | public void setInt(int index, int value) { |
287 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
288 | 45039 | fdiaz | this.set(attribute, value);
|
289 | 41805 | jjdelcerro | } |
290 | 40435 | jjdelcerro | |
291 | 44829 | omartinez | @Override
|
292 | 41805 | jjdelcerro | public void setLong(String name, long value) { |
293 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
294 | if ( attribute == null ) { |
||
295 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
296 | } |
||
297 | 45039 | fdiaz | this.set(attribute, value);
|
298 | 41805 | jjdelcerro | } |
299 | 40435 | jjdelcerro | |
300 | 44829 | omartinez | @Override
|
301 | 41805 | jjdelcerro | public void setLong(int index, long value) { |
302 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
303 | 45039 | fdiaz | this.set(attribute, value);
|
304 | 41805 | jjdelcerro | } |
305 | 40435 | jjdelcerro | |
306 | 44829 | omartinez | @Override
|
307 | 41805 | jjdelcerro | public void setString(String name, String value) { |
308 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
309 | if ( attribute == null ) { |
||
310 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
311 | } |
||
312 | this.set(attribute, value);
|
||
313 | } |
||
314 | 40435 | jjdelcerro | |
315 | 44829 | omartinez | @Override
|
316 | 41805 | jjdelcerro | public void setString(int index, String value) { |
317 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
318 | this.set(attribute, value);
|
||
319 | } |
||
320 | 40435 | jjdelcerro | |
321 | 44829 | omartinez | @Override
|
322 | 44655 | jjdelcerro | public void copyFrom(JsonObject values) { |
323 | 45102 | omartinez | this.copyFrom(values, null); |
324 | } |
||
325 | |||
326 | @Override
|
||
327 | public void copyFrom(JsonObject values, Predicate<FeatureAttributeDescriptor> filter) { |
||
328 | // iterate over the attributes and copy one by one
|
||
329 | 44655 | jjdelcerro | for (FeatureAttributeDescriptor attr : this.getType()) { |
330 | 45102 | omartinez | if( filter!=null && !filter.test(attr) ) { |
331 | continue;
|
||
332 | } |
||
333 | 44655 | jjdelcerro | if (attr==null || attr.isAutomatic() || attr.isReadOnly() || attr.isComputed() ) { |
334 | continue;
|
||
335 | } |
||
336 | String attrname = attr.getName();
|
||
337 | if( !values.containsKey(attrname) ) {
|
||
338 | continue;
|
||
339 | } |
||
340 | Object value;
|
||
341 | 45425 | jjdelcerro | JsonValue jsonValue = values.get(attrname); |
342 | 44655 | jjdelcerro | try {
|
343 | 45425 | jjdelcerro | switch( jsonValue.getValueType() ) {
|
344 | 44655 | jjdelcerro | case STRING:
|
345 | 45425 | jjdelcerro | String s = ((JsonString)jsonValue).getString();
|
346 | 44655 | jjdelcerro | switch(attr.getType()) {
|
347 | case DataTypes.GEOMETRY:
|
||
348 | 45425 | jjdelcerro | value = GeometryUtils.createFrom(s); |
349 | 44655 | jjdelcerro | break;
|
350 | 45425 | jjdelcerro | case DataTypes.TIMESTAMP:
|
351 | 44655 | jjdelcerro | try {
|
352 | 45425 | jjdelcerro | TemporalAccessor x = DateTimeFormatter.ISO_DATE_TIME.parse(s); |
353 | 44655 | jjdelcerro | LocalDateTime date = LocalDateTime.from(x); |
354 | 45425 | jjdelcerro | value = java.sql.Timestamp.valueOf(date); |
355 | 44655 | jjdelcerro | } catch(Exception ex) { |
356 | 45425 | jjdelcerro | value = s; |
357 | 44655 | jjdelcerro | } |
358 | break;
|
||
359 | 45425 | jjdelcerro | case DataTypes.DATE:
|
360 | try {
|
||
361 | TemporalAccessor x = DateTimeFormatter.ISO_DATE.parse(s); |
||
362 | LocalDate date = LocalDate.from(x); |
||
363 | value = java.sql.Date.valueOf(date); |
||
364 | } catch(Exception ex) { |
||
365 | value = s; |
||
366 | } |
||
367 | break;
|
||
368 | case DataTypes.TIME:
|
||
369 | try {
|
||
370 | TemporalAccessor x = DateTimeFormatter.ISO_TIME.parse(s); |
||
371 | LocalTime date = LocalTime.from(x); |
||
372 | value = java.sql.Time.valueOf(date); |
||
373 | } catch(Exception ex) { |
||
374 | value = s; |
||
375 | } |
||
376 | break;
|
||
377 | 44655 | jjdelcerro | case DataTypes.STRING:
|
378 | default:
|
||
379 | 45425 | jjdelcerro | value = s; |
380 | 44655 | jjdelcerro | break;
|
381 | } |
||
382 | break;
|
||
383 | case NUMBER:
|
||
384 | 45425 | jjdelcerro | JsonNumber n = (JsonNumber) jsonValue; |
385 | 44655 | jjdelcerro | switch(attr.getType()) {
|
386 | 45425 | jjdelcerro | case DataTypes.DECIMAL:
|
387 | 44655 | jjdelcerro | value = n.bigDecimalValue(); |
388 | break;
|
||
389 | case DataTypes.BYTE:
|
||
390 | value = n.bigDecimalValue(); |
||
391 | break;
|
||
392 | case DataTypes.FLOAT:
|
||
393 | case DataTypes.DOUBLE:
|
||
394 | value = n.doubleValue(); |
||
395 | break;
|
||
396 | case DataTypes.INT:
|
||
397 | value = n.intValue(); |
||
398 | break;
|
||
399 | case DataTypes.LONG:
|
||
400 | value = n.longValue(); |
||
401 | break;
|
||
402 | default:
|
||
403 | value = n.toString(); |
||
404 | break;
|
||
405 | } |
||
406 | break;
|
||
407 | case TRUE:
|
||
408 | value = true;
|
||
409 | break;
|
||
410 | case FALSE:
|
||
411 | value = false;
|
||
412 | break;
|
||
413 | case NULL:
|
||
414 | value = null;
|
||
415 | break;
|
||
416 | default:
|
||
417 | value = values.getString(attrname); |
||
418 | break;
|
||
419 | } |
||
420 | } catch(Exception ex) { |
||
421 | continue;
|
||
422 | } |
||
423 | if (value == null && !attr.allowNull()) { |
||
424 | continue;
|
||
425 | } |
||
426 | try {
|
||
427 | set(attr.getIndex(), value); |
||
428 | } catch(Throwable th) { |
||
429 | // Ignore
|
||
430 | } |
||
431 | } |
||
432 | 45039 | fdiaz | if (this.getType().getDefaultGeometryAttribute()!=null && this.getDefaultGeometry()==null) { |
433 | GeometryType geomType = this.getType().getDefaultGeometryAttribute().getGeomType();
|
||
434 | Set<String> keys = values.keySet(); |
||
435 | for (String key : keys) { |
||
436 | try {
|
||
437 | String wkt = values.getString(key);
|
||
438 | Geometry geometry = GeometryUtils.createFrom(wkt); |
||
439 | if (GeometryUtils.isSubtype(geomType.getType(), geometry.getType()) || GeometryUtils.canAggregate(geomType.getType(), geometry.getType())) {
|
||
440 | this.setDefaultGeometry(geometry);
|
||
441 | break;
|
||
442 | } |
||
443 | } catch (Throwable tr) { |
||
444 | LOG.trace("Can't get geometry from field {}.", new Object[]{key}); |
||
445 | }; |
||
446 | } |
||
447 | } |
||
448 | 44655 | jjdelcerro | } |
449 | |||
450 | 44829 | omartinez | @Override
|
451 | 41805 | jjdelcerro | public void copyFrom(Feature source) { |
452 | 45102 | omartinez | this.copyFrom(source, null); |
453 | } |
||
454 | |||
455 | @Override
|
||
456 | public void copyFrom(Feature source, Predicate<FeatureAttributeDescriptor> filter) { |
||
457 | 44815 | jjdelcerro | // iterate over the attributes and copy one by one
|
458 | FeatureType sourceType = source.getType(); |
||
459 | 44610 | jjdelcerro | for (FeatureAttributeDescriptor attr : this.getType()) { |
460 | 45102 | omartinez | if( filter!=null && !filter.test(attr) ) { |
461 | continue;
|
||
462 | } |
||
463 | 44610 | jjdelcerro | if (attr==null || attr.isAutomatic() || attr.isReadOnly() || attr.isComputed() ) { |
464 | continue;
|
||
465 | 43562 | jjdelcerro | } |
466 | 44815 | jjdelcerro | String attrname = attr.getName();
|
467 | if( sourceType.getAttributeDescriptor(attrname)==null ) { |
||
468 | continue;
|
||
469 | } |
||
470 | Object value = source.get(attrname);
|
||
471 | 44610 | jjdelcerro | if (value == null && !attr.allowNull()) { |
472 | continue;
|
||
473 | } |
||
474 | try {
|
||
475 | set(attr.getIndex(), value); |
||
476 | } catch(Throwable th) { |
||
477 | 45039 | fdiaz | LOG.trace("The exception thrown is: ", th);
|
478 | 44610 | jjdelcerro | } |
479 | 41805 | jjdelcerro | } |
480 | 45102 | omartinez | |
481 | 41805 | jjdelcerro | } |
482 | 45102 | omartinez | |
483 | 40435 | jjdelcerro | |
484 | 45102 | omartinez | |
485 | 44829 | omartinez | @Override
|
486 | 41805 | jjdelcerro | public void setInstant(String name, Instant value) { |
487 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
488 | if ( attribute == null ) { |
||
489 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
490 | } |
||
491 | this.set(attribute, value);
|
||
492 | } |
||
493 | 40435 | jjdelcerro | |
494 | 44829 | omartinez | @Override
|
495 | 41805 | jjdelcerro | public void setInstant(int index, Instant value) { |
496 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
497 | this.set(attribute, value);
|
||
498 | } |
||
499 | 40435 | jjdelcerro | |
500 | 44829 | omartinez | @Override
|
501 | 41805 | jjdelcerro | public void setInterval(String name, Interval value) { |
502 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
|
||
503 | if ( attribute == null ) { |
||
504 | throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature."); |
||
505 | } |
||
506 | this.set(attribute, value);
|
||
507 | } |
||
508 | 40435 | jjdelcerro | |
509 | 44829 | omartinez | @Override
|
510 | 41805 | jjdelcerro | public void setInterval(int index, Interval value) { |
511 | FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
||
512 | this.set(attribute, value);
|
||
513 | } |
||
514 | 44779 | omartinez | |
515 | @Override
|
||
516 | public Object getExtraValue(String name) { |
||
517 | Object value;
|
||
518 | 44829 | omartinez | FeatureExtraColumns columns = this.getType().getExtraColumns();
|
519 | 44779 | omartinez | int index = columns.getIndexOf(name);
|
520 | if (index >= 0) { |
||
521 | EditableFeatureAttributeDescriptor attrdesc = columns.get(index); |
||
522 | value = attrdesc.getFeatureAttributeEmulator().get(this);
|
||
523 | return value;
|
||
524 | } |
||
525 | value = this.data.getExtraValue(name);
|
||
526 | return value;
|
||
527 | } |
||
528 | 40435 | jjdelcerro | } |