Package com.alibaba.tamper.core

Examples of com.alibaba.tamper.core.BeanMappingException


    }

    public Object getNext() {
        currentIndex = currentIndex + 1;
        if (currentIndex > batchValues.length) {
            throw new BeanMappingException("batch values index is out of Array!");
        }
        return batchValues[currentIndex];
    }
View Full Code Here


        public Object convert(Object src, Class destClass) {
            if (src instanceof String && destClass.isEnum()) {
                return Enum.valueOf(destClass, (String) src);
            }

            throw new BeanMappingException("Unsupported convert: [" + src.getClass() + "," + destClass.getName() + "]");

        }
View Full Code Here

        public Object convert(Object src, Class destClass) {
            if (src.getClass().isEnum() && destClass == String.class) {
                return ((Enum) src).name(); // 返回定义的enum name
            }

            throw new BeanMappingException("Unsupported convert: [" + src.getClass() + "," + destClass.getName() + "]");
        }
View Full Code Here

            // Integer
            if (targetClass == Integer.class || targetClass == int.class) {
                long longValue = value.longValue();
                if (longValue > Integer.MAX_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too large for "
                                                   + targetClass.getName());
                }
                if (longValue < Integer.MIN_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too small "
                                                   + targetClass.getName());
                }
                return Integer.valueOf(value.intValue());
            }

            // Long
            if (targetClass == Long.class || targetClass == long.class) {
                return Long.valueOf(value.longValue());
            }

            // Boolean
            if (targetClass == Boolean.class || targetClass == boolean.class) {
                long longValue = value.longValue();
                return Boolean.valueOf(longValue > 0 ? true : false);
            }

            // Byte
            if (targetClass == Byte.class || targetClass == byte.class) {
                long longValue = value.longValue();
                if (longValue > Byte.MAX_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too large for "
                                                   + targetClass.getName());
                }
                if (longValue < Byte.MIN_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too small "
                                                   + targetClass.getName());
                }
                return Byte.valueOf(value.byteValue());
            }

            // Double
            if (targetClass == Double.class || targetClass == double.class) {
                return Double.valueOf(value.doubleValue());
            }

            // BigDecimal
            if (targetClass == BigDecimal.class) {
                if (value instanceof Float || value instanceof Double) {
                    return new BigDecimal(value.toString());
                } else if (value instanceof BigInteger) {
                    return new BigDecimal((BigInteger) value);
                } else {
                    return BigDecimal.valueOf(value.longValue());
                }
            }

            // BigInteger
            if (targetClass == BigInteger.class) {
                if (value instanceof BigDecimal) {
                    return ((BigDecimal) value).toBigInteger();
                } else {
                    return BigInteger.valueOf(value.longValue());
                }
            }

            // Short
            if (targetClass == Short.class || targetClass == short.class) {
                long longValue = value.longValue();
                if (longValue > Short.MAX_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too large for "
                                                   + targetClass.getName());
                }
                if (longValue < Short.MIN_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too small "
                                                   + targetClass.getName());
                }
                return Short.valueOf(value.shortValue());
            }

            // Float
            if (targetClass == Float.class || targetClass == float.class) {
                double doubleValue = value.doubleValue();
                if (doubleValue > Float.MAX_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too large for "
                                                   + targetClass.getName());
                }

                if (doubleValue < Float.MIN_VALUE) {
                    throw new BeanMappingException(srcClass.getName() + " value '" + value + "' is too small for "
                                                   + targetClass.getName());
                }
                return Float.valueOf(value.floatValue());
            }

            // Character
            if (targetClass == Character.class || targetClass == char.class) {
                long longValue = value.longValue();
                // Character没有很明显的值上下边界,直接依赖于jvm的转型
                return Character.valueOf((char) longValue);
            }

            throw new BeanMappingException("Unsupported convert: [" + srcClass.getName() + "," + targetClass.getName()
                                           + "]");
        }
View Full Code Here

            if (srcClass == Character.class || srcClass == char.class) {
                Character charvalue = (Character) src;
                return toCommon(srcClass, targetClass, Integer.valueOf((int) charvalue));
            }

            throw new BeanMappingException("Unsupported convert: [" + src + "," + targetClass.getName() + "]");
        }
View Full Code Here

        public Object convert(Object src, Class destClass) {
            if (String.class.isInstance(src)) { // 必须是字符串
                try {
                    return new SimpleDateFormat(DAY_FORMAT).parse((String) src);
                } catch (ParseException e) {
                    throw new BeanMappingException("convert failed: [" + src + "," + destClass.getName() + "]", e);
                }
            }

            throw new BeanMappingException("Unsupported convert: [" + src + "," + destClass.getName() + "]");
        }
View Full Code Here

        public Object convert(Object src, Class destClass) {
            if (String.class.isInstance(src)) { // 必须是字符串
                try {
                    return new SimpleDateFormat(TIME_FORMAT).parse((String) src);
                } catch (ParseException e) {
                    throw new BeanMappingException("convert failed: [" + src + "," + destClass.getName() + "]", e);
                }
            }

            throw new BeanMappingException("Unsupported convert: [" + src + "," + destClass.getName() + "]");
        }
View Full Code Here

        public Object convert(Object src, Class destClass) {
            if (Date.class.isInstance(src)) { // 必须是Date对象
                return new SimpleDateFormat(DAY_FORMAT).format((Date) src);
            }

            throw new BeanMappingException("Unsupported convert: [" + src + "," + destClass.getName() + "]");
        }
View Full Code Here

        public Object convert(Object src, Class destClass) {
            if (Date.class.isInstance(src)) { // 必须是Date对象
                return new SimpleDateFormat(TIME_FORMAT).format((Date) src);
            }

            throw new BeanMappingException("Unsupported convert: [" + src + "," + destClass.getName() + "]");
        }
View Full Code Here

                Calendar result = new GregorianCalendar();
                result.setTime(dest);
                return result;
            }

            throw new BeanMappingException("Unsupported convert: [" + src + "," + destClass.getName() + "]");
        }
View Full Code Here

TOP

Related Classes of com.alibaba.tamper.core.BeanMappingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.