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 2010/07/31 14:59:18 UTC

svn commit: r981048 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: XMLSchemaValidator.java util/XSTypeHelper.java

Author: mukulg
Date: Sat Jul 31 12:59:18 2010
New Revision: 981048

URL: http://svn.apache.org/viewvc?rev=981048&view=rev
Log:
doing little refactoring and some code formatting

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=981048&r1=981047&r2=981048&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Sat Jul 31 12:59:18 2010
@@ -59,6 +59,7 @@ import org.apache.xerces.impl.xs.models.
 import org.apache.xerces.impl.xs.models.XCMValidatorHelper;
 import org.apache.xerces.impl.xs.models.XSCMValidator;
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.util.AugmentationsImpl;
 import org.apache.xerces.util.IntStack;
 import org.apache.xerces.util.SymbolTable;
@@ -2201,8 +2202,8 @@ public class XMLSchemaValidator
             boolean typeSelected = false;
             XSTypeAlternativeImpl[] alternatives = fCurrentElemDecl.getTypeAlternatives();
             if (alternatives != null) {              
-                // construct a list of attributes, needed for CTA processing.
-                // This method call, adds inherited attributes as well, to the list
+                // construct a list of attributes needed for CTA processing.
+                // This method call adds inherited attributes as well, to the list
                 // of attributes.
                 XMLAttributes ctaAttributes = getAttributesForCTA(attributes);
                 
@@ -2600,7 +2601,7 @@ public class XMLSchemaValidator
         
         // inheritable attribute processing
         
-        // modify the Vector list, 'fInheritableAttrList' and pop the stack,
+        // modify the Vector list 'fInheritableAttrList' and pop the stack,
         // 'fInhrAttrCountStack', to reflect inheritable attributes processing. 
         if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
            if (fInhrAttrCountStack.size() > 0) {
@@ -4979,7 +4980,8 @@ public class XMLSchemaValidator
      * A class representing an inheritable attribute. This is used as an
      * intermediate storage, for inheritable attribute information.
      */
-    class InheritableAttribute {
+    class InheritableAttribute {       
+       
        String localName = "";
        String prefix = "";
        String uri = "";
@@ -5017,6 +5019,7 @@ public class XMLSchemaValidator
        public String getType() {
           return type; 
        }
+       
     } // class, InheritableAttribute
     
     
@@ -5035,14 +5038,14 @@ public class XMLSchemaValidator
           for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++) {
              String attrName = attributes.getLocalName(attrIndx);
              String attrUri = attributes.getURI(attrIndx);            
-             // iterate all the attributes declarations, of the complex type,
+             // iterate all the attribute declarations of a complex type,
              // for the current element.
              for (int attrUsesIndx = 0; attrUsesIndx < attributeUses.getLength(); attrUsesIndx++) {
                 XSAttributeUseImpl attrUseImpl = (XSAttributeUseImpl) attributeUses.get(attrUsesIndx);
                 XSAttributeDeclaration attrDecl = attrUseImpl.getAttrDeclaration();              
                 // the current element, has an inheritable attribute
                 if (attrName.equals(attrDecl.getName()) &&
-                      uriEqual(attrUri, attrDecl.getNamespace()) &&    
+                        XSTypeHelper.uriEqual(attrUri, attrDecl.getNamespace()) &&    
                       attrUseImpl.getInheritable()) {                   
                     InheritableAttribute inhrAttr = new InheritableAttribute(
                                             attributes.getLocalName(attrIndx),
@@ -5076,7 +5079,7 @@ public class XMLSchemaValidator
       // attributes only from the nearest ancestor, are added to the list
       for (int elemIndx = fInheritableAttrList.size() - 1; elemIndx > -1; elemIndx--) {        
          InheritableAttribute inhAttr = (InheritableAttribute) fInheritableAttrList.elementAt(elemIndx);
-         // if an inheritable attribute doesn't already exist, in the attributes
+         // if an inheritable attribute doesn't already exist in the attributes
          // list, add it to the list.
          if (!attributeExists(ctaAttributes, inhAttr)) {
             String rawName = "".equals(inhAttr.getPrefix()) ? inhAttr.getLocalName() : 
@@ -5101,31 +5104,14 @@ public class XMLSchemaValidator
           String localName = attributes.getLocalName(attrIndx);
           String uri = attributes.getURI(attrIndx);          
           if (localName.equals(inhAttr.getLocalName()) &&
-              uriEqual(uri, inhAttr.getUri())) {              
+                XSTypeHelper.uriEqual(uri, inhAttr.getUri())) {              
              attrExists = true;
              break;
           }
       }
       
       return attrExists;
+      
     } // attributeExists
     
-    
-    /*
-     * Check if two URI values are equal
-     */
-    private boolean uriEqual(String a, String b) {
-        boolean nsEqual = false;
-        
-        if ((a != null && b == null) ||
-            (a == null && b != null)) {
-           nsEqual = false;
-        } else if ((a == null && b == null) ||
-                    a.equals(b)) {
-           nsEqual = true;   
-        } 
-        
-        return nsEqual;
-    } // uriEqual
-    
 } // class SchemaValidator

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java?rev=981048&r1=981047&r2=981048&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java Sat Jul 31 12:59:18 2010
@@ -20,13 +20,14 @@ package org.apache.xerces.impl.xs.util;
 import org.apache.xerces.xs.XSTypeDefinition;
 
 /**
- * Utility methods related to schema types.
+ * Class defining utility/helper methods related to schema types.
  * 
  * @author Mukul Gandhi, IBM
  * @version $Id$
  */
 public class XSTypeHelper {
     
+    
     /*
      * Checks if the two schema type components are identical.
      */
@@ -34,31 +35,49 @@ public class XSTypeHelper {
                                                XSTypeDefinition typeDefn2) {
         boolean typesIdentical = false;
         
-        if ("anyType".equals(typeDefn1.getName()) && 
-            "anyType".equals(typeDefn2.getName())) {
+        String type1Name = typeDefn1.getName();
+        String type2Name = typeDefn2.getName();
+        
+        if ("anyType".equals(type1Name) && 
+            "anyType".equals(type2Name)) {
             typesIdentical = true;  
         }
         
-        if (!typesIdentical) {
-            String type1Ns = typeDefn1.getNamespace();
-            String type1Name = typeDefn1.getName();        
-            boolean nsEqual = false;           
-            if ((type1Ns != null && type1Ns.equals(typeDefn2.getNamespace())) ||
-                    (type1Ns == null && typeDefn2.getNamespace() == null)) {
-                nsEqual = true;   
-            }
-
-            if (nsEqual == true) {
-                if ((type1Name == null && typeDefn2.getName() == null) ||
-                        (type1Name != null && type1Name.equals(typeDefn2.getName()))
-                        && (schemaTypesIdentical(typeDefn1.getBaseType(),
-                                typeDefn2.getBaseType()))) {
-                    typesIdentical = true;   
+        if (!typesIdentical) {                        
+            if (uriEqual(typeDefn1.getNamespace(), typeDefn2.getNamespace())) {
+                // if targetNamespace of types are same, then check for 
+                // equality of type names and of the base type.
+                if ((type1Name == null && type2Name == null) ||
+                    (type1Name != null && type1Name.equals(type2Name))
+                          && (schemaTypesIdentical(typeDefn1.getBaseType(),
+                                                   typeDefn2.getBaseType()))) {
+                     typesIdentical = true;   
                 }
             }
         }
         
         return typesIdentical;
         
-    } // end of, schemaTypesIdentical
+    } // schemaTypesIdentical
+    
+    
+    /*
+     * Check if two URI values are equal.
+     */
+    public static boolean uriEqual(String uri1, String uri2) {
+        
+        boolean uriEqual = false;
+        
+        if ((uri1 != null && uri2 == null) ||
+            (uri1 == null && uri2 != null)) {
+           uriEqual = false;
+        } else if ((uri1 == null && uri2 == null) ||
+                    uri1.equals(uri2)) {
+           uriEqual = true;   
+        } 
+        
+        return uriEqual;
+        
+    } // uriEqual
+    
 }



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