Statistics
| Revision:

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 @ 46078

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