* The string to parse to the correct type.
* @return The string's value as the appropriate type.
* @throws XMLParseException
*/
private Object convertToFieldType(Field field, String valueString) throws XMLParsingException {
XMLField annotation = field.getAnnotation(XMLField.class);
if (int.class.isAssignableFrom(field.getType())) {
return Integer.parseInt(valueString);
} else if (long.class.isAssignableFrom(field.getType())) {
return Long.parseLong(valueString);
} else if (float.class.isAssignableFrom(field.getType())) {
return Float.parseFloat(valueString);
} else if (double.class.isAssignableFrom(field.getType())) {
return Double.parseDouble(valueString);
} else if (boolean.class.isAssignableFrom(field.getType())) {
return Boolean.parseBoolean(valueString);
} else if (BigDecimal.class.isAssignableFrom(field.getType())) {
return new BigDecimal(valueString);
} else if (Date.class.isAssignableFrom(field.getType())) {
try {
return new SimpleDateFormat(annotation.dateFormat()).parse(valueString);
} catch (ParseException e) {
throw new XMLParsingException("Encountered date parsing exception when parsing " + field.toString()
+ " with format " + field.getAnnotation(XMLField.class).dateFormat() + " for value "
+ valueString, e);
}