protected NodeValue cast(String s, NodeValue nv, XSDDatatype castType2) { // Plain cast. if (!castType.isValid(s)) throw new ExprEvalException("CastXSD: Not a valid literal form: " + s); // Unfortunately, validity testing happens in NodeValue.makeNode as well. return NodeValue.makeNode(s, castType); }
protected NodeValue cast(String s, NodeValue nv, XSDDatatype castType2) { if (whitespaceSurroundAllowed) // Maybe more convenient, but is not strictly correct. s = s.trim(); else { // Correct mode. No white space allowed around values types numeric, boolean, dateTime, ... // See also "JenaParameters.enableWhitespaceCheckingOfTypedLiterals" which defaults to false // (accept surrounding whitespace) // This CastXSD - not need to check it is an XSD datatype. // if ( castType.getURI().startsWith(XSDDatatype.XSD) && if (castType instanceof XSDBaseNumericType || castType.equals(XSDDatatype.XSDfloat) || castType.equals(XSDDatatype.XSDdouble) || castType.equals(XSDDatatype.XSDboolean) || castType instanceof XSDAbstractDateTimeType) // Includes durations, and Gregorian { if (s.startsWith(" ") || s.endsWith(" ")) throw new ExprEvalException( "CastXSD: Not a valid literal form (has whitespace): '" + s + "'"); } } // Plain cast. try { if (!castType.isValid(s)) throw new ExprEvalException("CastXSD: Not a valid literal form: '" + s + "'"); // Unfortunately, validity testing happens in NodeValue.makeNode as well. // but better error messages this way. return NodeValue.makeNode(s, castType); } catch (RuntimeException ex) { throw new ExprEvalException("CastXSD: Not a strictly valid literal form: '" + s + "'"); } }