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 |
/**
|
---|---|
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 |
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 |
import org.gvsig.fmap.dal.feature.FeatureType; |
33 |
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 |
EditableFeature { |
40 |
|
41 |
private DefaultFeature source;
|
42 |
|
43 |
protected DefaultEditableFeature(DefaultFeature feature) {
|
44 |
super(feature);
|
45 |
this.source = feature;
|
46 |
} |
47 |
|
48 |
protected DefaultEditableFeature(DefaultEditableFeature feature) {
|
49 |
super(feature);
|
50 |
this.source = (DefaultFeature) feature.getSource();
|
51 |
} |
52 |
|
53 |
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 |
|
59 |
public Feature getSource() {
|
60 |
return this.source; |
61 |
} |
62 |
|
63 |
public EditableFeature getEditable() {
|
64 |
return this; |
65 |
} |
66 |
|
67 |
public Feature getCopy() {
|
68 |
return new DefaultEditableFeature(this); |
69 |
} |
70 |
|
71 |
public Feature getNotEditableCopy() {
|
72 |
return new DefaultFeature(this); |
73 |
} |
74 |
|
75 |
public void setDefaultGeometry(Geometry geometry) { |
76 |
FeatureAttributeDescriptor attribute = this.getType()
|
77 |
.getAttributeDescriptor( |
78 |
this.getType().getDefaultGeometryAttributeIndex());
|
79 |
this.set(attribute, geometry);
|
80 |
} |
81 |
|
82 |
public void __setitem__(String name, Object value) { |
83 |
this.set(name, value);
|
84 |
} |
85 |
|
86 |
@Override
|
87 |
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 |
|
95 |
public void set(int index, Object value) { |
96 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
97 |
this.set(attribute, value);
|
98 |
} |
99 |
|
100 |
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 |
|
108 |
public void setArray(int index, Object[] value) { |
109 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
110 |
this.set(attribute, value);
|
111 |
} |
112 |
|
113 |
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 |
|
121 |
public void setBoolean(int index, boolean value) { |
122 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
123 |
this.set(attribute, Boolean.valueOf(value)); |
124 |
} |
125 |
|
126 |
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 |
|
134 |
public void setByte(int index, byte value) { |
135 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
136 |
this.set(attribute, new Byte(value)); |
137 |
} |
138 |
|
139 |
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 |
|
147 |
public void setDate(int index, Date value) { |
148 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
149 |
this.set(attribute, value);
|
150 |
} |
151 |
|
152 |
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 |
|
160 |
public void setDouble(int index, double value) { |
161 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
162 |
this.set(attribute, new Double(value)); |
163 |
} |
164 |
|
165 |
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 |
|
173 |
public void setFeature(int index, Feature value) { |
174 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
175 |
this.set(attribute, value);
|
176 |
} |
177 |
|
178 |
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 |
|
186 |
public void setFloat(int index, float value) { |
187 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
188 |
this.set(attribute, new Float(value)); |
189 |
} |
190 |
|
191 |
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 |
|
199 |
public void setGeometry(int index, Geometry value) { |
200 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
201 |
this.set(attribute, value);
|
202 |
} |
203 |
|
204 |
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 |
|
212 |
public void setInt(int index, int value) { |
213 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
214 |
this.set(attribute, new Integer(value)); |
215 |
} |
216 |
|
217 |
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 |
|
225 |
public void setLong(int index, long value) { |
226 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
227 |
this.set(attribute, new Long(value)); |
228 |
} |
229 |
|
230 |
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 |
|
238 |
public void setString(int index, String value) { |
239 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
240 |
this.set(attribute, value);
|
241 |
} |
242 |
|
243 |
public void copyFrom(Feature source) { |
244 |
// iterate over the attributes and copy one by one
|
245 |
FeatureType sourceType = source.getType(); |
246 |
for (FeatureAttributeDescriptor attr : this.getType()) { |
247 |
if (attr==null || attr.isAutomatic() || attr.isReadOnly() || attr.isComputed() ) { |
248 |
continue;
|
249 |
} |
250 |
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 |
} |
260 |
} |
261 |
|
262 |
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 |
|
270 |
public void setInstant(int index, Instant value) { |
271 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
272 |
this.set(attribute, value);
|
273 |
} |
274 |
|
275 |
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 |
|
283 |
public void setInterval(int index, Interval value) { |
284 |
FeatureAttributeDescriptor attribute = this.getType().getAttributeDescriptor(index);
|
285 |
this.set(attribute, value);
|
286 |
} |
287 |
} |