You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@apache.org on 2001/05/17 02:11:17 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/dtm CoroutineSAXParser.java CoroutineSAXParser_Xerces.java DTMManagerDefault.java
sboag 01/05/16 17:11:16
Modified: java/src/org/apache/xml/dtm Tag: DTM_EXP
CoroutineSAXParser.java
CoroutineSAXParser_Xerces.java
DTMManagerDefault.java
Log:
Updated CoRoutineSaxParser_Xerces so it no longer uses IncrementalXercesSaxParser.
The DTMManagerDefault now uses CoRoutineSaxParser_Xerces if it can.
Revision Changes Path
No revision
No revision
1.1.2.14 +179 -179 xml-xalan/java/src/org/apache/xml/dtm/Attic/CoroutineSAXParser.java
Index: CoroutineSAXParser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/CoroutineSAXParser.java,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -r1.1.2.13 -r1.1.2.14
--- CoroutineSAXParser.java 2001/05/16 21:05:07 1.1.2.13
+++ CoroutineSAXParser.java 2001/05/17 00:11:09 1.1.2.14
@@ -474,22 +474,22 @@
if(!fRunningInThread)
{
- try
- {
- fCoroutineManager.co_exit_to(exception,
- fParserCoroutineID,fAppCoroutineID);
- // %TBD% Do we need to wait for terminate?
- }
- catch(NoSuchMethodException e)
- {
- // Shouldn't happen unless we've miscoded our coroutine logic
- // "Shut down the garbage smashers on the detention level!"
- e.printStackTrace(System.err);
- fCoroutineManager.co_exit(fParserCoroutineID);
-
- // No need to throw shutdownException; we're already
- // in the process of murdering the parser.
- }
+ try
+ {
+ fCoroutineManager.co_exit_to(exception,
+ fParserCoroutineID,fAppCoroutineID);
+ // %TBD% Do we need to wait for terminate?
+ }
+ catch(NoSuchMethodException e)
+ {
+ // Shouldn't happen unless we've miscoded our coroutine logic
+ // "Shut down the garbage smashers on the detention level!"
+ e.printStackTrace(System.err);
+ fCoroutineManager.co_exit(fParserCoroutineID);
+
+ // No need to throw shutdownException; we're already
+ // in the process of murdering the parser.
+ }
}
if(null!=clientErrorHandler)
@@ -588,119 +588,119 @@
// continue to talk to.
if(!moreRemains)
{
- if(fRunningInThread)
- {
- // Just return. The command loop in run() will send the
- // "we're done" announcement and request the next command.
- return; // let the parser terminate itself
- }
-
- else try
- {
- // Forced Termination dialog. Say we're done, wait for a
- // termination request (don't accept anything else), and
- // shut down.
- arg = fCoroutineManager.co_resume(Boolean.FALSE, fParserCoroutineID,
- fAppCoroutineID);
- while(arg!=null)
- {
+ if(fRunningInThread)
+ {
+ // Just return. The command loop in run() will send the
+ // "we're done" announcement and request the next command.
+ return; // let the parser terminate itself
+ }
+
+ else try
+ {
+ // Forced Termination dialog. Say we're done, wait for a
+ // termination request (don't accept anything else), and
+ // shut down.
+ arg = fCoroutineManager.co_resume(Boolean.FALSE, fParserCoroutineID,
+ fAppCoroutineID);
+ while(arg!=null)
+ {
System.err.println(
"Filtering CoroutineSAXParser: unexpected resume parameter, "
+arg.getClass()+" with value=\""+arg+'"');
- // If you don't do this, it can loop forever with the above
+ // If you don't do this, it can loop forever with the above
// error printing out. -sb
- arg = new RuntimeException(
+ arg = new RuntimeException(
"Filtering CoroutineSAXParser: unexpected resume parameter, "
+arg.getClass()+" with value=\""+arg+'"');
- arg = fCoroutineManager.co_resume(arg, fParserCoroutineID,
- fAppCoroutineID);
- }
-
- fCoroutineManager.co_exit_to(arg, fParserCoroutineID, fAppCoroutineID);
- return; // let the parser return
- }
- catch(java.lang.NoSuchMethodException e)
- {
- // Shouldn't happen unless we've miscoded our coroutine logic
- // "Shut down the garbage smashers on the detention level!"
- e.printStackTrace(System.err);
- fCoroutineManager.co_exit(fParserCoroutineID);
- throw shutdownException;
- }
+ arg = fCoroutineManager.co_resume(arg, fParserCoroutineID,
+ fAppCoroutineID);
+ }
+
+ fCoroutineManager.co_exit_to(arg, fParserCoroutineID, fAppCoroutineID);
+ return; // let the parser return
+ }
+ catch(java.lang.NoSuchMethodException e)
+ {
+ // Shouldn't happen unless we've miscoded our coroutine logic
+ // "Shut down the garbage smashers on the detention level!"
+ e.printStackTrace(System.err);
+ fCoroutineManager.co_exit(fParserCoroutineID);
+ throw shutdownException;
+ }
} // if moreRemains
else try
{
arg = fCoroutineManager.co_resume(arg, fParserCoroutineID, fAppCoroutineID);
+
+ // %REVIEW% I'm really not happy with the following:
+ //
+ // If we're running in filter mode, driven by an external SAX
+ // event source, and have been been yielded back to with
+ // Boolean.FALSE (doMore(false)) there are two additional
+ // problems.
+ //
+ // First: Scott tells me that our technique of throwing an
+ // exception from the ContentHandler to terminate SAX parsing,
+ // while almost a universal practice in the SAX community, is not
+ // acceptable because we can't force this contract upon the event
+ // generator. (Though he feels we _can_ force them to accept a
+ // contract to explicitly send us a fatalError event if parsing
+ // terminates due to some other SAXException... basically, it's
+ // the old "this is a normal condition so it shouldn't be an
+ // exception" rationalle, which has some validity to it.)
+ // Instead, and despite the wasted cycles, he wants me to simply
+ // let the event stream run to completion without passing the
+ // events along to our own client. That requires disabling
+ // co_yeild() as well. IF AND WHEN SAX ADDS AN OFFICIAL
+ // STOP-PARSING-EARLY OPERATION, we can leverage that.
+ //
+ // Second: The current architecture of CoroutineSAXParser's
+ // coroutine transactions assumes that doMore(false) will be
+ // followed by either doParse(newInputSource), or
+ // doTerminate(). We must complete that coroutine dialog.
+ //
+ // "Black magic is a matter of symbolism and intent."
+ // -- Randall Garrett
+ //
+ // %TBD% We _MUST_ get away from this architecture and switch
+ // to CoroutineSAXFilter, just so we don't have to go through
+ // this "no, I don't want another file, thank you very much"
+ // transaction. In our application we should never need it,
+ // and the only justification for running the parse within a
+ // coroutine request -- capturing SAXExceptions -- could be
+ // handled per the above discussion.
+ //
+ if(!fRunningInThread && arg==Boolean.FALSE)
+ {
+ clientContentHandler=null;
+ clientLexicalHandler=null;
+ // Anyone else?
+
+ fNeverYieldAgain=true; // Horrendous kluge parsing to completion:
- // %REVIEW% I'm really not happy with the following:
- //
- // If we're running in filter mode, driven by an external SAX
- // event source, and have been been yielded back to with
- // Boolean.FALSE (doMore(false)) there are two additional
- // problems.
- //
- // First: Scott tells me that our technique of throwing an
- // exception from the ContentHandler to terminate SAX parsing,
- // while almost a universal practice in the SAX community, is not
- // acceptable because we can't force this contract upon the event
- // generator. (Though he feels we _can_ force them to accept a
- // contract to explicitly send us a fatalError event if parsing
- // terminates due to some other SAXException... basically, it's
- // the old "this is a normal condition so it shouldn't be an
- // exception" rationalle, which has some validity to it.)
- // Instead, and despite the wasted cycles, he wants me to simply
- // let the event stream run to completion without passing the
- // events along to our own client. That requires disabling
- // co_yeild() as well. IF AND WHEN SAX ADDS AN OFFICIAL
- // STOP-PARSING-EARLY OPERATION, we can leverage that.
- //
- // Second: The current architecture of CoroutineSAXParser's
- // coroutine transactions assumes that doMore(false) will be
- // followed by either doParse(newInputSource), or
- // doTerminate(). We must complete that coroutine dialog.
- //
- // "Black magic is a matter of symbolism and intent."
- // -- Randall Garrett
- //
- // %TBD% We _MUST_ get away from this architecture and switch
- // to CoroutineSAXFilter, just so we don't have to go through
- // this "no, I don't want another file, thank you very much"
- // transaction. In our application we should never need it,
- // and the only justification for running the parse within a
- // coroutine request -- capturing SAXExceptions -- could be
- // handled per the above discussion.
- //
- if(!fRunningInThread && arg==Boolean.FALSE)
- {
- clientContentHandler=null;
- clientLexicalHandler=null;
- // Anyone else?
-
- fNeverYieldAgain=true; // Horrendous kluge parsing to completion:
-
- // Forced Termination dialog. Say we're done, wait for a
- // termination request (don't accept anything else), and
- // shut down.
- arg = fCoroutineManager.co_resume(Boolean.FALSE, fParserCoroutineID,
- fAppCoroutineID);
- while(arg!=null)
- {
- String msg="Filtering CoroutineSAXParser: "+
- "unexpected resume parameter, "+
- arg.getClass()+" with value=\""+arg+'"';
+ // Forced Termination dialog. Say we're done, wait for a
+ // termination request (don't accept anything else), and
+ // shut down.
+ arg = fCoroutineManager.co_resume(Boolean.FALSE, fParserCoroutineID,
+ fAppCoroutineID);
+ while(arg!=null)
+ {
+ String msg="Filtering CoroutineSAXParser: "+
+ "unexpected resume parameter, "+
+ arg.getClass()+" with value=\""+arg+'"';
System.err.println(msg);
- // If you don't do this, it can loop forever with the above
+ // If you don't do this, it can loop forever with the above
// error printing out. -sb
- arg = new RuntimeException(msg);
- arg = fCoroutineManager.co_resume(arg, fParserCoroutineID,
- fAppCoroutineID);
- }
-
- fCoroutineManager.co_exit_to(arg, fParserCoroutineID, fAppCoroutineID);
- return; // let the parser run to completion and return
- }
+ arg = new RuntimeException(msg);
+ arg = fCoroutineManager.co_resume(arg, fParserCoroutineID,
+ fAppCoroutineID);
+ }
+
+ fCoroutineManager.co_exit_to(arg, fParserCoroutineID, fAppCoroutineID);
+ return; // let the parser run to completion and return
+ }
if (arg == null) {
fCoroutineManager.co_exit_to(arg, fParserCoroutineID, fAppCoroutineID);
@@ -995,70 +995,70 @@
}
}
- //================================================================
- /** Simple unit test. Attempt coroutine parsing of document indicated
- * by first argument (as a URI), report progress.
- */
- public static void main(String args[])
- {
- System.out.println("Starting...");
-
- org.xml.sax.XMLReader theSAXParser=
- new org.apache.xerces.parsers.SAXParser();
-
- CoroutineManager co = new CoroutineManager();
- int appCoroutineID = co.co_joinCoroutineSet(-1);
- if (appCoroutineID == -1)
- {
- System.out.println("ERROR: Couldn't allocate coroutine number.\n");
- return;
- }
- CoroutineSAXParser parser=
- new CoroutineSAXParser(co, appCoroutineID, theSAXParser);
- int parserCoroutineID = parser.getParserCoroutineID();
-
- // Use a serializer as our sample output
- org.apache.xml.serialize.XMLSerializer trace;
- trace=new org.apache.xml.serialize.XMLSerializer(System.out,null);
- parser.setContentHandler(trace);
- parser.setLexHandler(trace);
-
- // Tell coroutine to begin parsing, run while parsing is in progress
- for(int arg=0;arg<args.length;++arg)
- {
- InputSource source = new InputSource(args[arg]);
- Object result=null;
- boolean more=true;
- for(result = parser.doParse(source, appCoroutineID);
- (result instanceof Boolean && ((Boolean)result)==Boolean.TRUE);
- result = parser.doMore(more, appCoroutineID))
- {
- System.out.println("\nSome parsing successful, trying more.\n");
-
- // Special test: Terminate parsing early.
- if(arg+1<args.length && "!".equals(args[arg+1]))
- {
- ++arg;
- more=false;
- }
-
- }
-
- if (result instanceof Boolean && ((Boolean)result)==Boolean.FALSE)
- {
- System.out.println("\nParser ended (EOF or on request).\n");
- }
- else if (result == null) {
- System.out.println("\nUNEXPECTED: Parser says shut down prematurely.\n");
- }
- else if (result instanceof Exception) {
- System.out.println("\nParser threw exception:");
- ((Exception)result).printStackTrace();
- }
-
- }
-
- parser.doTerminate(appCoroutineID);
- }
+// //================================================================
+// /** Simple unit test. Attempt coroutine parsing of document indicated
+// * by first argument (as a URI), report progress.
+// */
+// public static void main(String args[])
+// {
+// System.out.println("Starting...");
+//
+// org.xml.sax.XMLReader theSAXParser=
+// new org.apache.xerces.parsers.SAXParser();
+//
+// CoroutineManager co = new CoroutineManager();
+// int appCoroutineID = co.co_joinCoroutineSet(-1);
+// if (appCoroutineID == -1)
+// {
+// System.out.println("ERROR: Couldn't allocate coroutine number.\n");
+// return;
+// }
+// CoroutineSAXParser parser=
+// new CoroutineSAXParser(co, appCoroutineID, theSAXParser);
+// int parserCoroutineID = parser.getParserCoroutineID();
+//
+// // Use a serializer as our sample output
+// org.apache.xml.serialize.XMLSerializer trace;
+// trace=new org.apache.xml.serialize.XMLSerializer(System.out,null);
+// parser.setContentHandler(trace);
+// parser.setLexHandler(trace);
+//
+// // Tell coroutine to begin parsing, run while parsing is in progress
+// for(int arg=0;arg<args.length;++arg)
+// {
+// InputSource source = new InputSource(args[arg]);
+// Object result=null;
+// boolean more=true;
+// for(result = parser.doParse(source, appCoroutineID);
+// (result instanceof Boolean && ((Boolean)result)==Boolean.TRUE);
+// result = parser.doMore(more, appCoroutineID))
+// {
+// System.out.println("\nSome parsing successful, trying more.\n");
+//
+// // Special test: Terminate parsing early.
+// if(arg+1<args.length && "!".equals(args[arg+1]))
+// {
+// ++arg;
+// more=false;
+// }
+//
+// }
+//
+// if (result instanceof Boolean && ((Boolean)result)==Boolean.FALSE)
+// {
+// System.out.println("\nParser ended (EOF or on request).\n");
+// }
+// else if (result == null) {
+// System.out.println("\nUNEXPECTED: Parser says shut down prematurely.\n");
+// }
+// else if (result instanceof Exception) {
+// System.out.println("\nParser threw exception:");
+// ((Exception)result).printStackTrace();
+// }
+//
+// }
+//
+// parser.doTerminate(appCoroutineID);
+// }
} // class CoroutineSAXParser
1.1.2.9 +7 -5 xml-xalan/java/src/org/apache/xml/dtm/Attic/CoroutineSAXParser_Xerces.java
Index: CoroutineSAXParser_Xerces.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/CoroutineSAXParser_Xerces.java,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- CoroutineSAXParser_Xerces.java 2001/05/16 23:47:56 1.1.2.8
+++ CoroutineSAXParser_Xerces.java 2001/05/17 00:11:11 1.1.2.9
@@ -62,6 +62,7 @@
import org.xml.sax.SAXException;
import java.io.IOException;
//import org.apache.xml.dtm.CoroutineManager;
+import org.apache.xerces.parsers.SAXParser;
/** <p>CoroutineSAXParser_Xerces takes advantage of the fact that Xerces
* incremental mode is already a coroutine of sorts, and just wraps our
@@ -84,7 +85,8 @@
// extends org.apache.xerces.parsers.SAXParser
implements CoroutineParser
{
- IncrementalXercesSaxParser incrementalParser;
+ // IncrementalXercesSaxParser incrementalParser;
+ SAXParser incrementalParser;
//
// Data
@@ -100,14 +102,14 @@
this(null,co,appCoroutineID);
}
- public CoroutineSAXParser_Xerces(IncrementalXercesSaxParser ixsp, CoroutineManager co, int appCoroutineID) {
+ public CoroutineSAXParser_Xerces(SAXParser ixsp, CoroutineManager co, int appCoroutineID) {
if(ixsp!=null)
incrementalParser=ixsp;
else
incrementalParser=new IncrementalXercesSaxParser();
- incrementalParser.initHandlers(true, incrementalParser, incrementalParser);
+ // incrementalParser.initHandlers(true, incrementalParser, incrementalParser);
}
//
@@ -223,8 +225,8 @@
{
if(!parsemore)
{
- fParseInProgress=false;
- return Boolean.FALSE;
+ fParseInProgress=false;
+ return Boolean.FALSE;
}
Object arg;
1.1.2.14 +10 -10 xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java
Index: DTMManagerDefault.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/DTMManagerDefault.java,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -u -r1.1.2.13 -r1.1.2.14
--- DTMManagerDefault.java 2001/05/16 15:14:24 1.1.2.13
+++ DTMManagerDefault.java 2001/05/17 00:11:12 1.1.2.14
@@ -203,16 +203,16 @@
int appCoroutine = coroutineManager.co_joinCoroutineSet(-1);
CoroutineParser coParser;
- // %TBD%
- // if(reader instanceof org.apache.xerces.parsers.SAXParser)
- // {
- // // CoroutineSAXParser_Xerces to avoid threading.
- // System.out.println("Creating a CoroutineSAXParser_Xerces");
- // coParser =
- // new CoroutineSAXParser_Xerces(coroutineManager, appCoroutine,
- // (org.apache.xerces.parsers.SAXParser)reader);
- // }
- // else
+ if(null != reader && reader instanceof org.apache.xerces.parsers.SAXParser)
+ {
+ // CoroutineSAXParser_Xerces to avoid threading.
+ // System.out.println("Using CoroutineSAXParser_Xerces to avoid threading");
+ coParser =
+ new CoroutineSAXParser_Xerces(
+ (org.apache.xerces.parsers.SAXParser)reader,
+ coroutineManager, appCoroutine);
+ }
+ else
{
// Create a CoroutineSAXParser that will run on the secondary thread.
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org