sboag 00/10/06 18:43:29
Modified: java/src/org/apache/xalan/stree Child.java DocumentImpl.java
ElementImpl.java Parent.java SourceTreeHandler.java
Log:
Fixed problem (again) with notification being correctly handled from a parser
error. Also, added loops to waits until when the child count is required.
Also, moved notification from Parent#setComplete to the SourceTreeHandler's
ContentHandler methods.
Revision Changes Path
1.7 +31 -37 xml-xalan/java/src/org/apache/xalan/stree/Child.java
Index: Child.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/stree/Child.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Child.java 2000/10/06 07:52:23 1.6
+++ Child.java 2000/10/07 01:43:29 1.7
@@ -8,6 +8,10 @@
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
+// Yuck. Have to do it right not, for synch issues.
+// There will be a better way...
+import org.apache.xalan.transformer.TransformerImpl;
+
public class Child extends UnImplNode implements DOMOrder
{
private Parent m_parent;
@@ -32,7 +36,7 @@
return true;
}
- protected Object getSynchObject()
+ protected TransformerImpl getTransformer()
{
DocumentImpl di = this.getDocumentImpl();
if(null != di)
@@ -41,30 +45,39 @@
if(null != sth)
{
sth = di.getSourceTreeHandler();
- org.apache.xalan.transformer.TransformerImpl ti
- = sth.getTransformer();
- if(null != ti)
- {
- Exception e = ti.getExceptionThrown();
- if(null != e)
- {
- throw new org.apache.xalan.utils.WrappedRuntimeException(e);
- }
- }
+ return sth.getTransformer();
}
}
- return this;
+ return null;
+ }
+
+ /**
+ * Get an object that is being synchronized
+ * with the parse thread, so that notification
+ * will work correctly.
+ */
+ protected Object getSynchObject()
+ {
+ Object obj = getTransformer();
+ return (null == obj) ? this : obj;
}
+ protected void throwParseError(Exception e)
+ {
+ throw new org.apache.xalan.utils.WrappedRuntimeException(e);
+ }
+
protected void throwIfParseError()
{
- // That's OK, it's as good a time as any to check again
- Exception pe
- =
this.getDocumentImpl().getSourceTreeHandler().getTransformer().getExceptionThrown();
- if(null != pe)
- throw new org.apache.xalan.utils.WrappedRuntimeException(pe);
+ TransformerImpl ti = getTransformer();
+
+ if(null != ti)
+ {
+ Exception e = ti.getExceptionThrown();
+ if(null != e)
+ throwParseError(e);
+ }
}
-
/**
* The position in the parent's list.
@@ -130,25 +143,6 @@
m_level = level;
}
- /**
- * <meta name="usage" content="internal"/>
- * Get the value of K. K is the maximum width of the tree.
- *
- public int getK()
- {
- return getDocumentImpl().getK();
- }
-
- /**
- * <meta name="usage" content="internal"/>
- * Get the value of Y. Y is the maximum depth of the tree.
- * Needed to calculate depth-first (document order) numbering.
- *
- public int getY()
- {
- return getDocumentImpl().getY();
- }
-
/**
* Get the root Document Implementation.
*/
1.7 +16 -3
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DocumentImpl.java 2000/10/06 07:52:23 1.6
+++ DocumentImpl.java 2000/10/07 01:43:29 1.7
@@ -22,6 +22,12 @@
m_bUpIndexer = new LevelIndexer();
}
+ DocumentImpl(SourceTreeHandler sth)
+ {
+ m_bUpIndexer = new LevelIndexer();
+ m_sourceTreeHandler = sth;
+ }
+
DocumentImpl(DocumentType doctype)
{
if(null != doctype)
@@ -266,15 +272,22 @@
Element elem = (Element)m_idAttributes.get(elementId);
// Make sure we're done parsing.
if (elem == null && !isComplete())
- {
- synchronized (getSynchObject())
+ {
+ Object synchObj = getSynchObject();
+ synchronized (synchObj)
{
try
{
// Don't really know why we should need the while loop,
// but we seem to come out of wait() too soon!
while (!isComplete())
- getSynchObject().wait();
+ {
+ synchObj.wait();
+ throwIfParseError();
+ elem = (Element)m_idAttributes.get(elementId);
+ if(null != elem)
+ return elem;
+ }
}
catch (InterruptedException e)
{
1.14 +10 -23
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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ElementImpl.java 2000/10/06 07:52:23 1.13
+++ ElementImpl.java 2000/10/07 01:43:29 1.14
@@ -13,7 +13,7 @@
{
private String m_name;
- private short attrsEnd;
+ private short attrsEnd = 0;
ElementImpl (String name)
{
@@ -100,17 +100,23 @@
* Note that this will only return the number of children
* added so far. If the isComplete property is false,
* it is likely that more children will be added.
+ * DON'T CALL THIS FUNCTION IF YOU CAN HELP IT!!!!!!
*/
public int getChildCount()
{
if (!isComplete())
{
- synchronized (getSynchObject())
+ Object synchObj = getSynchObject();
+ synchronized (synchObj)
{
try
{
- //System.out.println("Waiting... getelCount " );
- getSynchObject().wait();
+ // Here we have to wait until the element is complete
+ while (!isComplete())
+ {
+ synchObj.wait();
+ throwIfParseError();
+ }
}
catch (InterruptedException e)
{
@@ -276,25 +282,6 @@
*/
public int getAttrCount ()
{
- if (null == m_children && !isComplete())
- {
- // Force it to wait until at least an element child
- // has been added or end element.
- synchronized (getSynchObject())
- {
- try
- {
- //System.out.println("Waiting... getelCount " );
- getSynchObject().wait();
- }
- catch (InterruptedException e)
- {
- throwIfParseError();
- }
- //System.out.println("/// gotelcount " );
-
- }
- }
return attrsEnd;
}
1.9 +43 -55 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Parent.java 2000/10/06 07:52:23 1.8
+++ Parent.java 2000/10/07 01:43:29 1.9
@@ -28,17 +28,23 @@
* Note that this will only return the number of children
* added so far. If the isComplete property is false,
* it is likely that more children will be added.
+ * DON'T CALL THIS FUNCTION IF YOU CAN HELP IT!!!
*/
public int getChildCount()
{
if (!isComplete())
{
- synchronized (getSynchObject())
+ Object synchObj = getSynchObject();
+ synchronized (synchObj)
{
try
{
- //System.out.println("Waiting... getCount "+ this.getNodeName() );
- getSynchObject().wait();
+ // Here we have to wait until the element is complete
+ while (!isComplete())
+ {
+ synchObj.wait();
+ throwIfParseError();
+ }
}
catch (InterruptedException e)
{
@@ -61,20 +67,23 @@
public boolean hasChildNodes()
{
if (null == m_children && !isComplete())
{
- synchronized (getSynchObject())
+ Object synchObj = getSynchObject();
+ synchronized (synchObj)
{
try
{
- //System.out.println("Waiting... getCount " + this.getNodeName() );
- getSynchObject().wait();
+ // Only wait until the first child comes, or we are complete.
+ while (!isComplete())
+ {
+ synchObj.wait();
+ throwIfParseError();
+ if(null != m_children)
+ break;
+ }
}
catch (InterruptedException e)
{
- // That's OK, it's as good a time as any to check again
- Exception pe
- =
this.getDocumentImpl().getSourceTreeHandler().getTransformer().getExceptionThrown();
- if(null != pe)
- throw new org.apache.xalan.utils.WrappedRuntimeException(pe);
+ throwIfParseError();
}
//System.out.println("... getcount " );
}
@@ -108,22 +117,28 @@
m_children[i] : null;
if (child == null && !isComplete())
{
- synchronized (getSynchObject())
+ Object synchObj = getSynchObject();
+ synchronized (synchObj)
{
try
{
// System.out.println("Waiting... getChild " + i + " " +
getNodeName());
-
- getSynchObject().wait();
+ while (!isComplete())
+ {
+ synchObj.wait();
+ throwIfParseError();
+ // System.out.println("... gotChild " + i);
+ child = ((null != m_children) && (i >= 0) && i <
m_children.length) ?
+ m_children[i] : null;
+ if(null != child)
+ break;
+ }
}
catch (InterruptedException e)
{
throwIfParseError();
- }
- // System.out.println("... gotChild " + i);
- child = ((null != m_children) && (i >= 0) && i < m_children.length) ?
- m_children[i] : null;
}
+ }
}
return child;
@@ -258,7 +273,7 @@
* Flag that tells if this node is complete.
*/
private boolean m_isComplete = false;
-
+
/**
* Return if this node has had all it's children added, i.e.
* if a endElement event has occured.
@@ -266,28 +281,7 @@
public boolean isComplete()
{
if(!m_isComplete)
- {
- DocumentImpl di = this.getDocumentImpl();
- if(null != di)
- {
- SourceTreeHandler sth = di.getSourceTreeHandler();
- if(null != sth)
- {
- sth = di.getSourceTreeHandler();
- org.apache.xalan.transformer.TransformerImpl ti
- = sth.getTransformer();
- if(null != ti)
- {
- Exception e = ti.getExceptionThrown();
- if(null != e)
- {
- m_isComplete = true; // to be safe
- throw new org.apache.xalan.utils.WrappedRuntimeException(e);
- }
- }
- }
- }
- }
+ throwIfParseError();
return m_isComplete;
}
@@ -297,20 +291,14 @@
*/
public void setComplete(boolean isComplete)
{
- if(m_isComplete != isComplete)
- {
- m_isComplete = isComplete;
- if (m_isComplete)
- {
- Object synchObj = getSynchObject();
- // Notify anyone waiting for a child...
- synchronized (synchObj)
- {
- //System.out.println("notify set complete" + this.getNodeName());
- synchObj.notifyAll();
- }
- }
- }
+ m_isComplete = isComplete;
}
+
+ protected void throwParseError(Exception e)
+ {
+ m_isComplete = true;
+ super.throwParseError(e);
+ }
+
}
1.9 +26 -4
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SourceTreeHandler.java 2000/10/02 02:43:07 1.8
+++ SourceTreeHandler.java 2000/10/07 01:43:29 1.9
@@ -36,7 +36,7 @@
if (indexedLookup)
m_root = new IndexedDocImpl();
else
- m_root = new DocumentImpl();
+ m_root = new DocumentImpl(this);
}
/**
@@ -112,8 +112,19 @@
}
- private boolean indexedLookup = false; // for now
+ private boolean indexedLookup = false; // for now
+ private void notifyWaiters()
+ {
+ if(null != m_transformer)
+ {
+ synchronized (m_transformer)
+ {
+ m_transformer.notifyAll();
+ }
+ }
+ }
+
/**
* Implement the startDocument event.
*/
@@ -125,7 +136,7 @@
if (indexedLookup)
m_root = new IndexedDocImpl();
else
- m_root = new DocumentImpl();
+ m_root = new DocumentImpl(this);
}
((DocumentImpl)m_root).setSourceTreeHandler(this);
((DocumentImpl)m_root).setUid(1);
@@ -146,6 +157,7 @@
}
m_sourceTreeHandler.startDocument();
+ notifyWaiters();
}
@@ -164,6 +176,7 @@
{
m_transformer.transformNode(m_root);
}
+ notifyWaiters();
}
/**
@@ -175,6 +188,7 @@
{
pushShouldStripWhitespace(getShouldStripWhitespace());
m_sourceTreeHandler.startElement(ns, localName, name, atts);
+ notifyWaiters();
}
/**
@@ -186,7 +200,8 @@
{
((Parent)m_sourceTreeHandler.getCurrentNode()).setComplete(true);
m_sourceTreeHandler.endElement(ns, localName, name);
- popShouldStripWhitespace();
+ popShouldStripWhitespace();
+ notifyWaiters();
}
private boolean m_isCData = false;
@@ -246,6 +261,7 @@
m_sourceTreeHandler.cdata(ch, start, length);
else
m_sourceTreeHandler.characters(ch, start, length);
+ notifyWaiters();
}
/**
@@ -255,6 +271,7 @@
throws SAXException
{
m_sourceTreeHandler.charactersRaw(ch, start, length);
+ notifyWaiters();
}
/**
@@ -264,6 +281,7 @@
throws SAXException
{
m_sourceTreeHandler.charactersRaw(ch, start, length);
+ notifyWaiters();
}
/**
@@ -273,6 +291,7 @@
throws SAXException
{
m_sourceTreeHandler.processingInstruction(target, data);
+ notifyWaiters();
}
/**
@@ -291,6 +310,7 @@
throws SAXException
{
m_sourceTreeHandler.comment(ch, start, length);
+ notifyWaiters();
}
/**
@@ -316,6 +336,7 @@
throws SAXException
{
m_sourceTreeHandler.startEntity(name);
+ notifyWaiters();
}
/**
@@ -329,6 +350,7 @@
throws SAXException
{
m_sourceTreeHandler.endEntity(name);
+ notifyWaiters();
}
/**