You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/11/16 21:04:52 UTC
cvs commit: xml-xalan/java/src/org/apache/xpath/patterns FunctionPattern.java NodeTest.java
sboag 00/11/16 12:04:52
Modified: java/src/org/apache/xalan/templates ElemCopyOf.java
ElemForEach.java
java/src/org/apache/xalan/utils ObjectPool.java
java/src/org/apache/xpath SourceTreeManager.java
java/src/org/apache/xpath/axes LocPathIterator.java
UnionPathIterator.java WalkerFactory.java
java/src/org/apache/xpath/functions FuncCount.java
FuncId.java FuncSum.java FuncSystemProperty.java
java/src/org/apache/xpath/patterns FunctionPattern.java
NodeTest.java
Added: java/src/org/apache/xpath/axes ChildTestIterator.java
Log:
Add fast iterator for simple child tests without predicates.
Tried to do .detach on iterators but ran into too many regressions,
so I commented code out.
Revision Changes Path
1.6 +1 -0 xml-xalan/java/src/org/apache/xalan/templates/ElemCopyOf.java
Index: ElemCopyOf.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemCopyOf.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ElemCopyOf.java 2000/11/13 16:27:09 1.5
+++ ElemCopyOf.java 2000/11/16 20:04:50 1.6
@@ -210,6 +210,7 @@
tw.traverse(pos);
}
}
+ // nl.detach();
break;
case XObject.CLASS_RTREEFRAG :
handler.outputResultTreeFragment(value,
1.8 +3 -1 xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java
Index: ElemForEach.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ElemForEach.java 2000/11/15 19:41:04 1.7
+++ ElemForEach.java 2000/11/16 20:04:50 1.8
@@ -512,11 +512,13 @@
xctxt.popContextNodeList();
transformer.popElemTemplateElement();
popParams(xctxt);
+ // if(null != sourceNodes)
+ // sourceNodes.detach();
}
}
catch(SAXException se)
{
- throw new TransformerException(se);
+ transformer.getErrorListener().fatalError(new TransformerException(se));
}
}
1.5 +9 -8 xml-xalan/java/src/org/apache/xalan/utils/ObjectPool.java
Index: ObjectPool.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/utils/ObjectPool.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ObjectPool.java 2000/10/30 18:57:20 1.4
+++ ObjectPool.java 2000/11/16 20:04:50 1.5
@@ -176,13 +176,14 @@
{
// Make sure the object is of the correct type.
- if (objectType.isInstance(obj))
- {
- freeStack.addElement(obj);
- }
- else
- {
- throw new IllegalArgumentException("argument type invalid for pool");
- }
+ // Remove safety. -sb
+ // if (objectType.isInstance(obj))
+ // {
+ freeStack.addElement(obj);
+ // }
+ // else
+ // {
+ // throw new IllegalArgumentException("argument type invalid for pool");
+ // }
}
}
1.16 +20 -2 xml-xalan/java/src/org/apache/xpath/SourceTreeManager.java
Index: SourceTreeManager.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/SourceTreeManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- SourceTreeManager.java 2000/11/14 18:56:26 1.15
+++ SourceTreeManager.java 2000/11/16 20:04:50 1.16
@@ -397,13 +397,31 @@
}
reader.setContentHandler(handler);
+ if(handler instanceof org.xml.sax.DTDHandler)
+ reader.setDTDHandler((org.xml.sax.DTDHandler)handler);
try
{
- reader.setProperty("http://xml.org/sax/properties/lexical-handler",
- handler);
+ if(handler instanceof org.xml.sax.ext.LexicalHandler)
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler",
+ handler);
+ if(handler instanceof org.xml.sax.ext.DeclHandler)
+ reader.setProperty("http://xml.org/sax/properties/declaration-handler",
+ handler);
}
catch (org.xml.sax.SAXException se){}
+ try
+ {
+ if(handler instanceof org.xml.sax.ext.LexicalHandler)
+ reader.setProperty("http://xml.org/sax/handlers/LexicalHandler",
+ handler);
+ if(handler instanceof org.xml.sax.ext.DeclHandler)
+ reader.setProperty("http://xml.org/sax/handlers/DeclHandler",
+ handler);
+ }
+ catch(org.xml.sax.SAXNotRecognizedException snre)
+ {
+ }
InputSource isource = SAXSource.sourceToInputSource(source);
reader.parse(isource);
1.14 +1 -1 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- LocPathIterator.java 2000/11/14 23:15:10 1.13
+++ LocPathIterator.java 2000/11/16 20:04:50 1.14
@@ -108,7 +108,7 @@
/** The pool for cloned iterators. Iterators need to be cloned
* because the hold running state, and thus the original iterator
* expression from the stylesheet pool can not be used. */
- ObjectPool m_pool = new ObjectPool();
+ ObjectPool m_pool = new ObjectPool(this.getClass());
/** The last node that was fetched, usually by nextNode. */
Node m_lastFetched;
1.9 +1 -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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UnionPathIterator.java 2000/11/14 23:15:10 1.8
+++ UnionPathIterator.java 2000/11/16 20:04:50 1.9
@@ -150,7 +150,7 @@
}
/** NEEDSDOC Field m_pool */
- ObjectPool m_pool = new ObjectPool();
+ ObjectPool m_pool = new ObjectPool(this.getClass());
/**
* NEEDSDOC Method execute
1.7 +13 -1 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WalkerFactory.java 2000/11/13 16:27:30 1.6
+++ WalkerFactory.java 2000/11/16 20:04:50 1.7
@@ -181,6 +181,10 @@
{
return new ChildIterator(compiler, opPos);
}
+ else if(ONESTEP_CHILDREN_NO_PREDICATE == analysis)
+ {
+ return new ChildTestIterator(compiler, opPos);
+ }
else
{
return new LocPathIterator(compiler, opPos, true);
@@ -223,6 +227,9 @@
/** NEEDSDOC Field MULTISTEP_CHILDREN */
static final int MULTISTEP_CHILDREN = 6;
+ /** NEEDSDOC Field ONESTEP_CHILDREN */
+ static final int ONESTEP_CHILDREN_NO_PREDICATE = 8;
+
/**
* <meta name="usage" content="advanced"/>
*
@@ -291,7 +298,12 @@
analysisResult = NO_OPTIMIZE;
}
else
- analysisResult = ONESTEP_CHILDREN;
+ {
+ if(predAnalysis == HAS_NOPREDICATE)
+ analysisResult = ONESTEP_CHILDREN_NO_PREDICATE;
+ else
+ analysisResult = ONESTEP_CHILDREN;
+ }
}
else
{
1.1 xml-xalan/java/src/org/apache/xpath/axes/ChildTestIterator.java
Index: ChildTestIterator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xpath.axes;
import javax.xml.transform.TransformerException;
import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.patterns.NodeTest;
import org.apache.xpath.objects.XObject;
import org.w3c.dom.Node;
import org.w3c.dom.DOMException;
import org.w3c.dom.traversal.NodeFilter;
/**
* <meta name="usage" content="advanced"/>
* This class implements an optimized iterator for
* "node()" patterns, that is, any children of the
* context node.
* @see org.apache.xpath.axes.WalkerFactory#newLocPathIterator.
*/
public class ChildTestIterator extends LocPathIterator
{
NodeTest m_nodeTest;
/**
* Create a ChildTestIterator object.
*
* @param compiler A reference to the Compiler that contains the op map.
* @param opPos The position within the op map, which contains the
* location path expression for this itterator.
*
* @throws javax.xml.transform.TransformerException
*/
public ChildTestIterator(Compiler compiler, int opPos)
throws javax.xml.transform.TransformerException
{
super(compiler, opPos, false);
m_nodeTest = new NodeTest();
int firstStepPos = compiler.getFirstChildPos(opPos);
int whatToShow = compiler.getWhatToShow(firstStepPos);
if ((0 == (whatToShow
& (NodeFilter.SHOW_ATTRIBUTE | NodeFilter.SHOW_ELEMENT
| NodeFilter.SHOW_PROCESSING_INSTRUCTION))) || (whatToShow == NodeFilter.SHOW_ALL))
m_nodeTest.initNodeTest(whatToShow);
else
{
m_nodeTest.initNodeTest(whatToShow, compiler.getStepNS(firstStepPos),
compiler.getStepLocalName(firstStepPos));
}
}
/**
* Returns the next node in the set and advances the position of the
* iterator in the set. After a NodeIterator is created, the first call
* to nextNode() returns the first node in the set.
*
* @return The next <code>Node</code> in the set being iterated over, or
* <code>null</code> if there are no more members in that set.
*
* @exception DOMException
* INVALID_STATE_ERR: Raised if this method is called after the
* <code>detach</code> method was invoked.
*/
public Node nextNode() throws DOMException
{
// If the cache is on, and the node has already been found, then
// just return from the list.
if ((null != m_cachedNodes)
&& (m_cachedNodes.getCurrentPos() < m_cachedNodes.size()))
{
Node next = m_cachedNodes.nextNode();
this.setCurrentPos(m_cachedNodes.getCurrentPos());
return next;
}
if (m_foundLast)
return null;
Node next;
do
{
m_lastFetched = next = (null == m_lastFetched)
? m_context.getFirstChild()
: m_lastFetched.getNextSibling();
if(null != next)
{
try
{
XObject score = m_nodeTest.execute(m_execContext, next);
if(NodeTest.SCORE_NONE == score)
continue;
else
break;
}
catch(TransformerException te)
{
throw new org.apache.xalan.utils.WrappedRuntimeException(te);
}
}
else
break;
}
while(next != null);
if (null != next)
{
if (null != m_cachedNodes)
m_cachedNodes.addElement(m_lastFetched);
m_next++;
return next;
}
else
{
m_foundLast = true;
return null;
}
}
}
1.4 +1 -0 xml-xalan/java/src/org/apache/xpath/functions/FuncCount.java
Index: FuncCount.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncCount.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FuncCount.java 2000/11/13 16:27:33 1.3
+++ FuncCount.java 2000/11/16 20:04:51 1.4
@@ -97,6 +97,7 @@
{
i++;
}
+ // nl.detach();
return new XNumber((double) i);
}
1.4 +1 -0 xml-xalan/java/src/org/apache/xpath/functions/FuncId.java
Index: FuncId.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncId.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FuncId.java 2000/11/13 16:27:33 1.3
+++ FuncId.java 2000/11/16 20:04:51 1.4
@@ -174,6 +174,7 @@
usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet,
null != pos);
}
+ // ni.detach();
}
else if (XObject.CLASS_NULL == argType)
{
1.4 +1 -0 xml-xalan/java/src/org/apache/xpath/functions/FuncSum.java
Index: FuncSum.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSum.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FuncSum.java 2000/11/13 16:27:35 1.3
+++ FuncSum.java 2000/11/16 20:04:51 1.4
@@ -97,6 +97,7 @@
if (null != s)
sum += XString.castToNum(s);
}
+ // nodes.detach();
return new XNumber(sum);
}
1.4 +2 -1 xml-xalan/java/src/org/apache/xpath/functions/FuncSystemProperty.java
Index: FuncSystemProperty.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSystemProperty.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FuncSystemProperty.java 2000/11/13 16:27:35 1.3
+++ FuncSystemProperty.java 2000/11/16 20:04:51 1.4
@@ -223,7 +223,8 @@
}
catch (Exception ex)
{
- ex.printStackTrace();
+ // ex.printStackTrace();
+ throw new org.apache.xalan.utils.WrappedRuntimeException(ex);
}
}
}
1.5 +1 -0 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FunctionPattern.java 2000/11/13 16:27:54 1.4
+++ FunctionPattern.java 2000/11/16 20:04:51 1.5
@@ -141,6 +141,7 @@
break;
}
}
+ // nl.detach();
}
return score;
1.13 +66 -60 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- NodeTest.java 2000/11/13 16:27:54 1.12
+++ NodeTest.java 2000/11/16 20:04:51 1.13
@@ -136,7 +136,7 @@
/** NEEDSDOC Field SCORE_NODETEST */
static final XNumber SCORE_NODETEST =
- new XNumber(XPath.MATCH_SCORE_NODETEST);
+ new XNumber(XPath.MATCH_SCORE_NODETEST);
/** NEEDSDOC Field SCORE_NSWILD */
static final XNumber SCORE_NSWILD = new XNumber(XPath.MATCH_SCORE_NSWILD);
@@ -149,7 +149,7 @@
/** NEEDSDOC Field SCORE_NONE */
public static final XNumber SCORE_NONE =
- new XNumber(XPath.MATCH_SCORE_NONE);
+ new XNumber(XPath.MATCH_SCORE_NONE);
/**
* Constructor NodeTest
@@ -326,30 +326,10 @@
// System.out.println("subPartMatch - p: "+p+", t: "+t+", result: "+b);
return (p == t) || ((null != p) && ((t == WILD) || p.equals(t)));
}
-
- /**
- * Test a node to see if it matches the given node test.
- * @param xpath The xpath that is executing.
- * @param context The current source tree context node.
- * @param opPos The current position in the xpath.m_opMap array.
- * @param len The length of the argument.
- * @param len The type of the step.
- * @returns score in an XNumber, one of MATCH_SCORE_NODETEST,
- * MATCH_SCORE_NONE, MATCH_SCORE_OTHER, MATCH_SCORE_QNAME.
- *
- * NEEDSDOC @param xctxt
- *
- * NEEDSDOC ($objectName$) @return
- *
- * @throws javax.xml.transform.TransformerException
- */
- public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+
+ public XObject execute(XPathContext xctxt, Node context)
+ throws javax.xml.transform.TransformerException
{
-
- if (m_whatToShow == NodeFilter.SHOW_ALL)
- return m_score;
-
- Node context = xctxt.getCurrentNode();
short nodeType = context.getNodeType();
int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));
@@ -368,53 +348,79 @@
return subPartMatch(context.getNodeName(), m_name)
? m_score : SCORE_NONE;
- // From the draft: "Two expanded names are equal if they
- // have the same local part, and either both have no URI or
- // both have the same URI."
- // "A node test * is true for any node of the principal node type.
- // For example, child::* will select all element children of the
- // context node, and attribute::* will select all attributes of
- // the context node."
- // "A node test can have the form NCName:*. In this case, the prefix
- // is expanded in the same way as with a QName using the context
- // namespace declarations. The node test will be true for any node
- // of the principal type whose expanded name has the URI to which
- // the prefix expands, regardless of the local part of the name."
+ // From the draft: "Two expanded names are equal if they
+ // have the same local part, and either both have no URI or
+ // both have the same URI."
+ // "A node test * is true for any node of the principal node type.
+ // For example, child::* will select all element children of the
+ // context node, and attribute::* will select all attributes of
+ // the context node."
+ // "A node test can have the form NCName:*. In this case, the prefix
+ // is expanded in the same way as with a QName using the context
+ // namespace declarations. The node test will be true for any node
+ // of the principal type whose expanded name has the URI to which
+ // the prefix expands, regardless of the local part of the name."
case NodeFilter.SHOW_ATTRIBUTE :
- {
- int isNamespace = (m_whatToShow & SHOW_NAMESPACE);
-
- if (0 == isNamespace)
{
- DOMHelper dh = xctxt.getDOMHelper();
+ int isNamespace = (m_whatToShow & SHOW_NAMESPACE);
- if (!dh.isNamespaceNode(context))
- return (m_isTotallyWild || (subPartMatch(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
- ? m_score : SCORE_NONE;
- else
- return SCORE_NONE;
- }
- else
- {
- if (xctxt.getDOMHelper().isNamespaceNode(context))
+ if (0 == isNamespace)
{
- String ns = context.getNodeValue();
+ DOMHelper dh = xctxt.getDOMHelper();
- return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
+ if (!dh.isNamespaceNode(context))
+ return (m_isTotallyWild || (subPartMatch(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
+ ? m_score : SCORE_NONE;
+ else
+ return SCORE_NONE;
}
else
- return SCORE_NONE;
+ {
+ if (xctxt.getDOMHelper().isNamespaceNode(context))
+ {
+ String ns = context.getNodeValue();
+
+ return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
+ }
+ else
+ return SCORE_NONE;
+ }
}
- }
case NodeFilter.SHOW_ELEMENT :
- {
- DOMHelper dh = xctxt.getDOMHelper();
+ {
+ DOMHelper dh = xctxt.getDOMHelper();
- return (m_isTotallyWild || (subPartMatch(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
- ? m_score : SCORE_NONE;
- }
+ return (m_isTotallyWild || (subPartMatch(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
+ ? m_score : SCORE_NONE;
+ }
default :
return SCORE_NONE;
} // end switch(testType)
+ }
+
+ /**
+ * Test a node to see if it matches the given node test.
+ * @param xpath The xpath that is executing.
+ * @param context The current source tree context node.
+ * @param opPos The current position in the xpath.m_opMap array.
+ * @param len The length of the argument.
+ * @param len The type of the step.
+ * @returns score in an XNumber, one of MATCH_SCORE_NODETEST,
+ * MATCH_SCORE_NONE, MATCH_SCORE_OTHER, MATCH_SCORE_QNAME.
+ *
+ * NEEDSDOC @param xctxt
+ *
+ * NEEDSDOC ($objectName$) @return
+ *
+ * @throws javax.xml.transform.TransformerException
+ */
+ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
+ {
+
+ if (m_whatToShow == NodeFilter.SHOW_ALL)
+ return m_score;
+
+ Node context = xctxt.getCurrentNode();
+ return execute(xctxt, context);
}
}