Package org.modelmapper.internal

Examples of org.modelmapper.internal.Errors$Converter


           ConverterHome home =
               (ConverterHome)PortableRemoteObject.narrow(objref,
                                            ConverterHome.class);

           Converter currencyConverter = home.create();
           double amount = currencyConverter.dollarToYen(100.00);
           System.out.println(String.valueOf(amount));
           amount = currencyConverter.yenToEuro(100.00);
           System.out.println(String.valueOf(amount));

           System.exit(0);

       } catch (Exception ex) {
View Full Code Here


   * is thrown detailing any missing mappings.
   *
   * @throws ValidationException if any TypeMaps contain unmapped properties
   */
  public void validate() {
    Errors errors = new Errors();
    for (TypeMap<?, ?> typeMap : getTypeMaps()) {
      try {
        typeMap.validate();
      } catch (ValidationException e) {
        errors.merge(e.getErrorMessages());
      }
    }

    errors.throwValidationExceptionIfErrorsExist();
  }
View Full Code Here

      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();
  }
View Full Code Here

   * Creates a Number for the {@code source} and {@code destinationType}.
   */
  Number numberFor(String source, Class<?> destinationType) {
    String sourceString = source.trim();
    if (sourceString.length() == 0)
      throw new Errors().errorMapping(source, destinationType).toMappingException();

    try {
      if (destinationType.equals(Byte.class))
        return Byte.valueOf(source);
      if (destinationType.equals(Short.class))
        return Short.valueOf(source);
      if (destinationType.equals(Integer.class))
        return Integer.valueOf(source);
      if (destinationType.equals(Long.class))
        return Long.valueOf(source);
      if (destinationType.equals(Float.class))
        return Float.valueOf(source);
      if (destinationType.equals(Double.class))
        return Double.valueOf(source);
      if (destinationType.equals(BigDecimal.class))
        return new BigDecimal(source);
      if (destinationType.equals(BigInteger.class))
        return new BigInteger(source);
    } catch (Exception e) {
      throw new Errors().errorMapping(source, destinationType, e).toMappingException();
    }

    throw new Errors().errorMapping(source, destinationType).toMappingException();
  }
View Full Code Here

    for (int i = 0; i < FALSE_STRINGSS.length; i++)
      if (FALSE_STRINGSS[i].equals(stringValue))
        return Boolean.FALSE;

    throw new Errors().errorMapping(context.getSource(), context.getDestinationType())
        .toMappingException();
  }
View Full Code Here

    if (destinationType.equals(Time.class))
      return new Time(source);
    if (destinationType.equals(Timestamp.class))
      return new Timestamp(source);

    throw new Errors().errorMapping(source, destinationType).toMappingException();
  }
View Full Code Here

  }

  Date dateFor(String source, Class<?> destinationType) {
    String sourceString = toString().trim();
    if (sourceString.length() == 0)
      throw new Errors().errorMapping(source, destinationType).toMappingException();

    if (destinationType.equals(java.sql.Date.class)) {
      try {
        return java.sql.Date.valueOf(source);
      } catch (IllegalArgumentException e) {
        throw new Errors().addMessage(
            "String must be in JDBC format [yyyy-MM-dd] to create a java.sql.Date")
            .toMappingException();
      }
    }

    if (destinationType.equals(Time.class)) {
      try {
        return Time.valueOf(source);
      } catch (IllegalArgumentException e) {
        throw new Errors().addMessage(
            "String must be in JDBC format [HH:mm:ss] to create a java.sql.Time")
            .toMappingException();
      }
    }

    if (destinationType.equals(Timestamp.class)) {
      try {
        return Timestamp.valueOf(source);
      } catch (IllegalArgumentException e) {
        throw new Errors().addMessage(
            "String must be in JDBC format [yyyy-MM-dd HH:mm:ss.fffffffff] "
                + "to create a java.sql.Timestamp").toMappingException();
      }
    }

    throw new Errors().errorMapping(source, destinationType).toMappingException();
  }
View Full Code Here

  private static DatatypeFactory getDataTypeFactory() {
    if (dataTypeFactory == null) {
      try {
        dataTypeFactory = DatatypeFactory.newInstance();
      } catch (DatatypeConfigurationException e) {
        throw new Errors().addMessage(e,
            "Failed to create DataTypeFactory required for XMLGregorianCalendar conversion")
            .toMappingException();
      }
    }
View Full Code Here

      return null;

    Class<?> destinationType = context.getDestinationType();
    if (!Calendar.class.isAssignableFrom(destinationType)
        && !destinationType.equals(XMLGregorianCalendar.class))
      throw new Errors().errorMapping(source, destinationType).toMappingException();

    GregorianCalendar calendar = new GregorianCalendar();

    if (source instanceof Date)
      calendar.setTimeInMillis(((Date) source).getTime());
View Full Code Here

TOP

Related Classes of org.modelmapper.internal.Errors$Converter

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.