You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mu...@apache.org on 2013/02/15 01:37:10 UTC

svn commit: r1446413 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: XS11Constraints.java models/XS11CMRestriction.java util/XS11TypeHelper.java

Author: mukulg
Date: Fri Feb 15 00:37:09 2013
New Revision: 1446413

URL: http://svn.apache.org/r1446413
Log:
commiting fix for jira issue XERCESJ-1605. commiting few related test cases as well.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11CMRestriction.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java?rev=1446413&r1=1446412&r2=1446413&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java Fri Feb 15 00:37:09 2013
@@ -29,6 +29,7 @@ import org.apache.xerces.impl.xs.models.
 import org.apache.xerces.impl.xs.models.XS11CMRestriction;
 import org.apache.xerces.impl.xs.models.XSCMValidator;
 import org.apache.xerces.impl.xs.util.SimpleLocator;
+import org.apache.xerces.impl.xs.util.XS11TypeHelper;
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.util.SymbolHash;
@@ -133,8 +134,8 @@ class XS11Constraints extends XSConstrai
             // Types are not the same
             throw new XMLSchemaException("cos-element-consistent", new Object[] {type.fName, elem.fName});
         }
-
-        if (!isTypeTablesEquivalent(elem, existingElem)) {
+        
+        if (XS11TypeHelper.isTypeTablesComparable(elem.getTypeAlternatives(), existingElem.getTypeAlternatives()) && !isTypeTablesEquivalent(elem, existingElem)) {
             // Type tables are not equivalent
             throw new XMLSchemaException("cos-element-consistent.4.b", new Object[] {type.fName, elem.fName});  
         }
@@ -185,7 +186,7 @@ class XS11Constraints extends XSConstrai
                 if (grammar != null) {
                     final XSElementDecl gElem = grammar.getGlobalElementDecl(elem.fName);
                     if (gElem != null) {
-                        if (gElem != elem && !isTypeTablesEquivalent(elem, gElem)) {
+                        if (gElem != elem && XS11TypeHelper.isTypeTablesComparable(elem.getTypeAlternatives(), gElem.getTypeAlternatives()) && !isTypeTablesEquivalent(elem, gElem)) {
                             // Type tables are not equivalent
                             throw new XMLSchemaException("cos-element-consistent.4.b", new Object[] {type.fName, elem.fName});
                         }
@@ -200,29 +201,33 @@ class XS11Constraints extends XSConstrai
      */
     final public boolean isTypeTablesEquivalent(XSElementDecl elementDecl1, XSElementDecl elementDecl2) {
         
+        boolean typeTablesEquivalent = true;
+        
         final XSTypeAlternativeImpl[] typeTable1 = elementDecl1.getTypeAlternatives();
         final XSTypeAlternativeImpl[] typeTable2 = elementDecl2.getTypeAlternatives();
-
-        // both tables are absent
-        if (typeTable1 == typeTable2) {
-            return true;
-        }
         
-        // one of the tables is absent or has a different length
-        if (typeTable1 == null || typeTable2 == null 
-                || typeTable1.length != typeTable2.length) {
-            return false;
+        // if two type tables have different length
+        if (typeTable1.length != typeTable2.length) {
+            typeTablesEquivalent = false;
         }
 
-        for (int typeAltIdx = 0; typeAltIdx < typeTable1.length; typeAltIdx++) {
-            final XSTypeAlternativeImpl typeAlt1 = typeTable1[typeAltIdx];
-            final XSTypeAlternativeImpl typeAlt2 = typeTable2[typeAltIdx];
-            if (!isTypeAlternativesEquivalent(typeAlt1, typeAlt2)) {
-                return false;
+        if (typeTablesEquivalent) {
+            for (int typeAltIdx = 0; typeAltIdx < typeTable1.length; typeAltIdx++) {
+                final XSTypeAlternativeImpl typeAlt1 = typeTable1[typeAltIdx];
+                final XSTypeAlternativeImpl typeAlt2 = typeTable2[typeAltIdx];
+                if (!isTypeAlternativesEquivalent(typeAlt1, typeAlt2)) {
+                    typeTablesEquivalent = false;
+                    break;
+                }
             }
         }
 
-        return isTypeAlternativesEquivalent(elementDecl1.getDefaultTypeDefinition(), elementDecl2.getDefaultTypeDefinition());        
+        if (typeTablesEquivalent && !elementDecl1.isTypeTableOK()) {
+            typeTablesEquivalent = isTypeAlternativesEquivalent(elementDecl1.getDefaultTypeDefinition(), elementDecl2.getDefaultTypeDefinition()); 
+        }
+        
+        return typeTablesEquivalent;
+        
     } // isTypeTablesEquivalent
 
     /*

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11CMRestriction.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11CMRestriction.java?rev=1446413&r1=1446412&r2=1446413&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11CMRestriction.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11CMRestriction.java Fri Feb 15 00:37:09 2013
@@ -32,6 +32,7 @@ import org.apache.xerces.impl.xs.XSGramm
 import org.apache.xerces.impl.xs.XSOpenContentDecl;
 import org.apache.xerces.impl.xs.XSWildcardDecl;
 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
+import org.apache.xerces.impl.xs.util.XS11TypeHelper;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSNamedMap;
@@ -498,8 +499,8 @@ public final class XS11CMRestriction imp
         
         // 4.6 S.{type table} and G.{type table} either are both absent or
         //     are both present and equivalent. 
-        if (!xsc.isTypeTablesEquivalent(eb, ed)) {
-            return false;
+        if (XS11TypeHelper.isTypeTablesComparable(eb.getTypeAlternatives(), ed.getTypeAlternatives()) && !xsc.isTypeTablesEquivalent(eb, ed)) {
+           return false;
         }
 
         return true;

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java?rev=1446413&r1=1446412&r2=1446413&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java Fri Feb 15 00:37:09 2013
@@ -32,6 +32,7 @@ import org.apache.xerces.impl.validation
 import org.apache.xerces.impl.xs.SchemaSymbols;
 import org.apache.xerces.impl.xs.XSComplexTypeDecl;
 import org.apache.xerces.impl.xs.XSMessageFormatter;
+import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
@@ -312,4 +313,18 @@ public class XS11TypeHelper {
     } // getXPath2ResultSequence
     
     
+    /*
+     * Check if two type tables can be compared.
+     */
+    public static boolean isTypeTablesComparable(XSTypeAlternativeImpl[] typeTable1, XSTypeAlternativeImpl[] typeTable2) {
+       boolean typeTablesComparable = true;
+       
+       if (typeTable1 == null && typeTable2 == null) {
+           typeTablesComparable = false;  
+       }
+       
+       return typeTablesComparable; 
+    } // isTypeTablesComparable
+    
+    
 } // class XS11TypeHelper



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