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

History | View | Annotate | Download (10.7 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
import java.util.Date;
27
import java.util.Iterator;
28
29
import org.gvsig.fmap.dal.feature.EditableFeature;
30
import org.gvsig.fmap.dal.feature.Feature;
31
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
32 43562 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureType;
33 40435 jjdelcerro
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
34
import org.gvsig.fmap.geom.Geometry;
35
import org.gvsig.timesupport.Instant;
36
import org.gvsig.timesupport.Interval;
37
38
public class DefaultEditableFeature extends DefaultFeature implements
39 41805 jjdelcerro
        EditableFeature {
40 40435 jjdelcerro
41 41805 jjdelcerro
    private DefaultFeature source;
42 40435 jjdelcerro
43 41805 jjdelcerro
    protected DefaultEditableFeature(DefaultFeature feature) {
44
        super(feature);
45
        this.source = feature;
46
    }
47 40435 jjdelcerro
48 41805 jjdelcerro
    protected DefaultEditableFeature(DefaultEditableFeature feature) {
49
        super(feature);
50
        this.source = (DefaultFeature) feature.getSource();
51
    }
52 40435 jjdelcerro
53 41805 jjdelcerro
    public DefaultEditableFeature(DefaultFeatureStore store, FeatureProvider data) {
54
        // Se trata de un editable feature sobre una ya existente
55
        super(store, data);
56
        this.source = null;
57
    }
58 40435 jjdelcerro
59 41805 jjdelcerro
    public Feature getSource() {
60
        return this.source;
61
    }
62 40435 jjdelcerro
63 41805 jjdelcerro
    public EditableFeature getEditable() {
64
        return this;
65
    }
66 40435 jjdelcerro
67 41805 jjdelcerro
    public Feature getCopy() {
68
        return new DefaultEditableFeature(this);
69
    }
70 40435 jjdelcerro
71 41805 jjdelcerro
    public Feature getNotEditableCopy() {
72
        return new DefaultFeature(this);
73
    }
74 40435 jjdelcerro
75 41805 jjdelcerro
    public void setDefaultGeometry(Geometry geometry) {
76
        FeatureAttributeDescriptor attribute = this.getType()
77
                .getAttributeDescriptor(
78
                        this.getType().getDefaultGeometryAttributeIndex());
79
        this.set(attribute, geometry);
80
    }
81 40435 jjdelcerro
82 44390 jjdelcerro
    public void __setitem__(String name, Object value) {
83
        this.set(name, value);
84
    }
85
86
    @Override
87 41805 jjdelcerro
    public void set(String name, Object value) {
88
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
89
        if ( attribute == null ) {
90
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
91
        }
92
        this.set(attribute, value);
93
    }
94 40435 jjdelcerro
95 41805 jjdelcerro
    public void set(int index, Object value) {
96
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
97
        this.set(attribute, value);
98
    }
99 40435 jjdelcerro
100 41805 jjdelcerro
    public void setArray(String name, Object[] value) {
101
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
102
        if ( attribute == null ) {
103
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
104
        }
105
        this.set(attribute, value);
106
    }
107 40435 jjdelcerro
108 41805 jjdelcerro
    public void setArray(int index, Object[] value) {
109
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
110
        this.set(attribute, value);
111
    }
112 40435 jjdelcerro
113 41805 jjdelcerro
    public void setBoolean(String name, boolean value) {
114
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
115
        if ( attribute == null ) {
116
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
117
        }
118
        this.set(attribute, Boolean.valueOf(value));
119
    }
120 40435 jjdelcerro
121 41805 jjdelcerro
    public void setBoolean(int index, boolean value) {
122
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
123
        this.set(attribute, Boolean.valueOf(value));
124
    }
125 40435 jjdelcerro
126 41805 jjdelcerro
    public void setByte(String name, byte value) {
127
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
128
        if ( attribute == null ) {
129
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
130
        }
131
        this.set(attribute, new Byte(value));
132
    }
133 40435 jjdelcerro
134 41805 jjdelcerro
    public void setByte(int index, byte value) {
135
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
136
        this.set(attribute, new Byte(value));
137
    }
138 40435 jjdelcerro
139 41805 jjdelcerro
    public void setDate(String name, Date value) {
140
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
141
        if ( attribute == null ) {
142
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
143
        }
144
        this.set(attribute, value);
145
    }
146 40435 jjdelcerro
147 41805 jjdelcerro
    public void setDate(int index, Date value) {
148
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
149
        this.set(attribute, value);
150
    }
151 40435 jjdelcerro
152 41805 jjdelcerro
    public void setDouble(String name, double value) {
153
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
154
        if ( attribute == null ) {
155
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
156
        }
157
        this.set(attribute, new Double(value));
158
    }
159 40435 jjdelcerro
160 41805 jjdelcerro
    public void setDouble(int index, double value) {
161
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
162
        this.set(attribute, new Double(value));
163
    }
164 40435 jjdelcerro
165 41805 jjdelcerro
    public void setFeature(String name, Feature value) {
166
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
167
        if ( attribute == null ) {
168
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
169
        }
170
        this.set(attribute, value);
171
    }
172 40435 jjdelcerro
173 41805 jjdelcerro
    public void setFeature(int index, Feature value) {
174
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
175
        this.set(attribute, value);
176
    }
177 40435 jjdelcerro
178 41805 jjdelcerro
    public void setFloat(String name, float value) {
179
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
180
        if ( attribute == null ) {
181
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
182
        }
183
        this.set(attribute, new Float(value));
184
    }
185 40435 jjdelcerro
186 41805 jjdelcerro
    public void setFloat(int index, float value) {
187
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
188
        this.set(attribute, new Float(value));
189
    }
190 40435 jjdelcerro
191 41805 jjdelcerro
    public void setGeometry(String name, Geometry value) {
192
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
193
        if ( attribute == null ) {
194
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
195
        }
196
        this.set(attribute, value);
197
    }
198 40435 jjdelcerro
199 41805 jjdelcerro
    public void setGeometry(int index, Geometry value) {
200
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
201
        this.set(attribute, value);
202
    }
203 40435 jjdelcerro
204 41805 jjdelcerro
    public void setInt(String name, int value) {
205
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
206
        if ( attribute == null ) {
207
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
208
        }
209
        this.set(attribute, new Integer(value));
210
    }
211 40435 jjdelcerro
212 41805 jjdelcerro
    public void setInt(int index, int value) {
213
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
214
        this.set(attribute, new Integer(value));
215
    }
216 40435 jjdelcerro
217 41805 jjdelcerro
    public void setLong(String name, long 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, new Long(value));
223
    }
224 40435 jjdelcerro
225 41805 jjdelcerro
    public void setLong(int index, long value) {
226
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
227
        this.set(attribute, new Long(value));
228
    }
229 40435 jjdelcerro
230 41805 jjdelcerro
    public void setString(String name, String value) {
231
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
232
        if ( attribute == null ) {
233
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
234
        }
235
        this.set(attribute, value);
236
    }
237 40435 jjdelcerro
238 41805 jjdelcerro
    public void setString(int index, String value) {
239
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
240
        this.set(attribute, value);
241
    }
242 40435 jjdelcerro
243 41805 jjdelcerro
    public void copyFrom(Feature source) {
244
        // iterate over the attributes and copy one by one
245 43562 jjdelcerro
        FeatureType sourceType = source.getType();
246 44610 jjdelcerro
        for (FeatureAttributeDescriptor attr : this.getType()) {
247
            if (attr==null || attr.isAutomatic() || attr.isReadOnly() || attr.isComputed() ) {
248
                continue;
249 43562 jjdelcerro
            }
250 44610 jjdelcerro
            Object value = source.get(attr.getName());
251
            if (value == null && !attr.allowNull()) {
252
                continue;
253
            }
254
            try {
255
                set(attr.getIndex(), value);
256
            } catch(Throwable th) {
257
                // Ignore
258
            }
259 41805 jjdelcerro
        }
260
    }
261 40435 jjdelcerro
262 41805 jjdelcerro
    public void setInstant(String name, Instant 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 41805 jjdelcerro
    public void setInstant(int index, Instant value) {
271
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
272
        this.set(attribute, value);
273
    }
274 40435 jjdelcerro
275 41805 jjdelcerro
    public void setInterval(String name, Interval value) {
276
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(name);
277
        if ( attribute == null ) {
278
            throw new IllegalArgumentException("Attribute '" + name + "' does not exits in the feature.");
279
        }
280
        this.set(attribute, value);
281
    }
282 40435 jjdelcerro
283 41805 jjdelcerro
    public void setInterval(int index, Interval value) {
284
        FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
285
        this.set(attribute, value);
286
    }
287 40435 jjdelcerro
}