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