garyp 00/12/14 19:59:07
Modified: java/src/org/apache/xalan/stree DocumentFragmentImpl.java
DocumentImpl.java SourceTreeHandler.java
java/src/org/apache/xalan/transformer TransformerImpl.java
Added: java/src/org/apache/xalan/stree DocImpl.java
Log:
Separated DocumentFragmentImpl from DocumentImpl.
DocumentFragmentImpl no longer extends DocumentImpl. Instead, both now
extend a new class DocImpl.
This allows DocumentImpl to enforce the "one document element" constraint of
the DOM and implement all of the "create" methods while not forcing
DocumentFragmentImpl to do the same thing.
We now allow RTFs to have multiple element and text children per the XSLT
spec.
The common DocImpl superclass allows the root of the source tree to be either
a Document or DocumentFragment.
Revision Changes Path
1.7 +3 -3
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DocumentFragmentImpl.java 2000/11/07 22:22:32 1.6
+++ DocumentFragmentImpl.java 2000/12/15 03:59:06 1.7
@@ -63,7 +63,7 @@
* <meta name="usage" content="internal"/>
* Class to hold information about a DocumentFragment node
*/
-public class DocumentFragmentImpl extends DocumentImpl
+public class DocumentFragmentImpl extends DocImpl
implements DocumentFragment
{
@@ -71,11 +71,11 @@
* Constructor DocumentFragmentImpl
*
*/
- public DocumentFragmentImpl()
+ public DocumentFragmentImpl(DocumentImpl doc)
{
super();
-
+ setDoc(doc);
setComplete(true);
}
1.13 +5 -108
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DocumentImpl.java 2000/11/23 04:57:37 1.12
+++ DocumentImpl.java 2000/12/15 03:59:06 1.13
@@ -78,23 +78,8 @@
* interface. It rules over the tree, and may contain
* common information for the tree.
*/
-public class DocumentImpl extends Parent
+public class DocumentImpl extends DocImpl
{
- /** Aid to assigning a unique ID to the tree. */
- static int m_idCount = 0;
-
- /** The unique ID of this tree. */
- int m_id;
-
- /** Contains exception thrown from transformation thread,
- * if one occured. */
- public Exception m_exceptionThrown = null;
-
- /** This holds all the characters used, copied from the
- * characters events. This allows us to not have to allocate
- * a million little arrays. */
- FastStringBuffer m_chars = new FastStringBuffer(1024 * 64);
-
/**
* Constructor DocumentImpl. This constructor is
* not normally used by the transformation.
@@ -102,10 +87,8 @@
DocumentImpl()
{
- super(null);
- m_id = m_idCount++;
+ super();
setDoc(this);
-
// m_bUpIndexer = new LevelIndexer();
}
@@ -118,10 +101,8 @@
DocumentImpl(SourceTreeHandler sth)
{
- super(null);
- m_id = m_idCount++;
+ super();
setDoc(this);
-
// m_bUpIndexer = new LevelIndexer();
m_sourceTreeHandler = sth;
}
@@ -136,74 +117,20 @@
DocumentImpl(DocumentType doctype)
{
- super(null);
- m_id = m_idCount++;
+ super();
setDoc(this);
-
if (null != doctype)
m_docType = (DocumentTypeImpl) doctype;
// m_bUpIndexer = new LevelIndexer();
}
- /** A reference back to the source tree
- * handler that is creating this tree. */
- SourceTreeHandler m_sourceTreeHandler;
-
/**
- * Get a reference back to the source tree
- * handler that is creating this tree.
- *
- * @return SourceTreeHandler reference, could
- * be null (though maybe this should change. -sb).
- */
- SourceTreeHandler getSourceTreeHandler()
- {
- return m_sourceTreeHandler;
- }
-
- /**
- * Set a reference back to the source tree
- * handler that is creating this tree.
- *
- * @param h Should be a non-null reference to
- * the SourceTreeHandler that is creating this
- * tree.
- */
- void setSourceTreeHandler(SourceTreeHandler h)
- {
- m_sourceTreeHandler = h;
- }
-
- /**
* The document type that this tree conforms to. Is
* not normally used, and may well be null.
*/
DocumentTypeImpl m_docType;
- /** This tells how many children are in the tree. */
- int m_docOrderCount = 1;
-
- /**
- * Increment the document order count. Needs to be called
- * when a child is added.
- */
- protected void incrementDocOrderCount()
- {
- m_docOrderCount++;
- }
-
- /**
- * Get the number of nodes in the tree. Needs to be called
- * when a child is added.
- *
- * @return The number of children in the tree.
- */
- protected int getDocOrderCount()
- {
- return m_docOrderCount;
- }
-
/**
* For XML, this provides access to the Document Type Definition.
* For HTML documents, and XML documents which don't specify a DTD,
@@ -221,36 +148,6 @@
m_docType = (DocumentTypeImpl)docType;
}
-
- /** If this is true, the transformation is working off of
- * a secondary thread from the incoming SAX events, and
- * the secondary thread may have to wait for nodes be produced. */
- boolean m_useMultiThreading = false;
-
- /**
- * Set whether or not the tree being built should handle
- * transformation while the parse is still going on.
- *
- * @param b true if the transformation is working off of a
- * secondary thread, false otherwise.
- */
- 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.
- *
- * @return true if the transformation is working off of a
- * secondary thread, false otherwise.
- */
- public boolean getUseMultiThreading()
- {
- return m_useMultiThreading;
- }
-
/**
* The document element.
*/
@@ -380,7 +277,7 @@
*/
public DocumentFragment createDocumentFragment()
{
- return new DocumentFragmentImpl();
+ return new DocumentFragmentImpl(this);
}
/**
1.24 +17 -13
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- SourceTreeHandler.java 2000/12/13 19:26:02 1.23
+++ SourceTreeHandler.java 2000/12/15 03:59:06 1.24
@@ -150,7 +150,7 @@
private DOMBuilder m_sourceTreeHandler;
/** The root of the source document */
- private Document m_root; // Normally a Document
+ private DocImpl m_root; // Normally a Document but may be a
DocumentFragment
/** No longer used?? */
private boolean m_initedRoot;
@@ -180,7 +180,7 @@
*
* @param root root document of tree that will be created
*/
- public void setRoot(Document root)
+ public void setRoot(DocImpl root)
{
m_root = root;
}
@@ -193,7 +193,7 @@
*/
public void setExceptionThrown(Exception e)
{
- ((DocumentImpl) m_root).m_exceptionThrown = e;
+ m_root.m_exceptionThrown = e;
}
/** Source Document */
@@ -304,15 +304,16 @@
// System.out.println("startDocument: "+m_id);
synchronized (m_root)
{
- ((DocumentImpl) m_root).setSourceTreeHandler(this);
- ((DocumentImpl) m_root).setUid(1);
- ((DocumentImpl) m_root).setLevel(new Integer(1).shortValue());
- ((DocumentImpl) m_root).setUseMultiThreading(getUseMultiThreading());
+ m_root.setSourceTreeHandler(this);
+ m_root.setUid(1);
+ m_root.setLevel(new Integer(1).shortValue());
+ m_root.setUseMultiThreading(getUseMultiThreading());
if (m_root.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE)
- m_sourceTreeHandler = new StreeDOMBuilder(m_root,
(DocumentFragment)m_root);
+ m_sourceTreeHandler =
+ new StreeDOMBuilder(m_root.getOwnerDocument(),
(DocumentFragment) m_root);
else
- m_sourceTreeHandler = new StreeDOMBuilder(m_root);
+ m_sourceTreeHandler = new StreeDOMBuilder((Document) m_root);
pushShouldStripWhitespace(false);
m_sourceTreeHandler.startDocument();
@@ -348,7 +349,7 @@
public void endDocument() throws org.xml.sax.SAXException
{
// System.out.println("endDocument: "+m_id);
- ((Parent) m_root).setComplete(true);
+ m_root.setComplete(true);
m_eventsCount = m_maxEventsToNotify;
@@ -676,9 +677,12 @@
public void startDTD(String name, String publicId, String systemId)
throws org.xml.sax.SAXException
{
- DocumentImpl doc = ((DocumentImpl)m_root);
- DocumentTypeImpl dtd = new DocumentTypeImpl(doc, name, publicId,
systemId);
- ((DocumentImpl)m_root).setDoctype(dtd);
+ if (m_root instanceof DocumentImpl)
+ {
+ DocumentImpl doc = ((DocumentImpl)m_root);
+ DocumentTypeImpl dtd = new DocumentTypeImpl(doc, name, publicId,
systemId);
+ ((DocumentImpl)m_root).setDoctype(dtd);
+ }
}
/**
1.1 xml-xalan/java/src/org/apache/xalan/stree/DocImpl.java
Index: DocImpl.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 [EMAIL PROTECTED]
*
* 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.xalan.stree;
import org.apache.xml.utils.FastStringBuffer;
/**
* <meta name="usage" content="internal"/>
* Contains extended functionality that Xalan requires that is
* common in both the DocumentImpl and DocumentFragmentImpl
* classes. This leaves the DocumentImpl class free to simply implement
* the Document interface plus items peculiar to it.
*/
public abstract class DocImpl extends Parent
{
/** Aid to assigning a unique ID to the tree. */
static int m_idCount = 0;
/** The unique ID of this tree. */
int m_id;
/** This holds all the characters used, copied from the
* characters events. This allows us to not have to allocate
* a million little arrays. */
FastStringBuffer m_chars = new FastStringBuffer(1024 * 64);
/** Contains exception thrown from transformation thread,
* if one occured. */
public Exception m_exceptionThrown = null;
/**
* Constructor DocImpl
*/
public DocImpl()
{
super(null);
m_id = m_idCount++;
}
/** A reference back to the source tree
* handler that is creating this tree. */
SourceTreeHandler m_sourceTreeHandler;
/**
* Get a reference back to the source tree
* handler that is creating this tree.
*
* @return SourceTreeHandler reference, could
* be null (though maybe this should change. -sb).
*/
SourceTreeHandler getSourceTreeHandler()
{
return m_sourceTreeHandler;
}
/**
* Set a reference back to the source tree
* handler that is creating this tree.
*
* @param h Should be a non-null reference to
* the SourceTreeHandler that is creating this
* tree.
*/
void setSourceTreeHandler(SourceTreeHandler h)
{
m_sourceTreeHandler = h;
}
/** This tells how many children are in the tree. */
int m_docOrderCount = 1;
/**
* Increment the document order count. Needs to be called
* when a child is added.
*/
protected void incrementDocOrderCount()
{
m_docOrderCount++;
}
/**
* Get the number of nodes in the tree. Needs to be called
* when a child is added.
*
* @return The number of children in the tree.
*/
protected int getDocOrderCount()
{
return m_docOrderCount;
}
/** If this is true, the transformation is working off of
* a secondary thread from the incoming SAX events, and
* the secondary thread may have to wait for nodes be produced. */
boolean m_useMultiThreading = false;
/**
* Set whether or not the tree being built should handle
* transformation while the parse is still going on.
*
* @param b true if the transformation is working off of a
* secondary thread, false otherwise.
*/
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.
*
* @return true if the transformation is working off of a
* secondary thread, false otherwise.
*/
public boolean getUseMultiThreading()
{
return m_useMultiThreading;
}
}
1.62 +2 -1
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.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- TransformerImpl.java 2000/12/15 00:05:53 1.61
+++ TransformerImpl.java 2000/12/15 03:59:07 1.62
@@ -72,6 +72,7 @@
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.stree.SourceTreeHandler;
import org.apache.xalan.stree.DocumentImpl;
+import org.apache.xalan.stree.DocImpl;
import org.apache.xalan.templates.Constants;
import org.apache.xalan.templates.ElemAttributeSet;
import org.apache.xalan.templates.ElemTemplateElement;
@@ -1603,7 +1604,7 @@
// Create a ResultTreeFrag object.
DocumentImpl doc =
(DocumentImpl)((SourceTreeHandler)rtfHandler).getRoot();
resultFragment = doc.createDocumentFragment();
- ((SourceTreeHandler)rtfHandler).setRoot((Document)resultFragment);
+ ((SourceTreeHandler)rtfHandler).setRoot((DocImpl)resultFragment);
}
else
{