svn-gvsig-desktop / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / Feature.java @ 20412
History | View | Annotate | Download (11.4 KB)
1 |
package org.gvsig.data.vectorial; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Date; |
5 |
import java.util.HashMap; |
6 |
import java.util.Iterator; |
7 |
import java.util.Map; |
8 |
|
9 |
public abstract class Feature extends ArrayList implements IFeature{ |
10 |
protected IFeatureType featureType;
|
11 |
protected Object defaultGeometry; |
12 |
protected Object object; |
13 |
private boolean editing = false; |
14 |
private HashMap originalValues=new HashMap(); |
15 |
private boolean loading = false; |
16 |
|
17 |
public Feature(IFeatureType featureType){
|
18 |
super(featureType.size());
|
19 |
this.featureType=featureType;
|
20 |
for (int i = 0; i < featureType.size(); i++) { |
21 |
add(null);
|
22 |
} |
23 |
} |
24 |
public IFeatureType getType() {
|
25 |
return featureType;
|
26 |
} |
27 |
|
28 |
public Object getDefaultGeometry() { |
29 |
return defaultGeometry;
|
30 |
} |
31 |
|
32 |
public Object get(String name) { |
33 |
int i=featureType.getFieldIndex(name);
|
34 |
return super.get(i); |
35 |
} |
36 |
|
37 |
public int getInt(String name) { |
38 |
int i=featureType.getFieldIndex(name);
|
39 |
Integer value=(Integer)super.get(i); |
40 |
if (value==null) |
41 |
return 0; |
42 |
return value.intValue();
|
43 |
} |
44 |
|
45 |
public boolean getBoolean(String name) { |
46 |
int i=featureType.getFieldIndex(name);
|
47 |
Boolean value=(Boolean)super.get(i); |
48 |
if (value==null) |
49 |
return false; |
50 |
return value.booleanValue();
|
51 |
} |
52 |
|
53 |
public long getLong(String name) { |
54 |
int i=featureType.getFieldIndex(name);
|
55 |
Long value=(Long)super.get(i); |
56 |
if (value==null) |
57 |
return 0L; |
58 |
return value.longValue();
|
59 |
} |
60 |
|
61 |
public float getFloat(String name) { |
62 |
int i=featureType.getFieldIndex(name);
|
63 |
Float value=(Float)super.get(i); |
64 |
if (value==null) |
65 |
return 0F; |
66 |
return value.floatValue();
|
67 |
} |
68 |
|
69 |
public double getDouble(String name) { |
70 |
int i=featureType.getFieldIndex(name);
|
71 |
Double value=(Double)super.get(i); |
72 |
if (value==null) |
73 |
return 0D; |
74 |
return value.doubleValue();
|
75 |
} |
76 |
public String getString(String name) { |
77 |
int i=featureType.getFieldIndex(name);
|
78 |
String value=(String)super.get(i); |
79 |
return value;
|
80 |
} |
81 |
public String getString(int index) { |
82 |
String value=(String)super.get(index); |
83 |
return value;
|
84 |
} |
85 |
public Object get(int index) { |
86 |
return super.get(index); |
87 |
} |
88 |
|
89 |
public IFeature getFeature(int index) { |
90 |
IFeature value=(IFeature)super.get(index);
|
91 |
return value;
|
92 |
} |
93 |
|
94 |
public Object[] getArray(int index) { |
95 |
// TODO Auto-generated method stub
|
96 |
return null; |
97 |
} |
98 |
|
99 |
public int getInt(int index) { |
100 |
Integer value=(Integer)super.get(index); |
101 |
if (value==null) |
102 |
return 0; |
103 |
return value.intValue();
|
104 |
} |
105 |
|
106 |
public boolean getBoolean(int index) { |
107 |
Boolean value=(Boolean)super.get(index); |
108 |
if (value==null) |
109 |
return false; |
110 |
return value.booleanValue();
|
111 |
} |
112 |
|
113 |
public long getLong(int index) { |
114 |
Long value=(Long)super.get(index); |
115 |
if (value==null) |
116 |
return 0L; |
117 |
return value.longValue();
|
118 |
} |
119 |
|
120 |
public float getFloat(int index) { |
121 |
Float value=(Float)super.get(index); |
122 |
if (value==null) |
123 |
return 0F; |
124 |
return value.floatValue();
|
125 |
} |
126 |
|
127 |
public double getDouble(int index) { |
128 |
Double value=(Double)super.get(index); |
129 |
if (value==null) |
130 |
return 0D; |
131 |
return value.doubleValue();
|
132 |
} |
133 |
|
134 |
public Date getDate(int index) { |
135 |
return (Date)super.get(index); |
136 |
} |
137 |
|
138 |
public Date getDate(String name) { |
139 |
int i=featureType.getFieldIndex(name);
|
140 |
return (Date)super.get(i); |
141 |
} |
142 |
public void set(String name, Object value) throws IsNotFeatureSettingException { |
143 |
if (!editing && !loading)
|
144 |
throw new IsNotFeatureSettingException("setObject"); |
145 |
int i=featureType.getFieldIndex(name);
|
146 |
super.set(i,value);
|
147 |
// put(name,value);
|
148 |
} |
149 |
|
150 |
public void set(String name, int value) throws IsNotFeatureSettingException { |
151 |
if (!editing && !loading)
|
152 |
throw new IsNotFeatureSettingException("setInt"); |
153 |
int i=featureType.getFieldIndex(name);
|
154 |
if (editing)
|
155 |
originalValues.put(new Integer(i),new Integer(getInt(i))); |
156 |
super.set(i,new Integer(value)); |
157 |
// put(name,new Integer(value));
|
158 |
|
159 |
} |
160 |
|
161 |
public void set(String name, boolean value) throws IsNotFeatureSettingException { |
162 |
if (!editing && !loading)
|
163 |
throw new IsNotFeatureSettingException("setBoolean"); |
164 |
int i=featureType.getFieldIndex(name);
|
165 |
if (editing)
|
166 |
originalValues.put(new Integer(i),new Boolean(getBoolean(i))); |
167 |
super.set(i,new Boolean(value)); |
168 |
// put(name,new Boolean(value));
|
169 |
} |
170 |
|
171 |
public void set(String name, long value) throws IsNotFeatureSettingException { |
172 |
if (!editing && !loading)
|
173 |
throw new IsNotFeatureSettingException("setLong"); |
174 |
int i=featureType.getFieldIndex(name);
|
175 |
if (editing)
|
176 |
originalValues.put(new Integer(i),new Long(getLong(i))); |
177 |
super.set(i,new Long(value)); |
178 |
// put(name,new Long(value));
|
179 |
} |
180 |
|
181 |
public void set(String name, float value) throws IsNotFeatureSettingException { |
182 |
if (!editing && !loading)
|
183 |
throw new IsNotFeatureSettingException("setFloat"); |
184 |
int i=featureType.getFieldIndex(name);
|
185 |
if (editing)
|
186 |
originalValues.put(new Integer(i),new Float(getFloat(i))); |
187 |
super.set(i,new Float(value)); |
188 |
// put(name,new Float(value));
|
189 |
} |
190 |
|
191 |
public void set(String name, double value) throws IsNotFeatureSettingException { |
192 |
if (!editing && !loading)
|
193 |
throw new IsNotFeatureSettingException("setDouble"); |
194 |
int i=featureType.getFieldIndex(name);
|
195 |
if (editing)
|
196 |
originalValues.put(new Integer(i),new Double(getDouble(i))); |
197 |
super.set(i,new Double(value)); |
198 |
// put(name,new Double(value));
|
199 |
} |
200 |
|
201 |
public void setObject(int index, Object value) throws IsNotFeatureSettingException { |
202 |
if (!editing && !loading)
|
203 |
throw new IsNotFeatureSettingException("setObject"); |
204 |
if (editing){
|
205 |
//TODO falta comprobar que tipo y guardarlo en el originalValues
|
206 |
} |
207 |
super.set(index,value);
|
208 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
209 |
//
|
210 |
// put(name,value);
|
211 |
} |
212 |
|
213 |
public void set(int index, int value) throws IsNotFeatureSettingException { |
214 |
if (!editing && !loading)
|
215 |
throw new IsNotFeatureSettingException("setInt"); |
216 |
if (editing)
|
217 |
originalValues.put(new Integer(index),new Integer(getInt(index))); |
218 |
super.set(index,new Integer(value)); |
219 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
220 |
// put(name,new Integer(value));
|
221 |
} |
222 |
|
223 |
public void set(int index, boolean value) throws IsNotFeatureSettingException { |
224 |
if (!editing && !loading)
|
225 |
throw new IsNotFeatureSettingException("setBoolean"); |
226 |
if (editing)
|
227 |
originalValues.put(new Integer(index),new Boolean(getBoolean(index))); |
228 |
super.set(index,new Boolean(value)); |
229 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
230 |
// put(name,new Boolean(value));
|
231 |
} |
232 |
|
233 |
public void set(int index, long value) throws IsNotFeatureSettingException { |
234 |
if (!editing && !loading)
|
235 |
throw new IsNotFeatureSettingException("setLong"); |
236 |
if (editing)
|
237 |
originalValues.put(new Integer(index),new Long(getLong(index))); |
238 |
super.set(index,new Long(value)); |
239 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
240 |
// put(name,new Long(value));
|
241 |
} |
242 |
|
243 |
public void set(int index, float value) throws IsNotFeatureSettingException { |
244 |
if (!editing && !loading)
|
245 |
throw new IsNotFeatureSettingException("setFloat"); |
246 |
if (editing)
|
247 |
originalValues.put(new Integer(index),new Float(getFloat(index))); |
248 |
super.set(index,new Float(value)); |
249 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
250 |
// put(name,new Float(value));
|
251 |
} |
252 |
|
253 |
public void set(int index, double value) throws IsNotFeatureSettingException { |
254 |
if (!editing && !loading)
|
255 |
throw new IsNotFeatureSettingException("setDouble"); |
256 |
if (editing)
|
257 |
originalValues.put(new Integer(index),new Double(getDouble(index))); |
258 |
super.set(index,new Double(value)); |
259 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
260 |
// put(name,new Double(value));
|
261 |
} |
262 |
|
263 |
public void validateEnd(IFeatureStore featureStore) { |
264 |
getType().validateFeatureEnd(this,featureStore);
|
265 |
|
266 |
} |
267 |
|
268 |
public void validateModification(IFeatureStore featureStore) { |
269 |
getType().validateFeatureModifiction(this,featureStore);
|
270 |
} |
271 |
|
272 |
public void validate(IFeatureStore featureStore) { |
273 |
getType().validateFeature(this,featureStore);
|
274 |
} |
275 |
public IFeature getFeature(String name) { |
276 |
int i=featureType.getFieldIndex(name);
|
277 |
return (IFeature)super.get(i); |
278 |
} |
279 |
public Object getGeometry(int index) { |
280 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
281 |
return super.get(index); |
282 |
} |
283 |
public Object getGeometry(String name) { |
284 |
int i=featureType.getFieldIndex(name);
|
285 |
return super.get(i); |
286 |
} |
287 |
public byte getByte(int index) { |
288 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
289 |
Byte value=(Byte)super.get(index); |
290 |
if (value==null) |
291 |
return 0; |
292 |
return value.byteValue();
|
293 |
} |
294 |
public byte getByte(String name) { |
295 |
int i=featureType.getFieldIndex(name);
|
296 |
Byte value=(Byte)super.get(i); |
297 |
if (value==null) |
298 |
return 0; |
299 |
return value.byteValue();
|
300 |
} |
301 |
public void set(int index, byte value) throws IsNotFeatureSettingException { |
302 |
if (!editing && !loading)
|
303 |
throw new IsNotFeatureSettingException("setByte"); |
304 |
if (editing)
|
305 |
originalValues.put(new Integer(index),new Byte(getByte(index))); |
306 |
super.set(index,new Byte(value)); |
307 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
308 |
// put(name,new Byte(value));
|
309 |
} |
310 |
public void set(int index, String value) throws IsNotFeatureSettingException { |
311 |
if (!editing && !loading)
|
312 |
throw new IsNotFeatureSettingException("setString"); |
313 |
if (editing)
|
314 |
originalValues.put(new Integer(index),new String(getString(index))); |
315 |
super.set(index,value);
|
316 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
317 |
// put(name,new Byte(value));
|
318 |
} |
319 |
public void set(String name, byte value) throws IsNotFeatureSettingException { |
320 |
if (!editing && !loading)
|
321 |
throw new IsNotFeatureSettingException("setByte"); |
322 |
int i=featureType.getFieldIndex(name);
|
323 |
if (editing)
|
324 |
originalValues.put(new Integer(i),new Byte(getByte(i))); |
325 |
set(i,new Byte(value)); |
326 |
} |
327 |
public void setGeometry(String name,Object geometry) throws IsNotFeatureSettingException { |
328 |
if (!editing && !loading)
|
329 |
throw new IsNotFeatureSettingException("setGeometry"); |
330 |
int i=featureType.getFieldIndex(name);
|
331 |
if (editing){
|
332 |
//TODO falta poder clonar la geometr?a
|
333 |
// originalValues.put(new Integer(i),getGeometry(i).clone());
|
334 |
} |
335 |
set(i,geometry); |
336 |
if (featureType.getDefaultGeometry().equals(name)){
|
337 |
defaultGeometry=geometry; |
338 |
} |
339 |
} |
340 |
public void setGeometry(int index,Object geometry) throws IsNotFeatureSettingException { |
341 |
if (!editing && !loading)
|
342 |
throw new IsNotFeatureSettingException("setGeometry"); |
343 |
if (editing){
|
344 |
//TODO falta poder clonar la geometr?a
|
345 |
// originalValues.put(new Integer(index),getGeometry(index).clone());
|
346 |
} |
347 |
super.set(index,geometry);
|
348 |
// String name=((IFeatureAttributeDescriptor)featureType.get(index)).getName();
|
349 |
// put(name,geometry);
|
350 |
Iterator iterator=featureType.iterator();
|
351 |
while (iterator.hasNext()) {
|
352 |
IFeatureAttributeDescriptor fad = (IFeatureAttributeDescriptor) iterator.next(); |
353 |
if (fad.ordinal()==index && fad.getName().equals(featureType.getDefaultGeometry())){
|
354 |
defaultGeometry=geometry; |
355 |
} |
356 |
} |
357 |
} |
358 |
public void cancelEditing() { |
359 |
editing=false;
|
360 |
originalValues.clear(); |
361 |
|
362 |
} |
363 |
public void editing() { |
364 |
editing=true;
|
365 |
// originalValues.addAll(this);
|
366 |
} |
367 |
public Map getOriginalValues() { |
368 |
return originalValues;
|
369 |
} |
370 |
public void loading(){ |
371 |
loading=true;
|
372 |
} |
373 |
public void stopLoading(){ |
374 |
loading=false;
|
375 |
} |
376 |
} |