sboag 01/03/11 18:13:00
Modified: java/src/org/apache/xalan/processor ProcessorInclude.java
TransformerFactoryImpl.java
java/src/org/apache/xalan/serialize SerializerToXML.java
java/src/org/apache/xalan/stree StreeDOMHelper.java
java/src/org/apache/xalan/transformer ResultTreeHandler.java
TransformerIdentityImpl.java TreeWalker2Result.java
java/src/org/apache/xml/utils AttList.java TreeWalker.java
java/src/org/apache/xpath DOM2Helper.java XPathContext.java
Log:
The DOM2Helper#isNodeAfter(Node node1, Node node2) method
has been fixed so that it no longer does the try/catch thing if one
of the nodes doesn't implement DOMOrder, but instead does an
instanceof test. In StreeDOMHelper, it overloads this method and
*does* do the try/catch business, since almost always both nodes
will implement DOMOrder in this case, and this will be faster than
an instanceof test. Also, in various classes, I did some stuff to try
and make sure that a DOM2Helper wasn't being created and used
when a StreeDOMHelper is needed.
This addresses http://nagoya.apache.org/bugzilla/show_bug.cgi?id=800
and should give a good performance fix for foreign DOM processing.
Revision Changes Path
1.17 +1 -1
xml-xalan/java/src/org/apache/xalan/processor/ProcessorInclude.java
Index: ProcessorInclude.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorInclude.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ProcessorInclude.java 2001/01/31 20:54:35 1.16
+++ ProcessorInclude.java 2001/03/12 02:12:43 1.17
@@ -230,7 +230,7 @@
if (null != source && source instanceof DOMSource)
{
Node node = ((DOMSource)source).getNode();
- TreeWalker walker = new TreeWalker(handler);
+ TreeWalker walker = new TreeWalker(handler, new
org.apache.xpath.DOM2Helper());
try
{
1.28 +2 -2
xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- TransformerFactoryImpl.java 2001/03/12 00:59:10 1.27
+++ TransformerFactoryImpl.java 2001/03/12 02:12:44 1.28
@@ -190,7 +190,7 @@
try
{
TemplatesHandler builder = newTemplatesHandler();
- TreeWalker walker = new TreeWalker(builder);
+ TreeWalker walker = new TreeWalker(builder, new
org.apache.xpath.DOM2Helper());
walker.traverse(node);
@@ -356,7 +356,7 @@
{
if (null != node)
{
- TreeWalker walker = new TreeWalker(handler);
+ TreeWalker walker = new TreeWalker(handler, new
org.apache.xpath.DOM2Helper());
walker.traverse(node);
}
1.5 +17 -17
xml-xalan/java/src/org/apache/xalan/serialize/SerializerToXML.java
Index: SerializerToXML.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/SerializerToXML.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SerializerToXML.java 2001/03/07 18:18:18 1.4
+++ SerializerToXML.java 2001/03/12 02:12:47 1.5
@@ -575,13 +575,13 @@
accum(" \"");
accum(m_doctypeSystem);
- if (closeDecl)
- {
- accum("\">");
- outputLineSep();
- }
- else
- accum("\"");
+ if (closeDecl)
+ {
+ accum("\">");
+ outputLineSep();
+ }
+ else
+ accum("\"");
}
}
@@ -1915,7 +1915,7 @@
* @exception SAXException The application may raise an exception.
*/
public void elementDecl (String name, String model)
- throws SAXException
+ throws SAXException
{
if (m_inDoctype)
{
@@ -1953,11 +1953,11 @@
* @exception SAXException The application may raise an exception.
*/
public void attributeDecl (String eName,
- String aName,
- String type,
- String valueDefault,
- String value)
- throws SAXException
+ String aName,
+ String type,
+ String valueDefault,
+ String value)
+ throws SAXException
{
if (m_inDoctype)
{
@@ -2003,7 +2003,7 @@
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public void internalEntityDecl (String name, String value)
- throws SAXException
+ throws SAXException
{
if (m_inDoctype)
{
@@ -2031,8 +2031,8 @@
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public void externalEntityDecl (String name, String publicId,
- String systemId)
- throws SAXException
+ String systemId)
+ throws SAXException
{}
/**
@@ -2389,7 +2389,7 @@
try
{
- TreeWalker walker = new TreeWalker(this);
+ TreeWalker walker = new TreeWalker(this, new
org.apache.xpath.DOM2Helper());
walker.traverse(node);
}
1.11 +34 -0
xml-xalan/java/src/org/apache/xalan/stree/StreeDOMHelper.java
Index: StreeDOMHelper.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/stree/StreeDOMHelper.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- StreeDOMHelper.java 2000/12/18 23:12:13 1.10
+++ StreeDOMHelper.java 2001/03/12 02:12:49 1.11
@@ -144,4 +144,38 @@
return super.isNamespaceNode(n);
}
}
+
+ /**
+ * Overload DOM2Helper#isNodeAfter, making the assumption that both nodes
+ * implement DOMOrder, and handling things if this is not the case by
+ * catching a cast exception.
+ *
+ * @param node1 DOM Node to perform position comparison on.
+ * @param node2 DOM Node to perform position comparison on .
+ *
+ * @return false if node2 comes before node1, otherwise return true.
+ * You can think of this as
+ * <code>(node1.documentOrderPosition <=
node2.documentOrderPosition)</code>.
+ */
+ public boolean isNodeAfter(Node node1, Node node2)
+ {
+
+ // Assume first that the nodes are DTM nodes, since discovering node
+ // order is massivly faster for the DTM.
+ try
+ {
+ int index1 = ((org.apache.xpath.DOMOrder) node1).getUid();
+ int index2 = ((org.apache.xpath.DOMOrder) node2).getUid();
+
+ return index1 <= index2;
+ }
+ catch (ClassCastException cce)
+ {
+
+ // isNodeAfter will return true if node is after countedNode
+ // in document order. The base isNodeAfter is sloooow (relatively)
+ return super.isNodeAfter(node1, node2);
+ }
+ }
+
}
1.36 +1 -1
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.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- ResultTreeHandler.java 2001/03/11 21:58:47 1.35
+++ ResultTreeHandler.java 2001/03/12 02:12:51 1.36
@@ -793,7 +793,7 @@
{
DocumentFragment docFrag = obj.rtree(support);
- TreeWalker tw = new TreeWalker(this);
+ TreeWalker tw = new TreeWalker(this, support.getDOMHelper());
Node n;
for (n = docFrag.getFirstChild(); null != n; n = n.getNextSibling())
1.10 +15 -15
xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java
Index: TransformerIdentityImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TransformerIdentityImpl.java 2001/03/09 20:07:19 1.9
+++ TransformerIdentityImpl.java 2001/03/12 02:12:52 1.10
@@ -319,7 +319,7 @@
}
else
{
- TreeWalker walker = new TreeWalker(this);
+ TreeWalker walker = new TreeWalker(this, new
org.apache.xpath.DOM2Helper());
walker.traverse(dNode);
}
}
@@ -1258,10 +1258,10 @@
* @exception SAXException The application may raise an exception.
*/
public void elementDecl (String name, String model)
- throws SAXException
+ throws SAXException
{
- if (null != m_resultDeclHandler)
- m_resultDeclHandler.elementDecl(name, model);
+ if (null != m_resultDeclHandler)
+ m_resultDeclHandler.elementDecl(name, model);
}
@@ -1285,14 +1285,14 @@
* @exception SAXException The application may raise an exception.
*/
public void attributeDecl (String eName,
- String aName,
- String type,
- String valueDefault,
- String value)
- throws SAXException
+ String aName,
+ String type,
+ String valueDefault,
+ String value)
+ throws SAXException
{
if (null != m_resultDeclHandler)
- m_resultDeclHandler.attributeDecl(eName, aName,
type, valueDefault, value);
+ m_resultDeclHandler.attributeDecl(eName,
aName, type, valueDefault, value);
}
@@ -1310,10 +1310,10 @@
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public void internalEntityDecl (String name, String value)
- throws SAXException
+ throws SAXException
{
if (null != m_resultDeclHandler)
- m_resultDeclHandler.internalEntityDecl(name,
value);
+ m_resultDeclHandler.internalEntityDecl(name,
value);
}
@@ -1333,11 +1333,11 @@
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
public void externalEntityDecl (String name, String publicId,
- String systemId)
- throws SAXException
+ String systemId)
+ throws SAXException
{
if (null != m_resultDeclHandler)
- m_resultDeclHandler.externalEntityDecl(name,
publicId, systemId);
+ m_resultDeclHandler.externalEntityDecl(name,
publicId, systemId);
}
/**
1.9 +1 -1
xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java
Index: TreeWalker2Result.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TreeWalker2Result.java 2001/03/06 05:50:24 1.8
+++ TreeWalker2Result.java 2001/03/12 02:12:53 1.9
@@ -92,7 +92,7 @@
ResultTreeHandler handler)
{
- super(handler);
+ super(handler, transformer.getXPathContext().getDOMHelper());
m_transformer = transformer;
m_handler = handler;
1.5 +13 -13 xml-xalan/java/src/org/apache/xml/utils/AttList.java
Index: AttList.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/AttList.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AttList.java 2001/02/01 04:26:35 1.4
+++ AttList.java 2001/03/12 02:12:55 1.5
@@ -82,19 +82,19 @@
/** Local reference to DOMHelper */
DOMHelper m_dh;
- /**
- * Constructor AttList
- *
- *
- * @param attrs List of attributes this will contain
- */
- public AttList(NamedNodeMap attrs)
- {
-
- m_attrs = attrs;
- m_lastIndex = m_attrs.getLength() - 1;
- m_dh = new DOM2Helper();
- }
+// /**
+// * Constructor AttList
+// *
+// *
+// * @param attrs List of attributes this will contain
+// */
+// public AttList(NamedNodeMap attrs)
+// {
+//
+// m_attrs = attrs;
+// m_lastIndex = m_attrs.getLength() - 1;
+// m_dh = new DOM2Helper();
+// }
/**
* Constructor AttList
1.6 +3 -2 xml-xalan/java/src/org/apache/xml/utils/TreeWalker.java
Index: TreeWalker.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/TreeWalker.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TreeWalker.java 2001/01/07 04:20:51 1.5
+++ TreeWalker.java 2001/03/12 02:12:56 1.6
@@ -80,7 +80,7 @@
// DOM2Helper m_dh = new DOM2Helper();
/** DomHelper for this TreeWalker */
- protected DOMHelper m_dh = new DOM2Helper();
+ protected DOMHelper m_dh;
/**
* Get the ContentHandler used for the tree walk.
@@ -97,9 +97,10 @@
* @param contentHandler The implemention of the
* contentHandler operation (toXMLString, digest, ...)
*/
- public TreeWalker(ContentHandler contentHandler)
+ public TreeWalker(ContentHandler contentHandler, DOMHelper dh)
{
this.m_contentHandler = contentHandler;
+ m_dh = dh;
}
/**
1.14 +3 -3 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DOM2Helper.java 2001/01/02 03:47:13 1.13
+++ DOM2Helper.java 2001/03/12 02:12:58 1.14
@@ -273,18 +273,18 @@
// Assume first that the nodes are DTM nodes, since discovering node
// order is massivly faster for the DTM.
- try
+ if(node1 instanceof DOMOrder && node2 instanceof DOMOrder)
{
int index1 = ((DOMOrder) node1).getUid();
int index2 = ((DOMOrder) node2).getUid();
return index1 <= index2;
}
- catch (ClassCastException cce)
+ else
{
// isNodeAfter will return true if node is after countedNode
- // in document order. The base isNodeAfter is sloooow (relatively)
+ // in document order. The base isNodeAfter is sloooow (relatively).
return super.isNodeAfter(node1, node2);
}
}
1.18 +4 -6 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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- XPathContext.java 2001/01/02 03:47:13 1.17
+++ XPathContext.java 2001/03/12 02:12:59 1.18
@@ -113,7 +113,9 @@
/**
* Create an XPathContext instance.
*/
- public XPathContext(){}
+ public XPathContext()
+ {
+ }
/**
* Create an XPathContext instance.
@@ -261,7 +263,7 @@
* 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;
+ private DOMHelper m_domHelper = new DOM2Helper();
/**
* Get the DOMHelper associated with this execution context.
@@ -270,10 +272,6 @@
*/
public final DOMHelper getDOMHelper()
{
-
- if (null == m_domHelper)
- m_domHelper = new DOM2Helper();
-
return m_domHelper;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]