01: package com.silvermindsoftware.hitch.handlers.type;
02:
03: import java.math.BigDecimal;
04: import java.math.BigInteger;
05:
06: /**
07: * User: brandongoodin
08: * Date: May 14, 2007
09: * Time: 11:18:45 AM
10: */
11: public class BigDecimalTypeHandler implements TypeHandler {
12:
13: public Object convert(Object value) {
14: // if null just return
15: if (value == null)
16: return value;
17:
18: BigDecimal retVal = null;
19:
20: if (value instanceof BigDecimal) {
21: retVal = (BigDecimal) value;
22: } else if (value instanceof String) {
23: if (((String) value).trim().equals("")) {
24: retVal = null;
25: } else {
26: retVal = new BigDecimal((String) value);
27: }
28: } else if (value instanceof Double) {
29: retVal = new BigDecimal((Double) value);
30: } else if (value instanceof Integer) {
31: retVal = new BigDecimal((Integer) value);
32: } else if (value instanceof Long) {
33: retVal = new BigDecimal((Long) value);
34: } else if (value instanceof BigInteger) {
35: retVal = new BigDecimal((BigInteger) value);
36: } else {
37: throw new IllegalArgumentException(
38: "Could not convert object of type "
39: + value.getClass().getName()
40: + " to BigDecimal.");
41: }
42: return retVal;
43: }
44: }
|