jkesselm 02/02/08 15:33:50
Modified: java/src/org/apache/xalan/extensions
XSLProcessorContext.java
java/src/org/apache/xalan/lib/sql DTMDocument.java
java/src/org/apache/xalan/templates ElemForEach.java
FuncDocument.java FuncKey.java
java/src/org/apache/xalan/transformer KeyIterator.java
TransformerHandlerImpl.java TransformerImpl.java
java/src/org/apache/xml/dtm DTM.java
java/src/org/apache/xml/dtm/ref DTMDefaultBase.java
DTMDefaultBaseIterators.java DTMDocumentImpl.java
DTMNodeProxy.java
java/src/org/apache/xml/dtm/ref/sax2dtm SAX2RTFDTM.java
java/src/org/apache/xpath/axes IteratorPool.java
Log:
Bugzilla 6314: Additional support changes for multiple RTFs per DTM.
Many files affected, but the basic change is that dtm.getDocument()
with no arguments is meaningless when there are multiple docs in
a single DTM object; instead, folks should use the new getRootNode()
method or getOwnerDocument(), both of which take a node as input
and thus more clearly identify which document we're referring to.
Revision Changes Path
1.13 +6 -1
xml-xalan/java/src/org/apache/xalan/extensions/XSLProcessorContext.java
Index: XSLProcessorContext.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/XSLProcessorContext.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- XSLProcessorContext.java 7 Aug 2001 19:16:42 -0000 1.12
+++ XSLProcessorContext.java 8 Feb 2002 23:33:49 -0000 1.13
@@ -151,7 +151,7 @@
*/
public org.w3c.dom.Node getSourceTree()
{
- return sourceTree.getNode(sourceTree.getDocument());
+ return sourceTree.getNode(sourceTree.getDocumentRoot(sourceNode));
}
/** the current context node. */
@@ -235,6 +235,11 @@
{
DTM dtm = (DTM)obj;
DTMIterator iterator = new DescendantIterator();
+ // %%ISSUE%% getDocument may not be valid for DTMs shared by multiple
+ // document trees, eg RTFs. But in that case, we shouldn't be trying
+ // to iterate over the whole DTM; we should be iterating over
+ // dtm.getDocumentRoot(rootNodeHandle), and folks should have told us
+ // this by passing a more appropriate type.
iterator.setRoot(dtm.getDocument(), xctxt);
value = new XNodeSet(iterator);
}
1.7 +13 -1
xml-xalan/java/src/org/apache/xalan/lib/sql/DTMDocument.java
Index: DTMDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/DTMDocument.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DTMDocument.java 17 Jan 2002 19:29:38 -0000 1.6
+++ DTMDocument.java 8 Feb 2002 23:33:49 -0000 1.7
@@ -1469,7 +1469,8 @@
return super._firstch( parm1);
}
- /**
+ /** This call should follow DOM semantics, where the owner of a Document
node
+ * is null.
* @param parm1
* @return
*/
@@ -1477,6 +1478,17 @@
{
if (DEBUG) System.out.println("getOwnerDoc("+parm1+")");
return super.getOwnerDocument( parm1);
+ }
+
+ /** This call should follow DTM semantics, where the owner of a Document
node
+ * is itself.
+ * @param parm1
+ * @return
+ */
+ public int getDocumentRoot( int parm1 )
+ {
+ if (DEBUG) System.out.println("getOwnerDoc("+parm1+")");
+ return super.getDocumentRoot( parm1);
}
/**
1.24 +3 -0
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ElemForEach.java 10 Oct 2001 18:42:07 -0000 1.23
+++ ElemForEach.java 8 Feb 2002 23:33:49 -0000 1.24
@@ -453,6 +453,9 @@
if(DEBUG)
System.out.println("JJK***** CACHE RELEASE *****\n"+
"\tdtm="+dtm.getDocumentBaseURI());
+ // NOTE: This will work because this is _NOT_ a shared DTM, and thus has
+ // only a single Document node. If it could ever be an RTF or other
+ // shared DTM, this would require substantial rework.
xctxt.getSourceTreeManager().removeDocumentFromCache(dtm.getDocument());
xctxt.release(dtm,false);
}
1.25 +1 -1
xml-xalan/java/src/org/apache/xalan/templates/FuncDocument.java
Index: FuncDocument.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/FuncDocument.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- FuncDocument.java 17 Aug 2001 19:21:20 -0000 1.24
+++ FuncDocument.java 8 Feb 2002 23:33:49 -0000 1.25
@@ -124,7 +124,7 @@
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
- int docContext = dtm.getDocument();
+ int docContext = dtm.getDocumentRoot(context);
XObject arg = (XObject) this.getArg0().execute(xctxt);
String base = "";
1.13 +1 -1
xml-xalan/java/src/org/apache/xalan/templates/FuncKey.java
Index: FuncKey.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/FuncKey.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- FuncKey.java 19 Jun 2001 21:32:37 -0000 1.12
+++ FuncKey.java 8 Feb 2002 23:33:49 -0000 1.13
@@ -104,7 +104,7 @@
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
- int docContext = dtm.getDocument();
+ int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext)
{
1.11 +1 -1
xml-xalan/java/src/org/apache/xalan/transformer/KeyIterator.java
Index: KeyIterator.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/KeyIterator.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- KeyIterator.java 12 Jun 2001 19:15:25 -0000 1.10
+++ KeyIterator.java 8 Feb 2002 23:33:49 -0000 1.11
@@ -180,7 +180,7 @@
int context = getContext();
DTM dtm = this.getDTM(context);
- m_firstWalker.setRoot(dtm.getDocument());
+ m_firstWalker.setRoot(dtm.getDocumentRoot(context));
this.setLastUsedWalker(m_firstWalker);
this.setNextPosition(0);
}
1.14 +3 -0
xml-xalan/java/src/org/apache/xalan/transformer/TransformerHandlerImpl.java
Index: TransformerHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerHandlerImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TransformerHandlerImpl.java 6 Aug 2001 22:17:17 -0000 1.13
+++ TransformerHandlerImpl.java 8 Feb 2002 23:33:49 -0000 1.14
@@ -429,6 +429,9 @@
}
else
{
+ // %REVIEW% If this could ever be a shared DTM, we might need to
+ // retrieve the Document node _before_ issuing endDocument(), or
+ // use the getDocumentRoot(nodeHandle) method.
m_transformer.setSourceTreeDocForThread(m_dtm.getDocument());
m_transformer.run();
}
1.124 +8 -4
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.123
retrieving revision 1.124
diff -u -r1.123 -r1.124
--- TransformerImpl.java 1 Feb 2002 21:10:25 -0000 1.123
+++ TransformerImpl.java 8 Feb 2002 23:33:49 -0000 1.124
@@ -628,6 +628,9 @@
try
{
+ // NOTE: This will work because this is _NOT_ a shared DTM, and
thus has
+ // only a single Document node. If it could ever be an RTF or
other
+ // shared DTM, look at dtm.getDocumentRoot(nodeHandle).
this.transformNode(dtm.getDocument());
}
finally
@@ -1773,10 +1776,11 @@
rth.flushPending();
// Get the document ID. May not exist until the RTH has not only
- // recieved, but flushed, the startDocument... so waiting until
- // just before the end seems simplest/safest.
- resultFragment = dtmFrag.getDocument();
- }
+ // received, but flushed, the startDocument, and may be invalid
+ // again after the document has been closed (still debating that)
+ // ... so waiting until just before the end seems simplest/safest.
+ resultFragment = dtmFrag.getDocument();
+ }
finally
{
rth.endDocument();
1.6 +25 -10 xml-xalan/java/src/org/apache/xml/dtm/DTM.java
Index: DTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/DTM.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DTM.java 11 Oct 2001 15:18:10 -0000 1.5
+++ DTM.java 8 Feb 2002 23:33:49 -0000 1.6
@@ -375,25 +375,40 @@
public int getParent(int nodeHandle);
/**
- * Given a node handle, find the owning document node. Note that
- * the reason this can't just return 0 is that it needs to include the
- * document number portion of the node handle.
+ * Given a DTM which contains only a single document,
+ * find the Node Handle of the Document node. Note
+ * that if the DTM is configured so it can contain multiple
+ * documents, this call will return the Document currently
+ * under construction -- but may return null if it's between
+ * documents. Generally, you should use getOwnerDocument(nodeHandle)
+ * or getDocumentRoot(nodeHandle) instead.
*
- * @param nodeHandle the id of the node.
- * @return int Node handle of document, which should always be valid.
+ * @return int Node handle of document, or DTM.NULL if a shared DTM
+ * can not tell us which Document is currently active.
*/
public int getDocument();
/**
- * Given a node handle, find the owning document node. This has the exact
- * same semantics as the DOM Document method of the same name, in that if
- * the nodeHandle is a document node, it will return NULL.
+ * Given a node handle, find the owning document node. This version mimics
+ * the behavior of the DOM call by the same name.
*
* @param nodeHandle the id of the node.
- * @return int Node handle of owning document,
- * or DTM.NULL if the nodeHandle is a document.
+ * @return int Node handle of owning document, or DTM.NULL if the node was
+ * a Document.
+ * @see getDocumentRoot(int nodeHandle)
*/
public int getOwnerDocument(int nodeHandle);
+
+ /**
+ * Given a node handle, find the owning document node.
+ *
+ * @param nodeHandle the id of the node.
+ * @return int Node handle of owning document, or the node itself if it was
+ * a Document. (Note difference from DOM, where getOwnerDocument returns
+ * null for the Document node.)
+ * @see getOwnerDocument(int nodeHandle)
+ */
+ public int getDocumentRoot(int nodeHandle);
/**
* Get the string-value of a node as a String object
1.26 +15 -7
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBase.java
Index: DTMDefaultBase.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBase.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- DTMDefaultBase.java 23 Jan 2002 22:53:47 -0000 1.25
+++ DTMDefaultBase.java 8 Feb 2002 23:33:50 -0000 1.26
@@ -1412,19 +1412,27 @@
* aid porting of DOM code to DTM.</p>
*
* @param nodeHandle the id of the node.
- * @return int Node handle of owning document, or -1 if the nodeHandle is
- * a document.
+ * @return int Node handle of owning document, or -1 if the node was a
Docment
*/
public int getOwnerDocument(int nodeHandle)
{
- int type = getNodeType(nodeHandle);
+ if (DTM.DOCUMENT_NODE == getNodeType(nodeHandle))
+ return DTM.NULL;
- if (DTM.DOCUMENT_NODE == type)
- {
- return DTM.NULL;
- }
+ return getDocumentRoot(nodeHandle);
+ }
+ /**
+ * Given a node handle, find the owning document node. Unlike the DOM,
+ * this considers the owningDocument of a Document to be itself.
+ *
+ * @param nodeHandle the id of the node.
+ * @return int Node handle of owning document, or the nodeHandle if it is
+ * a Document.
+ */
+ public int getDocumentRoot(int nodeHandle)
+ {
return getDocument();
}
1.11 +5 -5
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBaseIterators.java
Index: DTMDefaultBaseIterators.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBaseIterators.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DTMDefaultBaseIterators.java 3 Dec 2001 18:08:12 -0000 1.10
+++ DTMDefaultBaseIterators.java 8 Feb 2002 23:33:50 -0000 1.11
@@ -677,7 +677,7 @@
if (_isRestartable)
{
- _startNode = getDocument();
+ _startNode = getDocumentRoot(node);
_currentNode = NULL;
return resetPosition();
@@ -1489,7 +1489,7 @@
else
_startNode = getParent(node);
- _currentNode = getDocument();
+ _currentNode = getDocumentRoot(node);
node = _startNode;
while (node != END)
@@ -1514,7 +1514,7 @@
public DTMAxisIterator reset()
{
- _currentNode = getDocument();
+ _currentNode = getDocumentRoot(_startNode);
m_ancestorsPos = m_ancestors.size()-1;
@@ -1533,9 +1533,9 @@
int pos = m_ancestorsPos--;
if(pos < 0)
- _currentNode = DTM.NULL;
+ _currentNode = DTM.NULL;
else
- _currentNode = m_ancestors.elementAt(pos);
+ _currentNode = m_ancestors.elementAt(pos);
return returnNode(next);
}
1.7 +18 -0
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDocumentImpl.java
Index: DTMDocumentImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDocumentImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DTMDocumentImpl.java 24 Aug 2001 04:49:31 -0000 1.6
+++ DTMDocumentImpl.java 8 Feb 2002 23:33:50 -0000 1.7
@@ -1431,6 +1431,24 @@
return (nodeHandle & DOCHANDLE_MASK);
}
+ /**
+ * Given a node handle, find the owning document node. This has the
DTM
+ * semantics; a Document node is its own owner.
+ *
+ * <p>%REVIEW% Since this is DOM-specific, it may belong at the DOM
+ * binding layer. Included here as a convenience function and to
+ * aid porting of DOM code to DTM.</p>
+ *
+ * @param nodeHandle the id of the node.
+ * @return int Node handle of owning document, or NULL if the
nodeHandle is
+ * a document.
+ */
+ public int getDocumentRoot(int nodeHandle) {
+ // Assumption that Document Node is always in 0 slot
+ if ((nodeHandle & NODEHANDLE_MASK) == 0)
+ return NULL;
+ return (nodeHandle & DOCHANDLE_MASK);
+ }
/**
* Get the string-value of a node as a String object
1.13 +2 -2
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMNodeProxy.java
Index: DTMNodeProxy.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMNodeProxy.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DTMNodeProxy.java 29 Nov 2001 19:41:51 -0000 1.12
+++ DTMNodeProxy.java 8 Feb 2002 23:33:50 -0000 1.13
@@ -475,8 +475,8 @@
*/
public final Document getOwnerDocument()
{
- return (Document)(dtm.getNode(dtm.getDocument()));
- //return new DTMNodeProxy(dtm, dtm.getDocument());
+ // Note that this uses the DOM-compatable version of the call
+ return (Document)(dtm.getNode(dtm.getOwnerDocument(node)));
}
/**
1.3 +12 -14
xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2RTFDTM.java
Index: SAX2RTFDTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2RTFDTM.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SAX2RTFDTM.java 31 Jan 2002 16:08:24 -0000 1.2
+++ SAX2RTFDTM.java 8 Feb 2002 23:33:50 -0000 1.3
@@ -172,27 +172,25 @@
}
/**
- * Given a node handle, find the owning document node. This has the exact
- * same semantics as the DOM Document method of the same name, in that if
- * the nodeHandle is a document node, it will return NULL.
+ * Given a node handle, find the owning document node, using DTM semantics
+ * (Document owns itself) rather than DOM semantics (Document has no
owner).
*
- * <p>%REVIEW% Since this is DOM-specific, it may belong at the DOM
- * binding layer. Included here as a convenience function and to
- * aid porting of DOM code to DTM.</p>
+ * (I'm counting on the fact that getOwnerDocument() is implemented on top
+ * of this call, in the superclass, to avoid having to rewrite that one.
+ * Be careful if that code changes!)
*
* @param nodeHandle the id of the node.
- * @return int Node handle of owning document, or -1 if the nodeHandle is
- * a document.
+ * @return int Node handle of owning document
*/
- public int getOwnerDocument(int nodeHandle)
+ public int getDocumentRoot(int nodeHandle)
{
for(int id=makeNodeIdentity(nodeHandle);
- id!=NULL;
- id=_parent(id))
- if(_type(id)==DTM.DOCUMENT_NODE)
- return id;
+ id!=NULL;
+ id=_parent(id))
+ if(_type(id)==DTM.DOCUMENT_NODE)
+ return makeNodeHandle(id);
- return DTM.NULL;
+ return DTM.NULL; // Safety net; should never happen
}
/**
1.3 +1 -1
xml-xalan/java/src/org/apache/xpath/axes/IteratorPool.java
Index: IteratorPool.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/IteratorPool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- IteratorPool.java 12 Jun 2001 19:16:18 -0000 1.2
+++ IteratorPool.java 8 Feb 2002 23:33:50 -0000 1.3
@@ -73,4 +73,4 @@
{
m_freeStack.addElement(obj);
}
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]