root / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / dbf / DBFFeature.java @ 20501
History | View | Annotate | Download (3.67 KB)
1 | 19844 | vcaballero | package org.gvsig.data.datastores.vectorial.file.dbf; |
---|---|---|---|
2 | 19401 | vcaballero | |
3 | 20130 | jmvivo | import java.text.DateFormat; |
4 | import java.text.ParseException; |
||
5 | import java.util.Date; |
||
6 | 20414 | vcaballero | import java.util.Iterator; |
7 | 19401 | vcaballero | import java.util.List; |
8 | 20130 | jmvivo | import java.util.Locale; |
9 | 19401 | vcaballero | |
10 | 20130 | jmvivo | import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile; |
11 | import org.gvsig.data.exception.ReadException; |
||
12 | 19441 | vcaballero | import org.gvsig.data.spatialprovisional.IExtent; |
13 | 20501 | vcaballero | import org.gvsig.data.vectorial.DefaultAttributeDescriptor; |
14 | 19401 | vcaballero | import org.gvsig.data.vectorial.Feature; |
15 | 20130 | jmvivo | import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
16 | 19401 | vcaballero | import org.gvsig.data.vectorial.IFeatureID; |
17 | import org.gvsig.data.vectorial.IFeatureType; |
||
18 | 20414 | vcaballero | import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
19 | 19401 | vcaballero | |
20 | 19736 | vcaballero | |
21 | 19401 | vcaballero | public class DBFFeature extends Feature{ |
22 | 20130 | jmvivo | protected static Locale ukLocale = new Locale("en", "UK"); |
23 | 20437 | vcaballero | protected DBFStore store;
|
24 | protected long featureIndex; |
||
25 | 19401 | vcaballero | |
26 | 20437 | vcaballero | protected DBFFeature(IFeatureType featureType, DBFStore store, long featureIndex) throws ReadException { |
27 | 19401 | vcaballero | super(featureType);
|
28 | 19736 | vcaballero | this.store=store;
|
29 | 19401 | vcaballero | this.featureIndex=featureIndex;
|
30 | 20437 | vcaballero | load(); |
31 | 19401 | vcaballero | } |
32 | |||
33 | 20130 | jmvivo | |
34 | 20437 | vcaballero | protected void load() throws ReadException{ |
35 | 20479 | jmvivo | 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 | 20130 | jmvivo | } |
44 | 20479 | jmvivo | |
45 | |||
46 | 20130 | jmvivo | } |
47 | 20479 | jmvivo | this.stopLoading();
|
48 | 20130 | jmvivo | } |
49 | |||
50 | 20479 | jmvivo | protected void loadValue(IFeatureAttributeDescriptor descriptor) throws ReadException, IsNotFeatureSettingException{ |
51 | 20501 | vcaballero | int i=((DefaultAttributeDescriptor)descriptor).originalPosition();
|
52 | 20479 | jmvivo | 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 | 19401 | vcaballero | public IFeatureID getID() {
|
100 | 19736 | vcaballero | return new DBFFeatureID(this.store,featureIndex); |
101 | 19401 | vcaballero | } |
102 | |||
103 | 19441 | vcaballero | public IExtent getExtent() {
|
104 | 19401 | vcaballero | return null; |
105 | } |
||
106 | |||
107 | public List getAllSRS() { |
||
108 | return null; |
||
109 | } |
||
110 | |||
111 | 19415 | vcaballero | public String getDefaultSRS() { |
112 | 19401 | vcaballero | return null; |
113 | } |
||
114 | |||
115 | } |