sboag 00/08/11 16:55:01
Modified: java/src/org/apache/xalan/stree DocumentFragmentImpl.java
DocumentImpl.java DocumentTypeImpl.java Parent.java
SourceTreeHandler.java
java/src/org/apache/xalan/transformer ResultTreeFrag.java
TransformerImpl.java
java/src/org/apache/xpath SourceTreeManager.java
Log:
Fixed problems with ResultTreeFragment traversal, ResultTreeFrag is now
derived from StreeDOMHelper.
Revision Changes Path
1.3 +6 -1
xml-xalan/java/src/org/apache/xalan/stree/DocumentFragmentImpl.java
Index: DocumentFragmentImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/stree/DocumentFragmentImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DocumentFragmentImpl.java 2000/08/11 19:32:07 1.2
+++ DocumentFragmentImpl.java 2000/08/11 23:54:56 1.3
@@ -3,8 +3,13 @@
import org.w3c.dom.Node;
import org.w3c.dom.DocumentFragment;
-public class DocumentFragmentImpl extends Parent implements DocumentFragment
+public class DocumentFragmentImpl extends DocumentImpl implements
DocumentFragment
{
+ public DocumentFragmentImpl()
+ {
+ setComplete(true);
+ }
+
/**
* A short integer indicating what type of node this is. The named
* constants for this value are defined in the org.w3c.dom.Node interface.
1.4 +20 -0
xml-xalan/java/src/org/apache/xalan/stree/DocumentImpl.java
Index: DocumentImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/stree/DocumentImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DocumentImpl.java 2000/08/11 19:32:07 1.3
+++ DocumentImpl.java 2000/08/11 23:54:57 1.4
@@ -87,6 +87,26 @@
return m_docType;
}
+ private boolean m_useMultiThreading = false;
+
+ /**
+ * Set whether or not the tree being built should handle
+ * transformation while the parse is still going on.
+ */
+ public void setUseMultiThreading(boolean b)
+ {
+ m_useMultiThreading = b;
+ }
+
+ /**
+ * Tell whether or not the tree being built should handle
+ * transformation while the parse is still going on.
+ */
+ public boolean getUseMultiThreading()
+ {
+ return m_useMultiThreading;
+ }
+
/**
* The document element.
*/
1.3 +1 -0
xml-xalan/java/src/org/apache/xalan/stree/DocumentTypeImpl.java
Index: DocumentTypeImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/stree/DocumentTypeImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DocumentTypeImpl.java 2000/08/11 19:32:08 1.2
+++ DocumentTypeImpl.java 2000/08/11 23:54:57 1.3
@@ -15,6 +15,7 @@
private String m_publicID;
private String m_systemID;
private String m_internalSubset;
+
/**
* A short integer indicating what type of node this is. The named
1.5 +25 -17 xml-xalan/java/src/org/apache/xalan/stree/Parent.java
Index: Parent.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/stree/Parent.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Parent.java 2000/08/04 19:35:22 1.4
+++ Parent.java 2000/08/11 23:54:57 1.5
@@ -180,6 +180,9 @@
doc = (DocumentImpl)this.getOwnerDocument();
doc.incrementDocOrderCount();
child.setUid(doc.getDocOrderCount());
+ if(!doc.getUseMultiThreading() && (child instanceof Parent))
+ ((Parent)child).setComplete(true);
+
}
catch(ClassCastException cce)
{
@@ -188,6 +191,8 @@
// which will be a problem when result tree fragments need to
// be treated like node-sets.
doc = null;
+ if(child instanceof Parent) // for now DocumentFragments can't be
built on another thread.
+ ((Parent)child).setComplete(true);
}
child.setParent(this);
child.setLevel((short)(getLevel() + 1));
@@ -196,29 +201,32 @@
if((null != doc) && (Node.ELEMENT_NODE == child.getNodeType()))
{
SourceTreeHandler sh = doc.getSourceTreeHandler();
- TransformerImpl transformer = sh.getTransformer();
- if(null != transformer)
+ if(null != sh)
{
- StylesheetRoot stylesheet= transformer.getStylesheet();
- try
+ TransformerImpl transformer = sh.getTransformer();
+ if(null != transformer)
{
- ElementImpl elem = (ElementImpl)child;
- WhiteSpaceInfo info
- = stylesheet.getWhiteSpaceInfo(transformer.getXPathContext(),
elem);
- boolean shouldStrip;
- if(null == info)
+ StylesheetRoot stylesheet= transformer.getStylesheet();
+ try
{
- shouldStrip = sh.getShouldStripWhitespace();
+ ElementImpl elem = (ElementImpl)child;
+ WhiteSpaceInfo info
+ = stylesheet.getWhiteSpaceInfo(transformer.getXPathContext(),
elem);
+ boolean shouldStrip;
+ if(null == info)
+ {
+ shouldStrip = sh.getShouldStripWhitespace();
+ }
+ else
+ {
+ shouldStrip = info.getShouldStripSpace();
+ }
+ sh.setShouldStripWhitespace(shouldStrip);
}
- else
+ catch(SAXException se)
{
- shouldStrip = info.getShouldStripSpace();
+ // TODO: Diagnostics
}
- sh.setShouldStripWhitespace(shouldStrip);
- }
- catch(SAXException se)
- {
- // TODO: Diagnostics
}
}
1.7 +22 -1
xml-xalan/java/src/org/apache/xalan/stree/SourceTreeHandler.java
Index: SourceTreeHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/stree/SourceTreeHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SourceTreeHandler.java 2000/08/09 20:05:28 1.6
+++ SourceTreeHandler.java 2000/08/11 23:54:57 1.7
@@ -90,8 +90,27 @@
{
}
- public boolean m_useMultiThreading = true;
+ private boolean m_useMultiThreading = false;
+ /**
+ * Set whether or not the tree being built should handle
+ * transformation while the parse is still going on.
+ */
+ public void setUseMultiThreading(boolean b)
+ {
+ m_useMultiThreading = b;
+ }
+
+ /**
+ * Tell whether or not the tree being built should handle
+ * transformation while the parse is still going on.
+ */
+ public boolean getUseMultiThreading()
+ {
+ return m_useMultiThreading;
+ }
+
+
private boolean indexedLookup = false; // for now
/**
@@ -110,6 +129,8 @@
((DocumentImpl)m_root).setSourceTreeHandler(this);
((DocumentImpl)m_root).setUid(1);
((DocumentImpl)m_root).setLevel(new Integer(1).shortValue());
+ ((DocumentImpl)m_root).setUseMultiThreading(getUseMultiThreading());
+
m_sourceTreeHandler = new StreeDOMBuilder(m_root);
setShouldStripWhitespace(false);
1.4 +19 -326
xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeFrag.java
Index: ResultTreeFrag.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeFrag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResultTreeFrag.java 2000/07/31 22:06:36 1.3
+++ ResultTreeFrag.java 2000/08/11 23:54:59 1.4
@@ -68,21 +68,21 @@
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.utils.UnImplNode;
+import org.apache.xalan.stree.DocumentFragmentImpl;
+
/**
* <meta name="usage" content="internal"/>
* Container of a result tree fragment.
*/
-public class ResultTreeFrag extends UnImplNode implements DocumentFragment
+public class ResultTreeFrag extends DocumentFragmentImpl implements NodeList
{
Document m_docFactory;
- NodeSet m_children;
XPathContext m_xsupport;
public ResultTreeFrag(Document docFactory, XPathContext support)
{
m_xsupport = support;
m_docFactory = docFactory;
- m_children = new NodeSet();
}
public ResultTreeFrag(Document docFactory, NodeSet children,
@@ -90,341 +90,34 @@
{
m_xsupport = support;
m_docFactory = docFactory;
- m_children = children;
- }
-
- /**
- * Throw an error.
- */
- // void error(int msg)
- // {
- // throw new RuntimeException(XSLMessages.createMessage(msg,
null));
- // }
-
- /**
- * The name of this node, depending on its type; see the table above.
- */
- public final String getNodeName()
- {
- return "#document-fragment";
- }
-
- /**
- * The value of this node, depending on its type; see the table above.
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
- * @exception DOMException
- * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
- * fit in a <code>DOMString</code> variable on the implementation
- * platform.
- */
- public String getNodeValue()
- throws DOMException
- {
- return "";
- }
-
- /**
- * DocumentFragments never have a nodeValue.
- * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
- */
- public void setNodeValue(String x)
- throws DOMException
- {
- // No action.
- }
-
- /**
- * A code representing the type of the underlying object, as defined above.
- */
- public final short getNodeType()
- {
- return Node.DOCUMENT_FRAGMENT_NODE;
}
-
- /**
- * The parent of this node. All nodes, except <code>Document</code>,
- * <code>DocumentFragment</code>, and <code>Attr</code> may have a parent.
- * However, if a node has just been created and not yet added to the tree,
- * or if it has been removed from the tree, this is <code>null</code>.
- */
- public Node getParentNode()
- {
- return null;
- }
-
- /**
- * A <code>NodeList</code> that contains all children of this node. If
there
- * are no children, this is a <code>NodeList</code> containing no nodes.
- * The content of the returned <code>NodeList</code> is "live" in the sense
- * that, for instance, changes to the children of the node object that
- * it was created from are immediately reflected in the nodes
returned by
- * the <code>NodeList</code> accessors; it is not a static snapshot of the
- * content of the node. This is true for every <code>NodeList</code>,
- * including the ones returned by the <code>getElementsByTagName</code>
- * method.
- */
+
public NodeList getChildNodes()
- {
- return m_children;
- }
-
- /**
- * The first child of this node. If there is no such node, this returns
- * <code>null</code>.
- */
- public Node getFirstChild()
- {
- int nChildren = m_children.getLength();
- return (nChildren > 0) ? m_children.item(0) : null;
- }
-
- /**
- * The last child of this node. If there is no such node, this returns
- * <code>null</code>.
- */
- public Node getLastChild()
{
- int nChildren = m_children.getLength();
- return (nChildren > 0) ? m_children.item(nChildren-1) : null;
+ return this;
}
-
- /**
- * The node immediately preceding this node. If there is no such node, this
- * returns <code>null</code>.
- */
- public Node getPreviousSibling()
- {
- return null;
- }
-
+
/**
- * The node immediately following this node. If there is no such node, this
- * returns <code>null</code>.
+ * Returns the <code>index</code> th item in the collection. If
+ * <code>index</code> is greater than or equal to the number of nodes in
+ * the list, this returns <code>null</code> .
+ * @param index Index into the collection.
+ * @return The node at the <code>index</code> th position in the
+ * <code>NodeList</code> , or <code>null</code> if that is not a valid
+ * index.
*/
- public Node getNextSibling()
+ public Node item(int index)
{
- return null;
+ return getChild(index);
}
/**
- * A <code>NamedNodeMap</code> containing the attributes of this node (if
it
- * is an <code>Element</code>) or <code>null</code> otherwise.
+ * The number of nodes in the list. The range of valid child node indices
+ * is 0 to <code>length-1</code> inclusive.
*/
- public NamedNodeMap getAttributes()
- {
- return null;
- }
-
- /**
- * The <code>Document</code> object associated with this node. This is also
- * the <code>Document</code> object used to create new nodes. When this
- * node is a <code>Document</code> this is <code>null</code>.
- */
- public Document getOwnerDocument()
- {
- return m_docFactory;
- }
-
- /**
- * Inserts the node <code>newChild</code> before the existing child node
- * <code>refChild</code>. If <code>refChild</code> is <code>null</code>,
- * insert <code>newChild</code> at the end of the list of children.
- * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
- * all of its children are inserted, in the same order, before
- * <code>refChild</code>. If the <code>newChild</code> is already in the
- * tree, it is first removed.
- * @param newChild The node to insert.
- * @param refChild The reference node, i.e., the node before which the new
- * node must be inserted.
- * @return The node being inserted.
- * @exception DOMException
- * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
- * allow children of the type of the <code>newChild</code> node, or if
- * the node to insert is one of this node's ancestors.
- * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
- * from a different document than the one that created this node.
- * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
- * <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of
- * this node.
- */
- public Node insertBefore(Node newChild,
- Node refChild)
- throws DOMException
- {
- // NodeSet mnl = (NodeSet)m_children;
- // int refIndex = (null == refChild)
- // ? mnl.getLength() : mnl.indexOf(refChild);
- return newChild;
- }
-
- /**
- * Replaces the child node <code>oldChild</code> with <code>newChild</code>
- * in the list of children, and returns the <code>oldChild</code> node. If
- * the <code>newChild</code> is already in the tree, it is first removed.
- * @param newChild The new node to put in the child list.
- * @param oldChild The node being replaced in the list.
- * @return The node replaced.
- * @exception DOMException
- * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
- * allow children of the type of the <code>newChild</code> node, or it
- * the node to put in is one of this node's ancestors.
- * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
- * from a different document than the one that created this node.
- * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
- * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
- * this node.
- */
- public Node replaceChild(Node newChild,
- Node oldChild)
- throws DOMException
- {
- NodeSet mnl = (NodeSet)m_children;
- int newChildIndex = mnl.indexOf(newChild);
- if(newChildIndex > -1)
- {
- mnl.removeElementAt(newChildIndex);
- }
- else
- {
- // throw exception.
- }
- int refIndex = (null == oldChild)
- ? -1 : mnl.indexOf(oldChild);
- if(refIndex > -1)
- {
- mnl.removeElement(oldChild);
- mnl.setElementAt(newChild, refIndex);
- }
- else
- {
- // Throw exception.
- }
- return oldChild;
- }
-
- /**
- * Removes the child node indicated by <code>oldChild</code> from the list
- * of children, and returns it.
- * @param oldChild The node being removed.
- * @return The node removed.
- * @exception DOMException
- * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
- * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
- * this node.
- */
- public Node removeChild(Node oldChild)
- throws DOMException
- {
- NodeSet mnl = (NodeSet)m_children;
- mnl.removeElement(oldChild);
- return oldChild;
- }
-
- /**
- * Adds the node <code>newChild</code> to the end of the list of children
of
- * this node. If the <code>newChild</code> is already in the tree, it is
- * first removed.
- * @param newChild The node to add.If it is a
<code>DocumentFragment</code>
- * object, the entire contents of the document fragment are moved into
- * the child list of this node
- * @return The node added.
- * @exception DOMException
- * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
- * allow children of the type of the <code>newChild</code> node, or if
- * the node to append is one of this node's ancestors.
- * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
- * from a different document than the one that created this node.
- * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
- */
- public Node appendChild(Node newChild)
- throws DOMException
- {
- NodeSet mnl = (NodeSet)m_children;
- mnl.addElement(newChild);
- return newChild;
- }
-
- /**
- * This is a convenience method to allow easy determination of whether a
- * node has any children.
- * @return <code>true</code> if the node has any children,
- * <code>false</code> if the node has no children.
- */
- public boolean hasChildNodes()
- {
- return m_children.getLength() > 0;
- }
-
- /**
- * Returns a duplicate of this node, i.e., serves as a generic copy
- * constructor for nodes. The duplicate node has no parent (
- * <code>parentNode</code> returns <code>null</code>.).
- * <br>Cloning an <code>Element</code> copies all attributes and their
- * values, including those generated by the XML processor to represent
- * defaulted attributes, but this method does not copy any text it contains
- * unless it is a deep clone, since the text is contained in a child
- * <code>Text</code> node. Cloning any other type of node simply returns a
- * copy of this node.
- * @param deep If <code>true</code>, recursively clone the subtree under
the
- * specified node; if <code>false</code>, clone only the node itself (and
- * its attributes, if it is an <code>Element</code>).
- * @return The duplicate node.
- */
- public Node cloneNode(boolean deep)
- {
- ResultTreeFrag newFrag = new ResultTreeFrag(m_docFactory, m_xsupport);
- if(deep)
- {
- int n = m_children.getLength();
- for(int i = 0; i < n; i++)
- {
- newFrag.appendChild(m_children.item(i).cloneNode(deep));
- }
- }
- return newFrag;
- }
-
- /** Unimplemented. */
- public void normalize()
- {
- error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED); //"normalize not
supported!");
- }
-
- /** Unimplemented. */
- public boolean supports(String feature,
- String version)
- {
- error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED); //"supports not
supported!");
- return false;
- }
-
- /** Unimplemented. */
- public String getNamespaceURI()
- {
- error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED); //"getNamespaceURI
not supported!");
- return null;
- }
-
- /** Unimplemented. */
- public String getPrefix()
- {
- error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED); //"getPrefix not
supported!");
- return null;
- }
-
- /** Unimplemented. */
- public void setPrefix(String prefix)
- throws DOMException
- {
- error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED); //"setPrefix not
supported!");
- }
-
- /** Unimplemented. */
- public String getLocalName()
+ public int getLength()
{
- error(XSLTErrorResources.ER_FUNCTION_NOT_SUPPORTED); //"getLocalName not
supported!");
- return null;
+ return getChildCount();
}
}
1.16 +1 -0
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TransformerImpl.java 2000/08/10 23:30:49 1.15
+++ TransformerImpl.java 2000/08/11 23:54:59 1.16
@@ -304,6 +304,7 @@
if(inputHandler instanceof org.apache.xalan.stree.SourceTreeHandler)
{
((org.apache.xalan.stree.SourceTreeHandler)inputHandler).setInputSource(xmlSource);
+
((org.apache.xalan.stree.SourceTreeHandler)inputHandler).setUseMultiThreading(true);
Node doc
=
((org.apache.xalan.stree.SourceTreeHandler)inputHandler).getRoot();
if(null != doc)
1.4 +1 -1
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SourceTreeManager.java 2000/08/04 19:33:27 1.3
+++ SourceTreeManager.java 2000/08/11 23:55:00 1.4
@@ -346,7 +346,7 @@
if(handler instanceof org.apache.xalan.stree.SourceTreeHandler)
{
// temp hack
-
((org.apache.xalan.stree.SourceTreeHandler)handler).m_useMultiThreading = false;
+
((org.apache.xalan.stree.SourceTreeHandler)handler).setUseMultiThreading(false);
}
reader.setContentHandler(handler);