|
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.
|