You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jk...@apache.org on 2002/04/18 21:31:20 UTC
cvs commit: xml-xalan/java/src/org/apache/xml/dtm/ref DTMManagerDefault.java IncrementalSAXSource_Xerces.java
jkesselm 02/04/18 12:31:20
Modified: java/src/org/apache/xml/dtm/ref Tag: Xalan3
DTMManagerDefault.java
IncrementalSAXSource_Xerces.java
Log:
XNI support now always used if available, with SAX as fallback.
Issues: DTMDefaultManager is still a bit more aware of Xerces2
than I want it to be. And the kluge of creating an Incremental Xerces
source and then running it non-incrementally, while producing
straightforward code, is a slightly ugly mixed metaphor.
Revision Changes Path
No revision
No revision
1.41.2.2 +268 -177 xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java
Index: DTMManagerDefault.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java,v
retrieving revision 1.41.2.1
retrieving revision 1.41.2.2
diff -u -r1.41.2.1 -r1.41.2.2
--- DTMManagerDefault.java 12 Apr 2002 18:26:19 -0000 1.41.2.1
+++ DTMManagerDefault.java 18 Apr 2002 19:31:20 -0000 1.41.2.2
@@ -292,243 +292,334 @@
int dtmPos = getFirstFreeDTMID();
int documentID = dtmPos << IDENT_DTM_NODE_BITS;
- if ((null != source) && source instanceof DOMSource)
+ if (source instanceof DOMSource)
{
+ // Simplest case: Wrap a DTM around an existing DOM.
+ //
+ // %REVIEW% May get more complicated if we start trying to match
+ // DOM2DTM implementations against specific DOM implementations,
+ // eg taking advantage of a particular DOM's hashability or
+ // userData hooks.
DOM2DTM dtm = new DOM2DTM(this, (DOMSource) source, documentID,
whiteSpaceFilter, xstringFactory, doIndexing);
-
addDTM(dtm, dtmPos, 0);
-
- // if (DUMPTREE)
- // {
- // dtm.dumpDTM();
- // }
-
return dtm;
}
- else
+
+ if(source==null)
{
- boolean isSAXSource = (null != source)
- ? (source instanceof SAXSource) : true;
- boolean isStreamSource = (null != source)
- ? (source instanceof StreamSource) : false;
+ // Set up a DTM which will accept a SAX input stream to be bound later.
+ // Note that XNI is _not_ currently an option in this case.
+ SAX2DTM dtm;
+
+ if(unique && !incremental && !doIndexing)
+ {
+ // Special case to support RTF construction into shared DTM.
+ // It should actually still work for other uses,
+ // but may be slightly deoptimized relative to the base
+ // to allow it to deal with carrying multiple documents.
+ //
+ // %REVIEW% This is a sloppy way to request this mode;
+ // we need to consider architectural improvements.
+ dtm = new SAX2RTFDTM(this, source, documentID, whiteSpaceFilter,
+ xstringFactory, doIndexing);
+ }
+ else // Create the basic SAX2DTM.
+ {
+ dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter,
+ xstringFactory, doIndexing);
+ }
+
+ addDTM(dtm, dtmPos, 0);
- if (isSAXSource || isStreamSource)
+ // If the source is null, but they requested an incremental build,
+ // then we still want to set up the IncrementalSAXSource stuff
+ // so it can be bound later.
+ if (this.m_incremental && incremental)
{
- XMLReader reader;
- InputSource xmlSource;
+ IncrementalSAXSource coParser=new IncrementalSAXSource_Filter();
+ dtm.setIncrementalSAXSource(coParser);
+ }
+
+ return dtm;
+ }
- if (null == source)
+ if (source instanceof StreamSource)
+ {
+
+ // Try processing it as XNI first, to get PSVI information!
+ XMLReader reader = getXMLReader(source);
+
+ InputSource xmlSource = SAXSource.sourceToInputSource(source);
+ String urlOfSource = xmlSource.getSystemId();
+ if (null != urlOfSource)
+ {
+ try
{
- xmlSource = null;
- reader = null;
+ urlOfSource=SystemIDResolver.getAbsoluteURI(urlOfSource);
}
- else
+ catch (Exception e)
{
- reader = getXMLReader(source);
- xmlSource = SAXSource.sourceToInputSource(source);
-
- String urlOfSource = xmlSource.getSystemId();
+ // %REVIEW% Is there a better way to send a warning?
+ System.err.println("Can not absolutize URL: " + urlOfSource);
+ }
+ xmlSource.setSystemId(urlOfSource);
+ } // urlOfSource fixup
+
+ // GONK -- Need a better test for whether Xerces2 is available
+ // This one involves creating a SAX reader, then discarding
+ // it in order to build a lower-level XNI reader. Wasteful.
+ // %REVIEW%
+ if(reader.getClass().getName().equals("org.apache.xerces.parsers.SAXParser"))
+ {
+ DTM dtm = new XNI2DTM(this, source, documentID, whiteSpaceFilter,
+ xstringFactory, doIndexing);
+ addDTM(dtm, dtmPos, 0);
- if (null != urlOfSource)
+ {
+ // %REVIEW% Currently this creates a new instance of Xerces, since
+ // there's no way to access the XNI APIs of an existing SAXParser.
+ // This is wasteful since a reader as already created.
+ // Can we rationalize this flow? Can we get Xerces improved?
+ IncrementalSAXSource_Xerces coParser;
+ coParser=(IncrementalSAXSource_Xerces)IncrementalSAXSource_Xerces.createIncrementalSAXSource();
+
+ // Bypass SAX; listen to the XNI stream
+ // %REVIEW% This shouldn't have a compile-time dependency on Xerces2!
+ // Can we fix it? (Change to Object?)
+ org.apache.xerces.xni.parser.XMLPullParserConfiguration xpc=
+ ((IncrementalSAXSource_Xerces)coParser).getXNIParserConfiguration();
+ ((XNI2DTM)dtm).setIncrementalXNISource(xpc);
+
+ try
{
- try
- {
- urlOfSource = SystemIDResolver.getAbsoluteURI(urlOfSource);
- }
- catch (Exception e)
- {
-
- // %REVIEW% Is there a better way to send a warning?
- System.err.println("Can not absolutize URL: " + urlOfSource);
- }
-
- xmlSource.setSystemId(urlOfSource);
+ // Launch parsing coroutine.
+ coParser.startParse(xmlSource);
+
+ // %REVIEW% Kluge: Run nominal incremental setup in non-incremental
+ // mode. Simplifies this code, but it's a badly mixed metaphor.
+ if(!this.m_incremental)
+ coParser.deliverAllNodes();
}
- }
-
- SAX2DTM dtm;
- if(source==null && unique && !incremental && !doIndexing)
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new org.apache.xml.utils.WrappedRuntimeException(e);
+ }
+
+ return dtm;
+ } // if incremental
+
+ } // If Xerces2
+
+ // Fallback: Turn it into a SAX request. (We _could_ just let
+ // it fall through unchanged and put an OR in SAX case, but
+ // I think making it explicit may be clearer now that we're got
+ // XNI involved in the mix.
+ source=new SAXSource(reader,xmlSource);
+ // FALL THROUGH to SAX processing
+ } // if streamsource
+
+
+ // if ((source instanceof SAXSource) || (source instanceof StreamSource))
+ if (source instanceof SAXSource)
+ {
+ XMLReader reader;
+ InputSource xmlSource;
+ SAX2DTM dtm;
+
+ reader = getXMLReader(source);
+ xmlSource = SAXSource.sourceToInputSource(source);
+
+ String urlOfSource = xmlSource.getSystemId();
+ if (null != urlOfSource)
+ {
+ try
{
- // Special case to support RTF construction into shared DTM.
- // It should actually still work for other uses,
- // but may be slightly deoptimized relative to the base
- // to allow it to deal with carrying multiple documents.
- //
- // %REVIEW% This is a sloppy way to request this mode;
- // we need to consider architectural improvements.
- dtm = new SAX2RTFDTM(this, source, documentID, whiteSpaceFilter,
- xstringFactory, doIndexing);
- }
- /**************************************************************/
- // EXPERIMENTAL 3/22/02
- else if(JKESS_XNI_EXPERIMENT && m_incremental)
- {
- dtm = new XNI2DTM(this, source, documentID, whiteSpaceFilter,
- xstringFactory, doIndexing);
+ urlOfSource=SystemIDResolver.getAbsoluteURI(urlOfSource);
}
- /**************************************************************/
- else // Create the basic SAX2DTM.
+ catch (Exception e)
{
- dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter,
- xstringFactory, doIndexing);
+ // %REVIEW% Is there a better way to send a warning?
+ System.err.println("Can not absolutize URL: " + urlOfSource);
}
+ xmlSource.setSystemId(urlOfSource);
+ }
- // Go ahead and add the DTM to the lookup table. This needs to be
- // done before any parsing occurs. Note offset 0, since we've just
- // created a new DTM.
- addDTM(dtm, dtmPos, 0);
+ /**************************************************************/
+ // EXPERIMENTAL 3/22/02
+ if(JKESS_XNI_EXPERIMENT && m_incremental)
+ {
+ dtm = new XNI2DTM(this, source, documentID, whiteSpaceFilter,
+ xstringFactory, doIndexing);
+ }
+ else // Create the basic SAX2DTM.
+ /**************************************************************/
+ {
+ dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter,
+ xstringFactory, doIndexing);
+ }
+ // Add the DTM to the lookup table with offset 0 (start of new DTM).
+ // This needs to be done before any parsing occurs.
+ addDTM(dtm, dtmPos, 0);
- boolean haveXercesParser =
- (null != reader)
- && (reader.getClass().getName().equals("org.apache.xerces.parsers.SAXParser") );
+ boolean haveXercesParser =
+ (null != reader)
+ && (reader.getClass().getName().equals("org.apache.xerces.parsers.SAXParser") );
- if (haveXercesParser)
- incremental = true; // No matter what. %REVIEW%
+ if (haveXercesParser)
+ incremental = true; // No matter what. %REVIEW%
- // If the reader is null, but they still requested an incremental build,
- // then we still want to set up the IncrementalSAXSource stuff.
- if (this.m_incremental && incremental /* || ((null == reader) && incremental) */)
+ // If the reader is null, but they still requested an incremental build,
+ // then we still want to set up the IncrementalSAXSource stuff.
+ if (this.m_incremental && incremental /* || ((null == reader) && incremental) */)
+ {
+ IncrementalSAXSource coParser=null;
+
+ if (haveXercesParser)
{
- IncrementalSAXSource coParser=null;
+ // IncrementalSAXSource_Xerces to avoid threading.
+ // %REVIEW% Currently this creates a new instance of Xerces, since
+ // there's no way to access the incremental parsing APIs in today's
+ // Xerces. This is wasteful since a reader was already created.
+ // Can we rationalize this flow?
+ try {
+ coParser=org.apache.xml.dtm.ref.IncrementalSAXSource_Xerces.createIncrementalSAXSource();
+ } catch( Exception ex ) {
+ ex.printStackTrace();
+ coParser=null;
+ }
+ }
- if (haveXercesParser)
+ if( coParser==null ) {
+ // Create a IncrementalSAXSource that will run on the secondary thread.
+ if (null == reader)
+ coParser = new IncrementalSAXSource_Filter();
+ else
{
- // IncrementalSAXSource_Xerces to avoid threading.
- try {
- coParser=org.apache.xml.dtm.ref.IncrementalSAXSource_Xerces.createIncrementalSAXSource();
- } catch( Exception ex ) {
- ex.printStackTrace();
- coParser=null;
- }
+ IncrementalSAXSource_Filter filter=new IncrementalSAXSource_Filter();
+ filter.setXMLReader(reader);
+ coParser=filter;
}
- if( coParser==null ) {
- // Create a IncrementalSAXSource that will run on the secondary thread.
- if (null == reader)
- coParser = new IncrementalSAXSource_Filter();
- else
- {
- IncrementalSAXSource_Filter filter=new IncrementalSAXSource_Filter();
- filter.setXMLReader(reader);
- coParser=filter;
- }
-
- }
+ }
-
+
/**************************************************************/
// EXPERIMENTAL 3/22/02
- if(JKESS_XNI_EXPERIMENT && m_incremental &
- dtm instanceof XNI2DTM &&
- coParser instanceof IncrementalSAXSource_Xerces)
- {
- org.apache.xerces.xni.parser.XMLPullParserConfiguration xpc=
- ((IncrementalSAXSource_Xerces)coParser).getXNIParserConfiguration();
- if(xpc!=null)
- // Bypass SAX; listen to the XNI stream
- ((XNI2DTM)dtm).setIncrementalXNISource(xpc);
- else
- // Listen to the SAX stream (will fail, diagnostically...)
- dtm.setIncrementalSAXSource(coParser);
- } else
+ if(JKESS_XNI_EXPERIMENT && m_incremental &
+ dtm instanceof XNI2DTM &&
+ coParser instanceof IncrementalSAXSource_Xerces)
+ {
+ org.apache.xerces.xni.parser.XMLPullParserConfiguration xpc=
+ ((IncrementalSAXSource_Xerces)coParser).getXNIParserConfiguration();
+ if(xpc!=null)
+ // Bypass SAX; listen to the XNI stream
+ ((XNI2DTM)dtm).setIncrementalXNISource(xpc);
+ else
+ // Listen to the SAX stream (will fail, diagnostically...)
+ dtm.setIncrementalSAXSource(coParser);
+ } else
/***************************************************************/
// Have the DTM set itself up as the IncrementalSAXSource's listener.
dtm.setIncrementalSAXSource(coParser);
- if (null == xmlSource)
- {
-
- // Then the user will construct it themselves.
- return dtm;
- }
-
- if(null == reader.getErrorHandler())
- reader.setErrorHandler(dtm);
- reader.setDTDHandler(dtm);
+ if (null == xmlSource)
+ {
- try
- {
+ // Then the user will construct it themselves.
+ return dtm;
+ }
- // Launch parsing coroutine. Launches a second thread,
- // if we're using IncrementalSAXSource.filter().
- coParser.startParse(xmlSource);
- }
- catch (RuntimeException re)
- {
+ if(null == reader.getErrorHandler())
+ reader.setErrorHandler(dtm);
+ reader.setDTDHandler(dtm);
- dtm.clearCoRoutine();
+ try
+ {
- throw re;
- }
- catch (Exception e)
- {
+ // Launch parsing coroutine. Launches a second thread,
+ // if we're using IncrementalSAXSource.filter().
+ coParser.startParse(xmlSource);
+ }
+ catch (RuntimeException re)
+ {
- dtm.clearCoRoutine();
+ dtm.clearCoRoutine();
- throw new org.apache.xml.utils.WrappedRuntimeException(e);
- }
+ throw re;
}
- else
+ catch (Exception e)
{
- if (null == reader)
- {
- // Then the user will construct it themselves.
- return dtm;
- }
+ dtm.clearCoRoutine();
- // not incremental
- reader.setContentHandler(dtm);
- reader.setDTDHandler(dtm);
- if(null == reader.getErrorHandler())
- reader.setErrorHandler(dtm);
+ throw new org.apache.xml.utils.WrappedRuntimeException(e);
+ }
+ }
+ else
+ {
+ if (null == reader)
+ {
- try
- {
- reader.setProperty(
- "http://xml.org/sax/properties/lexical-handler", dtm);
- }
- catch (SAXNotRecognizedException e){}
- catch (SAXNotSupportedException e){}
+ // Then the user will construct it themselves.
+ return dtm;
+ }
- try
- {
- reader.parse(xmlSource);
- }
- catch (RuntimeException re)
- {
+ // not incremental
+ reader.setContentHandler(dtm);
+ reader.setDTDHandler(dtm);
+ if(null == reader.getErrorHandler())
+ reader.setErrorHandler(dtm);
- dtm.clearCoRoutine();
+ try
+ {
+ reader.setProperty(
+ "http://xml.org/sax/properties/lexical-handler", dtm);
+ }
+ catch (SAXNotRecognizedException e){}
+ catch (SAXNotSupportedException e){}
- throw re;
- }
- catch (Exception e)
- {
+ try
+ {
+ reader.parse(xmlSource);
+ }
+ catch (RuntimeException re)
+ {
- dtm.clearCoRoutine();
+ dtm.clearCoRoutine();
- throw new org.apache.xml.utils.WrappedRuntimeException(e);
- }
+ throw re;
}
-
- if (DUMPTREE)
+ catch (Exception e)
{
- System.out.println("Dumping SAX2DOM");
- dtm.dumpDTM(System.err);
- }
- return dtm;
+ dtm.clearCoRoutine();
+
+ throw new org.apache.xml.utils.WrappedRuntimeException(e);
+ }
}
- else
- {
- // It should have been handled by a derived class or the caller
- // made a mistake.
- throw new DTMException(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUPPORTED, new Object[]{source})); //"Not supported: " + source);
+ if (DUMPTREE)
+ {
+ System.out.println("Dumping SAX2DOM");
+ dtm.dumpDTM(System.err);
}
+
+ return dtm;
+ }
+
+ else
+ {
+
+ // It should have been handled by a derived class or the caller
+ // made a mistake.
+ throw new DTMException(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUPPORTED, new Object[]{source})); //"Not supported: " + source);
}
}
1.8.6.2 +28 -1 xml-xalan/java/src/org/apache/xml/dtm/ref/IncrementalSAXSource_Xerces.java
Index: IncrementalSAXSource_Xerces.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/IncrementalSAXSource_Xerces.java,v
retrieving revision 1.8.6.1
retrieving revision 1.8.6.2
diff -u -r1.8.6.1 -r1.8.6.2
--- IncrementalSAXSource_Xerces.java 12 Apr 2002 18:26:19 -0000 1.8.6.1
+++ IncrementalSAXSource_Xerces.java 18 Apr 2002 19:31:20 -0000 1.8.6.2
@@ -369,7 +369,34 @@
return arg;
}
- // Private methods -- conveniences to hide the reflection details
+ static final Object[] parmstrue={Boolean.TRUE};
+
+ /** deliverAllNodes() is a simple API which tells the coroutine
+ * parser to run until all nodes have been delivered.
+ * This is a bit of a kluge, intended to address the case where
+ * we're using IncrementalSAXSource_Xerces not for its incrementality
+ * but as a wrapper around the Xerces XNI layer; its primary purpose
+ * is to simplify the logic in DTMManagerDefault.java
+ * */
+ public void deliverAllNodes ()
+ {
+ try
+ {
+ Object ret=(Boolean)(fConfigParse.invoke(fPullParserConfig,parmstrue));
+ }
+ catch(IllegalAccessException e)
+ {
+ // %REVIEW% shouldn't happen
+ e.printStackTrace();
+ }
+ catch(java.lang.reflect.InvocationTargetException e)
+ {
+ // %REVIEW% shouldn't happen
+ e.printStackTrace();
+ }
+ }
+
+ // Private methods -- conveniences to hide the reflection details
private boolean parseSomeSetup(InputSource source)
throws SAXException, IOException, IllegalAccessException,
java.lang.reflect.InvocationTargetException,
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org