xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject svn commit: r693496 - in /xerces/java/trunk/src/org/apache/xerces: impl/xs/traversers/XSDHandler.java jaxp/validation/XMLSchemaFactory.java
Date Tue, 09 Sep 2008 15:57:01 GMT
Author: mrglavas
Date: Tue Sep  9 08:57:01 2008
New Revision: 693496

URL: http://svn.apache.org/viewvc?rev=693496&view=rev
Log:
JIRA Issue #1313:
http://issues.apache.org/jira/browse/XERCESJ-1313

Completed support for schema loading from a StAX source.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
    xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.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=693496&r1=693495&r2=693496&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 Tue Sep  9
08:57:01 2008
@@ -24,6 +24,8 @@
 import java.util.Stack;
 import java.util.Vector;
 
+import javax.xml.stream.XMLStreamException;
+
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.XMLEntityManager;
 import org.apache.xerces.impl.XMLErrorReporter;
@@ -52,6 +54,7 @@
 import org.apache.xerces.util.DOMInputSource;
 import org.apache.xerces.util.DefaultErrorHandler;
 import org.apache.xerces.util.SAXInputSource;
+import org.apache.xerces.util.StAXInputSource;
 import org.apache.xerces.util.SymbolTable;
 import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.util.URI.MalformedURIException;
@@ -343,6 +346,7 @@
     
     SchemaDOMParser fSchemaParser;
     SchemaContentHandler fXSContentHandler;
+    StAXSchemaParser fStAXSchemaParser;
     XML11Configuration fAnnotationValidator;
     XSAnnotationGrammarPool fGrammarBucketAdapter;
     
@@ -525,7 +529,30 @@
                 return null;
             }
         	schemaRoot = DOMUtil.getRoot(schemaRootDoc);          
-        }            
+        }
+        else if (is instanceof StAXInputSource) {
+            StAXInputSource sis = (StAXInputSource)is;
+            if (fStAXSchemaParser == null) {
+                fStAXSchemaParser = new StAXSchemaParser();
+            }
+            fStAXSchemaParser.reset(fSchemaParser, fSymbolTable);
+            try {
+                if (sis.getXMLEventReader() != null) {
+                    fStAXSchemaParser.parse(sis.getXMLEventReader());
+                }
+                else {
+                    fStAXSchemaParser.parse(sis.getXMLStreamReader());
+                }
+            }
+            catch (XMLStreamException e) {
+                return null;
+            }
+            schemaRootDoc = fStAXSchemaParser.getDocument();
+            if (schemaRootDoc == null) {
+                return null;
+            }
+            schemaRoot = DOMUtil.getRoot(schemaRootDoc);
+        }
         else {
         	schemaRoot = getSchemaDocument(schemaNamespace, is,
                   referType == XSDDescription.CONTEXT_PREPARSE,
@@ -1760,7 +1787,30 @@
                 return null;
             }
             return DOMUtil.getRoot(root);          
-        }       
+        }
+        else if (schemaSource instanceof StAXInputSource) {
+            StAXInputSource sis = (StAXInputSource)schemaSource;
+            if (fStAXSchemaParser == null) {
+                fStAXSchemaParser = new StAXSchemaParser();
+            }
+            fStAXSchemaParser.reset(fSchemaParser, fSymbolTable);
+            try {
+                if (sis.getXMLEventReader() != null) {
+                    fStAXSchemaParser.parse(sis.getXMLEventReader());
+                }
+                else {
+                    fStAXSchemaParser.parse(sis.getXMLStreamReader());
+                }
+            }
+            catch (XMLStreamException e) {
+                return null;
+            }
+            Document root = fStAXSchemaParser.getDocument();
+            if (root == null) {
+                return null;
+            }
+            return DOMUtil.getRoot(root);
+        }
         return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(),
referElement);
     } // getSchema(String, String, String, boolean, short):  Document
     

Modified: xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java?rev=693496&r1=693495&r2=693496&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/jaxp/validation/XMLSchemaFactory.java Tue Sep
 9 08:57:01 2008
@@ -23,9 +23,11 @@
 import java.util.Locale;
 
 import javax.xml.XMLConstants;
+import javax.xml.stream.XMLEventReader;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
@@ -38,6 +40,7 @@
 import org.apache.xerces.util.SAXInputSource;
 import org.apache.xerces.util.SAXMessageFormatter;
 import org.apache.xerces.util.SecurityManager;
+import org.apache.xerces.util.StAXInputSource;
 import org.apache.xerces.util.XMLGrammarPoolImpl;
 import org.apache.xerces.xni.XNIException;
 import org.apache.xerces.xni.grammars.Grammar;
@@ -202,6 +205,16 @@
                 String systemID = domSource.getSystemId();          
                 xmlInputSources[i] = new DOMInputSource(node, systemID);
             }
+            else if (source instanceof StAXSource) {
+                StAXSource staxSource = (StAXSource) source;
+                XMLEventReader eventReader = staxSource.getXMLEventReader();
+                if (eventReader != null) {
+                    xmlInputSources[i] = new StAXInputSource(eventReader);
+                }
+                else {
+                    xmlInputSources[i] = new StAXInputSource(staxSource.getXMLStreamReader());
+                }
+            }
             else if (source == null) {
                 throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),

                         "SchemaSourceArrayMemberNull", null));



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


Mime
View raw message