|
From: <del...@us...> - 2010-10-30 15:18:13
|
Revision: 13063
http://exist.svn.sourceforge.net/exist/?rev=13063&view=rev
Author: deliriumsky
Date: 2010-10-30 15:18:04 +0000 (Sat, 30 Oct 2010)
Log Message:
-----------
Further work on improving error codes and error values for try/catch
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/Namespaces.java
branches/adam/eXist-xq3/src/org/exist/xquery/CastExpression.java
branches/adam/eXist-xq3/src/org/exist/xquery/CastableExpression.java
branches/adam/eXist-xq3/src/org/exist/xquery/DynamicAttributeConstructor.java
branches/adam/eXist-xq3/src/org/exist/xquery/DynamicCommentConstructor.java
branches/adam/eXist-xq3/src/org/exist/xquery/DynamicTypeCheck.java
branches/adam/eXist-xq3/src/org/exist/xquery/ElementConstructor.java
branches/adam/eXist-xq3/src/org/exist/xquery/EnclosedExpr.java
branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java
branches/adam/eXist-xq3/src/org/exist/xquery/Except.java
branches/adam/eXist-xq3/src/org/exist/xquery/ExternalModuleImpl.java
branches/adam/eXist-xq3/src/org/exist/xquery/ForExpr.java
branches/adam/eXist-xq3/src/org/exist/xquery/Function.java
branches/adam/eXist-xq3/src/org/exist/xquery/Intersection.java
branches/adam/eXist-xq3/src/org/exist/xquery/NodeComparison.java
branches/adam/eXist-xq3/src/org/exist/xquery/OpNumeric.java
branches/adam/eXist-xq3/src/org/exist/xquery/PIConstructor.java
branches/adam/eXist-xq3/src/org/exist/xquery/PathExpr.java
branches/adam/eXist-xq3/src/org/exist/xquery/Step.java
branches/adam/eXist-xq3/src/org/exist/xquery/Union.java
branches/adam/eXist-xq3/src/org/exist/xquery/UserDefinedFunction.java
branches/adam/eXist-xq3/src/org/exist/xquery/VariableReference.java
branches/adam/eXist-xq3/src/org/exist/xquery/XQueryContext.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/ExtCollection.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunBaseURI.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunCodepointsToString.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunIdRef.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunLang.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunLocalName.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunName.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunNamespaceURI.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunNodeName.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunNormalizeSpace.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunNormalizeUnicode.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunNumber.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunOneOrMore.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunResolveURI.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunSum.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunTokenize.java
branches/adam/eXist-xq3/src/org/exist/xquery/pragmas/ForceIndexUse.java
branches/adam/eXist-xq3/test/src/org/exist/xmldb/CollectionConfigurationTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/Namespaces.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/Namespaces.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/Namespaces.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -40,9 +40,12 @@
public final static String XQUERY_LOCAL_NS = "http://www.w3.org/2005/xquery-local-functions";
public final static String XPATH_DATATYPES_NS = "http://www.w3.org/2003/05/xpath-datatypes";
- public final static String XQUERY_XPATH_ERROR_NS = "http://www.w3.org/2005/xqt-errors/";
- public final static String XQUERY_XPATH_ERROR_PREFIX = "err";
+ public final static String W3C_XQUERY_XPATH_ERROR_NS = "http://www.w3.org/2005/xqt-errors/";
+ public final static String W3C_XQUERY_XPATH_ERROR_PREFIX = "err";
+ public final static String EXIST_XQUERY_XPATH_ERROR_NS = "http://www.exist-db.org/xqt-errors/";
+ public final static String EXIST_XQUERY_XPATH_ERROR_PREFIX = "exerr";
+
public final static String EXIST_NS = "http://exist.sourceforge.net/NS/exist";
public final static String RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
public final static String DC_NS = "http://purl.org/dc/elements/1.1/";
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/CastExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/CastExpression.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/CastExpression.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -83,11 +83,11 @@
}
//Should be handled by the parser
if (requiredType == Type.ATOMIC || (requiredType == Type.NOTATION && expression.returnsType() != Type.NOTATION)) {
- throw new XPathException(this, "err:XPST0080: cannot cast to " +
+ throw new XPathException(this, ErrorCodes.XPST0080, "Cannot cast to " +
Type.getTypeName(requiredType));
}
if (requiredType == Type.ANY_SIMPLE_TYPE || expression.returnsType() == Type.ANY_SIMPLE_TYPE || requiredType == Type.UNTYPED || expression.returnsType() == Type.UNTYPED) {
- throw new XPathException(this, "err:XPST0051: cannot cast to " +
+ throw new XPathException(this, ErrorCodes.XPST0051, "Cannot cast to " +
Type.getTypeName(requiredType));
}
@@ -102,7 +102,7 @@
Item item = seq.itemAt(0);
if (seq.hasMany() && Type.subTypeOf(requiredType, Type.ATOMIC))
- throw new XPathException(this, "err:XPTY0004: cardinality error: sequence with more than one item is not allowed here");
+ throw new XPathException(this, ErrorCodes.XPTY0004, "Cardinality error: sequence with more than one item is not allowed here", seq);
try {
// casting to QName needs special treatment
if(requiredType == Type.QNAME) {
@@ -111,8 +111,8 @@
else if(item.getType() == Type.ATOMIC || Type.subTypeOf(item.getType(), Type.STRING)) {
result = new QNameValue(context, item.getStringValue());
} else {
- throw new XPathException(this, "Cannot cast " + Type.getTypeName(item.getType()) +
- " to xs:QName");
+ throw new XPathException(this, ErrorCodes.XPTY0004, "Cannot cast " + Type.getTypeName(item.getType()) +
+ " to xs:QName", seq);
}
} else
result = item.convertTo(requiredType);
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/CastableExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/CastableExpression.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/CastableExpression.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -96,10 +96,10 @@
}
if (requiredType == Type.ATOMIC || (requiredType == Type.NOTATION && expression.returnsType() != Type.NOTATION))
- throw new XPathException(this, "err:XPST0080: cannot convert to " + Type.getTypeName(requiredType));
+ throw new XPathException(this, ErrorCodes.XPST0080, "Cannot convert to " + Type.getTypeName(requiredType));
if (requiredType == Type.ANY_SIMPLE_TYPE || expression.returnsType() == Type.ANY_SIMPLE_TYPE || requiredType == Type.UNTYPED || expression.returnsType() == Type.UNTYPED)
- throw new XPathException(this, "err:XPST0051: cannot convert to " + Type.getTypeName(requiredType));
+ throw new XPathException(this, ErrorCodes.XPST0051, "Cannot convert to " + Type.getTypeName(requiredType));
Sequence result;
//See : http://article.gmane.org/gmane.text.xml.xquery.general/1413
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/DynamicAttributeConstructor.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/DynamicAttributeConstructor.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/DynamicAttributeConstructor.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -113,12 +113,12 @@
try {
qn = QName.parse(context, nameSeq.getStringValue(), null);
} catch (IllegalArgumentException e) {
- throw new XPathException(this, "XPTY0004 '" + nameSeq.getStringValue() + "' is not a valid attribute name");
+ throw new XPathException(this, ErrorCodes.XPTY0004, nameSeq.getStringValue() + "' is not a valid attribute name");
}
//Not in the specs but... makes sense
if(!XMLChar.isValidName(qn.getLocalName()))
- throw new XPathException(this, "XPTY0004 '" + qn.getLocalName() + "' is not a valid attribute name");
+ throw new XPathException(this, ErrorCodes.XPTY0004, qn.getLocalName() + "' is not a valid attribute name");
String value;
Sequence valueSeq = valueExpr.eval(contextSequence, contextItem);
@@ -139,7 +139,7 @@
int nodeNr = builder.addAttribute(qn, value);
node = builder.getDocument().getAttribute(nodeNr);
} catch (DOMException e) {
- throw new XPathException(this, "err:XQDY0025: element has more than one attribute '" + qn + "'");
+ throw new XPathException(this, ErrorCodes.XQDY0025, "Element has more than one attribute '" + qn + "'");
}
} finally {
if (newDocumentContext)
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/DynamicCommentConstructor.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/DynamicCommentConstructor.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/DynamicCommentConstructor.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -92,7 +92,7 @@
}
if (buf.indexOf("--") != Constants.STRING_NOT_FOUND|| buf.toString().endsWith("-")) {
- throw new XPathException(this, "XQDY0072 '" + buf.toString() + "' is not a valid comment");
+ throw new XPathException(this, ErrorCodes.XQDY0072, buf.toString() + "' is not a valid comment");
}
int nodeNr = builder.comment(buf.toString());
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/DynamicTypeCheck.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/DynamicTypeCheck.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/DynamicTypeCheck.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -90,9 +90,9 @@
item = item.convertTo(requiredType);
//No way
} catch (XPathException e) {
- throw new XPathException(expression, "FOCH0002: Required type is " +
+ throw new XPathException(expression, ErrorCodes.FOCH0002, "Required type is " +
Type.getTypeName(requiredType) + " but got '" + Type.getTypeName(item.getType()) + "(" +
- item.getStringValue() + ")'");
+ item.getStringValue() + ")'", item.toSequence());
}
//Then, if numeric, try to refine the type
//xs:decimal(3) treat as xs:integer
@@ -101,9 +101,9 @@
item = item.convertTo(requiredType);
//No way
} catch (XPathException e) {
- throw new XPathException(expression, "FOCH0002: Required type is " +
+ throw new XPathException(expression, ErrorCodes.FOCH0002, "Required type is " +
Type.getTypeName(requiredType) + " but got '" + Type.getTypeName(item.getType()) + "(" +
- item.getStringValue() + ")'");
+ item.getStringValue() + ")'", item.toSequence());
}
//Then, if duration, try to refine the type
//No test on the type hierarchy ; this has to pass :
@@ -114,9 +114,9 @@
item = item.convertTo(requiredType);
//No way
} catch (XPathException e) {
- throw new XPathException(expression, "FOCH0002: Required type is " +
+ throw new XPathException(expression, ErrorCodes.FOCH0002, "Required type is " +
Type.getTypeName(requiredType) + " but got '" + Type.getTypeName(item.getType()) + "(" +
- item.getStringValue() + ")'");
+ item.getStringValue() + ")'", item.toSequence());
}
//Then, if date, try to refine the type
//No test on the type hierarchy
@@ -126,9 +126,9 @@
item = item.convertTo(requiredType);
//No way
} catch (XPathException e) {
- throw new XPathException(expression, "FOCH0002: Required type is " +
+ throw new XPathException(expression, ErrorCodes.FOCH0002, "Required type is " +
Type.getTypeName(requiredType) + " but got '" + Type.getTypeName(item.getType()) + "(" +
- item.getStringValue() + ")'");
+ item.getStringValue() + ")'", item.toSequence());
}
//URI type promotion: A value of type xs:anyURI (or any type derived
//by restriction from xs:anyURI) can be promoted to the type xs:string.
@@ -139,14 +139,14 @@
type = Type.STRING;
} else {
if (!(Type.subTypeOf(type, requiredType))) {
- throw new XPathException(expression, "FORG0001: " +
+ throw new XPathException(expression, ErrorCodes.FORG0001,
Type.getTypeName(item.getType()) + "(" + item.getStringValue() +
- ") is not a sub-type of " + Type.getTypeName(requiredType));
+ ") is not a sub-type of " + Type.getTypeName(requiredType), item.toSequence());
} else
- throw new XPathException(expression, "FOCH0002: Required type is " +
+ throw new XPathException(expression, ErrorCodes.FOCH0002, "Required type is " +
Type.getTypeName(requiredType) + " but got '" + Type.getTypeName(item.getType()) + "(" +
- item.getStringValue() + ")'");
+ item.getStringValue() + ")'", item.toSequence());
}
}
if (result != null)
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/ElementConstructor.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/ElementConstructor.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/ElementConstructor.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -101,13 +101,13 @@
QName qn = new QName(name, uri, "xmlns");
if (name.equalsIgnoreCase("xml")) {
- throw new XPathException(this, "XQST0070 : can not redefine '" + qn + "'");
+ throw new XPathException(this, ErrorCodes.XQST0070, "Can not redefine '" + qn + "'");
}
if (name.equalsIgnoreCase("xmlns")) {
- throw new XPathException(this, "XQST0070 : can not redefine '" + qn + "'");
+ throw new XPathException(this, ErrorCodes.XQST0070, "Can not redefine '" + qn + "'");
}
if (name.length()!=0 && uri.trim().length()==0) {
- throw new XPathException(this, "XQST0085 : cannot undeclare a prefix "+name+".");
+ throw new XPathException(this, ErrorCodes.XQST0085, "Cannot undeclare a prefix "+name+".");
}
addNamespaceDecl(qn);
}
@@ -119,7 +119,7 @@
} else {
for(int i = 0; i < namespaceDecls.length; i++) {
if (qn.equals(namespaceDecls[i]))
- throw new XPathException(this, "XQST0071 : duplicate definition for '" + qn + "'");
+ throw new XPathException(this, ErrorCodes.XQST0071, "Duplicate definition for '" + qn + "'");
}
QName decls[] = new QName[namespaceDecls.length + 1];
System.arraycopy(namespaceDecls, 0, decls, 0, namespaceDecls.length);
@@ -212,7 +212,7 @@
attrValues = constructor.eval(contextSequence, contextItem);
attrQName = QName.parse(context, constructor.getQName(), "");
if (attrs.getIndex(attrQName.getNamespaceURI(), attrQName.getLocalName()) != -1)
- throw new XPathException(this, "XQST0040 '" + attrQName.getLocalName() + "' is a duplicate attribute name");
+ throw new XPathException(this, ErrorCodes.XQST0040, attrQName.getLocalName() + "' is a duplicate attribute name");
attrs.addAttribute(attrQName.getNamespaceURI(), attrQName.getLocalName(),
attrQName.getStringValue(), "CDATA", attrValues.getStringValue());
}
@@ -232,7 +232,7 @@
try {
qn = QName.parse(context, qnitem.getStringValue());
} catch (IllegalArgumentException e) {
- throw new XPathException(this, "XPTY0004 '" + qnitem.getStringValue() + "' is not a valid element name");
+ throw new XPathException(this, ErrorCodes.XPTY0004, qnitem.getStringValue() + "' is not a valid element name");
}
//Use the default namespace if specified
@@ -248,7 +248,7 @@
//Not in the specs but... makes sense
if(!XMLChar.isValidName(qn.getLocalName()))
- throw new XPathException(this, "XPTY0004 '" + qnitem.getStringValue() + "' is not a valid element name");
+ throw new XPathException(this, ErrorCodes.XPTY0004, qnitem.getStringValue() + "' is not a valid element name");
// add namespace declaration nodes
int nodeNr = builder.startElement(qn, attrs);
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/EnclosedExpr.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/EnclosedExpr.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/EnclosedExpr.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -101,7 +101,7 @@
buf.setLength(0);
}
if (next.getType() == Type.ATTRIBUTE && !allowAttribs)
- throw new XPathException(this, "XQTY0024: An attribute may not appear after " +
+ throw new XPathException(this, ErrorCodes.XQTY0024, "An attribute may not appear after " +
"another child node.");
next.copyTo(context.getBroker(), receiver);
allowAttribs = next.getType() == Type.ATTRIBUTE;
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java 2010-10-30 12:16:56 UTC (rev 13062)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java 2010-10-30 15:18:04 UTC (rev 13063)
@@ -31,151 +31,158 @@
public class ErrorCodes {
/* XPath 2.0 http://www.w3.org/TR/xpath20/#id-errors */
- public static ErrorCode XPST0001 = new ErrorCode("XPST0001", "It is a static error if analysis of an expression relies on some component of the static context that has not been assigned a value.");
- public static ErrorCode XPDY0002 = new ErrorCode("XPDY0002", "It is a dynamic error if evaluation of an expression relies on some part of the dynamic context that has not been assigned a value.");
- public static ErrorCode XPST0003 = new ErrorCode("XPST0003", "It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF.");
- public static ErrorCode XPTY0004 = new ErrorCode("XPTY0004", "It is a type error if, during the static analysis phase, an expression is found to have a static type that is not appropriate for the context in which the expression occurs, or during the dynamic evaluation phase, the dynamic type of a value does not match a required type as specified by the matching rules in 2.5.4 SequenceType Matching.");
- public static ErrorCode XPST0005 = new ErrorCode("XPST0005", "During the analysis phase, it is a static error if the static type assigned to an expression other than the expression () or data(()) is empty-sequence().");
- public static ErrorCode XPTY0006 = new ErrorCode("XPTY0006", "(Not currently used.)");
- public static ErrorCode XPTY0007 = new ErrorCode("XPTY0007", "(Not currently used.)");
- public static ErrorCode XPST0008 = new ErrorCode("XPST0008", "It is a static error if an expression refers to an element name, attribute name, schema type name, namespace prefix, or variable name that is not defined in the static context, except for an ElementName in an ElementTest or an AttributeName in an AttributeTest.");
- public static ErrorCode XPST0010 = new ErrorCode("XPST0010", "An implementation must raise a static error if it encounters a reference to an axis that it does not support.");
- public static ErrorCode XPST0017 = new ErrorCode("XPST0017", "It is a static error if the expanded QName and number of arguments in a function call do not match the name and arity of a function signature in the static context.");
- public static ErrorCode XPTY0018 = new ErrorCode("XPTY0018", "It is a type error if the result of the last step in a path expression contains both nodes and atomic values.");
- public static ErrorCode XPTY0019 = new ErrorCode("XPTY0019", "It is a type error if the result of a step (other than the last step) in a path expression contains an atomic value.");
- public static ErrorCode XPTY0020 = new ErrorCode("XPTY0020", "It is a type error if, in an axis step, the context item is not a node.");
- public static ErrorCode XPDY0021 = new ErrorCode("XPDY0021", "(Not currently used.)");
- public static ErrorCode XPDY0050 = new ErrorCode("XPDY0050", "It is a dynamic error if the dynamic type of the operand of a treat expression does not match the sequence type specified by the treat expression. This error might also be raised by a path expression beginning with \"/\" or \"//\" if the context node is not in a tree that is rooted at a document node. This is because a leading \"/\" or \"//\" in a path expression is an abbreviation for an initial step that includes the clause treat as document-node().");
- public static ErrorCode XPST0051 = new ErrorCode("XPST0051", "It is a static error if a QName that is used as an AtomicType in a SequenceType is not defined in the in-scope schema types as an atomic type.");
- public static ErrorCode XPST0080 = new ErrorCode("XPST0080", "It is a static error if the target type of a cast or castable expression is xs:NOTATION or xs:anyAtomicType.");
- public static ErrorCode XPST0081 = new ErrorCode("XPST0081", "It is a static error if a QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces.");
- public static ErrorCode XPST0083 = new ErrorCode("XPST0083", "(Not currently used.)");
+ public static ErrorCode XPST0001 = new W3CErrorCode("XPST0001", "It is a static error if analysis of an expression relies on some component of the static context that has not been assigned a value.");
+ public static ErrorCode XPDY0002 = new W3CErrorCode("XPDY0002", "It is a dynamic error if evaluation of an expression relies on some part of the dynamic context that has not been assigned a value.");
+ public static ErrorCode XPST0003 = new W3CErrorCode("XPST0003", "It is a static error if an expression is not a valid instance of the grammar defined in A.1 EBNF.");
+ public static ErrorCode XPTY0004 = new W3CErrorCode("XPTY0004", "It is a type error if, during the static analysis phase, an expression is found to have a static type that is not appropriate for the context in which the expression occurs, or during the dynamic evaluation phase, the dynamic type of a value does not match a required type as specified by the matching rules in 2.5.4 SequenceType Matching.");
+ public static ErrorCode XPST0005 = new W3CErrorCode("XPST0005", "During the analysis phase, it is a static error if the static type assigned to an expression other than the expression () or data(()) is empty-sequence().");
+ public static ErrorCode XPTY0006 = new W3CErrorCode("XPTY0006", "(Not currently used.)");
+ public static ErrorCode XPTY0007 = new W3CErrorCode("XPTY0007", "(Not currently used.)");
+ public static ErrorCode XPST0008 = new W3CErrorCode("XPST0008", "It is a static error if an expression refers to an element name, attribute name, schema type name, namespace prefix, or variable name that is not defined in the static context, except for an ElementName in an ElementTest or an AttributeName in an AttributeTest.");
+ public static ErrorCode XPST0010 = new W3CErrorCode("XPST0010", "An implementation must raise a static error if it encounters a reference to an axis that it does not support.");
+ public static ErrorCode XPST0017 = new W3CErrorCode("XPST0017", "It is a static error if the expanded QName and number of arguments in a function call do not match the name and arity of a function signature in the static context.");
+ public static ErrorCode XPTY0018 = new W3CErrorCode("XPTY0018", "It is a type error if the result of the last step in a path expression contains both nodes and atomic values.");
+ public static ErrorCode XPTY0019 = new W3CErrorCode("XPTY0019", "It is a type error if the result of a step (other than the last step) in a path expression contains an atomic value.");
+ public static ErrorCode XPTY0020 = new W3CErrorCode("XPTY0020", "It is a type error if, in an axis step, the context item is not a node.");
+ public static ErrorCode XPDY0021 = new W3CErrorCode("XPDY0021", "(Not currently used.)");
+ public static ErrorCode XPDY0050 = new W3CErrorCode("XPDY0050", "It is a dynamic error if the dynamic type of the operand of a treat expression does not match the sequence type specified by the treat expression. This error might also be raised by a path expression beginning with \"/\" or \"//\" if the context node is not in a tree that is rooted at a document node. This is because a leading \"/\" or \"//\" in a path expression is an abbreviation for an initial step that includes the clause treat as document-node().");
+ public static ErrorCode XPST0051 = new W3CErrorCode("XPST0051", "It is a static error if a QName that is used as an AtomicType in a SequenceType is not defined in the in-scope schema types as an atomic type.");
+ public static ErrorCode XPST0080 = new W3CErrorCode("XPST0080", "It is a static error if the target type of a cast or castable expression is xs:NOTATION or xs:anyAtomicType.");
+ public static ErrorCode XPST0081 = new W3CErrorCode("XPST0081", "It is a static error if a QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces.");
+ public static ErrorCode XPST0083 = new W3CErrorCode("XPST0083", "(Not currently used.)");
/* XQuery 1.0 http://www.w3.org/TR/xquery/#id-errors */
- public static ErrorCode XQST0009 = new ErrorCode("XQST0009", "An implementation that does not support the Schema Import Feature must raise a static error if a Prolog contains a schema import.");
- public static ErrorCode XQST0012 = new ErrorCode("XQST0012", "It is a static error if the set of definitions contained in all schemas imported by a Prolog do not satisfy the conditions for schema validity specified in Sections 3 and 5 of [XML Schema] Part 1--i.e., each definition must be valid, complete, and unique.");
- public static ErrorCode XQST0013 = new ErrorCode("XQST0013", "It is a static error if an implementation recognizes a pragma but determines that its content is invalid.");
- public static ErrorCode XQST0014 = new ErrorCode("XQST0014", "(Not currently used.)");
- public static ErrorCode XQST0015 = new ErrorCode("XQST0015", "(Not currently used.)");
- public static ErrorCode XQST0016 = new ErrorCode("XQST0016", "An implementation that does not support the Module Feature raises a static error if it encounters a module declaration or a module import.");
- public static ErrorCode XQST0022 = new ErrorCode("XQST0022", "It is a static error if the value of a namespace declaration attribute is not a URILiteral.");
- public static ErrorCode XQTY0023 = new ErrorCode("XQTY0023", "(Not currently used.)");
- public static ErrorCode XQTY0024 = new ErrorCode("XQTY0024", "It is a type error if the content sequence in an element constructor contains an attribute node following a node that is not an attribute node.");
- public static ErrorCode XQDY0025 = new ErrorCode("XQDY0025", "It is a dynamic error if any attribute of a constructed element does not have a name that is distinct from the names of all other attributes of the constructed element.");
- public static ErrorCode XQDY0026 = new ErrorCode("XQDY0026", "It is a dynamic error if the result of the content expression of a computed processing instruction constructor contains the string \"?>\".");
- public static ErrorCode XQDY0027 = new ErrorCode("XQDY0027", "In a validate expression, it is a dynamic error if the root elem...
[truncated message content] |
|
From: <di...@us...> - 2011-01-23 18:53:40
|
Revision: 13619
http://exist.svn.sourceforge.net/exist/?rev=13619&view=rev
Author: dizzzz
Date: 2011-01-23 18:53:34 +0000 (Sun, 23 Jan 2011)
Log Message:
-----------
[ignore] wrap up of today. things are a bit unclear yet
Modified Paths:
--------------
branches/adam/eXist-xq3/nbproject/build-impl.xml
branches/adam/eXist-xq3/nbproject/genfiles.properties
branches/adam/eXist-xq3/nbproject/project.properties
branches/adam/eXist-xq3/nbproject/project.xml
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
branches/adam/eXist-xq3/test/src/xquery/TestRunner.java
branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml
Modified: branches/adam/eXist-xq3/nbproject/build-impl.xml
===================================================================
--- branches/adam/eXist-xq3/nbproject/build-impl.xml 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/nbproject/build-impl.xml 2011-01-23 18:53:34 UTC (rev 13619)
@@ -19,7 +19,7 @@
- cleanup
-->
-<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="eXist-1.5-impl">
+<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="try-catch-impl">
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
@@ -319,15 +319,18 @@
<attribute default="${build.classes.dir}" name="destdir"/>
<sequential>
<fail unless="javac.includes">Must set javac.includes</fail>
- <pathconvert pathsep="," property="javac.includes.binary">
+ <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
<path>
<filelist dir="@{destdir}" files="${javac.includes}"/>
</path>
<globmapper from="*.java" to="*.class"/>
</pathconvert>
+ <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
+ <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
<delete>
- <files includes="${javac.includes.binary}"/>
+ <files includesfile="${javac.includesfile.binary}"/>
</delete>
+ <delete file="${javac.includesfile.binary}"/>
</sequential>
</macrodef>
</target>
@@ -522,7 +525,7 @@
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
- <echo level="warn" message="Cycle detected: eXist-1.5 was already built"/>
+ <echo level="warn" message="Cycle detected: try-catch was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
@@ -976,7 +979,7 @@
<delete file="${built-clean.properties}" quiet="true"/>
</target>
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
- <echo level="warn" message="Cycle detected: eXist-1.5 was already built"/>
+ <echo level="warn" message="Cycle detected: try-catch was already built"/>
</target>
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
<mkdir dir="${build.dir}"/>
Modified: branches/adam/eXist-xq3/nbproject/genfiles.properties
===================================================================
--- branches/adam/eXist-xq3/nbproject/genfiles.properties 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/nbproject/genfiles.properties 2011-01-23 18:53:34 UTC (rev 13619)
@@ -3,6 +3,6 @@
nbbuild.xml.stylesheet.CRC32=958a1d3e@1.26.2.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=d27eb3f9
-nbproject/build-impl.xml.script.CRC32=9e93939f
-nbproject/build-impl.xml.stylesheet.CRC32=f33e10ff@1.38.2.45
+nbproject/build-impl.xml.data.CRC32=b4f7ba84
+nbproject/build-impl.xml.script.CRC32=37d6ceb5
+nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45
Modified: branches/adam/eXist-xq3/nbproject/project.properties
===================================================================
--- branches/adam/eXist-xq3/nbproject/project.properties 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/nbproject/project.properties 2011-01-23 18:53:34 UTC (rev 13619)
@@ -25,7 +25,6 @@
file.reference.milton-api-1.5.5-SNAPSHOT.jar=extensions/webdav/lib/milton-api-1.5.5-SNAPSHOT.jar
file.reference.milton-servlet-1.5.5-SNAPSHOT.jar=extensions/webdav/lib/milton-servlet-1.5.5-SNAPSHOT.jar
file.reference.mime-util-1.3.1.jar=extensions/webdav/lib/mime-util-1.3.1.jar
-file.reference.openid4java-full-0.9.5.jar=lib/user/openid4java-full-0.9.5.jar
file.reference.pkg-repo.jar=lib/core/pkg-repo.jar
file.reference.saxonb-9.1.0.8.jar=lib/endorsed/saxonb-9.1.0.8.jar
file.reference.saxonb-dom-9.1.0.8.jar=lib/endorsed/saxonb-dom-9.1.0.8.jar
@@ -247,8 +246,7 @@
${file.reference.jetty-util-7.1.6.v20100715.jar}:\
${file.reference.jetty-webapp-7.1.6.v20100715.jar}:\
${file.reference.jetty-websocket-7.1.6.v20100715.jar}:\
- ${file.reference.jetty-xml-7.1.6.v20100715.jar}:\
- ${file.reference.openid4java-full-0.9.5.jar}
+ ${file.reference.jetty-xml-7.1.6.v20100715.jar}
javadoc.additionalparam=-J-Xmx320m
build.classes.dir=${build.dir}/classes
file.reference.samples-src=samples/src
Modified: branches/adam/eXist-xq3/nbproject/project.xml
===================================================================
--- branches/adam/eXist-xq3/nbproject/project.xml 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/nbproject/project.xml 2011-01-23 18:53:34 UTC (rev 13619)
@@ -3,7 +3,7 @@
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
- <name>eXist-1.5</name>
+ <name>try-catch</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<source-roots>
<root id="src.dir" name="Core"/>
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-23 18:53:34 UTC (rev 13619)
@@ -28,8 +28,10 @@
import org.exist.dom.QName;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xquery.value.Item;
+import org.exist.xquery.value.QNameValue;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.SequenceType;
+import org.exist.xquery.value.StringValue;
import org.exist.xquery.value.Type;
/**
@@ -42,7 +44,7 @@
private final Expression tryTargetExpr;
- private final List<List> catchClauses = new ArrayList(5);
+ private final List<CatchClause> catchClauses = new ArrayList<CatchClause>();
// fixit! - declare static code, desc, value types
@@ -52,12 +54,10 @@
}
public void addCatchClause(List<String> catchErrorList, List<QName> catchVars, Expression catchExpr) {
- List clause = new ArrayList(3);
- clause.add(catchErrorList);
- clause.add(catchVars);
- clause.add(catchExpr);
- this.catchClauses.add(clause);
+ CatchClause catchClause = new CatchClause(catchErrorList, catchVars, catchExpr);
+
+ catchClauses.add(catchClause);
}
/* (non-Javadoc)
@@ -72,7 +72,7 @@
return tryTargetExpr;
}
- public List<List> getCatchClauses() {
+ public List<CatchClause> getCatchClauses() {
return catchClauses;
}
@@ -110,7 +110,12 @@
return tryTargetSeq;
} catch(XPathException xpe) {
+ System.out.println("Exception=" + xpe.getMessage());
+ System.out.println("Errorcode=" + xpe.getErrorCode().toString() + " qname=" + xpe.getErrorCode().getErrorQName());
+ // Get qname
+ QName errorCodeQname = xpe.getErrorCode().getErrorQName();
+
// Exception in thrown, catch expression will be evaluated.
// catchvars (CatchErrorCode (, CatchErrorDesc (, CatchErrorVal)?)? )
// need to be retrieved as variables
@@ -119,10 +124,16 @@
try {
// Iterate on all catch clauses
- for (List catchClause : catchClauses) {
+ for (CatchClause catchClause : catchClauses) {
- // Get catch variables and as declared variables
- List<QName> catchVars = (List<QName>) catchClause.get(1);
+//// DW: don't understand why this yields into a CCE
+// for(String txt : catchClause.getCatchErrorList()){
+// System.out.print( txt + "++++");
+// }
+// System.out.println();
+
+ // Get catch variables
+ List<QName> catchVars = (List<QName>) catchClause.getCatchVars();
LocalVariable mark1 = context.markLocalVariables(false);
int varPos = 0;
@@ -131,18 +142,19 @@
// "(" CatchErrorCode ("," CatchErrorDesc ("," CatchErrorVal)?)? ")"
for (QName catchVar : catchVars) {
-// System.out.println(">>>> localname="+catchVar.getLocalName()
-// + " stringvalue=" + catchVar.getStringValue()
-// + " prefix=" + catchVar.getPrefix()
-// + " " + catchVar.getNamespaceURI());
+ LocalVariable var = new LocalVariable(catchVar);
- LocalVariable var = new LocalVariable(catchVar);
+// System.out.println(catchVar.getStringValue() + "_=_" + catchVar.getLocalName());
// This should be in order of existance
// xs:QName, xs:string?, and item()* respectively.
switch (varPos) {
case 1:
var.setSequenceType(new SequenceType(Type.QNAME, Cardinality.EXACTLY_ONE));
+// QNameValue qnv = new QNameValue(context, catchVar);
+// qnv.add( new StringValue("aaa") );
+// var.setValue(qnv);
+ context.declareGlobalVariable(var);
break;
case 2:
var.setSequenceType(new SequenceType(Type.STRING, Cardinality.ZERO_OR_ONE));
@@ -156,13 +168,18 @@
}
// Evaluate catch expression
- catchResultSeq = ((Expression) catchClause.get(2)).eval(contextSequence, contextItem);
+ catchResultSeq = ((Expression) catchClause.getCatchExpr()).eval(contextSequence, contextItem);
} finally {
context.popLocalVariables(mark1);
}
}
+// } catch(Throwable ex){
+// ex.printStackTrace();
+// throw new XPathException(ex);
+
+
} finally {
context.popLocalVariables(mark0);
}
@@ -183,8 +200,8 @@
dumper.startIndent();
tryTargetExpr.dump(dumper);
dumper.endIndent();
- for (List catchClause: catchClauses) {
- Expression catchExpr = (Expression) catchClause.get(2);
+ for (CatchClause catchClause: catchClauses) {
+ Expression catchExpr = (Expression) catchClause.getCatchExpr();
dumper.nl().display("} catch (expr) {");
dumper.startIndent();
catchExpr.dump(dumper);
@@ -198,8 +215,8 @@
StringBuilder result = new StringBuilder();
result.append("try { ");
result.append(tryTargetExpr.toString());
- for (List catchClause: catchClauses) {
- Expression catchExpr = (Expression) catchClause.get(2);
+ for (CatchClause catchClause: catchClauses) {
+ Expression catchExpr = (Expression) catchClause.getCatchExpr();
result.append(" } catch (expr) { ");
result.append(catchExpr.toString());
result.append("}");
@@ -213,7 +230,7 @@
@Override
public int returnsType() {
// fixme! /ljo
- return ((Expression) catchClauses.get(0).get(2)).returnsType();
+ return ((Expression) catchClauses.get(0).getCatchExpr()).returnsType();
}
/* (non-Javadoc)
@@ -223,8 +240,8 @@
public void resetState(boolean postOptimization) {
super.resetState(postOptimization);
tryTargetExpr.resetState(postOptimization);
- for (List catchClause : catchClauses) {
- Expression catchExpr = (Expression) catchClause.get(2);
+ for (CatchClause catchClause : catchClauses) {
+ Expression catchExpr = (Expression) catchClause.getCatchExpr();
catchExpr.resetState(postOptimization);
}
}
@@ -236,7 +253,46 @@
}
+ /**
+ * Data container
+ */
public class CatchClause{
+ private List<String> catchErrorList = null;
+ private List<QName> catchVars = null;
+ private Expression catchExpr = null;
+
+ public CatchClause(List<String> catchErrorList, List<QName> catchVars, Expression catchExpr) {
+ this.catchErrorList=catchErrorList;
+ this.catchVars = catchVars;
+ this.catchExpr = catchExpr;
+ }
+
+ public List<String> getCatchErrorList() {
+ return catchErrorList;
+ }
+
+ public void setCatchErrorList(List<String> catchErrorList) {
+ this.catchErrorList = catchErrorList;
+ }
+
+ public Expression getCatchExpr() {
+ return catchExpr;
+ }
+
+ public void setCatchExpr(Expression catchExpr) {
+ this.catchExpr = catchExpr;
+ }
+
+ public List<QName> getCatchVars() {
+ return catchVars;
+ }
+
+ public void setCatchVars(List<QName> catchVars) {
+ this.catchVars = catchVars;
+ }
+
+
+
}
}
Modified: branches/adam/eXist-xq3/test/src/xquery/TestRunner.java
===================================================================
--- branches/adam/eXist-xq3/test/src/xquery/TestRunner.java 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/test/src/xquery/TestRunner.java 2011-01-23 18:53:34 UTC (rev 13619)
@@ -70,7 +70,7 @@
// A test failed, report it
if (passed.equals("false")) {
- System.err.println(resource.getContent());
+ //System.err.println(resource.getContent());
fail("Test " + test.getAttribute("n") + " failed");
}
}
@@ -116,6 +116,7 @@
(DatabaseInstanceManager) testCollection.getService(
"DatabaseInstanceManager", "1.0");
dim.shutdown();
+
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
Modified: branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml
===================================================================
--- branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml 2011-01-23 18:44:11 UTC (rev 13618)
+++ branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml 2011-01-23 18:53:34 UTC (rev 13619)
@@ -2,7 +2,7 @@
<TestSet>
<testName>xquery3 try-catch</testName>
<description>
- <p>Test xquery3 try-catch functionality, derived from w3c: http://www.w3.org/TR/xquery-30-use-cases/#try-catch-use-cases</p>
+ <p>Test xquery3 try-catch functionality</p>
<author>Dannes Wessels</author>
</description>
<setup>
@@ -47,6 +47,9 @@
<remove-collection collection="/db/xquery3"/>
</tearDown>
+ <!-- derived from w3c: http://www.w3.org/TR/xquery-30-use-cases/#try-catch-use-cases -->
+
+<!--
<test output="text">
<task>Usecases Q1</task>
<code><![CDATA[
@@ -64,6 +67,7 @@
</code>
<expected>An error occured, please ask your consultant for help.</expected>
</test>
+ -->
<test output="text">
<task>Usecases Q2</task>
@@ -109,6 +113,8 @@
</expected>
</test>
+ <!--
+
<test output="text">
<task>Usecases Q3</task>
<code><![CDATA[
@@ -142,12 +148,14 @@
</result>
</expected>
</test>
+ -->
<!-- the following tests are derived from http://www.w3.org/TR/xquery-30/#id-try-catch -->
-
+<!--
<test output="text">
<task>A try/catch expression without a CatchErrorList catches
- any error</task>
+ any error
+ </task>
<code><![CDATA[
let $x := "a b c"
return
@@ -164,7 +172,8 @@
<test output="text">
<task>The CatchErrorList in this try/catch expression specifies
- that only err:FORG0001 is caught</task>
+ that only err:FORG0001 is caught
+ </task>
<code><![CDATA[
let $x := "a b c"
return
@@ -176,12 +185,13 @@
}
]]>
</code>
- <expected>0</expected><!-- should fail -->
+ <expected>0</expected>
</test>
<test output="text">
<task>The CatchErrorList in this try/catch expression specifies
- that errors err:FORG0001 and err:XPTY0004 are caught</task>
+ that errors err:FORG0001 and err:XPTY0004 are caught
+ </task>
<code><![CDATA[
let $x := "a b c"
return
@@ -199,7 +209,8 @@
<test output="text">
<task>This try/catch expression shows how to bind variables to
the error code, error description, and error value. Since the
- CatchErrorList is a wildcard, it catches any error:</task>
+ CatchErrorList is a wildcard, it catches any error:
+ </task>
<code><![CDATA[
try {
fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'))
@@ -214,7 +225,8 @@
<test output="text">
<task>Errors raised by using the result of a try/catch expression
- are not caught, since they are outside the scope of the try expression.</task>
+ are not caught, since they are outside the scope of the try expression.
+ </task>
<code><![CDATA[
declare function local:thrice($x as xs:integer) as xs:integer
{
@@ -227,4 +239,6 @@
<expected>a</expected>
</test>
+ -->
+
</TestSet>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-24 17:11:56
|
Revision: 13625
http://exist.svn.sourceforge.net/exist/?rev=13625&view=rev
Author: dizzzz
Date: 2011-01-24 17:11:50 +0000 (Mon, 24 Jan 2011)
Log Message:
-----------
[ignore] an important step in try-catch
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
Added Paths:
-----------
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-24 16:35:05 UTC (rev 13624)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-24 17:11:50 UTC (rev 13625)
@@ -26,6 +26,7 @@
import org.exist.dom.DocumentSet;
import org.exist.dom.QName;
+import org.exist.xquery.ErrorCodes.ErrorCode;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.QNameValue;
@@ -110,11 +111,13 @@
return tryTargetSeq;
} catch(XPathException xpe) {
- System.out.println("Exception=" + xpe.getMessage());
- System.out.println("Errorcode=" + xpe.getErrorCode().toString() + " qname=" + xpe.getErrorCode().getErrorQName());
+// System.out.println("Exception=" + xpe.getMessage());
+// System.out.println("Errorcode=" + xpe.getErrorCode().toString() + " qname=" + xpe.getErrorCode().getErrorQName());
// Get qname
- QName errorCodeQname = xpe.getErrorCode().getErrorQName();
+ ErrorCode errorCode = xpe.getErrorCode();
+ System.out.println("aaaaa"+xpe.toString());
+ QName errorCodeQname = errorCode.getErrorQName();
// Exception in thrown, catch expression will be evaluated.
// catchvars (CatchErrorCode (, CatchErrorDesc (, CatchErrorVal)?)? )
@@ -123,61 +126,71 @@
LocalVariable mark0 = context.markLocalVariables(false);
try {
+ boolean errorMatched = false;
+
// Iterate on all catch clauses
for (CatchClause catchClause : catchClauses) {
-//// DW: don't understand why this yields into a CCE
-// for(String txt : catchClause.getCatchErrorList()){
-// System.out.print( txt + "++++");
-// }
-// System.out.println();
+ if(isErrorInList(errorCodeQname, catchClause.getCatchErrorList()) && !errorMatched){
- // Get catch variables
- List<QName> catchVars = (List<QName>) catchClause.getCatchVars();
- LocalVariable mark1 = context.markLocalVariables(false);
- int varPos = 0;
+ errorMatched=true;
- try {
- // catch variables
- // "(" CatchErrorCode ("," CatchErrorDesc ("," CatchErrorVal)?)? ")"
- for (QName catchVar : catchVars) {
+ // Get catch variables
+ List<QName> catchVars = (List<QName>) catchClause.getCatchVars();
+ LocalVariable mark1 = context.markLocalVariables(false);
+ int varPos = 1;
- LocalVariable var = new LocalVariable(catchVar);
+ try {
+ // catch variables
+ // "(" CatchErrorCode ("," CatchErrorDesc ("," CatchErrorVal)?)? ")"
+ for (QName catchVar : catchVars) {
-// System.out.println(catchVar.getStringValue() + "_=_" + catchVar.getLocalName());
-
- // This should be in order of existance
- // xs:QName, xs:string?, and item()* respectively.
- switch (varPos) {
- case 1:
- var.setSequenceType(new SequenceType(Type.QNAME, Cardinality.EXACTLY_ONE));
-// QNameValue qnv = new QNameValue(context, catchVar);
-// qnv.add( new StringValue("aaa") );
-// var.setValue(qnv);
- context.declareGlobalVariable(var);
- break;
- case 2:
- var.setSequenceType(new SequenceType(Type.STRING, Cardinality.ZERO_OR_ONE));
- break;
- case 3:
- var.setSequenceType(new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE));
- break;
+ catchVar.setPrefix(null);
+ catchVar.setNamespaceURI("");
+
+ LocalVariable var = new LocalVariable(catchVar);
+
+ // This should be in order of existance
+ // xs:QName, xs:string?, and item()* respectively.
+ switch (varPos) {
+ case 1:
+ var.setSequenceType(new SequenceType(Type.QNAME, Cardinality.EXACTLY_ONE));
+ QNameValue qnv = new QNameValue(context, catchVar);
+// qnv.add( new StringValue("aaa") );
+ var.setValue( new StringValue( xpe.getErrorCode().getErrorQName().getStringValue()) );
+ // context.declareGlobalVariable(var);
+ context.declareVariable(catchVar, var);
+
+ break;
+ case 2:
+ var.setSequenceType(new SequenceType(Type.STRING, Cardinality.ZERO_OR_ONE));
+ StringValue sv = new StringValue( xpe.getErrorCode().toString() );
+ var.setValue(sv);
+ break;
+ case 3:
+ var.setSequenceType(new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE));
+ break;
+ }
+ context.declareVariableBinding(var);
+ varPos++;
}
- context.declareVariableBinding(var);
- varPos++;
+
+
+ // Evaluate catch expression
+ catchResultSeq = ((Expression) catchClause.getCatchExpr()).eval(contextSequence, contextItem);
+
+ } finally {
+ context.popLocalVariables(mark1);
}
- // Evaluate catch expression
- catchResultSeq = ((Expression) catchClause.getCatchExpr()).eval(contextSequence, contextItem);
-
- } finally {
- context.popLocalVariables(mark1);
+ } else {
+ // if in the end nothing is set, rethrow
}
}
-// } catch(Throwable ex){
-// ex.printStackTrace();
-// throw new XPathException(ex);
+ if(!errorMatched){
+ throw xpe;
+ }
} finally {
@@ -252,7 +265,22 @@
visitor.visitTryCatch(this);
}
+ private boolean isErrorInList(QName error, List<String> errors){
+ String qError = error.getStringValue();
+ for(String lError : errors){
+ if("*".equals(lError)){
+ return true;
+ }
+
+ if(qError.equals(lError)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
/**
* Data container
*/
Added: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java (rev 0)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-24 17:11:50 UTC (rev 13625)
@@ -0,0 +1,166 @@
+package org.exist.xquery.functions.xquery3;
+
+import org.junit.Ignore;
+import org.xmldb.api.base.ResourceSet;
+
+import org.exist.test.EmbeddedExistTester;
+import org.exist.xquery.ErrorCodes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author wessels
+ */
+public class TryCatchTest extends EmbeddedExistTester {
+
+ public TryCatchTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ System.out.println("***********************");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ // TODO add test methods here.
+ // The methods must be annotated with annotation @Test. For example:
+ //
+ // @Test
+ // public void hello() {}
+ @Test
+ public void simpleCatch() {
+
+ String query = "try { a + 7 } catch * { 1 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("1", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+ @Test
+ public void catchWithCodeAndDescription() {
+
+ String query = "try { a + 7 } "
+ + "catch * ($errcode, $errdesc, $errval) "
+ + "{ $errcode, $errdesc } ";
+ try {
+ ResourceSet results = executeQuery(query);
+
+ assertEquals(2, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals(ErrorCodes.XPDY0002.getErrorQName().getStringValue(), r1);
+
+ String r2 = (String) results.getResource(1).getContent();
+ assertEquals(ErrorCodes.XPDY0002.toString(), r2);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+ @Test
+ public void catchWithError3Matches() {
+
+ String query = "try { a + 7 } "
+ + "catch err:XPDY0001 { 1 }"
+ + "catch err:XPDY0002 { 2 }"
+ + "catch err:XPDY0003 { 3 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("2", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test
+ public void catchWithErrorNoMatches() {
+
+ String query = "try { a + 7 } "
+ + "catch err:XPDY0001 { 1 }"
+ + "catch err:XPDY0002 { a }"
+ + "catch err:XPDY0003 { 3 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("2", r);
+
+ fail("Exception expected");
+
+ } catch (Throwable ex) {
+ // expected
+
+ }
+ }
+
+ @Test
+ public void catchWithError5Matches() {
+
+ String query = "try { a + 7 } "
+ + "catch err:XPDY0001 | err:XPDY0003 { 13 }"
+ + "catch err:XPDY0002 { 2 }"
+ + "catch err:XPDY0004 | err:XPDY0005 { 45 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("2", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test
+ public void catchWithError51Matches() {
+
+ String query = "try { a + 7 } "
+ + "catch err:XPDY0001 | * { 13 }"
+ + "catch err:XPDY0002 { 2 }"
+ + "catch err:XPDY0004 | err:XPDY0005 { 45 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("13", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-24 18:43:18
|
Revision: 13627
http://exist.svn.sourceforge.net/exist/?rev=13627&view=rev
Author: dizzzz
Date: 2011-01-24 18:43:11 +0000 (Mon, 24 Jan 2011)
Log Message:
-----------
[ignore] an other important step in try-catch
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
branches/adam/eXist-xq3/src/org/exist/xquery/XPathException.java
branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-24 18:25:09 UTC (rev 13626)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-24 18:43:11 UTC (rev 13627)
@@ -116,7 +116,12 @@
// Get qname
ErrorCode errorCode = xpe.getErrorCode();
- System.out.println("aaaaa"+xpe.toString());
+ if(errorCode==null){
+ String[] data = extractLocalName(xpe.getMessage());
+ errorCode = new ErrorCode( new QName(data[0], "err"), data[1]);
+ errorCode.getErrorQName().setPrefix("err");
+ System.out.println("Results="+data[0] + "/" + data[1]);
+ }
QName errorCodeQname = errorCode.getErrorQName();
// Exception in thrown, catch expression will be evaluated.
@@ -157,14 +162,14 @@
var.setSequenceType(new SequenceType(Type.QNAME, Cardinality.EXACTLY_ONE));
QNameValue qnv = new QNameValue(context, catchVar);
// qnv.add( new StringValue("aaa") );
- var.setValue( new StringValue( xpe.getErrorCode().getErrorQName().getStringValue()) );
+ var.setValue( new StringValue( errorCode.getErrorQName().getStringValue()) );
// context.declareGlobalVariable(var);
context.declareVariable(catchVar, var);
break;
case 2:
var.setSequenceType(new SequenceType(Type.STRING, Cardinality.ZERO_OR_ONE));
- StringValue sv = new StringValue( xpe.getErrorCode().toString() );
+ StringValue sv = new StringValue( errorCode.toString() );
var.setValue(sv);
break;
case 3:
@@ -280,7 +285,16 @@
return false;
}
+ private String[] extractLocalName(String errorText)
+ throws IllegalArgumentException {
+ int p = errorText.indexOf(':');
+ if (p == Constants.STRING_NOT_FOUND)
+ return new String[]{null,errorText};
+ return new String[]{ errorText.substring(0, p).trim(), errorText.substring(p+1).trim()};
+ }
+
+
/**
* Data container
*/
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/XPathException.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/XPathException.java 2011-01-24 18:25:09 UTC (rev 13626)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/XPathException.java 2011-01-24 18:43:11 UTC (rev 13627)
@@ -105,6 +105,16 @@
this.errorVal = errorVal;
}
+ // DWES : not sure?
+ public XPathException(ErrorCode errorCode, String errorDesc, Sequence errorVal) {
+ this.errorCode = errorCode;
+
+ if(errorDesc==null){
+ errorCode.toString();
+ }
+ this.errorVal = errorVal;
+ }
+
public XPathException(int line, int column, String message, Throwable cause) {
super(cause);
this.message = message;
Modified: branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml
===================================================================
--- branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml 2011-01-24 18:25:09 UTC (rev 13626)
+++ branches/adam/eXist-xq3/test/src/xquery/xq3_trycatch.xml 2011-01-24 18:43:11 UTC (rev 13627)
@@ -49,7 +49,7 @@
<!-- derived from w3c: http://www.w3.org/TR/xquery-30-use-cases/#try-catch-use-cases -->
-<!--
+
<test output="text">
<task>Usecases Q1</task>
<code><![CDATA[
@@ -67,7 +67,7 @@
</code>
<expected>An error occured, please ask your consultant for help.</expected>
</test>
- -->
+
<test output="text">
<task>Usecases Q2</task>
@@ -90,9 +90,7 @@
<expected>
<result>
<product>
- <name>broiler</name>
- Error: FORG0001
- </product>
+ <name>broiler</name>Error: err:FORG0001</product>
<product>
<name>toaster</name>
<margin>3</margin>
@@ -107,14 +105,14 @@
</product>
<product>
<name>shirt</name>
- <margin>3.3333333333333333</margin>
+ <margin>3.3333333333333335</margin>
</product>
</result>
</expected>
</test>
- <!--
-
+
+<!--
<test output="text">
<task>Usecases Q3</task>
<code><![CDATA[
@@ -151,7 +149,7 @@
-->
<!-- the following tests are derived from http://www.w3.org/TR/xquery-30/#id-try-catch -->
-<!--
+
<test output="text">
<task>A try/catch expression without a CatchErrorList catches
any error
@@ -169,7 +167,7 @@
</code>
<expected>0</expected>
</test>
-
+<!--
<test output="text">
<task>The CatchErrorList in this try/catch expression specifies
that only err:FORG0001 is caught
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-24 20:42:17
|
Revision: 13629
http://exist.svn.sourceforge.net/exist/?rev=13629&view=rev
Author: dizzzz
Date: 2011-01-24 20:42:11 +0000 (Mon, 24 Jan 2011)
Log Message:
-----------
[ignore] most tests work right now, excluding the thrid parameter
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-24 18:50:40 UTC (rev 13628)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-24 20:42:11 UTC (rev 13629)
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.log4j.Logger;
import org.exist.dom.DocumentSet;
import org.exist.dom.QName;
@@ -43,6 +44,8 @@
*/
public class TryCatchExpression extends AbstractExpression {
+ protected static final Logger LOG = Logger.getLogger(TryCatchExpression.class);
+
private final Expression tryTargetExpr;
private final List<CatchClause> catchClauses = new ArrayList<CatchClause>();
@@ -111,16 +114,15 @@
return tryTargetSeq;
} catch(XPathException xpe) {
-// System.out.println("Exception=" + xpe.getMessage());
-// System.out.println("Errorcode=" + xpe.getErrorCode().toString() + " qname=" + xpe.getErrorCode().getErrorQName());
-
// Get qname
ErrorCode errorCode = xpe.getErrorCode();
+
+ // if no QName is found, reconstruct one based on original string
if(errorCode==null){
String[] data = extractLocalName(xpe.getMessage());
errorCode = new ErrorCode( new QName(data[0], "err"), data[1]);
errorCode.getErrorQName().setPrefix("err");
- System.out.println("Results="+data[0] + "/" + data[1]);
+ LOG.debug("Parsed string for Errorcode. Qname='"+data[0] + "' message=" + data[1] + "'");
}
QName errorCodeQname = errorCode.getErrorQName();
@@ -150,6 +152,7 @@
// "(" CatchErrorCode ("," CatchErrorDesc ("," CatchErrorVal)?)? ")"
for (QName catchVar : catchVars) {
+ // restet qname and prefec
catchVar.setPrefix(null);
catchVar.setNamespaceURI("");
@@ -161,9 +164,7 @@
case 1:
var.setSequenceType(new SequenceType(Type.QNAME, Cardinality.EXACTLY_ONE));
QNameValue qnv = new QNameValue(context, catchVar);
-// qnv.add( new StringValue("aaa") );
var.setValue( new StringValue( errorCode.getErrorQName().getStringValue()) );
- // context.declareGlobalVariable(var);
context.declareVariable(catchVar, var);
break;
@@ -173,7 +174,14 @@
var.setValue(sv);
break;
case 3:
+ // TODO setting an empty sequens does not work, it does
+ // not make the variable visible
var.setSequenceType(new SequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE));
+ Sequence sequence = xpe.getErrorVal();
+ if(sequence==null ){
+ sequence = Sequence.EMPTY_SEQUENCE;
+ }
+ var.setValue(sequence);
break;
}
context.declareVariableBinding(var);
@@ -193,6 +201,7 @@
}
}
+ // If an error hasn't been catched, throw new one
if(!errorMatched){
throw xpe;
}
Modified: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-24 18:50:40 UTC (rev 13628)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-24 20:42:11 UTC (rev 13629)
@@ -163,4 +163,31 @@
fail(ex.getMessage());
}
}
+
+ @Test @Ignore("Third parameter needs to be improved.")
+ public void catchFullErrorCode() {
+
+ String query = "try { a + 7 } "
+ + "catch * ($errcode, $errdesc, $errval) "
+ + "{ $errcode, $errdesc, $errval } ";
+ try {
+ ResourceSet results = executeQuery(query);
+
+ assertEquals(3, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals(ErrorCodes.XPDY0002.getErrorQName().getStringValue(), r1);
+
+ String r2 = (String) results.getResource(1).getContent();
+ assertEquals(ErrorCodes.XPDY0002.toString(), r2);
+
+ String r3 = (String) results.getResource(2).getContent();
+ assertEquals(ErrorCodes.XPDY0002.toString(), r3);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-25 20:45:34
|
Revision: 13638
http://exist.svn.sourceforge.net/exist/?rev=13638&view=rev
Author: dizzzz
Date: 2011-01-25 20:45:27 +0000 (Tue, 25 Jan 2011)
Log Message:
-----------
[ignore] final fixes. one issue (testcase) left. Parser should return qname's in stead of values
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java 2011-01-25 18:41:35 UTC (rev 13637)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/ErrorCodes.java 2011-01-25 20:45:27 UTC (rev 13638)
@@ -211,6 +211,10 @@
public String toString() {
return "(" + errorQName.getNamespaceURI() + "#" + errorQName.getLocalName() + "):" + description;
}
+
+ public String getDescription(){
+ return description;
+ }
}
public static class W3CErrorCode extends ErrorCode {
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-25 18:41:35 UTC (rev 13637)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-25 20:45:27 UTC (rev 13638)
@@ -26,9 +26,11 @@
import org.apache.log4j.Logger;
import org.exist.dom.DocumentSet;
+import org.exist.dom.EmptyNodeSet;
import org.exist.dom.QName;
import org.exist.xquery.ErrorCodes.ErrorCode;
import org.exist.xquery.util.ExpressionDumper;
+import org.exist.xquery.value.EmptySequence;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.QNameValue;
import org.exist.xquery.value.Sequence;
@@ -152,6 +154,8 @@
// "(" CatchErrorCode ("," CatchErrorDesc ("," CatchErrorVal)?)? ")"
for (QName catchVar : catchVars) {
+ System.out.println("catchVar="+catchVar);
+
// restet qname and prefec
catchVar.setPrefix(null);
catchVar.setNamespaceURI("");
@@ -165,12 +169,10 @@
var.setSequenceType(new SequenceType(Type.QNAME, Cardinality.EXACTLY_ONE));
QNameValue qnv = new QNameValue(context, catchVar);
var.setValue( new StringValue( errorCode.getErrorQName().getStringValue()) );
- context.declareVariable(catchVar, var);
-
break;
case 2:
var.setSequenceType(new SequenceType(Type.STRING, Cardinality.ZERO_OR_ONE));
- StringValue sv = new StringValue( errorCode.toString() );
+ StringValue sv = new StringValue( errorCode.getDescription() );
var.setValue(sv);
break;
case 3:
Modified: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-25 18:41:35 UTC (rev 13637)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-25 20:45:27 UTC (rev 13638)
@@ -70,14 +70,14 @@
+ "{ $errcode, $errdesc } ";
try {
ResourceSet results = executeQuery(query);
-
+
assertEquals(2, results.getSize());
String r1 = (String) results.getResource(0).getContent();
assertEquals(ErrorCodes.XPDY0002.getErrorQName().getStringValue(), r1);
String r2 = (String) results.getResource(1).getContent();
- assertEquals(ErrorCodes.XPDY0002.toString(), r2);
+ assertEquals(ErrorCodes.XPDY0002.getDescription(), r2);
} catch (Throwable ex) {
ex.printStackTrace();
@@ -122,7 +122,6 @@
} catch (Throwable ex) {
// expected
-
}
}
@@ -164,7 +163,129 @@
}
}
- @Test @Ignore("Third parameter needs to be improved.")
+ @Test //@Ignore("where is the third parameter")
+ public void catchFnError3() {
+
+ String query = "try {"
+ + " fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'TEST', <ab/>) "
+ + "} catch * ($errcode, $errdesc, $errval) "
+ + "{ $errcode, $errdesc, $errval }";
+ try {
+ ResourceSet results = executeQuery(query);
+
+
+ assertEquals(3, results.getSize()); // Third parameter not there
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals("err:FOER0000", r1);
+
+ String r2 = (String) results.getResource(1).getContent();
+ assertEquals("TEST", r2);
+
+ String r3 = (String) results.getResource(2).getContent();
+ assertEquals("<ab/>", r3);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test
+ public void catchFnError2() {
+
+ String query = "try {"
+ + " fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'TEST') "
+ + "} catch * ($errcode, $errdesc) "
+ + "{ $errcode, $errdesc }";
+ try {
+ ResourceSet results = executeQuery(query);
+
+
+ assertEquals(2, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals("err:FOER0000", r1);
+
+ String r2 = (String) results.getResource(1).getContent();
+ assertEquals("TEST", r2); // <[(http://www.w3.org/2005/xqt-errors#FOER0000):]TEST>
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test
+ public void catchFnError2a() {
+
+ String query = "try {"
+ + " fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'TEST') "
+ + "} catch * ($errcode, $errdesc, $errval) "
+ + "{ $errcode, $errdesc }";
+ try {
+ ResourceSet results = executeQuery(query);
+
+
+ assertEquals(2, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals("err:FOER0000", r1);
+
+ String r2 = (String) results.getResource(1).getContent();
+ assertEquals("TEST", r2); // <[(http://www.w3.org/2005/xqt-errors#FOER0000):]TEST>
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test
+ public void catchFnError1() {
+
+ String query = "try {"
+ + " fn:error( fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000') ) "
+ + "} catch * ($errcode) "
+ + "{ $errcode }";
+ try {
+ ResourceSet results = executeQuery(query);
+
+ assertEquals(1, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals("err:FOER0000", r1);
+
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test
+ public void catchFnError1a() {
+
+ String query = "try {"
+ + " fn:error( fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000') ) "
+ + "} catch * ($errcode , $errdescr, $errval) "
+ + "{ $errcode }";
+ try {
+ ResourceSet results = executeQuery(query);
+
+ assertEquals(1, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals("err:FOER0000", r1);
+
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+ }
+
+ @Test @Ignore("issue with 3rd parameter")
public void catchFullErrorCode() {
String query = "try { a + 7 } "
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-29 19:26:14
|
Revision: 13690
http://exist.svn.sourceforge.net/exist/?rev=13690&view=rev
Author: dizzzz
Date: 2011-01-29 19:26:08 +0000 (Sat, 29 Jan 2011)
Log Message:
-----------
[ignore] cleanup, repaired testcase
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-29 18:40:42 UTC (rev 13689)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-29 19:26:08 UTC (rev 13690)
@@ -23,14 +23,13 @@
import java.util.ArrayList;
import java.util.List;
+
import org.apache.log4j.Logger;
-import org.exist.dom.DocumentSet;
-import org.exist.dom.EmptyNodeSet;
import org.exist.dom.QName;
+
import org.exist.xquery.ErrorCodes.ErrorCode;
import org.exist.xquery.util.ExpressionDumper;
-import org.exist.xquery.value.EmptySequence;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.QNameValue;
import org.exist.xquery.value.Sequence;
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java 2011-01-29 18:40:42 UTC (rev 13689)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java 2011-01-29 19:26:08 UTC (rev 13690)
@@ -24,15 +24,16 @@
import org.apache.log4j.Logger;
import org.exist.dom.QName;
+
import org.exist.xquery.BasicFunction;
import org.exist.xquery.Cardinality;
import org.exist.xquery.ErrorCodes;
import org.exist.xquery.ErrorCodes.ErrorCode;
-import org.exist.xquery.ErrorCodes.W3CErrorCode;
import org.exist.xquery.Function;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
+
import org.exist.xquery.value.FunctionParameterSequenceType;
import org.exist.xquery.value.QNameValue;
import org.exist.xquery.value.Sequence;
@@ -40,8 +41,10 @@
import org.exist.xquery.value.Type;
public class FunError extends BasicFunction {
- protected static final Logger logger = Logger.getLogger(FunError.class);
- public final static FunctionSignature signature[] = {
+
+ protected static final Logger logger = Logger.getLogger(FunError.class);
+
+ public final static FunctionSignature signature[] = {
new FunctionSignature(
new QName("error", Function.BUILTIN_FUNCTION_NS),
"Indicates that an irrecoverable error has occurred. The "
@@ -76,39 +79,48 @@
},
new SequenceType(Type.EMPTY, Cardinality.ZERO)),
};
-
- public FunError(XQueryContext context, FunctionSignature signature) {
- super(context, signature);
- }
- public final static ErrorCode DEFAULT_ERROR = ErrorCodes.FOER0000;
+ public FunError(XQueryContext context, FunctionSignature signature) {
+ super(context, signature);
+ }
+ public final static ErrorCode DEFAULT_ERROR = ErrorCodes.FOER0000;
- @Override
- public int returnsType() {
- return Type.EMPTY;
- }
+ @Override
+ public int returnsType() {
+ return Type.EMPTY;
+ }
- @Override
- public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
- ErrorCode errorCode = DEFAULT_ERROR;
- String errorDesc = "An error has been raised by the query";
- Sequence errorVal = Sequence.EMPTY_SEQUENCE;
- if (args.length > 0) {
- if(args.length > 1) {
- errorDesc = args[1].getStringValue();
- }
+ @Override
+ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
- if(!args[0].isEmpty()) {
- QName errorQName = ((QNameValue) args[0].itemAt(0)).getQName();
- errorCode = new ErrorCode(errorQName, errorDesc);
- }
+ // Define default values
+ ErrorCode errorCode = DEFAULT_ERROR;
+ String errorDesc = "An error has been raised by the query";
+ Sequence errorVal = Sequence.EMPTY_SEQUENCE;
- if(args.length == 3) {
- errorVal = args[2];
- }
+ // Enter if one or more parameters are supplied
+ if (args.length > 0) {
+
+ // If there are 2 arguments or more supplied
+ // use 2nd argument for error description
+ if (args.length > 1) {
+ errorDesc = args[1].getStringValue();
}
- logger.error(errorDesc + ": " + errorCode.toString());
- throw new XPathException(this, errorCode, errorDesc, errorVal);
- }
-}
\ No newline at end of file
+ // If first argument is not empty, get qname from argument
+ // and construct error code
+ if (!args[0].isEmpty()) {
+ QName errorQName = ((QNameValue) args[0].itemAt(0)).getQName();
+ errorCode = new ErrorCode(errorQName, errorDesc);
+ }
+
+ // If there is a third argument, us it.
+ if (args.length == 3) {
+ errorVal = args[2];
+ }
+ }
+
+ logger.error(errorDesc + ": " + errorCode.toString());
+ throw new XPathException(this, errorCode, errorDesc, errorVal);
+ }
+}
Modified: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-29 18:40:42 UTC (rev 13689)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-29 19:26:08 UTC (rev 13690)
@@ -158,7 +158,7 @@
}
}
- @Test
+ @Test
public void catchFnError3() {
String query = "try {"
@@ -203,7 +203,7 @@
assertEquals("err:FOER0000", r1);
String r2 = (String) results.getResource(1).getContent();
- assertEquals("TEST", r2);
+ assertEquals("TEST", r2);
} catch (Throwable ex) {
ex.printStackTrace();
@@ -228,7 +228,7 @@
assertEquals("err:FOER0000", r1);
String r2 = (String) results.getResource(1).getContent();
- assertEquals("TEST", r2); //
+ assertEquals("TEST", r2); //
} catch (Throwable ex) {
ex.printStackTrace();
@@ -236,7 +236,7 @@
}
}
- @Test
+ @Test
public void catchFnError1() {
String query = "try {"
@@ -249,7 +249,7 @@
assertEquals(1, results.getSize());
String r1 = (String) results.getResource(0).getContent();
- assertEquals("err:FOER0000", r1);
+ assertEquals("err:FOER0000", r1);
} catch (Throwable ex) {
@@ -280,34 +280,34 @@
}
}
- @Test @Ignore("issue with 3rd parameter")
+ @Test
public void catchFullErrorCode() {
String query = "try { a + 7 } "
+ "catch * ($errcode, $errdesc, $errval) "
- + "{ $errcode, $errdesc, $errval } ";
+ + "{ $errcode, $errdesc, empty($errval) } ";
try {
ResourceSet results = executeQuery(query);
- assertEquals(3, results.getSize());
+ assertEquals(3, results.getSize());
String r1 = (String) results.getResource(0).getContent();
assertEquals(ErrorCodes.XPDY0002.getErrorQName().getStringValue(), r1);
String r2 = (String) results.getResource(1).getContent();
- assertEquals(ErrorCodes.XPDY0002.toString(), r2);
+ assertEquals(ErrorCodes.XPDY0002.getDescription(), r2);
String r3 = (String) results.getResource(2).getContent();
- assertEquals(ErrorCodes.XPDY0002.toString(), r3);
+ assertEquals("true", r3);
} catch (Throwable ex) {
ex.printStackTrace();
- fail(ex.getMessage());
+ fail(ex.getMessage());
}
}
- @Test @Ignore(" <AST>:0:0: unexpected end of subtree") // leace at the <A></A>
+ @Test @Ignore(" <AST>:0:0: unexpected end of subtree") // leave out the <A></A> for fun
public void catchDefinedNamespace() {
String query =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-30 10:57:12
|
Revision: 13697
http://exist.svn.sourceforge.net/exist/?rev=13697&view=rev
Author: dizzzz
Date: 2011-01-30 10:57:06 +0000 (Sun, 30 Jan 2011)
Log Message:
-----------
[ignore] an attempt to get fix the namespace issue. an AST issue remains..... LJO, please help?
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java 2011-01-30 06:58:16 UTC (rev 13696)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java 2011-01-30 10:57:06 UTC (rev 13697)
@@ -111,6 +111,14 @@
// and construct error code
if (!args[0].isEmpty()) {
QName errorQName = ((QNameValue) args[0].itemAt(0)).getQName();
+
+// String prefix = errorQName.getPrefix();
+// if(prefix==null){
+// String ns = errorQName.getNamespaceURI();
+// prefix = getContext().getInScopePrefix(ns);
+// errorQName.setPrefix(prefix);
+// }
+
errorCode = new ErrorCode(errorQName, errorDesc);
}
Modified: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-30 06:58:16 UTC (rev 13696)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-30 10:57:06 UTC (rev 13697)
@@ -312,11 +312,11 @@
String query =
"declare namespace foo='http://foo.com'; "
- + "<A>try { "
- + " fn:error(fn:QName('http://foo.com', 'ValueToBig'), 'Value too big')"
- + "}"
- + "catch foo:ValueToBig { good }"
- + "catch * { wrong }</A>";
+ + "try { "
+ + " fn:error(fn:QName('http://foo.com', 'ERRORNAME'), 'ERRORTEXT')"
+ + "} "
+ + "catch foo:ERRORNAME { good } "
+ + "catch * { wrong } ";
try {
ResourceSet results = executeQuery(query);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-01-30 13:34:50
|
Revision: 13700
http://exist.svn.sourceforge.net/exist/?rev=13700&view=rev
Author: dizzzz
Date: 2011-01-30 13:34:44 +0000 (Sun, 30 Jan 2011)
Log Message:
-----------
[ignore] try-catch is only possible if xquery version='3.0'; is selected. Updated tests.
Note: default value is still 1.0; since "3.0" is just partly supported now.
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
branches/adam/eXist-xq3/src/org/exist/xquery/XQueryContext.java
branches/adam/eXist-xq3/src/org/exist/xquery/parser/XQueryTree.g
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-30 11:27:26 UTC (rev 13699)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/TryCatchExpression.java 2011-01-30 13:34:44 UTC (rev 13700)
@@ -27,6 +27,7 @@
import org.apache.log4j.Logger;
import org.exist.dom.QName;
+import org.exist.xquery.ErrorCodes.EXistErrorCode;
import org.exist.xquery.ErrorCodes.ErrorCode;
import org.exist.xquery.util.ExpressionDumper;
@@ -111,8 +112,15 @@
@Override
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
+
context.expressionStart(this);
+ if(getContext().getXQueryVersion()<30){
+ ErrorCode ec = new EXistErrorCode("EXXQDY0002", "The try-catch expression is supported "
+ + "for xquery version \"3.0\" and later.");
+ throw new XPathException(ec, ec.getDescription(), null);
+ }
+
try {
// Evaluate 'try' expression
Sequence tryTargetSeq = tryTargetExpr.eval(contextSequence, contextItem);
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/XQueryContext.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/XQueryContext.java 2011-01-30 11:27:26 UTC (rev 13699)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/XQueryContext.java 2011-01-30 13:34:44 UTC (rev 13700)
@@ -344,7 +344,9 @@
private DebuggeeJoint debuggeeJoint = null;
+ private int xqueryVersion = 10;
+
// TODO: expath repo manageer, may change
private static ExistRepository _repo = null;
@@ -3589,7 +3591,15 @@
return isVarDeclared( Debuggee.SESSION );
}
+ public void setXQueryVersion(int version) {
+ xqueryVersion=version;
+ }
+ public int getXQueryVersion(){
+ return xqueryVersion;
+ }
+
+
// ====================================================================================
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/parser/XQueryTree.g
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/parser/XQueryTree.g 2011-01-30 11:27:26 UTC (rev 13699)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/parser/XQueryTree.g 2011-01-30 13:34:44 UTC (rev 13700)
@@ -187,13 +187,12 @@
#(
v:VERSION_DECL
{
- if (v.getText().equals("1.1")) {
- //context.setVersion(11);
- }
- if (v.getText().equals("1.0")) {
- //context.setVersion(10);
+ if (v.getText().equals("3.0")) {
+ context.setXQueryVersion(30);
+ } else if (v.getText().equals("1.0")) {
+ context.setXQueryVersion(10);
} else {
- throw new XPathException(v, "err:XQST0031: Wrong XQuery version: require 1.0 or 1.1");
+ throw new XPathException(v, "err:XQST0031: Wrong XQuery version: require 1.0 or 3.0");
}
}
( enc:STRING_LITERAL )?
Modified: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-30 11:27:26 UTC (rev 13699)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-01-30 13:34:44 UTC (rev 13700)
@@ -5,6 +5,7 @@
import org.exist.test.EmbeddedExistTester;
import org.exist.xquery.ErrorCodes;
+import org.exist.xquery.XPathException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -41,15 +42,69 @@
}
@Test
- public void simpleCatch() {
+ public void xQuery3_1() {
+ String query = "xquery version '1.0';"
+ + "try { a + 7 } catch * { 1 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("1", r);
+ fail("exception expected");
+
+ } catch (Throwable t){
+
+ Throwable cause = t.getCause();
+ if(cause instanceof XPathException){
+ XPathException ex = (XPathException) cause;
+ assertEquals("exerr:EXXQDY0002", ex.getErrorCode().getErrorQName().getStringValue());
+
+ } else {
+ t.printStackTrace();
+ fail(t.getMessage());
+ }
+ }
+
+ }
+
+ @Test // default xquery version
+ public void xQuery3_2() {
+
String query = "try { a + 7 } catch * { 1 }";
try {
ResourceSet results = executeQuery(query);
String r = (String) results.getResource(0).getContent();
assertEquals("1", r);
+ fail("exception expected");
+ } catch (Throwable t){
+
+ Throwable cause = t.getCause();
+ if(cause instanceof XPathException){
+ XPathException ex = (XPathException) cause;
+ assertEquals("exerr:EXXQDY0002", ex.getErrorCode().getErrorQName().getStringValue());
+
+ } else {
+ t.printStackTrace();
+ fail(t.getMessage());
+ }
+ }
+
+ }
+
+ @Test
+ public void simpleCatch() {
+
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } catch * { 1 }";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+
+ assertEquals("1", r);
+
} catch (Throwable ex) {
ex.printStackTrace();
fail(ex.getMessage());
@@ -60,7 +115,8 @@
@Test
public void catchWithCodeAndDescription() {
- String query = "try { a + 7 } "
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } "
+ "catch * ($errcode, $errdesc, $errval) "
+ "{ $errcode, $errdesc } ";
try {
@@ -84,7 +140,8 @@
@Test
public void catchWithError3Matches() {
- String query = "try { a + 7 } "
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } "
+ "catch err:XPDY0001 { 1 }"
+ "catch err:XPDY0002 { 2 }"
+ "catch err:XPDY0003 { 3 }";
@@ -103,7 +160,8 @@
@Test
public void catchWithErrorNoMatches() {
- String query = "try { a + 7 } "
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } "
+ "catch err:XPDY0001 { 1 }"
+ "catch err:XPDY0002 { a }"
+ "catch err:XPDY0003 { 3 }";
@@ -123,7 +181,8 @@
@Test
public void catchWithError5Matches() {
- String query = "try { a + 7 } "
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } "
+ "catch err:XPDY0001 | err:XPDY0003 { 13 }"
+ "catch err:XPDY0002 { 2 }"
+ "catch err:XPDY0004 | err:XPDY0005 { 45 }";
@@ -142,7 +201,8 @@
@Test
public void catchWithError51Matches() {
- String query = "try { a + 7 } "
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } "
+ "catch err:XPDY0001 | * { 13 }"
+ "catch err:XPDY0002 { 2 }"
+ "catch err:XPDY0004 | err:XPDY0005 { 45 }";
@@ -161,7 +221,8 @@
@Test
public void catchFnError3() {
- String query = "try {"
+ String query = "xquery version '3.0';"
+ + "try {"
+ " fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'TEST', <ab/>) "
+ "} catch * ($errcode, $errdesc, $errval) "
+ "{ $errcode, $errdesc, $errval }";
@@ -189,7 +250,8 @@
@Test
public void catchFnError2() {
- String query = "try {"
+ String query = "xquery version '3.0';"
+ + "try {"
+ " fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'TEST') "
+ "} catch * ($errcode, $errdesc) "
+ "{ $errcode, $errdesc }";
@@ -214,7 +276,8 @@
@Test
public void catchFnError2a() {
- String query = "try {"
+ String query = "xquery version '3.0';"
+ + "try {"
+ " fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000'), 'TEST') "
+ "} catch * ($errcode, $errdesc, $errval) "
+ "{ $errcode, $errdesc }";
@@ -239,7 +302,8 @@
@Test
public void catchFnError1() {
- String query = "try {"
+ String query = "xquery version '3.0';"
+ + "try {"
+ " fn:error( fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000') ) "
+ "} catch * ($errcode) "
+ "{ $errcode }";
@@ -261,7 +325,8 @@
@Test
public void catchFnError1a() {
- String query = "try {"
+ String query = "xquery version '3.0';"
+ + "try {"
+ " fn:error( fn:QName('http://www.w3.org/2005/xqt-errors', 'err:FOER0000') ) "
+ "} catch * ($errcode , $errdescr, $errval) "
+ "{ $errcode }";
@@ -283,7 +348,8 @@
@Test
public void catchFullErrorCode() {
- String query = "try { a + 7 } "
+ String query = "xquery version '3.0';"
+ + "try { a + 7 } "
+ "catch * ($errcode, $errdesc, $errval) "
+ "{ $errcode, $errdesc, empty($errval) } ";
try {
@@ -310,8 +376,8 @@
@Test @Ignore(" <AST>:0:0: unexpected end of subtree") // leave out the <A></A> for fun
public void catchDefinedNamespace() {
- String query =
- "declare namespace foo='http://foo.com'; "
+ String query = "xquery version '3.0';"
+ + "declare namespace foo='http://foo.com'; "
+ "try { "
+ " fn:error(fn:QName('http://foo.com', 'ERRORNAME'), 'ERRORTEXT')"
+ "} "
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <di...@us...> - 2011-02-01 11:49:23
|
Revision: 13711
http://exist.svn.sourceforge.net/exist/?rev=13711&view=rev
Author: dizzzz
Date: 2011-02-01 11:49:14 +0000 (Tue, 01 Feb 2011)
Log Message:
-----------
[bugfix] fixed remaining namespace , found and isolated AST/antlr issie
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java 2011-02-01 11:17:47 UTC (rev 13710)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/functions/FunError.java 2011-02-01 11:49:14 UTC (rev 13711)
@@ -112,12 +112,13 @@
if (!args[0].isEmpty()) {
QName errorQName = ((QNameValue) args[0].itemAt(0)).getQName();
-// String prefix = errorQName.getPrefix();
-// if(prefix==null){
-// String ns = errorQName.getNamespaceURI();
-// prefix = getContext().getInScopePrefix(ns);
-// errorQName.setPrefix(prefix);
-// }
+// Set prefix if present
+ String prefix = errorQName.getPrefix();
+ if(prefix==null){
+ String ns = errorQName.getNamespaceURI();
+ prefix = getContext().getPrefixForURI(ns);
+ errorQName.setPrefix(prefix);
+ }
errorCode = new ErrorCode(errorQName, errorDesc);
}
Modified: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-02-01 11:17:47 UTC (rev 13710)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/TryCatchTest.java 2011-02-01 11:49:14 UTC (rev 13711)
@@ -373,12 +373,37 @@
}
- @Test @Ignore(" <AST>:0:0: unexpected end of subtree") // leave out the <A></A> for fun
- public void catchDefinedNamespace() {
+ @Test
+ public void catchDefinedNamespace1() {
String query = "xquery version '3.0';"
+ "declare namespace foo='http://foo.com'; "
+ "try { "
+ + " fn:error(fn:QName('http://foo.com', 'ERRORNAME'), 'ERRORTEXT') "
+ + "} "
+ + "catch foo:ERRORNAME { 'good' } "
+ + "catch * { 'bad' } ";
+ try {
+ ResourceSet results = executeQuery(query);
+
+ assertEquals(1, results.getSize());
+
+ String r1 = (String) results.getResource(0).getContent();
+ assertEquals("good", r1);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+ @Test @Ignore(" <AST>:0:0: unexpected end of subtree") // change good into 'good' and all is fine.
+ public void catchDefinedNamespace2() {
+
+ String query = "xquery version '3.0';"
+ + "declare namespace foo='http://foo.com'; "
+ + "try { "
+ " fn:error(fn:QName('http://foo.com', 'ERRORNAME'), 'ERRORTEXT')"
+ "} "
+ "catch foo:ERRORNAME { good } "
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <el...@us...> - 2011-02-25 09:52:45
|
Revision: 13846
http://exist.svn.sourceforge.net/exist/?rev=13846&view=rev
Author: ellefj
Date: 2011-02-25 09:52:38 +0000 (Fri, 25 Feb 2011)
Log Message:
-----------
[ignore] xq3 switch expression finalised. Test version 3. Also in test files.
Modified Paths:
--------------
branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java
branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml
Added Paths:
-----------
branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java
Modified: branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java
===================================================================
--- branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java 2011-02-24 20:55:49 UTC (rev 13845)
+++ branches/adam/eXist-xq3/src/org/exist/xquery/SwitchExpression.java 2011-02-25 09:52:38 UTC (rev 13846)
@@ -27,6 +27,8 @@
import org.exist.dom.DocumentSet;
import org.exist.dom.QName;
+import org.exist.xquery.ErrorCodes.EXistErrorCode;
+import org.exist.xquery.ErrorCodes.ErrorCode;
import org.exist.xquery.functions.FunDeepEqual;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xquery.value.AtomicValue;
@@ -81,6 +83,12 @@
public Sequence eval(Sequence contextSequence, Item contextItem)
throws XPathException {
+ if(getContext().getXQueryVersion() < 30){
+ ErrorCode ec = new EXistErrorCode("EXXQDY0002", "The switch expression is supported "
+ + "for xquery version \"3.0\" and later.");
+ throw new XPathException(ec, ec.getDescription(), null);
+ }
+
if (contextItem != null)
contextSequence = contextItem.toSequence();
Item opItem = operand.eval(contextSequence).itemAt(0);
Added: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java
===================================================================
--- branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java (rev 0)
+++ branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java 2011-02-25 09:52:38 UTC (rev 13846)
@@ -0,0 +1,128 @@
+/*
+ * eXist Open Source Native XML Database
+ * Copyright (C) 2011 The eXist Project
+ * http://exist-db.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $Id$
+ */
+package org.exist.xquery.functions.xquery3;
+
+import org.junit.Ignore;
+import org.xmldb.api.base.ResourceSet;
+
+import org.exist.test.EmbeddedExistTester;
+import org.exist.xquery.ErrorCodes;
+import org.exist.xquery.XPathException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author ljo
+ */
+public class SwitchTest extends EmbeddedExistTester {
+
+ public SwitchTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ System.out.println("***********************");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ // *******************************************
+
+ @Test
+ public void oneCaseCaseMatch() {
+ String query = "xquery version '3.0';"
+ + "let $animal := 'Cat' return"
+ + "switch ($animal)"
+ + "case 'Cow' return 'Moo'"
+ + "case 'Cat' return 'Meow'"
+ + "case 'Duck' return 'Quack'"
+ + "default return 'Odd noise!'";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+ assertEquals("Meow", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+ @Test
+ public void twoCaseDefault() {
+ String query = "xquery version '3.0';"
+ + "let $animal := 'Cat' return"
+ + "switch ($animal)"
+ + "case 'Cow' case 'Calf' return 'Moo'"
+ + "default return 'No Bull?'";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+ assertEquals("No Bull?", r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+
+
+ @Test
+ public void twoCaseCaseMatch() {
+ String query = "xquery version '3.0';"
+ + "let $animal := 'Calf' return"
+ + "switch ($animal)"
+ + "case 'Cow' case 'Calf' return 'Moo'"
+ + "case 'Cat' return 'Meow'"
+ + "case 'Duck' return 'Quack'"
+ + "default return 'Odd noise!'";
+ try {
+ ResourceSet results = executeQuery(query);
+ String r = (String) results.getResource(0).getContent();
+ assertEquals("Moo",r);
+
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ fail(ex.getMessage());
+ }
+
+ }
+}
Property changes on: branches/adam/eXist-xq3/test/src/org/exist/xquery/functions/xquery3/SwitchTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml
===================================================================
--- branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml 2011-02-24 20:55:49 UTC (rev 13845)
+++ branches/adam/eXist-xq3/test/src/xquery/xquery3/xq3_switch.xml 2011-02-25 09:52:38 UTC (rev 13846)
@@ -53,6 +53,7 @@
<task>A switch expression with all string case alternatives
</task>
<code><![CDATA[
+ xquery version "3.0";
let $animal := "Cat"
return
switch ($animal)
@@ -68,6 +69,7 @@
<task>A switch with multiple case clauses with one return
</task>
<code><![CDATA[
+ xquery version "3.0";
let $animal := "Calf"
return
switch ($animal)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|