You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/07/21 22:57:02 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/utils DOMBuilder.java
mmidy 00/07/21 13:57:02
Modified: java/src/org/apache/xalan/extensions
XSLProcessorContext.java
java/src/org/apache/xalan/stree ElementImpl.java
LevelIndexer.java Parent.java
SourceTreeHandler.java
java/src/org/apache/xalan/transformer TransformerImpl.java
java/src/org/apache/xalan/utils DOMBuilder.java
Log:
Enable multi-threading of processor and transformer
Revision Changes Path
1.3 +1 -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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XSLProcessorContext.java 2000/07/05 14:38:10 1.2
+++ XSLProcessorContext.java 2000/07/21 20:57:00 1.3
@@ -86,7 +86,7 @@
* Create a processor context to be passed to an extension.
* (Notice it is a package-only constructor).
*/
- XSLProcessorContext (TransformerImpl transformer,
+ public XSLProcessorContext (TransformerImpl transformer,
Stylesheet stylesheetTree,
Node sourceTree, Node sourceNode, QName mode)
{
1.3 +27 -9 xml-xalan/java/src/org/apache/xalan/stree/ElementImpl.java
Index: ElementImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/stree/ElementImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ElementImpl.java 2000/07/05 14:39:02 1.2
+++ ElementImpl.java 2000/07/21 20:57:00 1.3
@@ -71,7 +71,8 @@
*/
public Node getFirstChild()
{
- return (getChildCount() == 0) ? null : getChild(getLength());
+ // The call to getAttrCount gets the number of attributes in the list.
+ return (getChildCount() == 0) ? null : getChild(getAttrCount());
}
/**
@@ -84,7 +85,7 @@
throws ArrayIndexOutOfBoundsException, NullPointerException
{
// wait?
- if (i < getLength())
+ if (i < getAttrCount())
return (AttrImpl)m_children[i];
else
return null;
@@ -99,7 +100,24 @@
*/
public int getChildCount()
{
- return (null == m_children) ? 0 : m_children.length - getLength();
+ if (null == m_children && !isComplete())
+ {
+ synchronized (this)
+ {
+ try
+ {
+ //System.out.println("Waiting... getelCount " );
+ wait();
+ }
+ catch (InterruptedException e)
+ {
+ // That's OK, it's as good a time as any to check again
+ }
+ //System.out.println("/// gotelcount " );
+
+ }
+ }
+ return (null == m_children) ? 0 : m_children.length - getAttrCount();
}
@@ -225,7 +243,7 @@
*
* @return The number of attributes in the list.
*/
- public int getLength ()
+ public int getAttrCount ()
{
return attrsEnd;
}
@@ -332,7 +350,7 @@
*/
public int getIndex (String uri, String localPart)
{
- for (int i = 0; i < getLength(); i++)
+ for (int i = 0; i < getAttrCount(); i++)
{
AttrImplNS attr = (AttrImplNS)getChildAttribute(i);
if (attr.getLocalName().equals(localPart) &&
@@ -351,7 +369,7 @@
*/
public int getIndex (String rawName)
{
- for (int i = 0; i < getLength(); i++)
+ for (int i = 0; i < getAttrCount(); i++)
{
AttrImpl attr = getChildAttribute(i);
if (attr.getNodeName().equals(rawName))
@@ -415,9 +433,9 @@
return getValue(getIndex(rawName));
}
- //
- // Implement NamedNodeMap
- //
+ ////////////////////////////
+ // Implement NamedNodeMap //
+ ////////////////////////////
public Node getNamedItem(String name)
{
1.2 +1 -1 xml-xalan/java/src/org/apache/xalan/stree/LevelIndexer.java
Index: LevelIndexer.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/stree/LevelIndexer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LevelIndexer.java 2000/06/19 16:52:37 1.1
+++ LevelIndexer.java 2000/07/21 20:57:00 1.2
@@ -332,7 +332,7 @@
*/
protected class MultiKeyTable //extends Hashtable
{
- private MultiKeyTable()
+ protected MultiKeyTable()
{
super();
}
1.2 +73 -3 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Parent.java 2000/06/19 16:52:37 1.1
+++ Parent.java 2000/07/21 20:57:00 1.2
@@ -30,7 +30,24 @@
* it is likely that more children will be added.
*/
public int getChildCount()
- {
+ {
+ if (!isComplete())
+ {
+ synchronized (this)
+ {
+ try
+ {
+ //System.out.println("Waiting... getCount " );
+ wait();
+ }
+ catch (InterruptedException e)
+ {
+ // That's OK, it's as good a time as any to check again
+ }
+ //System.out.println("... getcount " );
+
+ }
+ }
return (null == m_children) ? 0 : m_children.length;
}
@@ -41,7 +58,23 @@
* <code>false</code> if the node has no children.
*/
public boolean hasChildNodes()
{
- return (getChildCount() == 0) ? false : true;
}
+ if (null == m_children && !isComplete())
+ {
+ synchronized (this)
+ {
+ try
+ {
+ //System.out.println("Waiting... getCount " );
+ wait();
+ }
+ catch (InterruptedException e)
+ {
+ // That's OK, it's as good a time as any to check again
+ }
+ //System.out.println("... getcount " );
+ }
+ }
+ return (null == m_children || m_children.length == 0) ? false : true;
}
/**
* <meta name="usage" content="internal"/>
@@ -64,8 +97,29 @@
throws ArrayIndexOutOfBoundsException, NullPointerException
{
// wait?
- return ((null != m_children) && (i >= 0) && i < m_children.length) ?
+
+ Child child = ((null != m_children) && (i >= 0) && i < m_children.length) ?
+ m_children[i] : null;
+ if (child == null && !isComplete())
+ {
+ synchronized (this)
+ {
+ try
+ {
+ System.out.println("Waiting... getChild " + i + " " + getNodeName());
+ wait();
+ }
+ catch (InterruptedException e)
+ {
+ // That's OK, it's as good a time as any to check again
+ }
+ System.out.println("... gotChild " + i);
+ child = ((null != m_children) && (i >= 0) && i < m_children.length) ?
m_children[i] : null;
+ }
+ }
+ return child;
+
}
/**
@@ -157,6 +211,14 @@
}
}
+ if (newChild.getNodeType() != Node.ATTRIBUTE_NODE)
+ {
+ // Notify anyone waiting for a child...
+ synchronized (this)
+ {
+ notifyAll();
+ }
+ }
return newChild;
}
@@ -183,6 +245,14 @@
public void setComplete(boolean isComplete)
{
m_isComplete = isComplete;
+ if (isComplete())
+ {
+ // Notify anyone waiting for a child...
+ synchronized (this)
+ {
+ notifyAll();
+ }
+ }
}
}
1.3 +6 -2 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SourceTreeHandler.java 2000/07/05 14:39:07 1.2
+++ SourceTreeHandler.java 2000/07/21 20:57:00 1.3
@@ -73,7 +73,7 @@
{
}
- private boolean m_useMultiThreading = false;
+ private boolean m_useMultiThreading = true;
private boolean indexedLookup = false; // for now
@@ -98,7 +98,9 @@
if(m_useMultiThreading && (null != m_transformer))
{
- m_transformer.transformNode(m_root);
+ Thread t = new Thread(m_transformer);
+ t.start();
+ //m_transformer.transformNode(m_root);
}
m_sourceTreeHandler.startDocument();
@@ -112,6 +114,7 @@
public void endDocument ()
throws SAXException
{
+ ((Parent)m_root).setComplete(true);
m_sourceTreeHandler.endDocument();
if(!m_useMultiThreading && (null != m_transformer))
@@ -137,6 +140,7 @@
String name)
throws SAXException
{
+ ((Parent)m_sourceTreeHandler.getCurrentNode()).setComplete(true);
m_sourceTreeHandler.endElement(ns, localName, name);
}
1.6 +21 -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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TransformerImpl.java 2000/07/18 01:37:30 1.5
+++ TransformerImpl.java 2000/07/21 20:57:01 1.6
@@ -162,7 +162,7 @@
* @see XSLTProcessorFactory
* @see XSLTProcessor
*/
-public class TransformerImpl extends XMLFilterImpl implements Transformer
+public class TransformerImpl extends XMLFilterImpl implements Transformer, Runnable
{
//==========================================================
// SECTION: Constructors
@@ -1061,8 +1061,8 @@
{
// Does this element have any children?
ElemTemplateElement firstChild = elem.getFirstChildElem();
- if(null == firstChild)
- return;
+ if(null == firstChild)
+ return;
XPathContext xctxt = getXPathContext();
@@ -1450,7 +1450,7 @@
public TraceManager getTraceManager()
{
return m_traceManager;
- }
+ }
/**
* Look up the value of a feature.
@@ -1485,6 +1485,23 @@
return true;
throw new SAXNotRecognizedException(name);
}
+ ////////////////////////
+ // Implement Runnable //
+ ////////////////////////
+ /**
+ * Run the transform thread.
+ */
+ public void run()
+ {
+ try
+ {
+ transformNode(((SourceTreeHandler)getInputContentHandler()).getRoot());
+ }
+ catch(Exception e)
+ {
+ ; // should have already been reported via the error handler?
+ }
+ }
} // end TransformerImpl class
1.3 +8 -0 xml-xalan/java/src/org/apache/xalan/utils/DOMBuilder.java
Index: DOMBuilder.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/utils/DOMBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMBuilder.java 2000/07/05 14:44:01 1.2
+++ DOMBuilder.java 2000/07/21 20:57:01 1.3
@@ -121,6 +121,14 @@
}
/**
+ * Get the node currently being processed.
+ */
+ public Node getCurrentNode()
+ {
+ return m_currentNode;
+ }
+
+ /**
* Return null since there is no Writer for this class.
*/
public java.io.Writer getWriter()