xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject svn commit: r696447 - in /xerces/java/trunk/src/org/apache/xerces: impl/xs/traversers/XSDHandler.java util/StAXInputSource.java
Date Wed, 17 Sep 2008 21:12:06 GMT
Author: mrglavas
Date: Wed Sep 17 14:12:06 2008
New Revision: 696447

URL: http://svn.apache.org/viewvc?rev=696447&view=rev
Log:
Added a flag to StAXInputSource which when set to true instructs the
consumer to consume all of the remaining events in the stream, even
if the current position is at the root of a subtree. This allows the
application to forget about XMLStreamReaders / XMLEventReaders it never
cares to read again after the event consumer completes its task without
sacrificing any resource recycling the StAX implementation may do once
the end of the input has been reached.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
    xerces/java/trunk/src/org/apache/xerces/util/StAXInputSource.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java?rev=696447&r1=696446&r2=696447&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java Wed Sep 17
14:12:06 2008
@@ -24,7 +24,9 @@
 import java.util.Stack;
 import java.util.Vector;
 
+import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.XMLEntityManager;
@@ -537,11 +539,24 @@
             }
             fStAXSchemaParser.reset(fSchemaParser, fSymbolTable);
             try {
-                if (sis.getXMLEventReader() != null) {
-                    fStAXSchemaParser.parse(sis.getXMLEventReader());
+                final boolean consumeRemainingContent = sis.shouldConsumeRemainingContent();
+                final XMLStreamReader streamReader = sis.getXMLStreamReader();
+                if (streamReader != null) {
+                    fStAXSchemaParser.parse(streamReader);
+                    if (consumeRemainingContent) {
+                        while (streamReader.hasNext()) {
+                            streamReader.next();
+                        }
+                    }
                 }
                 else {
-                    fStAXSchemaParser.parse(sis.getXMLStreamReader());
+                    final XMLEventReader eventReader = sis.getXMLEventReader();
+                    fStAXSchemaParser.parse(eventReader);
+                    if (consumeRemainingContent) {
+                        while (eventReader.hasNext()) {
+                            eventReader.nextEvent();
+                        }
+                    }
                 }
             }
             catch (XMLStreamException e) {
@@ -1795,11 +1810,24 @@
             }
             fStAXSchemaParser.reset(fSchemaParser, fSymbolTable);
             try {
-                if (sis.getXMLEventReader() != null) {
-                    fStAXSchemaParser.parse(sis.getXMLEventReader());
+                final boolean consumeRemainingContent = sis.shouldConsumeRemainingContent();
+                final XMLStreamReader streamReader = sis.getXMLStreamReader();
+                if (streamReader != null) {
+                    fStAXSchemaParser.parse(streamReader);
+                    if (consumeRemainingContent) {
+                        while (streamReader.hasNext()) {
+                            streamReader.next();
+                        }
+                    }
                 }
                 else {
-                    fStAXSchemaParser.parse(sis.getXMLStreamReader());
+                    final XMLEventReader eventReader = sis.getXMLEventReader();
+                    fStAXSchemaParser.parse(eventReader);
+                    if (consumeRemainingContent) {
+                        while (eventReader.hasNext()) {
+                            eventReader.nextEvent();
+                        }
+                    }
                 }
             }
             catch (XMLStreamException e) {

Modified: xerces/java/trunk/src/org/apache/xerces/util/StAXInputSource.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/util/StAXInputSource.java?rev=696447&r1=696446&r2=696447&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/util/StAXInputSource.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/util/StAXInputSource.java Wed Sep 17 14:12:06
2008
@@ -30,17 +30,30 @@
  */
 public final class StAXInputSource extends XMLInputSource {
     
-    private XMLStreamReader fStreamReader;
-    private XMLEventReader fEventReader;
+    private final XMLStreamReader fStreamReader;
+    private final XMLEventReader fEventReader;
+    private final boolean fConsumeRemainingContent;
     
     public StAXInputSource(XMLStreamReader source) {
+        this(source, false);
+    }
+    
+    public StAXInputSource(XMLStreamReader source, boolean consumeRemainingContent) {
         super(null, source.getLocation().getSystemId(), null);
         fStreamReader = source;
+        fEventReader = null;
+        fConsumeRemainingContent = consumeRemainingContent;
     }
     
     public StAXInputSource(XMLEventReader source) {
+        this(source, false);
+    }
+    
+    public StAXInputSource(XMLEventReader source, boolean consumeRemainingContent) {
         super(null, getEventReaderSystemId(source), null);
+        fStreamReader = null;
         fEventReader = source;
+        fConsumeRemainingContent = consumeRemainingContent;
     }
     
     public XMLStreamReader getXMLStreamReader() {
@@ -51,6 +64,10 @@
         return fEventReader;
     }
     
+    public boolean shouldConsumeRemainingContent() {
+        return fConsumeRemainingContent;
+    }
+    
     public void setSystemId(String systemId){
         throw new UnsupportedOperationException("Cannot set the system ID on a StAXInputSource");
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org


Mime
View raw message