public boolean evaluate(QName element, XMLAttributes attributes, NamespaceContext nsContext) throws Exception { Object obj = getValue(attributes, nsContext); // Implement XPath fn:boolean() function: // If $arg is the empty sequence, fn:boolean returns false. // TODO: how is this checked? if (obj == null) { return false; } // If $arg is a sequence whose first item is a node, fn:boolean returns true. // TODO: how to implement this? // If $arg is a singleton value of type xs:boolean or a derived from xs:boolean, fn:boolean returns $arg. if (obj instanceof Boolean) { return ((Boolean)obj).booleanValue(); } // If $arg is a singleton value of type xs:string or a type derived from xs:string, xs:anyURI or a type derived from xs:anyURI or xs:untypedAtomic, fn:boolean returns false if the operand value has zero length; otherwise it returns true. if (obj instanceof String) { return ((String)obj).length() > 0; } // If $arg is a singleton value of any numeric type or a type derived from a numeric type, fn:boolean returns false if the operand value is NaN or is numerically equal to zero; otherwise it returns true. // TODO: should check type and handle different numeric types differntly if (obj instanceof Double) { return ((Double)obj).doubleValue() != 0; } // In all other cases, fn:boolean raises a type error [err:FORG0006]. // TODO: need to distinguish between node (true) and other simple types (false). return true; }
private XPathSyntaxTreeNode CastExpr() throws XPathException { XPathSyntaxTreeNode n; QName name; n = SimpleValue(); switch ((nextTokenIndex == -1) ? nextToken() : nextTokenIndex) { case KEYWORD_CAST: consumeToken(KEYWORD_CAST); consumeToken(KEYWORD_AS); name = QName(); switch ((nextTokenIndex == -1) ? nextToken() : nextTokenIndex) { case SYMBOL_QUESTION: consumeToken(SYMBOL_QUESTION); break; default: array1[6] = gen; } return new CastNode(n, name); default: array1[7] = gen; } return n; }
public Object getValue(XMLAttributes attributes, NamespaceContext nsContext) throws Exception { XSSimpleType type = getSimpleType(); Object obj; if (child.getType() == TYPE_UNTYPED) { //attribute cast String attrValue = child.getValue(attributes, nsContext).toString(); obj = type.validate(attrValue, null, null); } else { //literal cast (perform using the string value of the literal node) obj = type.validate(child.getStringValue(), null, null); } //Workaround (this is here because double validator can only validate double values) if (type.getNumeric()) { obj = dvFactory.getBuiltInType("double").validate(obj, null, null); } return obj; }
private XPathSyntaxTreeNode ValueExpr() throws XPathException { switch ((nextTokenIndex == -1) ? nextToken() : nextTokenIndex) { case NCNAME: QName name = QName(); consumeToken(OPEN_PARAN); XPathSyntaxTreeNode n1 = SimpleValue(); consumeToken(CLOSE_PARAN); return new CastNode(n1, name); case SYMBOL_AT: case NUMERIC_LITERAL: case STRING_LITERAL: return CastExpr(); default: array1[3] = gen; consumeToken(-1); throw new XPathException("c-general-xpath"); } }
n1 = new CastNode(n1, name); switch ((nextTokenIndex == -1) ? nextToken() : nextTokenIndex) { case SYMBOL_EQ: