/** * Turn a possible numeric token into typed literal else a plain literal * @return the constructed literal node */ Node parseNumber(String lit) { if ( Character.isDigit(lit.charAt(0)) || (lit.charAt(0) == '-' && lit.length() > 1 && Character.isDigit(lit.charAt(1))) ) { if (lit.indexOf(".") != -1) { // Float? if (XSDDatatype.XSDfloat.isValid(lit)) { return NodeFactory.createLiteral(lit, "", XSDDatatype.XSDfloat); } } else { // Int? if (XSDDatatype.XSDint.isValid(lit)) { return NodeFactory.createLiteral(lit, "", XSDDatatype.XSDint); } } } // Default is a plain literal return NodeFactory.createLiteral(lit, "", false); }
/** * Test whether the given LiteralLabel is a valid instance * of this datatype. This takes into accound typing information * as well as lexical form - for example an xsd:string is * never considered valid as an xsd:integer (even if it is * lexically legal like "1"). */ @Override public boolean isValidLiteral(LiteralLabel lit) { return isBaseTypeCompatible(lit) && isValid(lit.getLexicalForm()); }
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) ; } }
if ( ! castType.isValid(s) ) throw new ExprEvalException("CastXSD: Not a valid literal form: '"+s+"'") ;