Package jodd.typeconverter

Examples of jodd.typeconverter.TypeConversionException


    try {
      long milliseconds = Long.parseLong(stringValue);
      return new Date(milliseconds);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here


        } else {
          return new HashSet<T>();
        }
      }

      throw new TypeConversionException("Unknown collection: " + collectionType.getName());
    }
    if (length > 0) {
      try {
        Constructor<Collection<T>> ctor = (Constructor<Collection<T>>) collectionType.getConstructor(int.class);
        return ctor.newInstance(Integer.valueOf(length));
      } catch (Exception ex) {
        // ignore exception
      }
    }

    try {
      return collectionType.newInstance();
    } catch (Exception ex) {
      throw new TypeConversionException(ex);
    }
  }
View Full Code Here

    }
    try {
      long milliseconds = Long.parseLong(stringValue);
      return new JDateTime(milliseconds);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

    // try yyyy-mm-dd for valueOf
    if (StringUtil.containsOnlyDigits(stringValue) == false) {
      try {
        return Date.valueOf(stringValue);
      } catch (IllegalArgumentException iaex) {
        throw new TypeConversionException(value, iaex);
      }
    }

    // assume string to be a number
    try {
      long milliseconds = Long.parseLong(stringValue);
      return new Date(milliseconds);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

      try {
        File tempFile = FileUtil.createTempFile();
        FileUtil.writeBytes(tempFile, (byte[])value);
        return tempFile;
      } catch (IOException ioex) {
        throw new TypeConversionException(ioex);
      }
    }
    if (type == String.class) {
      try {
        File tempFile = FileUtil.createTempFile();
        FileUtil.writeString(tempFile, value.toString());
        return tempFile;
      } catch (IOException ioex) {
        throw new TypeConversionException(ioex);
      }
    }
    throw new TypeConversionException(value);
  }
View Full Code Here

    // try yyyy-mm-dd for valueOf
    if (StringUtil.containsOnlyDigits(stringValue) == false) {
      try {
        return Time.valueOf(stringValue);
      } catch (IllegalArgumentException iaex) {
        throw new TypeConversionException(value, iaex);
      }
    }

    // assume string to be a number
    try {
      long milliseconds = Long.parseLong(stringValue);
      return new Time(milliseconds);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

      return new BigInteger(String.valueOf(((Number)value).longValue()));
    }
    try {
      return new BigInteger(value.toString().trim());
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

      if (StringUtil.startsWithChar(stringValue, '+')) {
        stringValue = stringValue.substring(1);
      }
      return Short.valueOf(stringValue);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

    if (value instanceof URL) {
      URL url = (URL) value;
      try {
        return url.toURI();
      } catch (URISyntaxException usex) {
        throw new TypeConversionException(value, usex);
      }
    }

    try {
      return new URI(value.toString());
    } catch (URISyntaxException usex) {
      throw new TypeConversionException(value, usex);
    }
  }
View Full Code Here

    // try yyyy-mm-dd for valueOf
    if (StringUtil.containsOnlyDigits(stringValue) == false) {
      try {
        return Timestamp.valueOf(stringValue);
      } catch (IllegalArgumentException iaex) {
        throw new TypeConversionException(value, iaex);
      }
    }

    // assume string to be a number
    try {
      long milliseconds = Long.parseLong(stringValue);
      return new Timestamp(milliseconds);
    } catch (NumberFormatException nfex) {
      throw new TypeConversionException(value, nfex);
    }
  }
View Full Code Here

TOP

Related Classes of jodd.typeconverter.TypeConversionException

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.