/** * Convert a String to a URI. * * @param sourceObject * @return * @throws ConversionException */ protected java.net.URI convertObjectToURI(Object sourceObject) throws ConversionException { if (sourceObject instanceof String) { try { return new java.net.URI((String) sourceObject); } catch (Exception ex) { } } throw ConversionException.couldNotBeConverted(sourceObject, java.net.URI.class); }
public static ConversionException couldNotBeConverted(Object mapping, Object descriptor, ConversionException exception) { Object sourceObject = exception.getSourceObject(); Class javaClass = exception.getClassToConvertTo(); Exception original = (Exception)exception.getInternalException(); Object[] args = { sourceObject, sourceObject.getClass(), mapping, descriptor, javaClass }; String message = ExceptionMessageGenerator.buildMessage(ConversionException.class, COULD_NOT_BE_CONVERTED_EXTENDED, args); ConversionException conversionException = new ConversionException(message, sourceObject, javaClass, original); conversionException.setStackTrace(exception.getStackTrace()); conversionException.setErrorCode(COULD_NOT_BE_CONVERTED_EXTENDED); return conversionException; }
public static ConversionException incorrectDateTimeFormat(String dateTimeString) { return incorrectDateTimeFormat(dateTimeString, Calendar.class); }
public static ConversionException incorrectTimeFormat(String timeString) { Object[] args = { timeString }; String message = ExceptionMessageGenerator.buildMessage(ConversionException.class, INCORRECT_TIME_FORMAT, args); ConversionException conversionException = new ConversionException(message, timeString, java.sql.Time.class, null); conversionException.setErrorCode(INCORRECT_TIME_FORMAT); return conversionException; }
} catch (Exception ex) { if (XMLConstants.DATE_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectDateFormat(sourceString); } else if (XMLConstants.TIME_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectTimeFormat(sourceString); } else if (XMLConstants.G_DAY_QNAME.equals(schemaTypeQName)) { throw XMLConversionException.incorrectGDayFormat(sourceString); throw new IllegalArgumentException(); } else { throw ConversionException.incorrectDateTimeFormat(sourceString); return xmlGregorianCalender; } else { throw ConversionException.incorrectDateFormat(sourceString); throw ConversionException.incorrectTimeFormat(sourceString); } else if (XMLConstants.G_DAY_QNAME.equals(schemaTypeQName)) { throw XMLConversionException.incorrectGDayFormat(sourceString); throw new IllegalArgumentException(); } else if (XMLConstants.DATE_TIME_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectDateTimeFormat(sourceString);
/** * Build a valid Class from the string that is passed in * @param sourceObject Valid instance of String */ protected Class convertObjectToClass(Object sourceObject) throws ConversionException { Class theClass = null; if (!(sourceObject instanceof String)) { throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CLASS); } try { // bug # 2799318 theClass = getPrimitiveClass((String)sourceObject); if (theClass == null) { theClass = Class.forName((String)sourceObject, true, getLoader()); } } catch (Exception exception) { throw ConversionException.couldNotBeConvertedToClass(sourceObject, ClassConstants.CLASS, exception); } return theClass; }
/** * Convert the HEX string to a byte array. * HEX allows for binary data to be printed. */ public static byte[] buildBytesFromHexString(String hex) { String tmpString = hex; if ((tmpString.length() % 2) != 0) { throw ConversionException.couldNotConvertToByteArray(hex); } byte[] bytes = new byte[tmpString.length() / 2]; int byteIndex; int strIndex; byte digit1; byte digit2; for (byteIndex = bytes.length - 1, strIndex = tmpString.length() - 2; byteIndex >= 0; byteIndex--, strIndex -= 2) { digit1 = (byte)Character.digit(tmpString.charAt(strIndex), 16); digit2 = (byte)Character.digit(tmpString.charAt(strIndex + 1), 16); if ((digit1 == -1) || (digit2 == -1)) { throw ConversionException.couldNotBeConverted(hex, ClassConstants.APBYTE); } bytes[byteIndex] = (byte)((digit1 * 16) + digit2); } return bytes; }
dateStringTokenizer = new StringTokenizer(dateString, "- "); } else { throw ConversionException.incorrectDateFormat(dateString); day = Integer.parseInt(dateStringTokenizer.nextToken()); } catch (NumberFormatException exception) { throw ConversionException.incorrectDateFormat(dateString);
public ObjectGraph createObjectGraph(String typeName) { ClassLoader loader = this.contextInput.classLoader; try { Class cls = PrivilegedAccessHelper.getClassForName(typeName, true, loader); return createObjectGraph(cls); } catch (Exception ex) { throw ConversionException.couldNotBeConvertedToClass(typeName, Class.class, ex); } }
public static ConversionException incorrectTimestampFormat(String timestampString) { Object[] args = { timestampString }; String message = ExceptionMessageGenerator.buildMessage(ConversionException.class, INCORRECT_TIMESTAMP_FORMAT, args); ConversionException conversionException = new ConversionException(message, timestampString, java.sql.Timestamp.class, null); conversionException.setErrorCode(INCORRECT_TIMESTAMP_FORMAT); return conversionException; }
} catch (Exception ex) { if (Constants.DATE_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectDateFormat(sourceString); } else if (Constants.TIME_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectTimeFormat(sourceString); } else if (Constants.G_DAY_QNAME.equals(schemaTypeQName)) { throw XMLConversionException.incorrectGDayFormat(sourceString); throw new IllegalArgumentException(); } else { throw ConversionException.incorrectDateTimeFormat(sourceString); return xmlGregorianCalender; } else { throw ConversionException.incorrectDateFormat(sourceString); throw ConversionException.incorrectTimeFormat(sourceString); } else if (Constants.G_DAY_QNAME.equals(schemaTypeQName)) { throw XMLConversionException.incorrectGDayFormat(sourceString); throw new IllegalArgumentException(); } else if (Constants.DATE_TIME_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectDateTimeFormat(sourceString);
/** * Build a valid Class from the string that is passed in * @param sourceObject Valid instance of String */ protected Class convertObjectToClass(Object sourceObject) throws ConversionException { Class theClass = null; if (!(sourceObject instanceof String)) { throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CLASS); } try { // bug # 2799318 theClass = getPrimitiveClass((String)sourceObject); if (theClass == null) { theClass = Class.forName((String)sourceObject, true, getLoader()); } } catch (Exception exception) { throw ConversionException.couldNotBeConvertedToClass(sourceObject, ClassConstants.CLASS, exception); } return theClass; }
/** * Convert the HEX string to a byte array. * HEX allows for binary data to be printed. */ public static byte[] buildBytesFromHexString(String hex) { String tmpString = hex; if ((tmpString.length() % 2) != 0) { throw ConversionException.couldNotConvertToByteArray(hex); } byte[] bytes = new byte[tmpString.length() / 2]; int byteIndex; int strIndex; byte digit1; byte digit2; for (byteIndex = bytes.length - 1, strIndex = tmpString.length() - 2; byteIndex >= 0; byteIndex--, strIndex -= 2) { digit1 = (byte)Character.digit(tmpString.charAt(strIndex), 16); digit2 = (byte)Character.digit(tmpString.charAt(strIndex + 1), 16); if ((digit1 == -1) || (digit2 == -1)) { throw ConversionException.couldNotBeConverted(hex, ClassConstants.APBYTE); } bytes[byteIndex] = (byte)((digit1 * 16) + digit2); } return bytes; }
dateStringTokenizer = new StringTokenizer(dateString, "- "); } else { throw ConversionException.incorrectDateFormat(dateString); day = Integer.parseInt(dateStringTokenizer.nextToken()); } catch (NumberFormatException exception) { throw ConversionException.incorrectDateFormat(dateString);
public ObjectGraph createObjectGraph(String typeName) { ClassLoader loader = this.contextInput.classLoader; try { Class cls = PrivilegedAccessHelper.getClassForName(typeName, true, loader); return createObjectGraph(cls); } catch (Exception ex) { throw ConversionException.couldNotBeConvertedToClass(typeName, Class.class, ex); } }
public static ConversionException couldNotBeConverted(Object mapping, Object descriptor, ConversionException exception) { Object sourceObject = exception.getSourceObject(); Class javaClass = exception.getClassToConvertTo(); Exception original = (Exception)exception.getInternalException(); Object[] args = { sourceObject, sourceObject.getClass(), mapping, descriptor, javaClass }; String message = ExceptionMessageGenerator.buildMessage(ConversionException.class, COULD_NOT_BE_CONVERTED_EXTENDED, args); ConversionException conversionException = new ConversionException(message, sourceObject, javaClass, original); conversionException.setStackTrace(exception.getStackTrace()); conversionException.setErrorCode(COULD_NOT_BE_CONVERTED_EXTENDED); return conversionException; }
public static ConversionException incorrectDateFormat(String dateString) { Object[] args = { dateString }; String message = ExceptionMessageGenerator.buildMessage(ConversionException.class, INCORRECT_DATE_FORMAT, args); ConversionException conversionException = new ConversionException(message, dateString, java.sql.Date.class, null); conversionException.setErrorCode(INCORRECT_DATE_FORMAT); return conversionException; }
/** * Convert a String to a URI. * * @param sourceObject * @return * @throws ConversionException */ protected java.net.URI convertObjectToURI(Object sourceObject) throws ConversionException { if (sourceObject instanceof String) { try { return new java.net.URI((String) sourceObject); } catch (Exception ex) { } } throw ConversionException.couldNotBeConverted(sourceObject, java.net.URI.class); }
} catch (Exception ex) { if (Constants.DATE_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectDateFormat(sourceString); } else if (Constants.TIME_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectTimeFormat(sourceString); } else if (Constants.G_DAY_QNAME.equals(schemaTypeQName)) { throw XMLConversionException.incorrectGDayFormat(sourceString); throw new IllegalArgumentException(); } else { throw ConversionException.incorrectDateTimeFormat(sourceString); return xmlGregorianCalender; } else { throw ConversionException.incorrectDateFormat(sourceString); throw ConversionException.incorrectTimeFormat(sourceString); } else if (Constants.G_DAY_QNAME.equals(schemaTypeQName)) { throw XMLConversionException.incorrectGDayFormat(sourceString); throw new IllegalArgumentException(); } else if (Constants.DATE_TIME_QNAME.equals(schemaTypeQName)) { throw ConversionException.incorrectDateTimeFormat(sourceString);
/** * Build a valid Class from the string that is passed in * @param sourceObject Valid instance of String */ protected Class convertObjectToClass(Object sourceObject) throws ConversionException { Class theClass = null; if (!(sourceObject instanceof String)) { throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CLASS); } try { // bug # 2799318 theClass = getPrimitiveClass((String)sourceObject); if (theClass == null) { theClass = Class.forName((String)sourceObject, true, getLoader()); } } catch (Exception exception) { throw ConversionException.couldNotBeConvertedToClass(sourceObject, ClassConstants.CLASS, exception); } return theClass; }