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/03/27 16:07:41 UTC

svn commit: r928212 - in /xerces/java/branches/xml-schema-1.1-dev: samples/xs/XSSerializer.java src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java src/org/apache/xerces/impl/xs/util/XSTypeHelper.java

Author: mukulg
Date: Sat Mar 27 15:07:41 2010
New Revision: 928212

URL: http://svn.apache.org/viewvc?rev=928212&view=rev
Log:
improvements to xsd 1.1 assertions equality (now considering namespace equality of schema types in assertions, as well). doing some refactoring as well, which leads to better code re-usability.

Added:
    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/samples/xs/XSSerializer.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java

Modified: xerces/java/branches/xml-schema-1.1-dev/samples/xs/XSSerializer.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/samples/xs/XSSerializer.java?rev=928212&r1=928211&r2=928212&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/samples/xs/XSSerializer.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/samples/xs/XSSerializer.java Sat Mar 27 15:07:41 2010
@@ -38,6 +38,7 @@ import org.apache.xerces.impl.xs.identit
 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
 import org.apache.xerces.impl.xs.identity.KeyRef;
 import org.apache.xerces.impl.xs.identity.Selector;
+import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSAttributeUse;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
@@ -1060,9 +1061,9 @@ public class XSSerializer {
                                                   attrUse.getAttrDeclaration();
            XSComplexTypeDefinition enclosingCTDefn = attrDecl.
                                                   getEnclosingCTDefinition();
-           boolean complexTypesIdentical = complexTypesIdentical(
-                                                           complexTypeDecl,
-                                                           enclosingCTDefn);
+           boolean complexTypesIdentical = XSTypeHelper.schemaTypesIdentical(
+                                                            complexTypeDecl,
+                                                            enclosingCTDefn);
            // do not add attributes, from the base type. they will be
            // serialized as part of the base type serialization.
            if (complexTypesIdentical) {
@@ -1072,31 +1073,7 @@ public class XSSerializer {
            }
         }
         
-    } // end of, addAttributesToComplexType
-
-    /*
-     * Checks if the two complex type components are identical.
-     */
-    private boolean complexTypesIdentical(XSComplexTypeDefinition 
-                                            complexTypeDefn1,
-                                          XSComplexTypeDefinition 
-                                            complexTypeDefn2) {
-        boolean complexTypesIdentical = false;
-        
-        String ct1Ns = complexTypeDefn1.getNamespace();
-        String ct1Name = complexTypeDefn1.getName();        
-        boolean nsEqual = false;           
-        if ((ct1Ns != null && ct1Ns.equals(complexTypeDefn2.getNamespace())) ||
-                  (ct1Ns == null && complexTypeDefn2.getNamespace() == null)) {
-           nsEqual = true;   
-        }
-        if (nsEqual == true && ct1Name.equals(complexTypeDefn2.getName())) {
-           complexTypesIdentical = true;   
-        }
-        
-        return complexTypesIdentical;
-        
-    } // end of, complexTypesIdentical
+    } // end of, addAttributesToComplexType    
 
     /*
      * Processing a "particle" from a complex type.

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java?rev=928212&r1=928211&r2=928212&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java Sat Mar 27 15:07:41 2010
@@ -19,6 +19,7 @@ package org.apache.xerces.impl.xs.assert
 
 import org.apache.xerces.impl.xs.AbstractPsychoPathImpl;
 import org.apache.xerces.impl.xs.traversers.XSDHandler;
+import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.xs.XSAssert;
 import org.apache.xerces.xs.XSConstants;
@@ -202,17 +203,17 @@ public class XSAssertImpl extends Abstra
     /*
      * Tests if two assert components are equal
      */
-    public boolean equals(XSAssertImpl assertComponent) {
+    public boolean equals(XSAssertImpl pAssertion) {
       boolean returnVal = false;
-        
-      String typeNameP = assertComponent.getTypeDefinition().getName();
-      String xpathStrP = assertComponent.getTest().getXPath().toString();
-      String typeNameThis = this.fTypeDefinition.getName();
-      String xpathStrThis = this.getTest().getXPath().toString();
-        
+      
+      String xpathStr = pAssertion.getTest().getXPath().toString();
+      String currXpathStr = this.getTest().getXPath().toString();        
+      
       // if type and the xpath string are same, the asserts are equal
-      if (typeNameThis.equals(typeNameP) && xpathStrThis.equals(xpathStrP)) {
-        returnVal = true;  
+      if (XSTypeHelper.schemaTypesIdentical(pAssertion.getTypeDefinition(),
+                                            fTypeDefinition) && 
+                                            currXpathStr.equals(xpathStr)) {
+         returnVal = true;  
       }
         
       return returnVal;

Added: 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=928212&view=auto
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java (added)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java Sat Mar 27 15:07:41 2010
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xerces.impl.xs.util;
+
+import org.apache.xerces.xs.XSTypeDefinition;
+
+/**
+ * Utility methods related to schema types.
+ * 
+ * @author Mukul Gandhi, IBM
+ * @version $Id: $
+ */
+public class XSTypeHelper {
+    
+    /*
+     * Checks if the two schema type components are identical.
+     */
+    public static boolean schemaTypesIdentical(XSTypeDefinition typeDefn1,
+                                               XSTypeDefinition typeDefn2) {
+        boolean typesIdentical = false;
+        
+        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 && type1Name.equals(typeDefn2.getName())) {
+           typesIdentical = true;   
+        }
+        
+        return typesIdentical;
+        
+    } // end of, schemaTypesIdentical
+}



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