sboag 01/05/21 22:48:53
Modified: java/src/org/apache/xalan/transformer Tag: DTM_EXP
ClonerToResultTree.java KeyRefIterator.java
ResultTreeHandler.java TransformerImpl.java
java/src/org/apache/xpath Tag: DTM_EXP DOM2Helper.java
DOMHelper.java DOMOrder.java XPathContext.java
java/src/org/apache/xpath/axes Tag: DTM_EXP AxesWalker.java
FilterExprWalker.java FollowingWalker.java
LocPathIterator.java PrecedingWalker.java
UnionPathIterator.java WalkerFactory.java
java/src/org/apache/xpath/compiler Tag: DTM_EXP
Compiler.java
java/src/org/apache/xpath/patterns Tag: DTM_EXP
FunctionPattern.java NodeTest.java StepPattern.java
Added: java/src/org/apache/xpath/patterns Tag: DTM_EXP
RelativeStepPattern.java
Removed: java/src/org/apache/xpath/patterns Tag: DTM_EXP
AncestorStepPattern.java
Log:
Made the pattern execution classes fully general, i.e. not dependent
on being the child or descendent axis (in reverse terms of match
patterns, the parent or ancestor). The patterns use the DTM
traversers, and may be a tiny bit slower. Also, non-absolute patterns
(i.e. not '/' or functions) have the magic "./" added on front, which
is needed to generilize the proximity predicates. Predicates are now
executed *after* the relative step is executed, so that proximity may
be properly counted in relation to the relative step node.
I've only tested these as proper match patterns. The next step
is to build the complex LocationPaths, and use them with the
coming match iterator.
Also, deleted some references to DOMHelper.
Revision Changes Path
No revision
No revision
1.9.2.4 +0 -1
xml-xalan/java/src/org/apache/xalan/transformer/ClonerToResultTree.java
Index: ClonerToResultTree.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ClonerToResultTree.java,v
retrieving revision 1.9.2.3
retrieving revision 1.9.2.4
diff -u -r1.9.2.3 -r1.9.2.4
--- ClonerToResultTree.java 2001/05/18 07:16:22 1.9.2.3
+++ ClonerToResultTree.java 2001/05/22 05:48:44 1.9.2.4
@@ -67,7 +67,6 @@
import org.xml.sax.Attributes;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.DOMHelper;
import org.apache.xalan.res.XSLTErrorResources;
/**
1.6.2.3 +0 -1
xml-xalan/java/src/org/apache/xalan/transformer/KeyRefIterator.java
Index: KeyRefIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/KeyRefIterator.java,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -u -r1.6.2.2 -r1.6.2.3
--- KeyRefIterator.java 2001/05/18 07:16:25 1.6.2.2
+++ KeyRefIterator.java 2001/05/22 05:48:44 1.6.2.3
@@ -121,7 +121,6 @@
m_name = ki.getName();
m_lookupKey = ref;
this.m_execContext = ki.getXPathContext();
- this.m_dhelper = ki.getDOMHelper();
}
/**
1.37.2.7 +0 -7
xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java
Index: ResultTreeHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java,v
retrieving revision 1.37.2.6
retrieving revision 1.37.2.7
diff -u -r1.37.2.6 -r1.37.2.7
--- ResultTreeHandler.java 2001/05/18 07:16:27 1.37.2.6
+++ ResultTreeHandler.java 2001/05/22 05:48:44 1.37.2.7
@@ -69,16 +69,9 @@
import org.apache.xml.utils.TreeWalker;
import org.apache.xml.utils.ObjectPool;
import org.apache.xml.utils.XMLCharacterRecognizer;
-import org.apache.xpath.DOMHelper;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.XPathContext;
-//import org.w3c.dom.Node;
-//import org.w3c.dom.traversal.NodeIterator;
-//import org.w3c.dom.Attr;
-//import org.w3c.dom.DocumentFragment;
-//import org.w3c.dom.NodeList;
-//import org.w3c.dom.NamedNodeMap;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.DTMFilter;
1.90.2.12 +1 -10
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.90.2.11
retrieving revision 1.90.2.12
diff -u -r1.90.2.11 -r1.90.2.12
--- TransformerImpl.java 2001/05/17 05:38:46 1.90.2.11
+++ TransformerImpl.java 2001/05/22 05:48:44 1.90.2.12
@@ -109,20 +109,11 @@
import org.apache.xpath.compiler.XPathParser;
import org.apache.xpath.axes.ContextNodeList;
-// Back support for liaisons
-import org.apache.xpath.DOM2Helper;
-
// Serializer Imports
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.serialize.Method;
-// DOM Imports
-//import org.w3c.dom.Attr;
-//import org.w3c.dom.DocumentFragment;
-//import org.w3c.dom.Document;
-//import org.w3c.dom.traversal.NodeIterator;
-//import org.w3c.dom.Node;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.DTMManager;
@@ -954,7 +945,7 @@
}
else
{
- doc = getXPathContext().getDOMHelper().createDocument();
+ doc = org.apache.xpath.DOMHelper.createDocument();
outputNode = doc;
type = outputNode.getNodeType();
((DOMResult)outputTarget).setNode(outputNode);
No revision
No revision
1.14.2.1 +1 -1 xml-xalan/java/src/org/apache/xpath/DOM2Helper.java
Index: DOM2Helper.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/DOM2Helper.java,v
retrieving revision 1.14
retrieving revision 1.14.2.1
diff -u -r1.14 -r1.14.2.1
--- DOM2Helper.java 2001/03/12 02:12:58 1.14
+++ DOM2Helper.java 2001/05/22 05:48:45 1.14.2.1
@@ -77,7 +77,7 @@
import javax.xml.transform.TransformerException;
/**
- * <meta name="usage" content="advanced"/>
+ * @deprecated Since the introduction of the DTM, this class will be removed.
* This class provides a DOM level 2 "helper", which provides services
currently
* not provided be the DOM standard.
*/
1.26.2.1 +2 -2 xml-xalan/java/src/org/apache/xpath/DOMHelper.java
Index: DOMHelper.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/DOMHelper.java,v
retrieving revision 1.26
retrieving revision 1.26.2.1
diff -u -r1.26 -r1.26.2.1
--- DOMHelper.java 2001/01/02 03:47:13 1.26
+++ DOMHelper.java 2001/05/22 05:48:46 1.26.2.1
@@ -76,7 +76,7 @@
import javax.xml.parsers.ParserConfigurationException;
/**
- * <meta name="usage" content="advanced"/>
+ * @deprecated Since the introduction of the DTM, this class will be removed.
* This class provides a front-end to DOM implementations, providing
* a number of utility functions that either aren't yet standardized
* by the DOM spec or that are defined in optional DOM modules and
@@ -106,7 +106,7 @@
* null if we can't find a DOM implementation that permits creating
* new empty Documents.
*/
- public Document createDocument()
+ public static Document createDocument()
{
try
1.3.2.1 +1 -0 xml-xalan/java/src/org/apache/xpath/DOMOrder.java
Index: DOMOrder.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/DOMOrder.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -r1.3 -r1.3.2.1
--- DOMOrder.java 2000/12/16 02:54:21 1.3
+++ DOMOrder.java 2001/05/22 05:48:46 1.3.2.1
@@ -57,6 +57,7 @@
package org.apache.xpath;
/**
+ * @deprecated Since the introduction of the DTM, this class will be removed.
* Nodes that implement this index can return a document order index.
* Eventually, this will be replaced by DOM 3 methods.
* (compareDocumentOrder and/or compareTreePosition.)
1.20.2.8 +29 -30 xml-xalan/java/src/org/apache/xpath/XPathContext.java
Index: XPathContext.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathContext.java,v
retrieving revision 1.20.2.7
retrieving revision 1.20.2.8
diff -u -r1.20.2.7 -r1.20.2.8
--- XPathContext.java 2001/05/18 07:17:01 1.20.2.7
+++ XPathContext.java 2001/05/22 05:48:46 1.20.2.8
@@ -448,36 +448,6 @@
return getVarStack().getVariable(this, qname);
}
- // ================ DOMHelper ===================
-
- /** The basic DOM helper for the root source tree.
- * Note that I have some worry about different source tree types
- * being mixed, so this may not be a perfect place for this.
- * Right now, I think all the DOM helpers can handle a DOM that
- * they don't know about. */
- private DOMHelper m_domHelper = new DOM2Helper();
-
- /**
- * Get the DOMHelper associated with this execution context.
- *
- * @return non-null reference to a DOM helper.
- */
- public final DOMHelper getDOMHelper()
- {
- return m_domHelper;
- }
-
- /**
- * Set the DOMHelper associated with this execution context.
- *
- * @param helper reference to a dom helper to be associated with this
- * execution context.
- */
- public void setDOMHelper(DOMHelper helper)
- {
- m_domHelper = helper;
- }
-
// ================ SourceTreeManager ===================
/** The source tree manager, which associates Source objects to source
@@ -749,6 +719,35 @@
{
m_currentNodes.popQuick();
}
+
+ /**
+ * Set the current context node.
+ *
+ * @param n the <a
href="http://www.w3.org/TR/xslt#dt-current-node">current node</a>.
+ */
+ public final void pushPredicateRoot(int n)
+ {
+ m_predicateRoots.push(n);
+ }
+
+ /**
+ * Pop the current context node.
+ */
+ public final void popPredicateRoot()
+ {
+ m_predicateRoots.popQuick();
+ }
+
+ /**
+ * Pop the current context node.
+ */
+ public final int getPredicateRoot()
+ {
+ return m_predicateRoots.peepOrNull();
+ }
+
+ /** A stack of the current sub-expression nodes. */
+ private NodeVector m_predicateRoots = new NodeVector();
/** A stack of the current sub-expression nodes. */
private NodeVector m_currentExpressionNodes = new NodeVector();
No revision
No revision
1.18.2.6 +0 -2 xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java
Index: AxesWalker.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java,v
retrieving revision 1.18.2.5
retrieving revision 1.18.2.6
diff -u -r1.18.2.5 -r1.18.2.6
--- AxesWalker.java 2001/05/19 07:05:51 1.18.2.5
+++ AxesWalker.java 2001/05/22 05:48:47 1.18.2.6
@@ -65,7 +65,6 @@
import org.apache.xpath.axes.SubContextList;
import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.compiler.OpCodes;
-import org.apache.xpath.DOMHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.patterns.NodeTestFilter;
@@ -894,7 +893,6 @@
private AxesWalker getEarliestWaiting()
{
- DOMHelper dh = m_lpi.getDOMHelper();
AxesWalker first = null;
int nWaiting = m_lpi.getWaitingCount();
1.14.2.4 +0 -1
xml-xalan/java/src/org/apache/xpath/axes/FilterExprWalker.java
Index: FilterExprWalker.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/FilterExprWalker.java,v
retrieving revision 1.14.2.3
retrieving revision 1.14.2.4
diff -u -r1.14.2.3 -r1.14.2.4
--- FilterExprWalker.java 2001/05/17 05:38:48 1.14.2.3
+++ FilterExprWalker.java 2001/05/22 05:48:47 1.14.2.4
@@ -62,7 +62,6 @@
import org.apache.xpath.XPathContext;
import org.apache.xpath.VariableStack;
import org.apache.xpath.objects.XObject;
-import org.apache.xpath.DOMHelper;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.compiler.OpCodes;
1.6.2.4 +0 -1
xml-xalan/java/src/org/apache/xpath/axes/FollowingWalker.java
Index: FollowingWalker.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/FollowingWalker.java,v
retrieving revision 1.6.2.3
retrieving revision 1.6.2.4
diff -u -r1.6.2.3 -r1.6.2.4
--- FollowingWalker.java 2001/05/19 07:05:51 1.6.2.3
+++ FollowingWalker.java 2001/05/22 05:48:47 1.6.2.4
@@ -61,7 +61,6 @@
import org.apache.xpath.axes.LocPathIterator;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.DOMHelper;
//import org.w3c.dom.Node;
import org.apache.xml.dtm.DTM;
1.24.2.6 +0 -29
xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java
Index: LocPathIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java,v
retrieving revision 1.24.2.5
retrieving revision 1.24.2.6
diff -u -r1.24.2.5 -r1.24.2.6
--- LocPathIterator.java 2001/05/17 05:38:48 1.24.2.5
+++ LocPathIterator.java 2001/05/22 05:48:47 1.24.2.6
@@ -60,14 +60,6 @@
import java.util.Vector;
import java.util.Stack;
-// DOM imports
-//import org.w3c.dom.traversal.NodeIterator;
-//import org.w3c.dom.traversal.TreeWalker;
-//import org.w3c.dom.traversal.NodeFilter;
-//import org.w3c.dom.Node;
-//import org.w3c.dom.NamedNodeMap;
-//import org.w3c.dom.DOMException;
-//import org.w3c.dom.NodeList;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.DTMFilter;
@@ -78,7 +70,6 @@
import org.apache.xpath.XPath;
import org.apache.xpath.compiler.OpMap;
import org.apache.xpath.compiler.Compiler;
-import org.apache.xpath.DOMHelper;
import org.apache.xpath.compiler.OpCodes;
import org.apache.xpath.compiler.PsuedoNames;
import org.apache.xpath.NodeSet;
@@ -321,7 +312,6 @@
this.m_currentContextNode = execContext.getCurrentExpressionNode();
this.m_execContext = execContext;
this.m_prefixResolver = execContext.getNamespaceContext();
- this.m_dhelper = execContext.getDOMHelper();
if (m_isTopLevel)
{
@@ -347,7 +337,6 @@
this.m_currentContextNode = context;
this.m_execContext = execContext;
this.m_prefixResolver = execContext.getNamespaceContext();
- this.m_dhelper = execContext.getDOMHelper();
if (m_isTopLevel)
{
@@ -647,7 +636,6 @@
m_cdtm = null;
this.m_execContext = null;
this.m_prefixResolver = null;
- this.m_dhelper = null;
this.m_varStackPos = -1;
this.m_varStackContext = 0;
@@ -964,17 +952,6 @@
}
/**
- * The DOM helper for the given context;
- *
- * @return The DOMHelper that should be used,
- * or null if initContext has not been called.
- */
- public final DOMHelper getDOMHelper()
- {
- return m_dhelper;
- }
-
- /**
* The node context for the iterator.
*
* @return The node context, same as getRoot().
@@ -1193,12 +1170,6 @@
/** This is true if nextNode returns null. */
transient protected boolean m_foundLast = false;
-
- /**
- * Quicker access to the DOM helper than going through the
- * XPathContext object.
- */
- transient protected DOMHelper m_dhelper;
/**
* The context node for this iterator, which doesn't change through
1.10.2.3 +0 -1
xml-xalan/java/src/org/apache/xpath/axes/PrecedingWalker.java
Index: PrecedingWalker.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/PrecedingWalker.java,v
retrieving revision 1.10.2.2
retrieving revision 1.10.2.3
diff -u -r1.10.2.2 -r1.10.2.3
--- PrecedingWalker.java 2001/05/06 02:09:51 1.10.2.2
+++ PrecedingWalker.java 2001/05/22 05:48:47 1.10.2.3
@@ -59,7 +59,6 @@
import org.apache.xpath.axes.LocPathIterator;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.DOMHelper;
//import org.w3c.dom.Node;
import org.apache.xml.dtm.DTM;
1.15.2.6 +0 -1
xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java
Index: UnionPathIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/UnionPathIterator.java,v
retrieving revision 1.15.2.5
retrieving revision 1.15.2.6
diff -u -r1.15.2.5 -r1.15.2.6
--- UnionPathIterator.java 2001/05/17 05:38:49 1.15.2.5
+++ UnionPathIterator.java 2001/05/22 05:48:47 1.15.2.6
@@ -73,7 +73,6 @@
import org.apache.xpath.Expression;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
-import org.apache.xpath.DOMHelper;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.compiler.Compiler;
1.13.2.1 +513 -104
xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java
Index: WalkerFactory.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -r1.13 -r1.13.2.1
--- WalkerFactory.java 2001/02/10 19:56:06 1.13
+++ WalkerFactory.java 2001/05/22 05:48:47 1.13.2.1
@@ -59,12 +59,14 @@
import org.apache.xpath.compiler.OpCodes;
import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.patterns.NodeTest;
+import org.apache.xpath.patterns.StepPattern;
+import org.apache.xpath.Expression;
import org.w3c.dom.traversal.NodeFilter;
/**
- * This class is both a factory for XPath location path expressions,
- * which are built from the opcode map output, and an analysis engine
+ * This class is both a factory for XPath location path expressions,
+ * which are built from the opcode map output, and an analysis engine
* for the location path expressions in order to provide optimization hints.
*/
public class WalkerFactory
@@ -78,7 +80,7 @@
* @param context The current source tree context node.
*
* @param lpi The owning location path iterator.
- * @param compiler non-null reference to compiler object that has
processed
+ * @param compiler non-null reference to compiler object that has processed
* the XPath operations into an opcode map.
* @param stepOpCodePos The opcode position for the step.
*
@@ -115,7 +117,7 @@
* @param context The current source tree context node.
*
* @param lpi The owning location path iterator object.
- * @param compiler non-null reference to compiler object that has
processed
+ * @param compiler non-null reference to compiler object that has processed
* the XPath operations into an opcode map.
* @param stepOpCodePos The opcode position for the step.
* @param stepIndex The top-level step index withing the iterator.
@@ -140,8 +142,8 @@
walker = createDefaultWalker(compiler, stepOpCodePos, lpi, analysis);
walker.init(compiler, stepOpCodePos, stepType);
- // walker.setAnalysis(analysis);
+ // walker.setAnalysis(analysis);
if (null == firstWalker)
{
firstWalker = walker;
@@ -163,10 +165,10 @@
}
/**
- * Create a new LocPathIterator iterator. The exact type of iterator
+ * Create a new LocPathIterator iterator. The exact type of iterator
* returned is based on an analysis of the XPath operations.
*
- * @param compiler non-null reference to compiler object that has
processed
+ * @param compiler non-null reference to compiler object that has processed
* the XPath operations into an opcode map.
* @param opPos The position of the operation code for this itterator.
*
@@ -178,23 +180,24 @@
Compiler compiler, int opPos)
throws javax.xml.transform.TransformerException
{
+
int firstStepPos = compiler.getFirstChildPos(opPos);
int analysis = analyze(compiler, firstStepPos, 0);
-
-
+
// Is the iteration exactly one child step?
if ((BIT_CHILD | 0x00000001) == (analysis & (BIT_CHILD | BITS_COUNT)))
{
+
// BIT_NODETEST_ANY: 1000000000000000000000000000000
// BIT_PREDICATE: 1000000000000
// new iterator: ChildIterator: 1000000000000010000000000000001,
node()
// Does the pattern specify *any* child with no predicate? (i.e.
select="child::node()".
- if ((BIT_NODETEST_ANY == (analysis & BIT_NODETEST_ANY)) &&
- !(BIT_PREDICATE == (analysis & BIT_PREDICATE)))
+ if ((BIT_NODETEST_ANY == (analysis & BIT_NODETEST_ANY))
+ &&!(BIT_PREDICATE == (analysis & BIT_PREDICATE)))
{
if (DEBUG_ITERATOR_CREATION)
- System.out.println("new iterator: ChildIterator: "
- + Integer.toBinaryString(analysis) + ", "
+ System.out.println("new iterator: ChildIterator: "
+ + Integer.toBinaryString(analysis) + ", "
+ compiler.toString());
// Use simple child iteration without any test.
@@ -203,27 +206,29 @@
else
{
if (DEBUG_ITERATOR_CREATION)
- System.out.println("new iterator: ChildTestIterator: "
- + Integer.toBinaryString(analysis) + ", "
+ System.out.println("new iterator: ChildTestIterator: "
+ + Integer.toBinaryString(analysis) + ", "
+ compiler.toString());
// Else use simple node test iteration with predicate test.
return new ChildTestIterator(compiler, opPos, analysis);
}
}
+
// Is the iteration a one-step attribute pattern (i.e. select="@foo")?
else if ((BIT_ATTRIBUTE | 0x00000001)
== (analysis & (BIT_ATTRIBUTE | BITS_COUNT)))
{
if (DEBUG_ITERATOR_CREATION)
- System.out.println("new iterator: AttributeIterator: "
- + Integer.toBinaryString(analysis) + ", "
+ System.out.println("new iterator: AttributeIterator: "
+ + Integer.toBinaryString(analysis) + ", "
+ compiler.toString());
// Then use a simple iteration of the attributes, with node test
// and predicate testing.
return new AttributeIterator(compiler, opPos, analysis);
}
+
// Analysis of "//center":
// bits: 1001000000001010000000000000011
// count: 3
@@ -236,30 +241,32 @@
// "//table[3]", because this has to be analyzed as
// "/descendant-or-self::node()/table[3]" in order for the indexes
// to work right.
- else if (0 == (BIT_PREDICATE & analysis) &&
- (((BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | 0x00000001)
- == (analysis
- & (BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF | BITS_COUNT)))
||
- ((BIT_DESCENDANT_OR_SELF | BIT_SELF | 0x00000002)
- == (analysis
- & (BIT_DESCENDANT_OR_SELF | BIT_SELF | BITS_COUNT)))
-
- /* ".//center" -- 1000010000001010000000000000011 */
- || ((BIT_DESCENDANT_OR_SELF | BIT_SELF | BIT_CHILD |
BIT_NODETEST_ANY | 0x00000003)
- == (analysis
- & (BIT_DESCENDANT_OR_SELF | BIT_SELF | BIT_CHILD |
BIT_NODETEST_ANY | BITS_COUNT)))
-
- /* "//center" -- 1001000000001010000000000000011 */
- || ((BIT_DESCENDANT_OR_SELF | BIT_ROOT | BIT_CHILD |
BIT_NODETEST_ANY |
- BIT_ANY_DESCENDANT_FROM_ROOT | 0x00000003)
- == (analysis
- & (BIT_DESCENDANT_OR_SELF | BIT_ROOT | BIT_CHILD |
- BIT_NODETEST_ANY | BIT_ANY_DESCENDANT_FROM_ROOT |
BITS_COUNT))))
- )
+ else if (0 == (BIT_PREDICATE
+ & analysis) && (((BIT_DESCENDANT | BIT_DESCENDANT_OR_SELF
+ | 0x00000001) == (analysis
+ & (BIT_DESCENDANT |
BIT_DESCENDANT_OR_SELF | BITS_COUNT))) || ((BIT_DESCENDANT_OR_SELF
+ | BIT_SELF
+ | 0x00000002) == (analysis
+ & (BIT_DESCENDANT_OR_SELF
+ | BIT_SELF | BITS_COUNT)))
+
+ /* ".//center" -- 1000010000001010000000000000011 */
+ || ((BIT_DESCENDANT_OR_SELF | BIT_SELF | BIT_CHILD | BIT_NODETEST_ANY
+ | 0x00000003) == (analysis
+ & (BIT_DESCENDANT_OR_SELF | BIT_SELF | BIT_CHILD
+ | BIT_NODETEST_ANY | BITS_COUNT)))
+
+ /* "//center" -- 1001000000001010000000000000011 */
+ || ((BIT_DESCENDANT_OR_SELF | BIT_ROOT | BIT_CHILD | BIT_NODETEST_ANY
+ | BIT_ANY_DESCENDANT_FROM_ROOT
+ | 0x00000003) == (analysis
+ & (BIT_DESCENDANT_OR_SELF | BIT_ROOT | BIT_CHILD
+ | BIT_NODETEST_ANY | BIT_ANY_DESCENDANT_FROM_ROOT
+ | BITS_COUNT)))))
{
if (DEBUG_ITERATOR_CREATION)
- System.out.println("new iterator: DescendantIterator: "
- + Integer.toBinaryString(analysis) + ", "
+ System.out.println("new iterator: DescendantIterator: "
+ + Integer.toBinaryString(analysis) + ", "
+ compiler.toString());
return new DescendantIterator(compiler, opPos, analysis);
@@ -267,24 +274,25 @@
else
{
if (DEBUG_ITERATOR_CREATION)
- System.out.println("new iterator: LocPathIterator: "
- + Integer.toBinaryString(analysis) + ", "
+ System.out.println("new iterator: LocPathIterator: "
+ + Integer.toBinaryString(analysis) + ", "
+ compiler.toString());
+
return new LocPathIterator(compiler, opPos, analysis, true);
}
}
/**
- * Analyze the location path and return 32 bits that give information
about
- * the location path as a whole. See the BIT_XXX constants for meaning
about
+ * Analyze the location path and return 32 bits that give information about
+ * the location path as a whole. See the BIT_XXX constants for meaning
about
* each of the bits.
*
- * @param compiler non-null reference to compiler object that has
processed
+ * @param compiler non-null reference to compiler object that has processed
* the XPath operations into an opcode map.
* @param stepOpCodePos The opcode position for the step.
* @param stepIndex The top-level step index withing the iterator.
*
- * @return 32 bits as an integer that give information about the location
+ * @return 32 bits as an integer that give information about the location
* path as a whole.
*
* @throws javax.xml.transform.TransformerException
@@ -344,11 +352,13 @@
analysisResult |= BIT_DESCENDANT;
break;
case OpCodes.FROM_DESCENDANTS_OR_SELF :
+
// Use a special bit to to make sure we get the right analysis of
"//foo".
- if(2 == stepCount && BIT_ROOT == analysisResult)
+ if (2 == stepCount && BIT_ROOT == analysisResult)
{
analysisResult |= BIT_ANY_DESCENDANT_FROM_ROOT;
}
+
analysisResult |= BIT_DESCENDANT_OR_SELF;
break;
case OpCodes.FROM_FOLLOWING :
@@ -399,11 +409,379 @@
return analysisResult;
}
+ /**
+ * NEEDSDOC Method loadSteps
+ *
+ *
+ * NEEDSDOC @param mpi
+ * NEEDSDOC @param compiler
+ * NEEDSDOC @param stepOpCodePos
+ * NEEDSDOC @param stepIndex
+ *
+ * NEEDSDOC (loadSteps) @return
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ static StepPattern loadSteps(
+ MatchPatternIterator mpi, Compiler compiler, int stepOpCodePos,
int stepIndex)
+ throws javax.xml.transform.TransformerException
+ {
+
+ int stepType;
+ StepPattern step = null;
+ StepPattern firstStep = null, prevStep = null;
+ int ops[] = compiler.getOpMap();
+ int analysis = analyze(compiler, stepOpCodePos, stepIndex);
+
+ while (OpCodes.ENDOP != (stepType = ops[stepOpCodePos]))
+ {
+ step = createDefaultStepPattern(compiler, stepOpCodePos, mpi,
analysis);
+
+ //step.init(compiler, stepOpCodePos, stepType);
+ // walker.setAnalysis(analysis);
+ if (null == firstStep)
+ {
+ firstStep = step;
+ }
+ else
+ {
+
+ //prevStep.setNextWalker(step);
+ step.setRelativePathPattern(prevStep);
+ }
+
+ prevStep = step;
+ stepOpCodePos = compiler.getNextStepPos(stepOpCodePos);
+
+ if (stepOpCodePos < 0)
+ break;
+ }
+
+ return step; // start from last pattern?? //firstStep;
+ }
+
+ /**
+ * NEEDSDOC Method createDefaultStepPattern
+ *
+ *
+ * NEEDSDOC @param compiler
+ * NEEDSDOC @param opPos
+ * NEEDSDOC @param mpi
+ * NEEDSDOC @param analysis
+ *
+ * NEEDSDOC (createDefaultStepPattern) @return
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ private static StepPattern createDefaultStepPattern(
+ Compiler compiler, int opPos, MatchPatternIterator mpi, int
analysis)
+ throws javax.xml.transform.TransformerException
+ {
+
+ StepPattern ai = null;
+ int stepType = compiler.getOp(opPos);
+ boolean simpleInit = false;
+ int totalNumberWalkers = (analysis & BITS_COUNT);
+ boolean prevIsOneStepDown = true;
+ int firstStepPos = compiler.getFirstChildPos(opPos);
+ int whatToShow = compiler.getWhatToShow(opPos);
+
+ switch (stepType)
+ {
+ case OpCodes.OP_VARIABLE :
+ case OpCodes.OP_EXTFUNCTION :
+ case OpCodes.OP_FUNCTION :
+ case OpCodes.OP_GROUP :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: FilterExprWalker: " + analysis
+ + ", " + compiler.toString());
+
+ //ai = new FilterExprWalker(lpi);
+ Expression expr;
+
+ switch (stepType)
+ {
+ case OpCodes.OP_GROUP :
+ expr = compiler.compile(opPos);
+ break;
+ default :
+ expr = compiler.compile(opPos + 2);
+ }
+
+ // ai = new FunctionPattern(expr);
+ simpleInit = true;
+ break;
+ case OpCodes.FROM_ROOT :
+ whatToShow = NodeFilter.SHOW_DOCUMENT
+ | NodeFilter.SHOW_DOCUMENT_FRAGMENT;
+
+ if (0 == (analysis
+ & ~(BIT_ROOT | BIT_CHILD | BIT_ATTRIBUTE | BIT_NAMESPACE
+ | BIT_PREDICATE | BITS_COUNT)))
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: RootWalkerMultiStep: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = //new StepPattern(NodeFilter.SHOW_DOCUMENT |
NodeFilter.SHOW_DOCUMENT_FRAGMENT);
+ // new RootStepPattern(whatToShow);
+ }
+ else
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: RootWalker: " + analysis + ", "
+ + compiler.toString());
+
+ // ai = //new StepPattern(NodeFilter.SHOW_DOCUMENT |
NodeFilter.SHOW_DOCUMENT_FRAGMENT);
+ // new RootStepPattern(whatToShow);
+ }
+ break;
+ case OpCodes.FROM_ANCESTORS :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: AncestorWalker: " + analysis + ", "
+ + compiler.toString());
+
+ whatToShow = compiler.getWhatToShow(opPos);
+
+ // ai = new RelativeStepPattern(whatToShow, mpi);
+ break;
+ case OpCodes.FROM_ANCESTORS_OR_SELF :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: AncestorOrSelfWalker: " + analysis
+ + ", " + compiler.toString());
+
+ whatToShow = compiler.getWhatToShow(opPos);
+
+ // ai = new AncestorOrSelfStepPattern(whatToShow, mpi);
+ break;
+ case OpCodes.FROM_ATTRIBUTES :
+ whatToShow = NodeFilter.SHOW_ATTRIBUTE;
+
+ if (1 == totalNumberWalkers)
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: AttributeWalkerOneStep: "
+ + analysis + ", " + compiler.toString());
+
+ // TODO: We should be able to do this as long as this is
+ // the last step.
+ // ai = /*new StepPattern(NodeFilter.SHOW_ATTRIBUTE,
+ // compiler.getStepNS(opPos),
+ //
compiler.getStepLocalName(opPos));*/
+ // new AttributeStepPattern(whatToShow);
+ }
+ else
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: AttributeWalker: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = /*new StepPattern(NodeFilter.SHOW_ATTRIBUTE,
+ // compiler.getStepNS(opPos),
+ //
compiler.getStepLocalName(opPos));*/
+ // new AttributeStepPattern(whatToShow);
+ }
+ break;
+ case OpCodes.FROM_NAMESPACE :
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: NamespaceWalker: " + analysis + ", "
+ + compiler.toString());
+
+ // ai = new NamespaceStepPattern(whatToShow);
+ break;
+ case OpCodes.FROM_CHILDREN :
+ if (1 == totalNumberWalkers)
+ {
+
+ // I don't think this will ever happen any more. -sb
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: ChildWalkerOneStep: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = new ChildStepPattern(whatToShow);
+ }
+ else
+ {
+ if (0 == (analysis
+ & ~(BIT_ROOT | BIT_CHILD | BIT_ATTRIBUTE | BIT_NAMESPACE
+ | BIT_PREDICATE | BITS_COUNT)))
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: ChildWalkerMultiStep: "
+ + analysis + ", " + compiler.toString());
+
+ // ai = new ChildStepPattern(whatToShow);
+ }
+ else
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: ChildWalker: " + analysis + ", "
+ + compiler.toString());
+
+ //ai = new ChildWalker(lpi);
+ //int firstStepPos = compiler.getFirstChildPos(opPos);
+ //int whatToShow = compiler.getWhatToShow(firstStepPos);
+ // ai = new ChildStepPattern(whatToShow);
+ }
+ }
+ break;
+ case OpCodes.FROM_DESCENDANTS :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: DescendantWalker: " + analysis
+ + ", " + compiler.toString());
+
+ whatToShow = compiler.getWhatToShow(opPos);
+
+ // ai = new DescendantStepPattern(whatToShow);
+ break;
+ case OpCodes.FROM_DESCENDANTS_OR_SELF :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: DescendantOrSelfWalker: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = new DescendantOrSelfStepPattern(whatToShow);
+ break;
+ case OpCodes.FROM_FOLLOWING :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: FollowingWalker: " + analysis + ", "
+ + compiler.toString());
+
+ // ai = new FollowingStepPattern(whatToShow);
+ break;
+ case OpCodes.FROM_FOLLOWING_SIBLINGS :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: FollowingSiblingWalker: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = new FollowingSiblingStepPattern(whatToShow);
+ break;
+ case OpCodes.FROM_PRECEDING :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: PrecedingWalker: " + analysis + ", "
+ + compiler.toString());
+
+ whatToShow = compiler.getWhatToShow(opPos);
+
+ // ai = new PrecedingStepPattern(whatToShow, mpi);
+ break;
+ case OpCodes.FROM_PRECEDING_SIBLINGS :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: PrecedingSiblingWalker: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = new PrecedingSiblingStepPattern(whatToShow, mpi);
+ break;
+ case OpCodes.FROM_PARENT :
+ prevIsOneStepDown = false;
+
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: ParentWalker: " + analysis + ", "
+ + compiler.toString());
+
+ // ai = new ParentStepPattern(whatToShow);
+ break;
+ case OpCodes.FROM_SELF :
+ if (1 == totalNumberWalkers)
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: SelfWalkerOneStep: " + analysis
+ + ", " + compiler.toString());
+
+ // ai = new SelfStepPattern(whatToShow);
+ }
+ else
+ {
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: SelfWalker: " + analysis + ", "
+ + compiler.toString());
+
+ // ai = new SelfStepPattern(whatToShow);
+ }
+ break;
+ case OpCodes.MATCH_ATTRIBUTE :
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: AttributeWalker(MATCH_ATTRIBUTE): "
+ + analysis + ", " + compiler.toString());
+
+ // ai = new AttributeStepPattern(whatToShow);
+ break;
+ case OpCodes.MATCH_ANY_ANCESTOR :
+ if (DEBUG_WALKER_CREATION)
+ System.out.println("new walker: ChildWalker(MATCH_ANY_ANCESTOR): "
+ + analysis + ", " + compiler.toString());
+
+ // ai = new ChildStepPattern(whatToShow);
+ break;
+ case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
+ if (DEBUG_WALKER_CREATION)
+ System.out.println(
+ "new walker: ChildWalker(MATCH_IMMEDIATE_ANCESTOR): " + analysis
+ + ", " + compiler.toString());
+
+ // ai = new ChildStepPattern(whatToShow);
+ break;
+ default :
+ throw new RuntimeException("Programmer's assertion: unknown opcode: "
+ + stepType);
+ }
+
+ if (simpleInit)
+ {
+ ai.initNodeTest(NodeFilter.SHOW_ALL);
+ }
+ else
+ {
+
+ //int whatToShow = compiler.getWhatToShow(opPos);
+
+ /*
+ System.out.print("construct: ");
+ NodeTest.debugWhatToShow(whatToShow);
+ System.out.println("or stuff: "+(whatToShow &
(NodeFilter.SHOW_ATTRIBUTE
+ | NodeFilter.SHOW_ELEMENT
+ | NodeFilter.SHOW_PROCESSING_INSTRUCTION)));
+ */
+ if ((0 == (whatToShow
+ & (NodeFilter.SHOW_ATTRIBUTE | NodeFilter.SHOW_ELEMENT
+ | NodeFilter.SHOW_PROCESSING_INSTRUCTION))) ||
(whatToShow == NodeFilter.SHOW_ALL))
+ ai.initNodeTest(whatToShow);
+ else
+ {
+ ai.initNodeTest(whatToShow, compiler.getStepNS(opPos),
+ compiler.getStepLocalName(opPos));
+ }
+ }
+
+ int argLen = compiler.getFirstPredicateOpPos(opPos);
+
+ ai.setPredicates(compiler.getCompiledPredicates(argLen));
+
+ return ai;
+ }
+
/**
- * Analyze a step and give information about it's predicates. Right now
this
+ * Analyze a step and give information about it's predicates. Right now
this
* just returns true or false if the step has a predicate.
*
- * @param compiler non-null reference to compiler object that has
processed
+ * @param compiler non-null reference to compiler object that has processed
* the XPath operations into an opcode map.
* @param opPos The opcode position for the step.
* @param stepType The type of step, one of OP_GROUP, etc.
@@ -439,11 +817,11 @@
/**
* Create the proper Walker from the axes type.
*
- * @param compiler non-null reference to compiler object that has
processed
+ * @param compiler non-null reference to compiler object that has processed
* the XPath operations into an opcode map.
* @param opPos The opcode position for the step.
* @param lpi The owning location path iterator.
- * @param analysis 32 bits of analysis, from which the type of AxesWalker
+ * @param analysis 32 bits of analysis, from which the type of AxesWalker
* may be influenced.
*
* @return non-null reference to AxesWalker derivative.
@@ -475,50 +853,58 @@
case OpCodes.OP_FUNCTION :
case OpCodes.OP_GROUP :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: FilterExprWalker: " + analysis
+ ", " + compiler.toString());
+
ai = new FilterExprWalker(lpi);
simpleInit = true;
break;
case OpCodes.FROM_ROOT :
- if (0 == (analysis & ~(BIT_ROOT | BIT_CHILD | BIT_ATTRIBUTE |
- BIT_NAMESPACE | BIT_PREDICATE | BITS_COUNT)))
+ if (0 == (analysis
+ & ~(BIT_ROOT | BIT_CHILD | BIT_ATTRIBUTE | BIT_NAMESPACE
+ | BIT_PREDICATE | BITS_COUNT)))
{
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: RootWalkerMultiStep: " + analysis
+ ", " + compiler.toString());
-
+
ai = new RootWalkerMultiStep(lpi);
}
else
{
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: RootWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: RootWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new RootWalker(lpi);
}
break;
case OpCodes.FROM_ANCESTORS :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: AncestorWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: AncestorWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new AncestorWalker(lpi);
break;
case OpCodes.FROM_ANCESTORS_OR_SELF :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: AncestorOrSelfWalker: " + analysis
+ ", " + compiler.toString());
+
ai = new AncestorOrSelfWalker(lpi);
break;
case OpCodes.FROM_ATTRIBUTES :
if (1 == totalNumberWalkers)
{
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: AttributeWalkerOneStep: " +
analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: AttributeWalkerOneStep: "
+ + analysis + ", " + compiler.toString());
// TODO: We should be able to do this as long as this is
// the last step.
@@ -529,93 +915,111 @@
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: AttributeWalker: " + analysis
+ ", " + compiler.toString());
-
+
ai = new AttributeWalker(lpi);
}
break;
case OpCodes.FROM_NAMESPACE :
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: NamespaceWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: NamespaceWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new NamespaceWalker(lpi);
break;
case OpCodes.FROM_CHILDREN :
if (1 == totalNumberWalkers)
{
+
// I don't think this will ever happen any more. -sb
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: ChildWalkerOneStep: " + analysis
+ ", "
- + compiler.toString());
+ System.out.println("new walker: ChildWalkerOneStep: " + analysis
+ + ", " + compiler.toString());
ai = new ChildWalkerOneStep(lpi);
}
else
{
- if (0 == (analysis & ~(BIT_ROOT | BIT_CHILD | BIT_ATTRIBUTE |
- BIT_NAMESPACE | BIT_PREDICATE | BITS_COUNT)))
+ if (0 == (analysis
+ & ~(BIT_ROOT | BIT_CHILD | BIT_ATTRIBUTE | BIT_NAMESPACE
+ | BIT_PREDICATE | BITS_COUNT)))
{
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: ChildWalkerMultiStep: " +
analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: ChildWalkerMultiStep: "
+ + analysis + ", " + compiler.toString());
ai = new ChildWalkerMultiStep(lpi);
}
else
{
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: ChildWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: ChildWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new ChildWalker(lpi);
}
}
break;
case OpCodes.FROM_DESCENDANTS :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: DescendantWalker: " + analysis
+ ", " + compiler.toString());
+
ai = new DescendantWalker(lpi);
break;
case OpCodes.FROM_DESCENDANTS_OR_SELF :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: DescendantOrSelfWalker: " + analysis
+ ", " + compiler.toString());
+
ai = new DescendantOrSelfWalker(lpi);
break;
case OpCodes.FROM_FOLLOWING :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: FollowingWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: FollowingWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new FollowingWalker(lpi);
break;
case OpCodes.FROM_FOLLOWING_SIBLINGS :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: FollowingSiblingWalker: " + analysis
+ ", " + compiler.toString());
+
ai = new FollowingSiblingWalker(lpi);
break;
case OpCodes.FROM_PRECEDING :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: PrecedingWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: PrecedingWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new PrecedingWalker(lpi);
break;
case OpCodes.FROM_PRECEDING_SIBLINGS :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
System.out.println("new walker: PrecedingSiblingWalker: " + analysis
+ ", " + compiler.toString());
+
ai = new PrecedingSiblingWalker(lpi);
break;
case OpCodes.FROM_PARENT :
prevIsOneStepDown = false;
+
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: ParentWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: ParentWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new ParentWalker(lpi);
break;
case OpCodes.FROM_SELF :
@@ -630,27 +1034,32 @@
else
{
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: SelfWalker: " + analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: SelfWalker: " + analysis + ", "
+ + compiler.toString());
+
ai = new SelfWalker(lpi);
}
break;
case OpCodes.MATCH_ATTRIBUTE :
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: AttributeWalker(MATCH_ATTRIBUTE): "
+ analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: AttributeWalker(MATCH_ATTRIBUTE): "
+ + analysis + ", " + compiler.toString());
+
ai = new AttributeWalker(lpi);
break;
case OpCodes.MATCH_ANY_ANCESTOR :
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker: ChildWalker(MATCH_ANY_ANCESTOR): "
+ analysis
- + ", " + compiler.toString());
+ System.out.println("new walker: ChildWalker(MATCH_ANY_ANCESTOR): "
+ + analysis + ", " + compiler.toString());
+
ai = new ChildWalker(lpi);
break;
case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
if (DEBUG_WALKER_CREATION)
- System.out.println("new walker:
ChildWalker(MATCH_IMMEDIATE_ANCESTOR): " + analysis
- + ", " + compiler.toString());
+ System.out.println(
+ "new walker: ChildWalker(MATCH_IMMEDIATE_ANCESTOR): " + analysis
+ + ", " + compiler.toString());
+
ai = new ChildWalker(lpi);
break;
default :
@@ -695,7 +1104,7 @@
/**
* First 8 bits are the number of top-level location steps. Hopefully
- * there will never be more that 255 location steps!!!
+ * there will never be more that 255 location steps!!!
*/
public static final int BITS_COUNT = 0x000000FF;
@@ -746,30 +1155,31 @@
/**
* Bit is on if any of the walkers contain a filter (i.e. id(), extension
- * function, etc.) step.
+ * function, etc.) step.
*/
public static final int BIT_FILTER = (0x00001000 << 14);
/** Bit is on if any of the walkers contain a root step. */
public static final int BIT_ROOT = (0x00001000 << 15);
-
- /** If any of these bits are on, the expression may likely traverse
outside
- * the given subtree. */
- public static final int BITMASK_TRAVERSES_OUTSIDE_SUBTREE
- = (BIT_NAMESPACE // ??
- | BIT_PRECEDING_SIBLING
- | BIT_PRECEDING
- | BIT_FOLLOWING_SIBLING
- | BIT_FOLLOWING
- | BIT_PARENT // except
parent of attrs.
- | BIT_ANCESTOR_OR_SELF
- | BIT_ANCESTOR
- | BIT_FILTER
- | BIT_ROOT);
/**
+ * If any of these bits are on, the expression may likely traverse outside
+ * the given subtree.
+ */
+ public static final int BITMASK_TRAVERSES_OUTSIDE_SUBTREE = (BIT_NAMESPACE
// ??
+ |
BIT_PRECEDING_SIBLING
+ |
BIT_PRECEDING
+ |
BIT_FOLLOWING_SIBLING
+ |
BIT_FOLLOWING
+ | BIT_PARENT
// except parent of attrs.
+ |
BIT_ANCESTOR_OR_SELF
+ |
BIT_ANCESTOR
+ | BIT_FILTER
+ | BIT_ROOT);
+
+ /**
* Bit is on if any of the walkers can go backwards in document
- * order from the context node.
+ * order from the context node.
*/
public static final int BIT_BACKWARDS_SELF = (0x00001000 << 16);
@@ -778,13 +1188,12 @@
/**
* Bit is on if any of the walkers contain an node() test. This is
- * really only useful if the count is 1.
+ * really only useful if the count is 1.
*/
public static final int BIT_NODETEST_ANY = (0x00001000 << 18);
-
+
// can't go higher than 18!
/** Bit is on if the expression is a match pattern. */
public static final int BIT_MATCH_PATTERN = (0x00001000 << 19);
-
}
No revision
No revision
1.23.2.2 +66 -8
xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
retrieving revision 1.23.2.1
retrieving revision 1.23.2.2
diff -u -r1.23.2.1 -r1.23.2.2
--- Compiler.java 2001/05/06 02:09:53 1.23.2.1
+++ Compiler.java 2001/05/22 05:48:51 1.23.2.2
@@ -89,6 +89,7 @@
import javax.xml.transform.SourceLocator;
import org.apache.xml.utils.SAXSourceLocator;
import org.apache.xml.dtm.DTMFilter;
+import org.apache.xml.dtm.Axis;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.TransformerException;
@@ -829,6 +830,8 @@
return DTMFilter.SHOW_ALL;
}
}
+
+private static final boolean DEBUG = false;
/**
* Compile a step pattern unit expression, used for both location paths
@@ -851,47 +854,72 @@
int stepType = getOpMap()[opPos];
if (OpCodes.ENDOP == stepType)
+ {
return null;
+ }
+
+ boolean addMagicSelf = true;
int endStep = getNextOpPos(opPos);
// int nextStepType = getOpMap()[endStep];
StepPattern pattern;
-
+
// boolean isSimple = ((OpCodes.ENDOP == nextStepType) && (stepCount ==
0));
int argLen;
switch (stepType)
{
case OpCodes.OP_FUNCTION :
+ if(DEBUG)
+ System.out.println("MATCH_FUNCTION: "+m_currentPattern);
+ addMagicSelf = false;
argLen = m_opMap[opPos + OpMap.MAPINDEX_LENGTH];
- pattern = new FunctionPattern(compileFunction(opPos));
+ pattern = new FunctionPattern(compileFunction(opPos), Axis.PARENT,
Axis.CHILD);
break;
case OpCodes.FROM_ROOT :
+ if(DEBUG)
+ System.out.println("FROM_ROOT, "+m_currentPattern);
+ addMagicSelf = false;
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
- pattern = new StepPattern(DTMFilter.SHOW_DOCUMENT |
DTMFilter.SHOW_DOCUMENT_FRAGMENT);
+ pattern = new StepPattern(DTMFilter.SHOW_DOCUMENT |
+ DTMFilter.SHOW_DOCUMENT_FRAGMENT,
+ Axis.PARENT, Axis.CHILD);
break;
case OpCodes.MATCH_ATTRIBUTE :
+ if(DEBUG)
+ System.out.println("MATCH_ATTRIBUTE:
"+getStepLocalName(startOpPos)+", "+m_currentPattern);
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
pattern = new StepPattern(DTMFilter.SHOW_ATTRIBUTE,
getStepNS(startOpPos),
- getStepLocalName(startOpPos));
+ getStepLocalName(startOpPos),
+ Axis.PARENT, Axis.ATTRIBUTE);
break;
case OpCodes.MATCH_ANY_ANCESTOR :
+ if(DEBUG)
+ System.out.println("MATCH_ANY_ANCESTOR:
"+getStepLocalName(startOpPos)+", "+m_currentPattern);
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
- pattern = new AncestorStepPattern(getWhatToShow(startOpPos),
+ int what = getWhatToShow(startOpPos);
+ // bit-o-hackery, but this code is due for the morgue anyway...
+ if(0x00000500 == what)
+ addMagicSelf = false;
+ pattern = new RelativeStepPattern(getWhatToShow(startOpPos),
getStepNS(startOpPos),
- getStepLocalName(startOpPos));
+ getStepLocalName(startOpPos),
+ Axis.ANCESTOR, Axis.CHILD);
break;
case OpCodes.MATCH_IMMEDIATE_ANCESTOR :
+ if(DEBUG)
+ System.out.println("MATCH_IMMEDIATE_ANCESTOR:
"+getStepLocalName(startOpPos)+", "+m_currentPattern);
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
pattern = new StepPattern(getWhatToShow(startOpPos),
getStepNS(startOpPos),
- getStepLocalName(startOpPos));
+ getStepLocalName(startOpPos),
+ Axis.PARENT, Axis.CHILD);
break;
default :
error(XPATHErrorResources.ER_UNKNOWN_MATCH_OPERATION, null);
//"unknown match operation!");
@@ -900,7 +928,37 @@
}
pattern.setPredicates(getCompiledPredicates(opPos + argLen));
- pattern.setRelativePathPattern(ancestorPattern);
+ if(null == ancestorPattern)
+ {
+ // This is the magic and invisible "." at the head of every
+ // match pattern, and corresponds to the current node in the context
+ // list, from where predicates are counted.
+ // So, in order to calculate "foo[3]", it has to count from the
+ // current node in the context list, so, from that current node,
+ // the full pattern is really "self::node()/child::foo[3]". If you
+ // translate this to a select pattern from the node being tested,
+ // which is really how we're treating match patterns, it works out to
+ // self::foo/parent::node[child::foo[3]]", or close enough.
+ int axis;
+ int predicateAxis;
+ if(addMagicSelf)
+ {
+ axis = Axis.PARENT;
+ predicateAxis = Axis.CHILD;
+ StepPattern selfPattern = new StepPattern(DTMFilter.SHOW_ALL,
+ Axis.PARENT, Axis.CHILD);
+ // We need to keep the new nodetest from affecting the score...
+ XNumber score = pattern.getStaticScore();
+ pattern.setRelativePathPattern(selfPattern);
+ pattern.setStaticScore(score);
+ selfPattern.setStaticScore(score);
+ }
+ }
+ else
+ {
+ // System.out.println("Setting "+ancestorPattern+" as relative to
"+pattern);
+ pattern.setRelativePathPattern(ancestorPattern);
+ }
StepPattern relativePathPattern = stepPattern(endStep, stepCount + 1,
pattern);
No revision
No revision
1.7.2.4 +17 -17
xml-xalan/java/src/org/apache/xpath/patterns/FunctionPattern.java
Index: FunctionPattern.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/FunctionPattern.java,v
retrieving revision 1.7.2.3
retrieving revision 1.7.2.4
diff -u -r1.7.2.3 -r1.7.2.4
--- FunctionPattern.java 2001/05/10 20:49:21 1.7.2.3
+++ FunctionPattern.java 2001/05/22 05:48:51 1.7.2.4
@@ -57,17 +57,13 @@
package org.apache.xpath.patterns;
import org.apache.xpath.XPath;
-import org.apache.xpath.DOMHelper;
import org.apache.xpath.Expression;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
-
-//import org.w3c.dom.Node;
-//import org.w3c.dom.traversal.NodeIterator;
-
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
+import org.apache.xml.dtm.Axis;
/**
* <meta name="usage" content="advanced"/>
@@ -77,16 +73,18 @@
{
/**
- * Construct a FunctionPattern from a
+ * Construct a FunctionPattern from a
* [EMAIL PROTECTED] org.apache.xpath.functions.Function expression}.
*
*
* @param a should be a [EMAIL PROTECTED]
org.apache.xpath.functions.Function expression}.
+ *
+ * NEEDSDOC @param expr
*/
- public FunctionPattern(Expression expr)
+ public FunctionPattern(Expression expr, int axis, int predaxis)
{
- super(0, null, null);
+ super(0, null, null, axis, predaxis);
m_functionExpr = expr;
}
@@ -103,8 +101,10 @@
calcTargetString();
}
- /** Should be a [EMAIL PROTECTED] org.apache.xpath.functions.Function
expression}.
- * @serial */
+ /**
+ * Should be a [EMAIL PROTECTED] org.apache.xpath.functions.Function
expression}.
+ * @serial
+ */
Expression m_functionExpr;
/**
@@ -112,22 +112,21 @@
*
* @param xctxt XPath runtime context.
*
- * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
+ * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
- public XObject execute(XPathContext xctxt) throws
javax.xml.transform.TransformerException
+ public XObject execute(XPathContext xctxt)
+ throws javax.xml.transform.TransformerException
{
int context = xctxt.getCurrentNode();
XObject obj = m_functionExpr.execute(xctxt);
-
- DTMIterator nl = obj.nodeset();
-
+ DTMIterator nl = obj.nodeset();
XNumber score = SCORE_NONE;
if (null != nl)
@@ -145,6 +144,7 @@
break;
}
}
+
// nl.detach();
}
1.20.2.5 +82 -43
xml-xalan/java/src/org/apache/xpath/patterns/NodeTest.java
Index: NodeTest.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/NodeTest.java,v
retrieving revision 1.20.2.4
retrieving revision 1.20.2.5
diff -u -r1.20.2.4 -r1.20.2.5
--- NodeTest.java 2001/05/07 13:16:12 1.20.2.4
+++ NodeTest.java 2001/05/22 05:48:51 1.20.2.5
@@ -64,24 +64,27 @@
import org.apache.xpath.objects.XObject;
import org.apache.xpath.WhitespaceStrippingElementMatcher;
import org.apache.xml.utils.PrefixResolver;
-
import org.apache.xml.dtm.DTMFilter;
import org.apache.xml.dtm.DTM;
/**
* <meta name="usage" content="advanced"/>
- * This is the basic node test class for both match patterns and location
path
+ * This is the basic node test class for both match patterns and location
path
* steps.
*/
public class NodeTest extends Expression
{
- /** The namespace or local name for node tests with a wildcard.
- * @see <a href="http://www.w3.org/TR/xpath#NT-NameTest">the XPath
NameTest production.</a> */
+ /**
+ * The namespace or local name for node tests with a wildcard.
+ * @see <a href="http://www.w3.org/TR/xpath#NT-NameTest">the XPath
NameTest production.</a>
+ */
public static final String WILD = "*";
-
- /** The URL to pass to the Node#supports method, to see if the
- * DOM has already been stripped of whitespace nodes. */
+
+ /**
+ * The URL to pass to the Node#supports method, to see if the
+ * DOM has already been stripped of whitespace nodes.
+ */
public static final String SUPPORTS_PRE_STRIPPING =
"http://xml.apache.org/xpath/features/whitespace-pre-stripping";
@@ -109,8 +112,10 @@
return m_whatToShow;
}
- /** The namespace to be tested for, which may be null.
- * @serial */
+ /**
+ * The namespace to be tested for, which may be null.
+ * @serial
+ */
String m_namespace;
/**
@@ -123,8 +128,10 @@
return m_namespace;
}
- /** The local name to be tested for.
- * @serial */
+ /**
+ * The local name to be tested for.
+ * @serial
+ */
String m_name;
/**
@@ -137,42 +144,51 @@
return (null == m_name) ? "" : m_name;
}
- /** Statically calculated score for this test. One of
- * [EMAIL PROTECTED] #SCORE_NODETEST},
- * [EMAIL PROTECTED] #SCORE_NONE},
- * [EMAIL PROTECTED] #SCORE_NSWILD},
+ /**
+ * Statically calculated score for this test. One of
+ * [EMAIL PROTECTED] #SCORE_NODETEST},
+ * [EMAIL PROTECTED] #SCORE_NONE},
+ * [EMAIL PROTECTED] #SCORE_NSWILD},
* [EMAIL PROTECTED] #SCORE_QNAME}, or
* [EMAIL PROTECTED] #SCORE_OTHER}.
* @serial
*/
XNumber m_score;
- /**
+ /**
* The match score if the pattern consists of just a NodeTest.
- * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a> */
+ * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a>
+ */
public static final XNumber SCORE_NODETEST =
new XNumber(XPath.MATCH_SCORE_NODETEST);
- /**
+ /**
* The match score if the pattern pattern has the form NCName:*.
- * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a> */
- public static final XNumber SCORE_NSWILD = new
XNumber(XPath.MATCH_SCORE_NSWILD);
+ * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a>
+ */
+ public static final XNumber SCORE_NSWILD =
+ new XNumber(XPath.MATCH_SCORE_NSWILD);
- /**
+ /**
* The match score if the pattern has the form
* of a QName optionally preceded by an @ character.
- * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a> */
- public static final XNumber SCORE_QNAME = new
XNumber(XPath.MATCH_SCORE_QNAME);
+ * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a>
+ */
+ public static final XNumber SCORE_QNAME =
+ new XNumber(XPath.MATCH_SCORE_QNAME);
- /**
+ /**
* The match score if the pattern consists of something
* other than just a NodeTest or just a qname.
- * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a> */
- public static final XNumber SCORE_OTHER = new
XNumber(XPath.MATCH_SCORE_OTHER);
+ * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a>
+ */
+ public static final XNumber SCORE_OTHER =
+ new XNumber(XPath.MATCH_SCORE_OTHER);
- /**
+ /**
* The match score if no match is made.
- * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a> */
+ * @see <a href="http://www.w3.org/TR/xslt#conflict">XSLT Specification -
5.5 Conflict Resolution for Template Rules</a>
+ */
public static final XNumber SCORE_NONE =
new XNumber(XPath.MATCH_SCORE_NONE);
@@ -206,7 +222,7 @@
public NodeTest(){}
/**
- * Initialize this node test by setting the whatToShow property, and
+ * Initialize this node test by setting the whatToShow property, and
* calculating the score that this test will return if a test succeeds.
*
*
@@ -221,8 +237,8 @@
}
/**
- * Initialize this node test by setting the whatToShow property and the
- * namespace and local name, and
+ * Initialize this node test by setting the whatToShow property and the
+ * namespace and local name, and
* calculating the score that this test will return if a test succeeds.
*
*
@@ -240,9 +256,29 @@
calcScore();
}
- /** True if this test has a null namespace and a local name of [EMAIL
PROTECTED] #WILD}.
- * @serial */
+ /**
+ * True if this test has a null namespace and a local name of [EMAIL
PROTECTED] #WILD}.
+ * @serial
+ */
private boolean m_isTotallyWild;
+
+ /**
+ * Get the static score for this node test.
+ * @return Should be one of the SCORE_XXX constants.
+ */
+ public XNumber getStaticScore()
+ {
+ return m_score;
+ }
+
+ /**
+ * Set the static score for this node test.
+ * @param score Should be one of the SCORE_XXX constants.
+ */
+ public void setStaticScore(XNumber score)
+ {
+ m_score = score;
+ }
/**
* Static calc of match score.
@@ -354,12 +390,12 @@
// System.out.println("subPartMatch - p: "+p+", t: "+t+", result: "+b);
return (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
}
-
+
/**
- * This is temporary to patch over Xerces issue with representing DOM
+ * This is temporary to patch over Xerces issue with representing DOM
* namespaces as "".
*
- * @param p part string from the node, which may represent the null
namespace
+ * @param p part string from the node, which may represent the null
namespace
* as null or as "".
* @param t target string, which may be [EMAIL PROTECTED] #WILD}.
*
@@ -368,10 +404,12 @@
private static final boolean subPartMatchNS(String p, String t)
{
- return (p == t) || ((null != p) && ((p.length() > 0) ? ((t == WILD) ||
p.equals(t)) : null == t));
+ return (p == t)
+ || ((null != p)
+ && ((p.length() > 0)
+ ? ((t == WILD) || p.equals(t)) : null == t));
}
-
/**
* Tell what the test score is for the given node.
*
@@ -379,9 +417,9 @@
* @param xctxt XPath runtime context.
* @param context The node being tested.
*
- * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
+ * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
@@ -390,6 +428,7 @@
public XObject execute(XPathContext xctxt, int context)
throws javax.xml.transform.TransformerException
{
+
DTM dtm = xctxt.getDTM(context);
short nodeType = dtm.getNodeType(context);
@@ -407,6 +446,7 @@
return m_score;
case DTMFilter.SHOW_CDATA_SECTION :
case DTMFilter.SHOW_TEXT :
+
// was:
// return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
// ? m_score : SCORE_NONE;
@@ -436,8 +476,7 @@
case DTMFilter.SHOW_ATTRIBUTE :
case DTMFilter.SHOW_ELEMENT :
{
- return (m_isTotallyWild ||
(subPartMatchNS(dtm.getNamespaceURI(context), m_namespace)
- && subPartMatch(dtm.getLocalName(context), m_name)))
+ return (m_isTotallyWild ||
(subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) &&
subPartMatch(dtm.getLocalName(context), m_name)))
? m_score : SCORE_NONE;
}
default :
1.19.2.2 +215 -179
xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java
Index: StepPattern.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java,v
retrieving revision 1.19.2.1
retrieving revision 1.19.2.2
diff -u -r1.19.2.1 -r1.19.2.2
--- StepPattern.java 2001/04/10 18:45:46 1.19.2.1
+++ StepPattern.java 2001/05/22 05:48:52 1.19.2.2
@@ -62,13 +62,10 @@
import org.apache.xml.utils.PrefixResolver;
import org.apache.xpath.axes.SubContextList;
import org.apache.xpath.compiler.PsuedoNames;
-
-// import org.w3c.dom.traversal.NodeFilter;
-// import org.w3c.dom.Node;
-// import org.w3c.dom.traversal.NodeIterator;
-
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMFilter;
+import org.apache.xml.dtm.DTMAxisTraverser;
+import org.apache.xml.dtm.Axis;
/**
* <meta name="usage" content="advanced"/>
@@ -77,6 +74,12 @@
public class StepPattern extends NodeTest implements SubContextList
{
+ /** NEEDSDOC Field m_axisForPredicate */
+ protected int m_axisForPredicate;
+
+ /** NEEDSDOC Field m_axis */
+ protected int m_axis;
+
/**
* Construct a StepPattern that tests for namespaces and node names.
*
@@ -85,10 +88,17 @@
* @param namespace The namespace to be tested.
* @param name The local name to be tested.
*/
- public StepPattern(int whatToShow, String namespace, String name)
+ public StepPattern(int whatToShow, String namespace, String name,
+ int axis, int axisForPredicate)
{
super(whatToShow, namespace, name);
+
+ m_axis = axis;
+ m_axisForPredicate = axisForPredicate;
+
+// m_axis = Axis.PARENT;
+// m_axisForPredicate = Axis.CHILD;
}
/**
@@ -97,17 +107,27 @@
*
* @param whatToShow Bit set defined mainly by [EMAIL PROTECTED]
org.w3c.dom.traversal.NodeFilter}.
*/
- public StepPattern(int whatToShow)
+ public StepPattern(int whatToShow,
+ int axis, int axisForPredicate)
{
+
super(whatToShow);
+
+ m_axis = axis;
+ m_axisForPredicate = axisForPredicate;
+
+// m_axis = Axis.PARENT;
+// m_axisForPredicate = Axis.CHILD;
}
- /** The target local name or psuedo name, for hash table lookup
optimization.
- * @serial */
+ /**
+ * The target local name or psuedo name, for hash table lookup
optimization.
+ * @serial
+ */
String m_targetString; // only calculate on head
-
+
/**
- * Calculate the local name or psuedo name of the node that this pattern
will test,
+ * Calculate the local name or psuedo name of the node that this pattern
will test,
* for hash table lookup optimization.
*
* @see org.apache.xpath.compiler.PsuedoNames
@@ -124,7 +144,7 @@
break;
case DTMFilter.SHOW_TEXT :
case DTMFilter.SHOW_CDATA_SECTION :
- case (DTMFilter.SHOW_TEXT | DTMFilter.SHOW_CDATA_SECTION):
+ case (DTMFilter.SHOW_TEXT | DTMFilter.SHOW_CDATA_SECTION) :
m_targetString = PsuedoNames.PSEUDONAME_TEXT;
break;
case DTMFilter.SHOW_ALL :
@@ -147,7 +167,7 @@
}
/**
- * Get the local name or psuedo name of the node that this pattern will
test,
+ * Get the local name or psuedo name of the node that this pattern will
test,
* for hash table lookup optimization.
*
*
@@ -177,34 +197,38 @@
{
m_relativePathPattern = expr;
-
+
calcScore();
}
- /** The list of predicate expressions for this pattern step.
- * @serial */
+ /**
+ * The list of predicate expressions for this pattern step.
+ * @serial
+ */
Expression[] m_predicates;
-
+
/**
- * Tell if this expression or it's subexpressions can traverse outside
+ * Tell if this expression or it's subexpressions can traverse outside
* the current subtree.
- *
- * NOTE: Ancestors tests with predicates are problematic, and will require
+ *
+ * NOTE: Ancestors tests with predicates are problematic, and will require
* special treatment.
- *
+ *
* @return true if traversal outside the context node's subtree can occur.
*/
- public boolean canTraverseOutsideSubtree()
- {
+ public boolean canTraverseOutsideSubtree()
+ {
+
int n = getPredicateCount();
- for (int i = 0; i < n; i++)
+
+ for (int i = 0; i < n; i++)
{
- if(getPredicate(i).canTraverseOutsideSubtree())
+ if (getPredicate(i).canTraverseOutsideSubtree())
return true;
}
-
+
return false;
- }
+ }
/**
* Get a predicate expression.
@@ -234,7 +258,7 @@
* Set the predicates for this match pattern step.
*
*
- * @param predicates An array of expressions that define predicates
+ * @param predicates An array of expressions that define predicates
* for this step.
*/
public void setPredicates(Expression[] predicates)
@@ -266,144 +290,108 @@
*
* @param xctxt XPath runtime context.
*
- * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
+ * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
- public XObject executeStep(XPathContext xctxt)
+ public XObject execute(XPathContext xctxt)
throws javax.xml.transform.TransformerException
{
- XObject score;
+ XObject score = super.execute(xctxt);
- score = super.execute(xctxt);
-
if (score == NodeTest.SCORE_NONE)
- {
-
- // System.out.println("executeStep: "+this.m_name+" = "+score);
- return score;
- }
-
- int n = getPredicateCount();
-
- if (n == 0)
return score;
- // xctxt.setNamespaceContext(m_lpi.getPrefixResolver());
- // xctxt.pushCurrentNode(context);
- try
+ else if (null != m_relativePathPattern)
{
- xctxt.pushSubContextList(this);
-
- for (int i = 0; i < n; i++)
- {
- XObject pred;
-
- pred = m_predicates[i].execute(xctxt);
-
- if (XObject.CLASS_NUMBER == pred.getType())
- {
- if (this.getProximityPosition(xctxt) != (int) pred.num())
- {
- score = NodeTest.SCORE_NONE;
-
- break;
- }
- }
- else if (!pred.bool())
- {
- score = NodeTest.SCORE_NONE;
-
- break;
- }
-
- // countProximityPosition(++m_predicateIndex);
- }
+ return m_relativePathPattern.executeRelativePathPattern(xctxt, this);
}
- finally
+ else
{
- xctxt.popSubContextList();
+ // System.out.println("PredicateRoot: "+xctxt.getPredicateRoot());
+ int current = xctxt.getCurrentNode();
+ return score;
+ // int parent = xctxt.getDTM(current).getParent(current);
+ // return executePredicates(xctxt, this, score, current, current);
}
-
- // System.out.println("executeStep: "+this.m_name+" = "+score);
- return score;
}
/**
- * Get the proximity position index of the current node based on this
+ * Get the proximity position index of the current node based on this
* node test.
*
*
* @param xctxt XPath runtime context.
*
- * @return the proximity position index of the current node based on the
+ * @return the proximity position index of the current node based on the
* node test.
*/
public int getProximityPosition(XPathContext xctxt)
{
int context = xctxt.getCurrentNode();
-
DTM dtm = xctxt.getDTM(context);
-
- // System.out.println("context: "+context.getNodeName());
- int parentContext = dtm.getParent(context);
- // System.out.println("parentContext: "+parentContext.getNodeName());
- try
+ int parentContext = xctxt.getPredicateRoot();
{
- xctxt.pushCurrentNode(parentContext);
- int pos = 0;
-
- for (int child = dtm.getFirstChild(parentContext); child != DTM.NULL;
- child = dtm.getNextSibling(child))
+ // System.out.println("parentContext: "+parentContext.getNodeName());
+ try
{
- try
- {
- xctxt.pushCurrentNode(child);
+ xctxt.pushCurrentNode(parentContext);
+
+ int pos = 0;
+ DTMAxisTraverser traverser =
dtm.getAxisTraverser(m_axisForPredicate);
- if (NodeTest.SCORE_NONE != super.execute(xctxt))
+ for (int child = traverser.first(parentContext); DTM.NULL != child;
+ child = traverser.next(parentContext, child))
+ {
+ try
{
- pos++;
+ xctxt.pushCurrentNode(child);
- if (child == context)
+ if (NodeTest.SCORE_NONE != super.execute(xctxt))
{
- return pos;
+ pos++;
+
+ if (child == context)
+ {
+ return pos;
+ }
}
}
- }
- finally
- {
- xctxt.popCurrentNode();
+ finally
+ {
+ xctxt.popCurrentNode();
+ }
}
}
- }
- catch (javax.xml.transform.TransformerException se)
- {
+ catch (javax.xml.transform.TransformerException se)
+ {
- // TODO: should keep throw sax exception...
- throw new java.lang.RuntimeException(se.getMessage());
- }
- finally
- {
- xctxt.popCurrentNode();
+ // TODO: should keep throw sax exception...
+ throw new java.lang.RuntimeException(se.getMessage());
+ }
+ finally
+ {
+ xctxt.popCurrentNode();
- // xctxt.popContextNodeList();
+ // xctxt.popContextNodeList();
+ }
}
return 0;
}
/**
- * Get the count of the nodes that match the test, which is the proximity
- * position of the last node that can pass this test in the sub context
- * selection. In XSLT 1-based indexing, this count is the index of the
last
+ * Get the count of the nodes that match the test, which is the proximity
+ * position of the last node that can pass this test in the sub context
+ * selection. In XSLT 1-based indexing, this count is the index of the
last
* node.
*
*
@@ -416,44 +404,51 @@
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
- int parentContext = dtm.getParent(context);
- try
+ int parentContext = xctxt.getPredicateRoot();
{
- xctxt.pushCurrentNode(parentContext);
-
- int count = 0;
- for (int child = dtm.getFirstChild(parentContext); child != DTM.NULL;
- child = dtm.getNextSibling(child))
+ // System.out.println("parentContext: "+parentContext.getNodeName());
+ try
{
- try
- {
- xctxt.pushCurrentNode(child);
+ xctxt.pushCurrentNode(parentContext);
- if (NodeTest.SCORE_NONE != super.execute(xctxt))
- count++;
- }
- finally
+ int count = 0;
+ DTMAxisTraverser traverser =
dtm.getAxisTraverser(m_axisForPredicate);
+
+ for (int child = traverser.first(parentContext); DTM.NULL != child;
+ child = traverser.next(parentContext, child))
{
- xctxt.popCurrentNode();
+ try
+ {
+ xctxt.pushCurrentNode(child);
+
+ if (NodeTest.SCORE_NONE != super.execute(xctxt))
+ count++;
+ }
+ finally
+ {
+ xctxt.popCurrentNode();
+ }
}
+
+ return count;
}
+ catch (javax.xml.transform.TransformerException se)
+ {
- return count;
- }
- catch (javax.xml.transform.TransformerException se)
- {
+ // TODO: should keep throw sax exception...
+ throw new java.lang.RuntimeException(se.getMessage());
+ }
+ finally
+ {
+ xctxt.popCurrentNode();
- // TODO: should keep throw sax exception...
- throw new java.lang.RuntimeException(se.getMessage());
+ // xctxt.popContextNodeList();
+ }
}
- finally
- {
- xctxt.popCurrentNode();
- // xctxt.popContextNodeList();
- }
+ // return 0;
}
/**
@@ -461,78 +456,119 @@
*
*
* @param xctxt The XPath runtime context.
+ * NEEDSDOC @param prevStep
*
- * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
+ * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
+ * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
- public XObject executeRelativePathPattern(XPathContext xctxt)
- throws javax.xml.transform.TransformerException
+ public XObject executeRelativePathPattern(
+ XPathContext xctxt, StepPattern prevStep)
+ throws javax.xml.transform.TransformerException
{
- XObject score;
- int currentNode = xctxt.getCurrentNode();
- DTM dtm = xctxt.getDTM(currentNode);
- int parent = dtm.getParent(currentNode);
+ XObject score = NodeTest.SCORE_NONE;
+ int context = xctxt.getCurrentNode();
+ DTM dtm = xctxt.getDTM(context);
- if (DTM.NULL != parent)
+ if (null != dtm)
{
- try
+ DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
+ int predContext = xctxt.getCurrentNode();
+
+ for (int relative = traverser.first(context); DTM.NULL != relative;
+ relative = traverser.next(context, relative))
{
- xctxt.pushCurrentNode(parent);
+ try
+ {
+ xctxt.pushCurrentNode(relative);
- score = execute(xctxt);
+ score = execute(xctxt);
- if (score != NodeTest.SCORE_NONE)
- score = SCORE_OTHER;
- }
- finally
- {
- xctxt.popCurrentNode();
+ if (score != NodeTest.SCORE_NONE)
+ {
+ score = executePredicates( xctxt, prevStep, SCORE_OTHER,
+ predContext, relative);
+
+ if (score != NodeTest.SCORE_NONE)
+ break;
+ }
+ }
+ finally
+ {
+ xctxt.popCurrentNode();
+ }
}
}
- else
- score = NodeTest.SCORE_NONE;
return score;
}
/**
- * Test the current node to see if it matches the given node test, and if
- * it does, and there is a relative path pattern, execute that to see if
it
- * matches also.
+ * NEEDSDOC Method executePredicates
*
- * @param xctxt XPath runtime context.
*
- * @return [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
- * [EMAIL PROTECTED]
org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
+ * NEEDSDOC @param xctxt
+ * NEEDSDOC @param prevStep
+ * NEEDSDOC @param score
+ *
+ * NEEDSDOC (executePredicates) @return
*
* @throws javax.xml.transform.TransformerException
*/
- public XObject execute(XPathContext xctxt) throws
javax.xml.transform.TransformerException
+ private static XObject executePredicates(
+ XPathContext xctxt, StepPattern prevStep, XObject score,
+ int context, int predicateRootContext)
+ throws javax.xml.transform.TransformerException
{
-
- XObject score;
- // int n = getPredicateCount();
- score = executeStep(xctxt);
+ int n = prevStep.getPredicateCount();
- if ((score != NodeTest.SCORE_NONE) && (null != m_relativePathPattern))
+ if (n != 0)
{
- score = m_relativePathPattern.executeRelativePathPattern(xctxt);
+ try
+ {
+ xctxt.pushCurrentNode(context);
+ xctxt.pushSubContextList(prevStep);
+ xctxt.pushPredicateRoot(predicateRootContext);
+
+ for (int i = 0; i < n; i++)
+ {
+ XObject pred = prevStep.m_predicates[i].execute(xctxt);
+
+ if (XObject.CLASS_NUMBER == pred.getType())
+ {
+ if (prevStep.getProximityPosition(xctxt) != (int) pred.num())
+ {
+ score = NodeTest.SCORE_NONE;
+
+ break;
+ }
+ }
+ else if (!pred.bool())
+ {
+ score = NodeTest.SCORE_NONE;
+
+ break;
+ }
+ }
+ }
+ finally
+ {
+ xctxt.popCurrentNode();
+ xctxt.popSubContextList();
+ xctxt.popPredicateRoot();
+ }
}
return score;
}
- /** Set to true to send diagnostics about pattern matches to the consol.
*/
+ /** Set to true to send diagnostics about pattern matches to the consol. */
private static final boolean DEBUG_MATCHES = false;
/**
No revision
No revision
1.1.2.1 +150 -0
xml-xalan/java/src/org/apache/xpath/patterns/Attic/RelativeStepPattern.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]