From: <sha...@us...> - 2009-02-07 11:57:27
|
Revision: 8569 http://exist.svn.sourceforge.net/exist/?rev=8569&view=rev Author: shabanovd Date: 2009-02-07 11:57:19 +0000 (Sat, 07 Feb 2009) Log Message: ----------- [ignore] atomized value match; changing test strategy Modified Paths: -------------- branches/shabanovd/xslt/extensions/fluent/src/org/exist/fluent/Node.java branches/shabanovd/xslt/src/org/exist/xquery/Atomize.java branches/shabanovd/xslt/src/org/exist/xquery/DynamicCardinalityCheck.java branches/shabanovd/xslt/src/org/exist/xquery/DynamicTypeCheck.java branches/shabanovd/xslt/src/org/exist/xquery/LocationStep.java branches/shabanovd/xslt/src/org/exist/xquery/UntypedValueCheck.java branches/shabanovd/xslt/src/org/exist/xslt/XSLStylesheet.java branches/shabanovd/xslt/src/org/exist/xslt/expression/ForEach.java branches/shabanovd/xslt/src/org/exist/xslt/expression/Template.java branches/shabanovd/xslt/src/org/exist/xslt/expression/ValueOf.java branches/shabanovd/xslt/test/src/org/exist/xslt/test/XSLTestCase.java Modified: branches/shabanovd/xslt/extensions/fluent/src/org/exist/fluent/Node.java =================================================================== --- branches/shabanovd/xslt/extensions/fluent/src/org/exist/fluent/Node.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/extensions/fluent/src/org/exist/fluent/Node.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -192,7 +192,7 @@ public Node completed(org.w3c.dom.Node[] nodes) { Transaction tx = Database.requireTransaction(); try { - tx.lockWrite(node.getDocument()); + tx.lockWrite((DocumentImpl) node.getDocument()); DocumentTrigger trigger = fireTriggerBefore(tx); StoredNode result = null; if (nodes.length == 1) { @@ -247,7 +247,7 @@ } else { Transaction tx = Database.requireTransaction(); try { - if (parent instanceof StoredNode) tx.lockWrite(((StoredNode) parent).getDocument()); + if (parent instanceof StoredNode) tx.lockWrite((DocumentImpl) ((StoredNode) parent).getDocument()); DocumentTrigger trigger = fireTriggerBefore(tx); parent.removeChild(tx.tx, child); fireTriggerAfter(tx, trigger); Modified: branches/shabanovd/xslt/src/org/exist/xquery/Atomize.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xquery/Atomize.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xquery/Atomize.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -32,7 +32,7 @@ */ public class Atomize extends AbstractExpression { - private final Expression expression; + private Expression expression; //UNDERSTAND: is it safe to remove final public Atomize(XQueryContext context, Expression expr) { super(context); @@ -136,4 +136,20 @@ public XQueryAST getASTNode() { return expression.getASTNode(); } + + public Expression getExpression(int index) { + if (index == 0) + return expression; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } + + public int getLength() { + return 1; + } + + public void replaceExpression(int index, Expression expr) { + if (index == 0) + expression = expr; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } } Modified: branches/shabanovd/xslt/src/org/exist/xquery/DynamicCardinalityCheck.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xquery/DynamicCardinalityCheck.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xquery/DynamicCardinalityCheck.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -35,7 +35,7 @@ */ public class DynamicCardinalityCheck extends AbstractExpression { - final private Expression expression; + private Expression expression; //UNDERSTAND: is it safe to remove final final private int requiredCardinality; private Error error; @@ -141,4 +141,20 @@ public void accept(ExpressionVisitor visitor) { expression.accept(visitor); } + + public Expression getExpression(int index) { + if (index == 0) + return expression; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } + + public int getLength() { + return 1; + } + + public void replaceExpression(int index, Expression expr) { + if (index == 0) + expression = expr; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } } Modified: branches/shabanovd/xslt/src/org/exist/xquery/DynamicTypeCheck.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xquery/DynamicTypeCheck.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xquery/DynamicTypeCheck.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -35,7 +35,7 @@ */ public class DynamicTypeCheck extends AbstractExpression { - final private Expression expression; + private Expression expression; //UNDERSTAND: is it safe to remove final final private int requiredType; public DynamicTypeCheck(XQueryContext context, int requiredType, Expression expr) { @@ -203,4 +203,20 @@ public void accept(ExpressionVisitor visitor) { expression.accept(visitor); } + + public Expression getExpression(int index) { + if (index == 0) + return expression; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } + + public int getLength() { + return 1; + } + + public void replaceExpression(int index, Expression expr) { + if (index == 0) + expression = expr; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } } \ No newline at end of file Modified: branches/shabanovd/xslt/src/org/exist/xquery/LocationStep.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xquery/LocationStep.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xquery/LocationStep.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -1213,7 +1213,7 @@ + " cannot be applied to an atomic value."); result = null;//TODO: contextSequence; } else { - result = matchSelf(context, contextSequence); + result = matchSelf(context, contextItem.toSequence());//contextSequence } break; case Constants.ATTRIBUTE_AXIS: Modified: branches/shabanovd/xslt/src/org/exist/xquery/UntypedValueCheck.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xquery/UntypedValueCheck.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xquery/UntypedValueCheck.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -36,7 +36,7 @@ */ public class UntypedValueCheck extends AbstractExpression { - private final Expression expression; + private Expression expression; //UNDERSTAND: is it safe to remove final private final int requiredType; private final Error error; @@ -162,4 +162,20 @@ public void accept(ExpressionVisitor visitor) { expression.accept(visitor); } + + public Expression getExpression(int index) { + if (index == 0) + return expression; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } + + public int getLength() { + return 1; + } + + public void replaceExpression(int index, Expression expr) { + if (index == 0) + expression = expr; + throw new IndexOutOfBoundsException("Index: "+index+", Size: "+getLength()); + } } Modified: branches/shabanovd/xslt/src/org/exist/xslt/XSLStylesheet.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xslt/XSLStylesheet.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xslt/XSLStylesheet.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -281,7 +281,7 @@ } for (Template template : templates) { - if (template.matched(item.toSequence(), item)) { //contextSequence + if (template.matched(contextSequence, item)) { //contextSequence matched = true; Sequence res = template.eval(contextSequence, item); Modified: branches/shabanovd/xslt/src/org/exist/xslt/expression/ForEach.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xslt/expression/ForEach.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xslt/expression/ForEach.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -79,11 +79,17 @@ } public void analyze(AnalyzeContextInfo contextInfo) throws XPathException { - super.analyze(contextInfo); - + boolean atRootCall = false; + if (attr_select != null) { select = new PathExpr(getContext()); Pattern.parse(getContext(), attr_select, select); + + if ((contextInfo.getFlags() & DOT_TEST) != 0) { + atRootCall = true; + _check_(select); + contextInfo.removeFlag(DOT_TEST); + } } for (Expression expr : steps) { @@ -96,6 +102,11 @@ steps.remove(expr); } } + + super.analyze(contextInfo); + + if (atRootCall) + contextInfo.addFlag(DOT_TEST); } // protected void _check_(PathExpr path) { Modified: branches/shabanovd/xslt/src/org/exist/xslt/expression/Template.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xslt/expression/Template.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xslt/expression/Template.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -63,6 +63,7 @@ public class Template extends Declaration implements Parameted, Comparable<Template> { private String attr_match = null; + private String attr_priority = null; private PathExpr match = null; private QName name = null; @@ -78,6 +79,7 @@ public void setToDefaults() { attr_match = null; + attr_priority = null; match = null; name = null; @@ -94,11 +96,7 @@ } else if (attr_name.equals(NAME)) { name = new QName(attr.getValue()); } else if (attr_name.equals(PRIORITY)) { - try { - priority = Double.valueOf(attr.getValue()); - } catch (NumberFormatException e) { - compileError(XSLExceptions.ERR_XTSE0530); - } + attr_priority = attr.getValue(); } else if (attr_name.equals(MODE)) { // mode = attr.getValue();//TODO: write } else if (attr_name.equals(AS)) { @@ -107,6 +105,9 @@ } public void analyze(AnalyzeContextInfo contextInfo) throws XPathException { + if (isRootMatch()) + contextInfo.addFlag(DOT_TEST); + super.analyze(contextInfo); if (attr_match != null) { @@ -115,8 +116,14 @@ _check_(match); } - - priority = computedPriority(); + if (attr_priority != null) + try { + priority = Double.valueOf(attr_priority); + } catch (NumberFormatException e) { + compileError(XSLExceptions.ERR_XTSE0530); + } + else + priority = computedPriority(); setUseStaticContext(true); } @@ -231,8 +238,8 @@ dumper.display(" name = "+name); if (mode != null) dumper.display(" mode = "+mode); - if (priority != null) - dumper.display(" priority = "+priority); + if (attr_priority != null) + dumper.display(" priority = "+attr_priority); if (as != null) dumper.display(" as = "+as); @@ -253,8 +260,8 @@ result.append(" name = "+name.getStringValue()); if (mode != null) result.append(" mode = "+mode); - if (priority != null) - result.append(" priority = "+priority); + if (attr_priority != null) + result.append(" priority = "+attr_priority); if (as != null) result.append(" as = "+as); Modified: branches/shabanovd/xslt/src/org/exist/xslt/expression/ValueOf.java =================================================================== --- branches/shabanovd/xslt/src/org/exist/xslt/expression/ValueOf.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/src/org/exist/xslt/expression/ValueOf.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -84,16 +84,26 @@ } public void analyze(AnalyzeContextInfo contextInfo) throws XPathException { - super.analyze(contextInfo); + boolean atRootCall = false;//XXX: rewrite if (attr_select != null) { select = new PathExpr(getContext()); Pattern.parse(getContext(), attr_select, select); //UNDERSTAND: <node>text<node> step = "." -> SELF:node(), but need CHILD:node() - _check_childNodes_(select); -// _check_(select, true); + if ((contextInfo.getFlags() & DOT_TEST) != 0) { + atRootCall = true; + _check_(select); + contextInfo.removeFlag(DOT_TEST); + } + + _check_childNodes_(select); } + + super.analyze(contextInfo); + + if (atRootCall) + contextInfo.addFlag(DOT_TEST); } // protected void _check_(Expression path) { Modified: branches/shabanovd/xslt/test/src/org/exist/xslt/test/XSLTestCase.java =================================================================== --- branches/shabanovd/xslt/test/src/org/exist/xslt/test/XSLTestCase.java 2009-02-06 19:31:59 UTC (rev 8568) +++ branches/shabanovd/xslt/test/src/org/exist/xslt/test/XSLTestCase.java 2009-02-07 11:57:19 UTC (rev 8569) @@ -182,7 +182,7 @@ public void tearDown() throws Exception { } -// @Test + @Test public void testSimpleTransform() { try { XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0"); @@ -380,14 +380,17 @@ @Test public void testBench() throws Exception { - String query = null; + long start_time; + long end_time; + + String query = null; String content = null; int passed = 0; boolean passing; Map<String, String> testInfo; - String reqTest = null;//"bottles"; + String reqTest = null;//"total"; for (String testName : bench.keySet()) { if ((reqTest != null) && (!testName.equals(reqTest))) @@ -399,50 +402,57 @@ testInfo = bench.get(testName); - if (testInfo.containsKey("storeBeforeTest")) + System.out.print(testName+": "); + if (testInfo.containsKey("storeBeforeTest")) { + System.out.print("skipping"); + if (testInfo.containsKey("comment")) + System.out.print(" ("+testInfo.get("comment")+")"); + System.out.println(); continue; + } - System.out.print(testName+": "); String input = loadFile(testInfo.get("input")); String stylesheet = loadFile(testInfo.get("stylesheet")); try { - XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0"); + start_time = System.currentTimeMillis(); + + XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0"); query = "xquery version \"1.0\";\n" + "declare namespace transform=\"http://exist-db.org/xquery/transform\";\n" + "declare variable $xml {"+input+"};\n" + "declare variable $xslt {"+stylesheet+"};\n" + -// "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + -// " <body>\n" + - "transform:transform($xml, $xslt, ())\n";// + -// " </body>\n" + -// "</html>"; + "transform:transform($xml, $xslt, ())\n"; ResourceSet result = service.query(query); - //check there is one result - assertEquals(1, result.getSize()); + end_time = System.currentTimeMillis(); - content = (String) result.getResource(0).getContent(); + //check there is one result +// assertEquals(1, result.getSize()); + content = ""; + for (int i = 0; i < result.getSize(); i++) + content = content + (String) result.getResource(i).getContent(); + //check the content assertTrue(checkResult(testInfo.get("reference"), content)); } catch (Exception e) { // System.out.println("************************************** query ******************************"); // System.out.println(query); -// System.out.println("************************************* content ******************************"); -// System.out.println(content); + System.out.println("************************************* content ******************************"); + System.out.println(content); passing = false; throw new RuntimeException(e); } if (passing) { - System.out.println("pass"); + end_time = end_time - start_time; + System.out.println("pass ("+end_time+" ms)"); passed++; - } -// else -// System.out.println("faild"); + } else + System.out.println("faild"); } System.out.println(" "+passed+" of "+bench.keySet().size()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |