Package br.com.caelum.iogi.exceptions

Examples of br.com.caelum.iogi.exceptions.ConversionException


      return instantiateFromName(enumClass, stringValue, to);
  }

  private void ensureTargetIsAnEnum(final Target<?> to) {
    if (!Enum.class.isAssignableFrom(to.getClassType()))
      throw new ConversionException("Target %s does not represent a Java enum.", to);
  }
View Full Code Here


    try {
      final Object[] enumConstants = enumClass.getEnumConstants();
      final int ordinal = Integer.parseInt(ordinalAsString);
      return enumConstants[ordinal];
    } catch (final Exception e) {
      throw new ConversionException("Failed to interpret '%s' as an ordinal index into enum '%s' " +
          "(when trying to fulfill target %s)",
          ordinalAsString, enumClass.getName(), to);
    }
  }
View Full Code Here

  private Object instantiateFromName(final Class<?> type, final String name, final Target<?> to) {
    try {
      final Class<? extends Enum> enumClass = (Class<? extends Enum>) type;
      return Enum.valueOf(enumClass, name);
    } catch (final IllegalArgumentException iae) {
      throw new ConversionException("Attempted to convert '%s' to an enum value of type '%s' " +
          "(when trying to fulfill target %s)",
          name, type.getName(), to);
    }
  }
View Full Code Here

    }
    catch (final ConversionException e) {
      throw e;
    }
    catch (final Exception e) {
      throw new ConversionException(e, "Exception when trying to convert '%s' to a '%s' named '%s'", stringValue, target.getType(), target.getName());
    }
  }
View Full Code Here

      return instantiateFromName(enumClass, stringValue, to);
  }

  private void ensureTargetIsAnEnum(final Target<?> to) {
    if (!Enum.class.isAssignableFrom(to.getClassType()))
      throw new ConversionException("Target %s does not represent a Java enum.", to);
  }
View Full Code Here

    try {
      final Object[] enumConstants = enumClass.getEnumConstants();
      final int ordinal = Integer.parseInt(ordinalAsString);
      return enumConstants[ordinal];
    } catch (final Exception e) {
      throw new ConversionException("Failed to interpret '%s' as an ordinal index into enum '%s' " +
          "(when trying to fulfill target %s)",
          ordinalAsString, enumClass.getName(), to);
    }
  }
View Full Code Here

  private Object instantiateFromName(final Class<?> type, final String name, final Target<?> to) {
    try {
      final Class<? extends Enum> enumClass = (Class<? extends Enum>) type;
      return Enum.valueOf(enumClass, name);
    } catch (final IllegalArgumentException iae) {
      throw new ConversionException("Attempted to convert '%s' to an enum value of type '%s' " +
          "(when trying to fulfill target %s)",
          name, type.getName(), to);
    }
  }
View Full Code Here

  }

  @Override
  protected Character convert(final String stringValue, final Target<?> to) {
    if (stringValue.length() != 1)
      throw new ConversionException("Cannot convert string \"%s\" to a single character (in order to fulfill %s).", stringValue, to);
    return stringValue.charAt(0);
  }
View Full Code Here

TOP

Related Classes of br.com.caelum.iogi.exceptions.ConversionException

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.