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