Examples of ConversionException


Examples of org.more.convert.ConversionException

        }
        // Byte
        if (targetType.equals(Byte.class)) {
            long longValue = value.longValue();
            if (longValue > Byte.MAX_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too large for " + this.toString(targetType));
            }
            if (longValue < Byte.MIN_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too small " + this.toString(targetType));
            }
            return new Byte(value.byteValue());
        }
        // Short
        if (targetType.equals(Short.class)) {
            long longValue = value.longValue();
            if (longValue > Short.MAX_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too large for " + this.toString(targetType));
            }
            if (longValue < Short.MIN_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too small " + this.toString(targetType));
            }
            return new Short(value.shortValue());
        }
        // Integer
        if (targetType.equals(Integer.class)) {
            long longValue = value.longValue();
            if (longValue > Integer.MAX_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too large for " + this.toString(targetType));
            }
            if (longValue < Integer.MIN_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too small " + this.toString(targetType));
            }
            return new Integer(value.intValue());
        }
        // Long
        if (targetType.equals(Long.class)) {
            return new Long(value.longValue());
        }
        // Float
        if (targetType.equals(Float.class)) {
            if (value.doubleValue() > Float.MAX_VALUE) {
                throw new ConversionException(this.toString(sourceType) + " value '" + value + "' is too large for " + this.toString(targetType));
            }
            return new Float(value.floatValue());
        }
        // Double
        if (targetType.equals(Double.class)) {
            return new Double(value.doubleValue());
        }
        // BigDecimal
        if (targetType.equals(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 (targetType.equals(BigInteger.class)) {
            if (value instanceof BigDecimal) {
                return ((BigDecimal) value).toBigInteger();
            } else {
                return BigInteger.valueOf(value.longValue());
            }
        }
        String msg = this.toString(this.getClass()) + " cannot handle conversion to '" + this.toString(targetType) + "'";
        throw new ConversionException(msg);
    }
View Full Code Here

Examples of org.mvel2.ConversionException

   @Override
   public Object convertFrom(final Object in)
   {
      if (!CNV.containsKey(in.getClass()))
      {
         throw new ConversionException("cannot convert type: "
                  + in.getClass().getName() + " to: " + Boolean.class.getName());
      }
      return CNV.get(in.getClass()).convert(in);
   }
View Full Code Here

Examples of org.springframework.binding.convert.ConversionException

            this.sourceClass = sourceClass;
            this.targetClass = targetClass;
        }

        public Object convert(Object source, Class targetClass, ConversionContext context) throws ConversionException {
            throw new ConversionException("test", targetClass);
        }
View Full Code Here

Examples of org.strecks.exceptions.ConversionException

    {
      convert = BeanUtilsConverter.getInstance().convert(toConvert, clazz);
    }
    catch (Exception e)
    {
      throw new ConversionException(e);
    }
    return convert;
  }
View Full Code Here

Examples of org.strecks.exceptions.ConversionException

    {
      convert = BeanUtilsConverter.getInstance().convert(toConvert);
    }
    catch (Exception e)
    {
      throw new ConversionException(e);
    }
    return convert;
  }
View Full Code Here

Examples of org.strecks.exceptions.ConversionException

      return formatter.parse(toConvert);
    }
    catch (ParseException e)
    {
      // should have already been validated so this is not recoverable
      throw new ConversionException("Unable to convert value " + toConvert + " to Date using pattern "
          + getDatePattern());
    }
  }
View Full Code Here

Examples of org.strecks.exceptions.ConversionException

    {
      convert = BeanUtilsConverter.getInstance().convert(toConvert, clazz);
    }
    catch (Exception e)
    {
      throw new ConversionException(e);
    }
    return convert;
  }
View Full Code Here

Examples of org.strecks.exceptions.ConversionException

    {
      convert = BeanUtilsConverter.getInstance().convert(toConvert);
    }
    catch (Exception e)
    {
      throw new ConversionException(e);
    }
    return convert;
  }
View Full Code Here

Examples of our.apache.commons.beanutils.ConversionException

        if (value == null) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException("No value specified");
            }
        }

        if (value instanceof Boolean) {
            return (value);
        }

        try {
            String stringValue = value.toString();
            if (stringValue.equalsIgnoreCase("yes") ||
                stringValue.equalsIgnoreCase("enabled") ||
                stringValue.equalsIgnoreCase("y") ||
                stringValue.equalsIgnoreCase("true") ||
                stringValue.equalsIgnoreCase("on") ||
                stringValue.equalsIgnoreCase("1")) {
                return (Boolean.TRUE);
            } else if (stringValue.equalsIgnoreCase("no") ||
                       stringValue.equalsIgnoreCase("disabled") ||
                       stringValue.equalsIgnoreCase("n") ||
                       stringValue.equalsIgnoreCase("false") ||
                       stringValue.equalsIgnoreCase("off") ||
                       stringValue.equalsIgnoreCase("0")) {
                return (Boolean.FALSE);
            } else if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException(stringValue);
            }
        } catch (ClassCastException e) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException(e);
            }
        }

    }
View Full Code Here

Examples of pt.ist.fenixWebFramework.renderers.components.converters.ConversionException

        public Object convert(Class type, Object value) {
            final String numberText = ((String) value).trim();
            try {
                return numberText.length() == 0 ? null : new Money(numberText);
            } catch (NumberFormatException e) {
                throw new ConversionException("renderers.converter.money", e, true, value);
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.