class JMSMessagePropertySupport {

    @SuppressWarnings("unchecked")
    public static <T> T convertPropertyTo(String name, Object value, Class<T> target) throws JMSException {
        if (value == null) {
            if (Boolean.class.equals(target)) {
                return (T) Boolean.FALSE;
            } else if (Float.class.equals(target) || Double.class.equals(target)) {
                throw new NullPointerException("property " + name + " was null");
            } else if (Number.class.isAssignableFrom(target)) {
                throw new NumberFormatException("property " + name + " was null");
            } else {
                return null;
            }
        }

        T rc = (T) TypeConversionSupport.convert(value, target);
        if (rc == null) {
            throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a " + target.getName());
        }

        return rc;
    }

}