public BigDecimal getDecimal() { raise(new ExprEvalTypeException("Not a decimal: "+this)) ; return null ; } public float getFloat() { raise(new ExprEvalTypeException("Not a float: "+this)) ; return Float.NaN ; }
public BigInteger getInteger() { raise(new ExprEvalTypeException("Not an integer: "+this)) ; return null ; } public BigDecimal getDecimal() { raise(new ExprEvalTypeException("Not a decimal: "+this)) ; return null ; }
public double getDouble() { raise(new ExprEvalTypeException("Not a double: "+this)) ; return Double.NaN ; } // Value representation for all date and time values.
public String getString() { raise(new ExprEvalTypeException("Not a string: "+this)) ; return null ; } public String getLang() { raise(new ExprEvalTypeException("Not a string: "+this)) ; return null ; }
public float getFloat() { raise(new ExprEvalTypeException("Not a float: "+this)) ; return Float.NaN ; } public double getDouble() { raise(new ExprEvalTypeException("Not a double: "+this)) ; return Double.NaN ; }
public boolean getBoolean() { raise(new ExprEvalTypeException("Not a boolean: "+this)) ; return false ; } public String getString() { raise(new ExprEvalTypeException("Not a string: "+this)) ; return null ; }
public String getLang() { raise(new ExprEvalTypeException("Not a string: "+this)) ; return null ; } public NodeValueSortKey getSortKey() { raise(new ExprEvalTypeException("Not a sort key: "+this)) ; return null ; }
public XMLGregorianCalendar getDateTime() { raise(new ExprEvalTypeException("No DateTime value: "+this)) ; return null ; } public Duration getDuration() { raise(new ExprEvalTypeException("Not a duration: "+this)) ; return null ; }
public NodeValueSortKey getSortKey() { raise(new ExprEvalTypeException("Not a sort key: "+this)) ; return null ; }
public Duration getDuration() { raise(new ExprEvalTypeException("Not a duration: "+this)) ; return null ; }
private void forceToNode() { if ( node == null ) node = asNode() ; if ( node == null ) raise(new ExprEvalException("Not a node: "+this)) ; }
public static String lang(Node node) { if ( !node.isLiteral() ) NodeValue.raise(new ExprTypeException("lang: Not a literal: " + FmtUtils.stringForNode(node))) ; String s = node.getLiteralLanguage() ; if ( s == null ) s = "" ; return s ; }
public static String str(Node node) { if ( node.isLiteral() ) return node.getLiteral().getLexicalForm() ; if ( node.isURI() ) return node.getURI() ; // if ( node.isBlank() ) return node.getBlankNodeId().getLabelString() ; // if ( node.isBlank() ) return "" ; if ( node.isBlank() ) NodeValue.raise(new ExprTypeException("Blank node: " + node)) ; NodeValue.raise(new ExprEvalException("Not a string: " + node)) ; return "[undef]" ; }
public static Node datatype(Node node) { if ( !node.isLiteral() ) { NodeValue.raise(new ExprTypeException("datatype: Not a literal: " + node)) ; return null ; } String s = node.getLiteralDatatypeURI() ; boolean plainLiteral = (s == null || s.equals("")) ; if ( plainLiteral ) { boolean simpleLiteral = (node.getLiteralLanguage() == null || node.getLiteralLanguage().equals("")) ; if ( !simpleLiteral ) return NodeConst.rdfLangString ; return XSD.xstring.asNode() ; } return NodeFactory.createURI(s) ; }
public static boolean rdfTermEquals(Node n1, Node n2) { if ( n1.equals(n2) ) return true ; if ( n1.isLiteral() && n2.isLiteral() ) { // Two literals, may be sameTerm by language tag case insensitivity. String lang1 = n1.getLiteralLanguage() ; String lang2 = n2.getLiteralLanguage() ; if ( !lang1.equals("") && lang1.equalsIgnoreCase(lang2) ) { // Two language tags, equal by case insensitivity. boolean b = n1.getLiteralLexicalForm().equals(n2.getLiteralLexicalForm()) ; if ( b ) return true ; } // Two literals, different terms, different language tags. NodeValue.raise(new ExprEvalException("Mismatch in RDFterm-equals: " + n1 + ", " + n2)) ; } // One or both not a literal. return false ; }
public static NodeValue lang(NodeValue nv) { if ( nv.isLangString() ) return NodeValue.makeString(nv.getLang()) ; if ( nv.isLiteral() ) return NodeValue.nvEmptyString ; NodeValue.raise(new ExprTypeException("lang: Not a literal: " + nv.asQuotedString())) ; return null ; }
/** LANGMATCHES * * @param nv The language string * @param langPattern The pattern to match against * @return Boolean nodeValue */ public static NodeValue langMatches(NodeValue nv, String langPattern) { Node node = nv.asNode() ; if ( !node.isLiteral() ) { NodeValue.raise(new ExprTypeException("langMatches: not a literal: " + node)) ; return null ; } String langStr = node.getLiteralLexicalForm() ; return NodeValue.booleanReturn(langMatches(langStr, langPattern)); }
/** {@literal F&O} fn:boolean */ public static boolean booleanEffectiveValue(NodeValue nv) { // Apply the "boolean effective value" rules // boolean: value of the boolean (strictly, if derived from xsd:boolean) // plain literal: lexical form length(string) > 0 // numeric: number != Nan && number != 0 // http://www.w3.org/TR/xquery/#dt-ebv if ( nv.isBoolean() ) return nv.getBoolean() ; if ( nv.isString() || nv.isLangString() ) // Plain literals. return ! nv.getString().isEmpty() ; if ( nv.isInteger() ) return !nv.getInteger().equals(BigInteger.ZERO) ; if ( nv.isDecimal() ) return !nv.getDecimal().equals(BigDecimal.ZERO) ; if ( nv.isDouble() ) return nv.getDouble() != 0.0 ; NodeValue.raise(new ExprEvalException("Not a boolean effective value (wrong type): " + nv)) ; // Does not return return false ; }