public Column[] map(ValueMapping vm,
String name,
ColumnIO io,
boolean adapt) {
// all enum classes have a static method called 'values()'
// that returns an array of all the enum values
try {
Method m = vm.getType().getMethod("values", (Class[]) null);
_vals = (Enum[]) m.invoke(null, (Object[]) null);
} catch (Exception e) {
throw new MetaDataException().setCause(e);
}
Column col = new Column();
col.setName(name);
if (_ordinal)
col.setJavaType(JavaTypes.SHORT);
else {
// look for the longest enum value name; use 20 as min length to
// leave room for future long names
int len = 20;
for (int i = 0; i < _vals.length; i++)
len = Math.max(_vals[i].name().length(), len);
col.setJavaType(JavaTypes.STRING);
col.setSize(len);
}
return new Column[]{ col };
}
|