root / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / dbf / DBFFeature.java @ 20501
History | View | Annotate | Download (3.67 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.Iterator; |
7 |
import java.util.List; |
8 |
import java.util.Locale; |
9 |
|
10 |
import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile; |
11 |
import org.gvsig.data.exception.ReadException; |
12 |
import org.gvsig.data.spatialprovisional.IExtent; |
13 |
import org.gvsig.data.vectorial.DefaultAttributeDescriptor; |
14 |
import org.gvsig.data.vectorial.Feature; |
15 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
16 |
import org.gvsig.data.vectorial.IFeatureID; |
17 |
import org.gvsig.data.vectorial.IFeatureType; |
18 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
19 |
|
20 |
|
21 |
public class DBFFeature extends Feature{ |
22 |
protected static Locale ukLocale = new Locale("en", "UK"); |
23 |
protected DBFStore store;
|
24 |
protected long featureIndex; |
25 |
|
26 |
protected DBFFeature(IFeatureType featureType, DBFStore store, long featureIndex) throws ReadException { |
27 |
super(featureType);
|
28 |
this.store=store;
|
29 |
this.featureIndex=featureIndex;
|
30 |
load(); |
31 |
} |
32 |
|
33 |
|
34 |
protected void load() throws ReadException{ |
35 |
Iterator iterator=featureType.iterator();
|
36 |
this.loading();
|
37 |
while (iterator.hasNext()) {
|
38 |
IFeatureAttributeDescriptor descriptor = (IFeatureAttributeDescriptor) iterator.next(); |
39 |
try {
|
40 |
this.loadValue(descriptor);
|
41 |
} catch (IsNotFeatureSettingException e) {
|
42 |
throw new ReadException(store.getName(),e); |
43 |
} |
44 |
|
45 |
|
46 |
} |
47 |
this.stopLoading();
|
48 |
} |
49 |
|
50 |
protected void loadValue(IFeatureAttributeDescriptor descriptor) throws ReadException, IsNotFeatureSettingException{ |
51 |
int i=((DefaultAttributeDescriptor)descriptor).originalPosition();
|
52 |
if (store.dbf.getFieldCount()<=i)
|
53 |
return;
|
54 |
String value=store.dbf.getStringFieldValue((int) this.featureIndex, i); |
55 |
value=value.trim(); |
56 |
String fieldType=descriptor.getDataType();
|
57 |
if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_STRING)){
|
58 |
this.set(i,value);
|
59 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){ |
60 |
try{
|
61 |
Double.parseDouble(value);
|
62 |
}catch (NumberFormatException e) { |
63 |
value="0";
|
64 |
} |
65 |
this.set(i,Double.parseDouble(value)); |
66 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_INT)){ |
67 |
this.set(i,Integer.parseInt(value)); |
68 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){ |
69 |
this.set(i,Float.parseFloat(value)); |
70 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_LONG)){ |
71 |
this.set(i,Long.parseLong(value)); |
72 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){ |
73 |
this.set(i,Boolean.parseBoolean(value)); |
74 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){ |
75 |
this.set(i,Byte.parseByte(value)); |
76 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DATE)){ |
77 |
String year = value.substring(0, 4); |
78 |
String month = value.substring(4, 6); |
79 |
String day = value.substring(6, 8); |
80 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, ukLocale); |
81 |
/* Calendar c = Calendar.getInstance();
|
82 |
c.clear();
|
83 |
c.set(Integer.parseInt(year), Integer.parseInt(month),
|
84 |
Integer.parseInt(day));
|
85 |
c.set(Calendar.MILLISECOND, 0); */
|
86 |
String strAux = month + "/" + day + "/" + year; |
87 |
Date dat=null; |
88 |
try {
|
89 |
dat = df.parse(strAux); |
90 |
} catch (ParseException e) { |
91 |
throw new ReadException(this.store.getName(),e); |
92 |
} |
93 |
this.set(i,dat);
|
94 |
}else{
|
95 |
this.set(i,descriptor.getDefaultValue());
|
96 |
} |
97 |
} |
98 |
|
99 |
public IFeatureID getID() {
|
100 |
return new DBFFeatureID(this.store,featureIndex); |
101 |
} |
102 |
|
103 |
public IExtent getExtent() {
|
104 |
return null; |
105 |
} |
106 |
|
107 |
public List getAllSRS() { |
108 |
return null; |
109 |
} |
110 |
|
111 |
public String getDefaultSRS() { |
112 |
return null; |
113 |
} |
114 |
|
115 |
} |