return source;
if (destinationType.equals(Byte.class)) {
long longValue = source.longValue();
if (longValue > Byte.MAX_VALUE)
throw new Errors().errorTooLarge(source, destinationType).toMappingException();
if (longValue < Byte.MIN_VALUE)
throw new Errors().errorTooSmall(source, destinationType).toMappingException();
return Byte.valueOf(source.byteValue());
}
if (destinationType.equals(Short.class)) {
long longValue = source.longValue();
if (longValue > Short.MAX_VALUE)
throw new Errors().errorTooLarge(source, destinationType).toMappingException();
if (longValue < Short.MIN_VALUE)
throw new Errors().errorTooSmall(source, destinationType).toMappingException();
return Short.valueOf(source.shortValue());
}
if (destinationType.equals(Integer.class)) {
long longValue = source.longValue();
if (longValue > Integer.MAX_VALUE)
throw new Errors().errorTooLarge(source, destinationType).toMappingException();
if (longValue < Integer.MIN_VALUE)
throw new Errors().errorTooSmall(source, destinationType).toMappingException();
return Integer.valueOf(source.intValue());
}
if (destinationType.equals(Long.class))
return Long.valueOf(source.longValue());
if (destinationType.equals(Float.class)) {
if (source.doubleValue() > Float.MAX_VALUE)
throw new Errors().errorTooLarge(source, destinationType).toMappingException();
return Float.valueOf(source.floatValue());
}
if (destinationType.equals(Double.class))
return Double.valueOf(source.doubleValue());
if (destinationType.equals(BigDecimal.class)) {
if (source instanceof Float || source instanceof Double)
return new BigDecimal(source.toString());
else if (source instanceof BigInteger)
return new BigDecimal((BigInteger) source);
else
return BigDecimal.valueOf(source.longValue());
}
if (destinationType.equals(BigInteger.class)) {
if (source instanceof BigDecimal)
return ((BigDecimal) source).toBigInteger();
else
return BigInteger.valueOf(source.longValue());
}
throw new Errors().errorMapping(source, destinationType).toMappingException();
}