Revision 20421 trunk/libraries/libDataSourceBaseDrivers/src/org/gvsig/data/datastores/vectorial/file/dbf/DBFFeature.java
DBFFeature.java | ||
---|---|---|
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
|
32 |
void load(DbaseFile dbf) throws ReadException, IsNotFeatureSettingException{ |
|
33 |
Iterator iterator=featureType.iterator(); |
|
34 |
this.loading(); |
|
35 |
while (iterator.hasNext()) { |
|
36 |
IFeatureAttributeDescriptor descriptor = (IFeatureAttributeDescriptor) iterator.next(); |
|
37 |
int i=descriptor.ordinal(); |
|
38 |
if (dbf.getFieldCount()<=i) |
|
39 |
return; |
|
40 |
String value=dbf.getStringFieldValue((int) this.featureIndex, i); |
|
41 |
value=value.trim(); |
|
42 |
String fieldType=descriptor.getDataType(); |
|
43 |
if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_STRING)){ |
|
44 |
this.set(i,value); |
|
45 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){ |
|
46 |
try{ |
|
47 |
Double.parseDouble(value); |
|
48 |
}catch (NumberFormatException e) { |
|
49 |
value="0"; |
|
32 |
void load(DbaseFile dbf) throws ReadException{ |
|
33 |
try{ |
|
34 |
Iterator iterator=featureType.iterator(); |
|
35 |
this.loading(); |
|
36 |
while (iterator.hasNext()) { |
|
37 |
IFeatureAttributeDescriptor descriptor = (IFeatureAttributeDescriptor) iterator.next(); |
|
38 |
int i=descriptor.ordinal(); |
|
39 |
if (dbf.getFieldCount()<=i) |
|
40 |
return; |
|
41 |
String value=dbf.getStringFieldValue((int) this.featureIndex, i); |
|
42 |
value=value.trim(); |
|
43 |
String fieldType=descriptor.getDataType(); |
|
44 |
if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_STRING)){ |
|
45 |
this.set(i,value); |
|
46 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DOUBLE)){ |
|
47 |
try{ |
|
48 |
Double.parseDouble(value); |
|
49 |
}catch (NumberFormatException e) { |
|
50 |
value="0"; |
|
51 |
} |
|
52 |
this.set(i,Double.parseDouble(value)); |
|
53 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_INT)){ |
|
54 |
this.set(i,Integer.parseInt(value)); |
|
55 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){ |
|
56 |
this.set(i,Float.parseFloat(value)); |
|
57 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_LONG)){ |
|
58 |
this.set(i,Long.parseLong(value)); |
|
59 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){ |
|
60 |
this.set(i,Boolean.parseBoolean(value)); |
|
61 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){ |
|
62 |
this.set(i,Byte.parseByte(value)); |
|
63 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DATE)){ |
|
64 |
String year = value.substring(0, 4); |
|
65 |
String month = value.substring(4, 6); |
|
66 |
String day = value.substring(6, 8); |
|
67 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, ukLocale); |
|
68 |
/* Calendar c = Calendar.getInstance(); |
|
69 |
c.clear(); |
|
70 |
c.set(Integer.parseInt(year), Integer.parseInt(month), |
|
71 |
Integer.parseInt(day)); |
|
72 |
c.set(Calendar.MILLISECOND, 0); */ |
|
73 |
String strAux = month + "/" + day + "/" + year; |
|
74 |
Date dat=null; |
|
75 |
try { |
|
76 |
dat = df.parse(strAux); |
|
77 |
} catch (ParseException e) { |
|
78 |
throw new ReadException(this.store.getName(),e); |
|
79 |
} |
|
80 |
this.set(i,dat); |
|
81 |
}else{ |
|
82 |
this.set(i,null); |
|
50 | 83 |
} |
51 |
this.set(i,Double.parseDouble(value)); |
|
52 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_INT)){ |
|
53 |
this.set(i,Integer.parseInt(value)); |
|
54 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_FLOAT)){ |
|
55 |
this.set(i,Float.parseFloat(value)); |
|
56 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_LONG)){ |
|
57 |
this.set(i,Long.parseLong(value)); |
|
58 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BOOLEAN)){ |
|
59 |
this.set(i,Boolean.parseBoolean(value)); |
|
60 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_BYTE)){ |
|
61 |
this.set(i,Byte.parseByte(value)); |
|
62 |
}else if (fieldType.equals(IFeatureAttributeDescriptor.TYPE_DATE)){ |
|
63 |
String year = value.substring(0, 4); |
|
64 |
String month = value.substring(4, 6); |
|
65 |
String day = value.substring(6, 8); |
|
66 |
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, ukLocale); |
|
67 |
/* Calendar c = Calendar.getInstance(); |
|
68 |
c.clear(); |
|
69 |
c.set(Integer.parseInt(year), Integer.parseInt(month), |
|
70 |
Integer.parseInt(day)); |
|
71 |
c.set(Calendar.MILLISECOND, 0); */ |
|
72 |
String strAux = month + "/" + day + "/" + year; |
|
73 |
Date dat=null; |
|
74 |
try { |
|
75 |
dat = df.parse(strAux); |
|
76 |
} catch (ParseException e) { |
|
77 |
throw new ReadException(this.store.getName(),e); |
|
78 |
} |
|
79 |
this.set(i,dat); |
|
80 |
}else{ |
|
81 |
this.set(i,null); |
|
82 | 84 |
} |
85 |
this.stopLoading(); |
|
86 |
}catch (IsNotFeatureSettingException e) { |
|
87 |
e.printStackTrace(); |
|
83 | 88 |
} |
84 |
this.stopLoading(); |
|
85 |
|
|
86 | 89 |
} |
87 | 90 |
|
88 | 91 |
public IFeatureID getID() { |
Also available in: Unified diff