You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2011/04/06 18:20:29 UTC

svn commit: r1089519 - /xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java

Author: sandygao
Date: Wed Apr  6 16:20:29 2011
New Revision: 1089519

URL: http://svn.apache.org/viewvc?rev=1089519&view=rev
Log:
Sometimes grammar objects in a schema get out of sync. We end up having multiple objects for the same namespace.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDHandler.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=1089519&r1=1089518&r2=1089519&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 Apr  6 16:20:29 2011
@@ -69,8 +69,8 @@ import org.apache.xerces.util.StAXInputS
 import org.apache.xerces.util.StAXLocationWrapper;
 import org.apache.xerces.util.SymbolHash;
 import org.apache.xerces.util.SymbolTable;
-import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.util.URI.MalformedURIException;
+import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XNIException;
 import org.apache.xerces.xni.grammars.Grammar;
@@ -561,10 +561,27 @@ public class XSDHandler {
         } //is instanceof XMLInputSource
 
         if (schemaRoot == null) {
-            // something went wrong right off the hop
             if (is instanceof XSInputSource) {
-                return fGrammarBucket.getGrammar(desc.getTargetNamespace());
+                // Need to return a grammar. If the XSInputSource has a list
+                // of grammar objects, then get the first one and return it.
+                // If it has a list of components, then get the grammar that
+                // contains the first component and return it.
+                // If we return null, the XMLSchemaLoader will think nothing
+                // was loaded, and will not try to put the grammar objects
+                // into the grammar pool.
+                XSInputSource xsinput = (XSInputSource)is;
+                SchemaGrammar[] grammars = xsinput.getGrammars();
+                if (grammars != null && grammars.length > 0) {
+                    grammar = fGrammarBucket.getGrammar(grammars[0].getTargetNamespace());
+                }
+                else {
+                    XSObject[] components = xsinput.getComponents();
+                    if (components != null && components.length > 0) {
+                        grammar = fGrammarBucket.getGrammar(components[0].getNamespace());
+                    }
+                }
             }
+            // something went wrong right off the hop
             return grammar;
         }
 
@@ -2686,16 +2703,31 @@ public class XSDHandler {
     }
 
     private void addNewImportedGrammars(SchemaGrammar srcGrammar, SchemaGrammar dstGrammar) {
-        final Vector igs1 = srcGrammar.getImportedGrammars();
-        if (igs1 != null) {
-            Vector igs2 = dstGrammar.getImportedGrammars();
-            
-            if (igs2 == null) {
-                igs2 = ((Vector) igs1.clone());
-                dstGrammar.setImportedGrammars(igs2);
-            }
-            else {
-                updateImportList(igs1, igs2);
+        final Vector src = srcGrammar.getImportedGrammars();
+        if (src != null) {
+            Vector dst = dstGrammar.getImportedGrammars();
+            if (dst == null) {
+                dst = new Vector();
+                dstGrammar.setImportedGrammars(dst);
+            }
+            final int size = src.size();
+            for (int i=0; i<size; i++) {
+                SchemaGrammar sg = (SchemaGrammar) src.elementAt(i);
+                // Can't use the object from the source import list directly.
+                // It's possible there is already a grammar with the same
+                // namespace in the bucket but a different object.
+                // This can happen if the bucket has grammar A1, and we try
+                // to add B and A2, where A2 imports B. When B is added, we
+                // create a new object B' and store it in the bucket. Then we
+                // try to merge A2 and A1. We can't use B. Need to get B' from
+                // the bucket and store it in A's import list.
+                SchemaGrammar sg1 = fGrammarBucket.getGrammar(sg.getTargetNamespace());
+                if (sg1 != null) {
+                    sg = sg1;
+                }
+                if (!containedImportedGrammar(dst, sg)) {
+                    dst.add(sg);
+                }
             }
         }
     }



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