/*
* Everything in the result is a string, apart from Member
*/
if (valueClass.equals(mondrian.olap.Member.class)) {
if (!(value instanceof mondrian.olap.Member)) {
throw new JRException("Field '" + jrField.getName() + "' is of class '"
+ value.getClass()
+ "' and can not be converted to class " + valueClass.getName());
}
return value;
}
/*
* Convert the rest from String
*/
String fieldValue = (String) value;
if (fieldValue == null)
{
return null;
}
if (Number.class.isAssignableFrom(valueClass)){
fieldValue = fieldValue.trim();
}
if (fieldValue.length() == 0){
fieldValue = "0";
}
if (valueClass.equals(String.class)) {
return fieldValue;
} else if (valueClass.equals(Boolean.class)) {
return fieldValue.equalsIgnoreCase("true") ? Boolean.TRUE : Boolean.FALSE;
} else if (valueClass.equals(Byte.class)) {
return new Byte(fieldValue);
} else if (valueClass.equals(Integer.class)) {
return Integer.valueOf(fieldValue);
} else if (valueClass.equals(Long.class)) {
return new Long(fieldValue);
} else if (valueClass.equals(Short.class)) {
return new Short(fieldValue);
} else if (valueClass.equals(Double.class)) {
return new Double(fieldValue);
} else if (valueClass.equals(Float.class)) {
return new Float(fieldValue);
} else if (valueClass.equals(java.math.BigDecimal.class)) {
return new java.math.BigDecimal(fieldValue);
} else if (valueClass.equals(java.util.Date.class)) {
return dateFormat.parse(fieldValue);
} else if (valueClass.equals(java.sql.Timestamp.class)) {
return new java.sql.Timestamp(dateFormat.parse(fieldValue).getTime());
} else if (valueClass.equals(java.sql.Time.class)) {
return new java.sql.Time(dateFormat.parse(fieldValue).getTime());
} else if (valueClass.equals(java.lang.Number.class)) {
return new Double(fieldValue);
} else {
throw new JRException("Field '" + jrField.getName() + "', string value '" + fieldValue + "' is of class '"
+ fieldValues.get(jrField.getName()).getClass()
+ "' and can not be converted to class " + valueClass.getName());
}
} catch (Exception e) {
throw new JRException("Unable to get value for field '" + jrField.getName() + "' of class '" + valueClass.getName() + "'", e);
}
}