root / branches / Mobile_Compatible_Hito_1 / libFMap / src-file / org / gvsig / data / datastores / vectorial / file / dbf / DBFFeature.java @ 21606
History | View | Annotate | Download (3.15 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.dbf; |
---|---|
2 |
|
3 |
import java.text.DateFormat; |
4 |
import java.text.ParseException; |
5 |
import java.util.Date; |
6 |
import java.util.List; |
7 |
import java.util.Locale; |
8 |
|
9 |
import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile; |
10 |
import org.gvsig.data.exception.ReadException; |
11 |
import org.gvsig.data.spatialprovisional.IExtent; |
12 |
import org.gvsig.data.vectorial.Feature; |
13 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
14 |
import org.gvsig.data.vectorial.IFeatureID; |
15 |
import org.gvsig.data.vectorial.IFeatureType; |
16 |
|
17 |
|
18 |
public class DBFFeature extends Feature{ |
19 |
protected static Locale ukLocale = new Locale("en", "UK"); |
20 |
private DBFStore store;
|
21 |
private long featureIndex; |
22 |
|
23 |
DBFFeature(IFeatureType featureType, DBFStore store, long featureIndex) {
|
24 |
super(featureType);
|
25 |
this.store=store;
|
26 |
this.featureIndex=featureIndex;
|
27 |
} |
28 |
|
29 |
|
30 |
void load(DbaseFile dbf) throws ReadException { |
31 |
for (int i=0;i<this.featureType.size();i++) { |
32 |
IFeatureAttributeDescriptor descriptor= (IFeatureAttributeDescriptor)this.featureType.get(i);
|
33 |
if (dbf.getFieldCount()<=i)
|
34 |
return;
|
35 |
String value=dbf.getStringFieldValue((int) this.featureIndex, i); |
36 |
value=value.trim(); |
37 |
String fieldType=descriptor.getDataType();
|
38 |
if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_STRING)){
|
39 |
this.set(i,value);
|
40 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){ |
41 |
try{
|
42 |
Double.parseDouble(value);
|
43 |
}catch (NumberFormatException e) { |
44 |
value="0";
|
45 |
} |
46 |
this.set(i,Double.parseDouble(value)); |
47 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_INT)){ |
48 |
this.set(i,Integer.parseInt(value)); |
49 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){ |
50 |
this.set(i,Float.parseFloat(value)); |
51 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_LONG)){ |
52 |
this.set(i,Long.parseLong(value)); |
53 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){ |
54 |
this.set(i,Boolean.valueOf(value)); |
55 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){ |
56 |
this.set(i,Byte.parseByte(value)); |
57 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DATE)){ |
58 |
String year = value.substring(0, 4); |
59 |
String month = value.substring(4, 6); |
60 |
String day = value.substring(6, 8); |
61 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, ukLocale); |
62 |
/* Calendar c = Calendar.getInstance();
|
63 |
c.clear();
|
64 |
c.set(Integer.parseInt(year), Integer.parseInt(month),
|
65 |
Integer.parseInt(day));
|
66 |
c.set(Calendar.MILLISECOND, 0); */
|
67 |
String strAux = month + "/" + day + "/" + year; |
68 |
Date dat=null; |
69 |
try {
|
70 |
dat = df.parse(strAux); |
71 |
} catch (ParseException e) { |
72 |
throw new ReadException(this.store.getName(),e); |
73 |
} |
74 |
this.set(i,dat);
|
75 |
}else{
|
76 |
this.set(i,null); |
77 |
} |
78 |
} |
79 |
|
80 |
} |
81 |
|
82 |
public IFeatureID getID() {
|
83 |
return new DBFFeatureID(this.store,featureIndex); |
84 |
} |
85 |
|
86 |
public IExtent getExtent() {
|
87 |
return null; |
88 |
} |
89 |
|
90 |
public List getAllSRS() { |
91 |
return null; |
92 |
} |
93 |
|
94 |
public String getDefaultSRS() { |
95 |
return null; |
96 |
} |
97 |
|
98 |
} |