Author: mukulg
Date: Mon May  9 09:13:02 2011
New Revision: 1100926

URL: http://svn.apache.org/viewvc?rev=1100926&view=rev
Log:
improving the implementation of schema 1.1 rule "element declaration 
consistent" for type table equivalence. this improvement passes the related W3C 
XML Schema 1.1 tests.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=1100926&r1=1100925&r2=1100926&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
 Mon May  9 09:13:02 2011
@@ -206,6 +206,7 @@
         cos-ct-extends.1.4.3.2.2.3.4 = cos-ct-extends.1.4.3.2.2.3.4: The 
namespace constraint of the wildcard on the open content of the base type must 
be a subset of the namespace constraint of the wildcard on the open content of 
the derived type. This is not the case for type ''{0}''.
         cos-content-act-restrict.5.3 = cos-content-act-restrict.5.3: Error for 
type ''{0}''. The attribute use ''{1}'' in this type has value of 
''inheritable'', which is inconsistent with the value in the base type.    
         cos-element-consistent = cos-element-consistent: Error for type 
''{0}''. Multiple elements with name ''{1}'', with different types, appear in 
the model group.
+        cos-element-consistent.4 = cos-element-consistent.4: Error for type 
''{0}''. Multiple elements with name ''{1}'', with non equivalent type tables, 
appear in the model group.
         cos-list-of-atomic = cos-list-of-atomic: In the definition of list 
type ''{0}'', type ''{1}'' is an invalid list element type because it is not 
atomic (''{1}'' is either a list type, or a union type which contains a list).
         cos-nonambig = cos-nonambig: {0} and {1} (or elements from their 
substitution group) violate \"Unique Particle Attribution\". During validation 
against this schema, ambiguity would be created for those two particles.
         cos-particle-extends.3.1 = cos-particle-extends.3.1: When both a 
derived type and its base have particles with <all> as their {term}s, the 
minOccurs of the derived particle needs to be equal to that of its base.

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java?rev=1100926&r1=1100925&r2=1100926&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xpath/XPath20.java
 Mon May  9 09:13:02 2011
@@ -67,6 +67,10 @@ public class XPath20 {
             return false;
         }
     }
+    
+    public String getXPathStrValue() {
+       return fExpression; 
+    }
 
 }
 

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java?rev=1100926&r1=1100925&r2=1100926&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
 Mon May  9 09:13:02 2011
@@ -23,10 +23,12 @@ import org.apache.xerces.impl.dv.Invalid
 import org.apache.xerces.impl.dv.ValidatedInfo;
 import org.apache.xerces.impl.dv.ValidationContext;
 import org.apache.xerces.impl.dv.XSSimpleType;
+import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
 import org.apache.xerces.impl.xs.models.CMBuilder;
 import org.apache.xerces.impl.xs.models.XSCMValidator;
 import org.apache.xerces.impl.xs.util.SimpleLocator;
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.util.SymbolHash;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSObjectList;
@@ -537,12 +539,76 @@ public abstract class XSConstraints {
 
             if (elem.fType != existingElem.fType) {
                 // Types are not the same
-                throw new XMLSchemaException("cos-element-consistent",
-                        new Object[] {type.fName, elem.fName});
-
+                throw new XMLSchemaException("cos-element-consistent", new 
Object[] {type.fName, elem.fName});
+            }
+            else if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && 
!isTypeTablesEquivalent(elem, existingElem)) {
+                // Type tables are not equivalent
+                throw new XMLSchemaException("cos-element-consistent.4", new 
Object[] {type.fName, elem.fName});  
             }
         }
     }
+    
+    /*
+     * Check if two type tables are equivalent.
+     */
+    private boolean isTypeTablesEquivalent(XSElementDecl elementDecl1, 
XSElementDecl elementDecl2) {
+        
+        boolean isTypeTablesEquivalent = true;
+        
+        XSTypeAlternativeImpl[] typeTable1 = 
elementDecl1.getTypeAlternatives();
+        XSTypeAlternativeImpl[] typeTable2 = 
elementDecl2.getTypeAlternatives();
+        
+        if (typeTable1 != null && typeTable2 != null) {
+            if (typeTable1.length != typeTable2.length) {
+                isTypeTablesEquivalent = false; 
+            }
+            else {
+                for (int typeAltIdx = 0; typeAltIdx < typeTable1.length; 
typeAltIdx++) {
+                    XSTypeAlternativeImpl typeAlt1 = typeTable1[typeAltIdx];
+                    XSTypeAlternativeImpl typeAlt2 = typeTable2[typeAltIdx];
+                    if (!isTypeAlternativesEquivalent(typeAlt1, typeAlt2)) {
+                        isTypeTablesEquivalent = false;
+                        break;
+                    }
+                }
+            }
+            if (isTypeTablesEquivalent && 
!isTypeAlternativesEquivalent(elementDecl1.getDefaultTypeDefinition(), 
elementDecl2.getDefaultTypeDefinition())) {
+                isTypeTablesEquivalent = false; 
+            }
+        }
+        else if ((typeTable1 != null && typeTable2 == null) || (typeTable1 == 
null && typeTable2 != null)) {
+            isTypeTablesEquivalent = false;  
+        }
+        
+        return isTypeTablesEquivalent;
+        
+    } // isTypeTablesEquivalent
+    
+    /*
+     * Check if two type alternative components are equivalent.
+     */
+    private boolean isTypeAlternativesEquivalent(XSTypeAlternativeImpl 
typeAlt1, XSTypeAlternativeImpl typeAlt2) {
+        
+        boolean isTypeAlternativesEquivalent = false;
+        
+        String defNamespace1 = typeAlt1.getXPathDefaultNamespace();
+        String defNamespace2 = typeAlt2.getXPathDefaultNamespace();
+        String testStr1 = (typeAlt1.getTest() == null) ? null : 
typeAlt1.getTest().toString();
+        String testStr2 = (typeAlt2.getTest() == null) ? null : 
typeAlt2.getTest().toString();
+        XSTypeDefinition typeDefn1 = typeAlt1.getTypeDefinition();
+        XSTypeDefinition typeDefn2 = typeAlt2.getTypeDefinition();
+        
+        if (((defNamespace1 == null && defNamespace2 == null) || 
(defNamespace1 != null && defNamespace2 != null && 
defNamespace1.equals(defNamespace2))) &&
+            ((testStr1 == null && testStr2 == null) || (testStr1 != null && 
testStr2 != null && (testStr1.trim()).equals(testStr2.trim()))) &&
+            (XSTypeHelper.isSchemaTypesIdentical(typeDefn1, typeDefn2))) {
+              isTypeAlternativesEquivalent = true;
+        }
+        
+        // TO DO: equivalence check for namespace bindings and base URI
+        
+        return isTypeAlternativesEquivalent;
+        
+    } // isTypeAlternativesEquivalent
 
     // to check whether two element overlap, as defined in constraint UPA
     protected boolean overlapUPA(XSElementDecl element1,

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java?rev=1100926&r1=1100925&r2=1100926&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
 Mon May  9 09:13:02 2011
@@ -27,7 +27,6 @@ import org.apache.xerces.impl.xs.Abstrac
 import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XMLAttributes;
-import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -106,7 +105,7 @@ public class Test extends AbstractPsycho
     }
 
     public String toString() {
-        return fXPath.toString();
+        return fXPath.getXPathStrValue();
     }
     
     /*



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to