xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject svn commit: r694381 - in /xerces/java/trunk/src/org/apache/xerces: impl/xs/traversers/StAXSchemaParser.java util/JAXPNamespaceContextWrapper.java
Date Thu, 11 Sep 2008 17:43:38 GMT
Author: mrglavas
Date: Thu Sep 11 10:43:36 2008
New Revision: 694381

URL: http://svn.apache.org/viewvc?rev=694381&view=rev
Log:
Fixing a bug. When the schema loader is provided with StAX input the annotation
strings in the XSModel were all missing namespace declarations on the root of
the document fragment. Need to report the prefixes to the NamespaceContext and
return them from getAllPrefixes().

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/StAXSchemaParser.java
    xerces/java/trunk/src/org/apache/xerces/util/JAXPNamespaceContextWrapper.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/StAXSchemaParser.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/StAXSchemaParser.java?rev=694381&r1=694380&r2=694381&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/StAXSchemaParser.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/StAXSchemaParser.java Thu Sep
11 10:43:36 2008
@@ -84,10 +84,15 @@
     private final XMLStringBuffer fStringBuffer = new XMLStringBuffer();
     private int fDepth;
     
+    public StAXSchemaParser() {
+        fNamespaceContext.setDeclaredPrefixes(fDeclaredPrefixes);
+    }
+    
     public void reset(SchemaDOMParser schemaDOMParser, SymbolTable symbolTable) {
         fSchemaDOMParser = schemaDOMParser;
         fSymbolTable = symbolTable;
         fNamespaceContext.setSymbolTable(fSymbolTable);
+        fNamespaceContext.reset();
     }
 
     public Document getDocument() {
@@ -116,6 +121,7 @@
                     fillXMLAttributes(start);
                     fillDeclaredPrefixes(start);
                     addNamespaceDeclarations();
+                    fNamespaceContext.pushContext();
                     fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                     break;
                 case XMLStreamConstants.END_ELEMENT:
@@ -124,6 +130,7 @@
                     fillDeclaredPrefixes(end);
                     fLocationWrapper.setLocation(end.getLocation());
                     fSchemaDOMParser.endElement(fElementQName, null);
+                    fNamespaceContext.popContext();
                     --fDepth;
                     if (fDepth <= 0) {
                         break loop;
@@ -195,6 +202,7 @@
                     fillXMLAttributes(input);
                     fillDeclaredPrefixes(input);
                     addNamespaceDeclarations();
+                    fNamespaceContext.pushContext();
                     fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                     break;
                 case XMLStreamConstants.END_ELEMENT:
@@ -204,6 +212,7 @@
                         input.getLocalName(), input.getPrefix());
                     fillDeclaredPrefixes(input);
                     fSchemaDOMParser.endElement(fElementQName, null);
+                    fNamespaceContext.popContext();
                     --fDepth;
                     if (fDepth <= 0) {
                         break loop;

Modified: xerces/java/trunk/src/org/apache/xerces/util/JAXPNamespaceContextWrapper.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/util/JAXPNamespaceContextWrapper.java?rev=694381&r1=694380&r2=694381&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/util/JAXPNamespaceContextWrapper.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/util/JAXPNamespaceContextWrapper.java Thu Sep
11 10:43:36 2008
@@ -17,8 +17,11 @@
 
 package org.apache.xerces.util;
 
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.TreeSet;
+import java.util.Vector;
 
 import javax.xml.XMLConstants;
 
@@ -36,7 +39,11 @@
     private javax.xml.namespace.NamespaceContext fNamespaceContext;
     private SymbolTable fSymbolTable;
     private List fPrefixes;
-
+    private final Vector fAllPrefixes = new Vector();
+    
+    private int[] fContext = new int[8];
+    private int fCurrentContext;
+    
     public JAXPNamespaceContextWrapper(SymbolTable symbolTable) {
         setSymbolTable(symbolTable);
     }
@@ -94,21 +101,28 @@
     }
     
     public Enumeration getAllPrefixes() {
-        // It's not possible to get the list of all prefixes from the NamespaceContext
-        // so the best we can do is return an empty enumeration.
-        return new Enumeration () {
-            public boolean hasMoreElements() {
-                return false;
-            }
-            public Object nextElement() {
-                return null;
-            }
-        };
+        // There may be duplicate prefixes in the list so we 
+        // first transfer them to a set to ensure uniqueness.
+        return Collections.enumeration(new TreeSet(fAllPrefixes));
     }
 
-    public void pushContext() {}
+    public void pushContext() {
+        // extend the array, if necessary
+        if (fCurrentContext + 1 == fContext.length) {
+            int[] contextarray = new int[fContext.length * 2];
+            System.arraycopy(fContext, 0, contextarray, 0, fContext.length);
+            fContext = contextarray;
+        }
+        // push context
+        fContext[++fCurrentContext] = fAllPrefixes.size();
+        if (fPrefixes != null) {
+            fAllPrefixes.addAll(fPrefixes);
+        }
+    }
 
-    public void popContext() {}
+    public void popContext() {
+        fAllPrefixes.setSize(fContext[fCurrentContext--]);
+    }
 
     public boolean declarePrefix(String prefix, String uri) {
         return true;
@@ -122,6 +136,10 @@
         return (String) fPrefixes.get(index);
     }
 
-    public void reset() {}
+    public void reset() {
+        fCurrentContext = 0;
+        fContext[fCurrentContext] = 0;
+        fAllPrefixes.clear();
+    }
 
 } // JAXPNamespaceContextWrapper



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


Mime
View raw message