public Calendar evaluateAsDate(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException { String literal = evaluateAsString(cexp, context); try { return ISO8601DateParser.parseCal(literal); } catch (Exception ex) { String errmsg = "Invalid date: " + literal; __log.error(errmsg, ex); throw new FaultException(cexp.getOwner().constants.qnInvalidExpressionValue, errmsg); } }
public static Object toJavaObject(QName type, String value) { String foundType = null; try { if (isDecimal(type)) { foundType = "number"; return Long.valueOf(value); } else if (isFloat(type)) { foundType = "double"; return Double.valueOf(value); } else if (isBoolean(type)) { foundType = "boolean"; return Boolean.valueOf(value); } else if (isFloat(type)) { foundType = "double"; return Double.valueOf(value); } else if (isDate(type)) { foundType = "date"; return ISO8601DateParser.parseCal(value); } else if (isString(type)) { foundType = "string"; return value; } } catch (Exception nfe) { throw new IllegalArgumentException("The type " + foundType + " has been detected using the XSD type " + type + " but the parsing failed! The provided value is probably not of the right type:" + nfe.toString()); } throw new IllegalArgumentException("Couldn't find java type for " + type); }
public Calendar evaluateAsDate(OExpression cexp, EvaluationContext context) throws FaultException, EvaluationException { List literal = DOMUtils.toList(evaluate(cexp, context)); if (literal.size() == 0) throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "No results for expression: " + cexp); if (literal.size() > 1) throw new FaultException(cexp.getOwner().constants.qnSelectionFailure, "Multiple results for expression: " + cexp); Object date =literal.get(0); if (date instanceof Calendar) return (Calendar) date; if (date instanceof Date) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) date); return cal; } if (date instanceof Element) date = ((Element) date).getTextContent(); if (date instanceof Text) date = ((Text) date).getTextContent(); try { return ISO8601DateParser.parseCal(date.toString()); } catch (Exception ex) { String errmsg = "Invalid date: " + literal; __log.error(errmsg, ex); throw new FaultException(cexp.getOwner().constants.qnInvalidExpressionValue,errmsg); } }
return ISO8601DateParser.parseCal(date.toString()); } catch (Exception ex) { String errmsg = "Invalid date: " + literal;