use of com.linuxense.javadbf.DBFField in project pentaho-kettle by pentaho.
the class XBase method getFields.
@SuppressWarnings("fallthrough")
public RowMetaInterface getFields() throws KettleException {
String debug = "get fields from XBase file";
RowMetaInterface row = new RowMeta();
try {
// Fetch all field information
//
debug = "allocate data types";
datatype = new byte[reader.getFieldCount()];
for (int i = 0; i < reader.getFieldCount(); i++) {
if (log.isDebug()) {
debug = "get field #" + i;
}
DBFField field = reader.getField(i);
ValueMetaInterface value = null;
datatype[i] = field.getDataType();
switch(datatype[i]) {
case // Memo
DBFField.FIELD_TYPE_M:
debug = "memo field";
if ((log != null) && log.isDebug()) {
log.logDebug("Field #" + i + " is a memo-field! (" + field.getName() + ")");
}
case // Character
DBFField.FIELD_TYPE_C:
// case DBFField.FIELD_TYPE_P: // Picture
debug = "character field";
value = new ValueMetaString(field.getName());
value.setLength(field.getFieldLength());
break;
// Integer
case FIELD_TYPE_I:
// Numeric
case DBFField.FIELD_TYPE_N:
case // Float
DBFField.FIELD_TYPE_F:
debug = "Number field";
value = new ValueMetaNumber(field.getName());
value.setLength(field.getFieldLength(), field.getDecimalCount());
break;
case // Logical
DBFField.FIELD_TYPE_L:
debug = "Logical field";
value = new ValueMetaBoolean(field.getName());
value.setLength(-1, -1);
break;
case // Date
DBFField.FIELD_TYPE_D:
debug = "Date field";
value = new ValueMetaDate(field.getName());
value.setLength(-1, -1);
break;
default:
if ((log != null) && (log.isDebug())) {
log.logDebug("Unknown Datatype" + datatype[i]);
}
}
if (value != null) {
row.addValueMeta(value);
}
}
} catch (Exception e) {
throw new KettleException("Error reading DBF metadata (in part " + debug + ")", e);
}
return row;
}
Aggregations