ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1310816 - in /webservices/xmlschema/trunk/xmlschema-core/src: main/java/org/apache/ws/commons/schema/ main/java/org/apache/ws/commons/schema/utils/ test/java/tests/ test/resources/
Date Sat, 07 Apr 2012 18:36:37 GMT
Author: dkulp
Date: Sat Apr  7 18:36:36 2012
New Revision: 1310816

URL: http://svn.apache.org/viewvc?rev=1310816&view=rev
Log:
[XMLSCHEMA-7] Fix issues with multiple xsd:key/keyrefs not being output.
Patch from Marc Giger applied

Modified:
    webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
    webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
    webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ConstraintsTest.java
    webservices/xmlschema/trunk/xmlschema-core/src/test/resources/constraints.xsd

Modified: webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?rev=1310816&r1=1310815&r2=1310816&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
Sat Apr  7 18:36:36 2012
@@ -425,7 +425,7 @@ public class SchemaBuilder {
         if (keyEl != null) {
             while (keyEl != null) {
                 element.getConstraints().add(handleConstraint(keyEl, XmlSchemaKey.class));
-                keyEl = XDOMUtil.getNextSiblingElement(keyEl, "key");
+                keyEl = XDOMUtil.getNextSiblingElementNS(keyEl, XmlSchema.SCHEMA_NS,  "key");
             }
         }
 
@@ -438,7 +438,7 @@ public class SchemaBuilder {
                     keyRef.refer = getRefQName(name, el);
                 }
                 element.getConstraints().add(keyRef);
-                keyrefEl = XDOMUtil.getNextSiblingElement(keyrefEl, "keyref");
+                keyrefEl = XDOMUtil.getNextSiblingElementNS(keyrefEl, XmlSchema.SCHEMA_NS,
"keyref");
             }
         }
 
@@ -446,7 +446,7 @@ public class SchemaBuilder {
         if (uniqueEl != null) {
             while (uniqueEl != null) {
                 element.getConstraints().add(handleConstraint(uniqueEl, XmlSchemaUnique.class));
-                uniqueEl = XDOMUtil.getNextSiblingElement(uniqueEl, "unique");
+                uniqueEl = XDOMUtil.getNextSiblingElementNS(uniqueEl, XmlSchema.SCHEMA_NS,
"unique");
             }
         }
 

Modified: webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java?rev=1310816&r1=1310815&r2=1310816&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
Sat Apr  7 18:36:36 2012
@@ -118,7 +118,7 @@ public class DOMUtil {
         // search for node
         Node child = parent.getFirstChild();
         while (child != null) {
-            if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(elemName))
{
+            if (child.getNodeType() == Node.ELEMENT_NODE && child.getLocalName().equals(elemName))
{
                 return (Element)child;
             }
             child = child.getNextSibling();
@@ -137,7 +137,7 @@ public class DOMUtil {
         // search for node
         Node child = parent.getLastChild();
         while (child != null) {
-            if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(elemName))
{
+            if (child.getNodeType() == Node.ELEMENT_NODE && child.getLocalName().equals(elemName))
{
                 return (Element)child;
             }
             child = child.getPreviousSibling();
@@ -156,7 +156,7 @@ public class DOMUtil {
         // search for node
         Node sibling = node.getNextSibling();
         while (sibling != null) {
-            if (sibling.getNodeType() == Node.ELEMENT_NODE && sibling.getNodeName().equals(elemName))
{
+            if (sibling.getNodeType() == Node.ELEMENT_NODE && sibling.getLocalName().equals(elemName))
{
                 return (Element)sibling;
             }
             sibling = sibling.getNextSibling();
@@ -244,7 +244,7 @@ public class DOMUtil {
         while (child != null) {
             if (child.getNodeType() == Node.ELEMENT_NODE) {
                 for (String elemName : elemNames) {
-                    if (child.getNodeName().equals(elemName)) {
+                    if (child.getLocalName().equals(elemName)) {
                         return (Element)child;
                     }
                 }
@@ -267,7 +267,7 @@ public class DOMUtil {
         while (child != null) {
             if (child.getNodeType() == Node.ELEMENT_NODE) {
                 for (String elemName : elemNames) {
-                    if (child.getNodeName().equals(elemName)) {
+                    if (child.getLocalName().equals(elemName)) {
                         return (Element)child;
                     }
                 }
@@ -290,7 +290,7 @@ public class DOMUtil {
         while (sibling != null) {
             if (sibling.getNodeType() == Node.ELEMENT_NODE) {
                 for (String elemName : elemNames) {
-                    if (sibling.getNodeName().equals(elemName)) {
+                    if (sibling.getLocalName().equals(elemName)) {
                         return (Element)sibling;
                     }
                 }
@@ -387,7 +387,7 @@ public class DOMUtil {
         while (child != null) {
             if (child.getNodeType() == Node.ELEMENT_NODE) {
                 Element element = (Element)child;
-                if (element.getNodeName().equals(elemName)
+                if (element.getLocalName().equals(elemName)
                     && element.getAttribute(attrName).equals(attrValue)) {
                     return element;
                 }
@@ -411,7 +411,7 @@ public class DOMUtil {
         while (child != null) {
             if (child.getNodeType() == Node.ELEMENT_NODE) {
                 Element element = (Element)child;
-                if (element.getNodeName().equals(elemName)
+                if (element.getLocalName().equals(elemName)
                     && element.getAttribute(attrName).equals(attrValue)) {
                     return element;
                 }
@@ -436,7 +436,7 @@ public class DOMUtil {
         while (sibling != null) {
             if (sibling.getNodeType() == Node.ELEMENT_NODE) {
                 Element element = (Element)sibling;
-                if (element.getNodeName().equals(elemName)
+                if (element.getLocalName().equals(elemName)
                     && element.getAttribute(attrName).equals(attrValue)) {
                     return element;
                 }
@@ -483,7 +483,7 @@ public class DOMUtil {
 
     // return the name of this element
     public static String getName(Node node) {
-        return node.getNodeName();
+        return node.getLocalName();
     } // getLocalName(Element): String
 
     /**
@@ -491,7 +491,7 @@ public class DOMUtil {
      */
     public static String getLocalName(Node node) {
         String name = node.getLocalName();
-        return name != null ? name : node.getNodeName();
+        return name != null ? name : node.getLocalName();
     } // getLocalName(Element): String
 
     public static Element getParent(Element elem) {

Modified: webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ConstraintsTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ConstraintsTest.java?rev=1310816&r1=1310815&r2=1310816&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ConstraintsTest.java (original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/ConstraintsTest.java Sat
Apr  7 18:36:36 2012
@@ -19,33 +19,22 @@
 
 package tests;
 
+import org.apache.ws.commons.schema.*;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.StringWriter;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
-
-import javax.xml.namespace.QName;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaIdentityConstraint;
-import org.apache.ws.commons.schema.XmlSchemaKey;
-import org.apache.ws.commons.schema.XmlSchemaKeyref;
-import org.apache.ws.commons.schema.XmlSchemaUnique;
-import org.apache.ws.commons.schema.XmlSchemaXPath;
-
-import org.junit.Assert;
-import org.junit.Test;
 
 public class ConstraintsTest extends Assert {
 
     /**
      * This method will test the unique, key, and keyref constaints.
-     * 
+     *
      * @throws Exception Any exception encountered
      */
     @Test
@@ -83,75 +72,121 @@ public class ConstraintsTest extends Ass
         assertEquals(new QName("http://soapinterop.org/types", "constraintTest"), elem.getQName());
 
         List<XmlSchemaIdentityConstraint> c = elem.getConstraints();
-        assertEquals(4, c.size());
+        assertEquals(6, c.size());
 
-        Set<String> s = new HashSet<String>();
-        s.add(XmlSchemaKey.class.getName());
-        s.add(XmlSchemaKeyref.class.getName());
-        s.add(XmlSchemaUnique.class.getName());
-        for (int i = 0; i < c.size(); i++) {
-            Object o = c.get(i);
-            if (o instanceof XmlSchemaKey) {
-                XmlSchemaKey key = (XmlSchemaKey)o;
-                assertEquals("keyTest", key.getName());
-
-                XmlSchemaXPath selectorXpath = key.getSelector();
-                assertEquals("tns:products/tns:productName", selectorXpath.getXPath());
-
-                List<XmlSchemaXPath> fields = key.getFields();
-                assertEquals(1, fields.size());
-                XmlSchemaXPath fieldXpath = null;
-                for (int j = 0; j < fields.size(); j++) {
-                    fieldXpath = fields.get(j);
-                }
-                assertNotNull(fieldXpath);
-                assertEquals("@productId", fieldXpath.getXPath());
-            } else if (o instanceof XmlSchemaKeyref) {
-                XmlSchemaKeyref keyref = (XmlSchemaKeyref)o;
-                assertNotNull(keyref);
-                assertEquals("keyRefTest", keyref.getName());
-                assertEquals(new QName("http://soapinterop.org/types", "keyTest"), keyref.getRefer());
-
-                XmlSchemaXPath selectorXpath = keyref.getSelector();
-                assertEquals("tns:manufacturers/tns:location/tns:productName", selectorXpath.getXPath());
-
-                List<XmlSchemaXPath> fields = keyref.getFields();
-                assertEquals(1, fields.size());
-                XmlSchemaXPath fieldXpath = null;
-                for (int j = 0; j < fields.size(); j++) {
-                    fieldXpath = fields.get(j);
-                }
-                assertNotNull(fieldXpath);
-                assertEquals("@productId", fieldXpath.getXPath());
-            } else if (o instanceof XmlSchemaUnique) {
-                XmlSchemaUnique unique = (XmlSchemaUnique)o;
-                assertNotNull(unique);
-                if ("uniqueTest".equals(unique.getName())) {
-                    XmlSchemaXPath selectorXpath = unique.getSelector();
-                    assertEquals("tns:manufacturers/tns:location", selectorXpath.getXPath());
-    
-                    List<XmlSchemaXPath> fields = unique.getFields();
-                    assertEquals(1, fields.size());
-                    XmlSchemaXPath fieldXpath = null;
-                    for (int j = 0; j < fields.size(); j++) {
-                        fieldXpath = fields.get(j);
-                    }
-                    assertNotNull(fieldXpath);
-                    assertEquals("@district", fieldXpath.getXPath());
-                }
-            } else {
-                fail("An unexpected constraint of \"" + o.getClass().getName() + "\" was
found.");
+        {
+            assertTrue(c.get(0) instanceof XmlSchemaKey);
+            XmlSchemaKey key = (XmlSchemaKey) c.get(0);
+            assertEquals("keyTest", key.getName());
+            XmlSchemaXPath selectorXpath = key.getSelector();
+            assertEquals("tns:products/tns:productName", selectorXpath.getXPath());
+
+            List<XmlSchemaXPath> fields = key.getFields();
+            assertEquals(1, fields.size());
+            XmlSchemaXPath fieldXpath = null;
+            for (int j = 0; j < fields.size(); j++) {
+                fieldXpath = fields.get(j);
+            }
+            assertNotNull(fieldXpath);
+            assertEquals("@productId", fieldXpath.getXPath());
+        }
+        {
+            assertTrue(c.get(1) instanceof XmlSchemaKey);
+            XmlSchemaKey key = (XmlSchemaKey) c.get(1);
+            assertEquals("keyTest2", key.getName());
+            XmlSchemaXPath selectorXpath = key.getSelector();
+            assertEquals("tns:products/tns:productName", selectorXpath.getXPath());
+
+            List<XmlSchemaXPath> fields = key.getFields();
+            assertEquals(1, fields.size());
+            XmlSchemaXPath fieldXpath = null;
+            for (int j = 0; j < fields.size(); j++) {
+                fieldXpath = fields.get(j);
+            }
+            assertNotNull(fieldXpath);
+            assertEquals("@productId", fieldXpath.getXPath());
+        }
+        {
+            assertTrue(c.get(2) instanceof XmlSchemaKeyref);
+            XmlSchemaKeyref keyref = (XmlSchemaKeyref) c.get(2);
+            assertEquals("keyRefTest", keyref.getName());
+            assertEquals(new QName("http://soapinterop.org/types", "keyTest"), keyref.getRefer());
+
+            XmlSchemaXPath selectorXpath = keyref.getSelector();
+            assertEquals("tns:manufacturers/tns:location/tns:productName", selectorXpath.getXPath());
+
+            List<XmlSchemaXPath> fields = keyref.getFields();
+            assertEquals(1, fields.size());
+            XmlSchemaXPath fieldXpath = null;
+            for (int j = 0; j < fields.size(); j++) {
+                fieldXpath = fields.get(j);
+            }
+            assertNotNull(fieldXpath);
+            assertEquals("@productId", fieldXpath.getXPath());
+        }
+        {
+            assertTrue(c.get(3) instanceof XmlSchemaKeyref);
+            XmlSchemaKeyref keyref = (XmlSchemaKeyref) c.get(3);
+            assertEquals("keyRefTest2", keyref.getName());
+            assertEquals(new QName("http://soapinterop.org/types", "keyTest2"), keyref.getRefer());
+
+            XmlSchemaXPath selectorXpath = keyref.getSelector();
+            assertEquals("tns:manufacturers/tns:location/tns:productName", selectorXpath.getXPath());
+
+            List<XmlSchemaXPath> fields = keyref.getFields();
+            assertEquals(1, fields.size());
+            XmlSchemaXPath fieldXpath = null;
+            for (int j = 0; j < fields.size(); j++) {
+                fieldXpath = fields.get(j);
+            }
+            assertNotNull(fieldXpath);
+            assertEquals("@productId", fieldXpath.getXPath());
+
+        }
+        {
+            assertTrue(c.get(4) instanceof XmlSchemaUnique);
+            XmlSchemaUnique unique = (XmlSchemaUnique) c.get(4);
+            assertNotNull(unique);
+            assertEquals("uniqueTest", unique.getName());
+            XmlSchemaXPath selectorXpath = unique.getSelector();
+            assertEquals("tns:manufacturers/tns:location", selectorXpath.getXPath());
+
+            List<XmlSchemaXPath> fields = unique.getFields();
+            assertEquals(1, fields.size());
+            XmlSchemaXPath fieldXpath = null;
+            for (int j = 0; j < fields.size(); j++) {
+                fieldXpath = fields.get(j);
+            }
+            assertNotNull(fieldXpath);
+            assertEquals("@district", fieldXpath.getXPath());
+        }
+        {
+            assertTrue(c.get(5) instanceof XmlSchemaUnique);
+            XmlSchemaUnique unique = (XmlSchemaUnique) c.get(5);
+            assertNotNull(unique);
+            assertEquals("uniqueTest2", unique.getName());
+            XmlSchemaXPath selectorXpath = unique.getSelector();
+            assertEquals("tns:products/tns:productName", selectorXpath.getXPath());
+
+            List<XmlSchemaXPath> fields = unique.getFields();
+            assertEquals(1, fields.size());
+            XmlSchemaXPath fieldXpath = null;
+            for (int j = 0; j < fields.size(); j++) {
+                fieldXpath = fields.get(j);
             }
-            s.remove(o.getClass().getName());
+            assertNotNull(fieldXpath);
+            assertEquals("@productId", fieldXpath.getXPath());
         }
 
-        assertTrue("The set should have been empty, but instead contained: " + s + ".", s.isEmpty());
-        
         StringWriter writer = new StringWriter();
         schema.write(writer);
         String str = writer.toString();
-        assertTrue(str.contains("uniqueTest"));
-        assertTrue(str.contains("uniqueTest2"));
+        assertTrue(str.contains("name=\"uniqueTest\""));
+        assertTrue(str.contains("name=\"uniqueTest2\""));
+        assertTrue(str.contains("name=\"keyTest\""));
+        assertTrue(str.contains("name=\"keyTest2\""));
+        assertTrue(str.contains("name=\"keyRefTest\""));
+        assertTrue(str.contains("name=\"keyRefTest2\""));
     }
 
 }

Modified: webservices/xmlschema/trunk/xmlschema-core/src/test/resources/constraints.xsd
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/resources/constraints.xsd?rev=1310816&r1=1310815&r2=1310816&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/resources/constraints.xsd (original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/resources/constraints.xsd Sat Apr
 7 18:36:36 2012
@@ -16,75 +16,84 @@
   ~ specific language governing permissions and limitations
   ~ under the License.
   -->
-<schema xmlns="http://www.w3.org/2001/XMLSchema"
-        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:tns="http://soapinterop.org/types"
         targetNamespace="http://soapinterop.org/types"
         elementFormDefault="qualified">
 
-  <element name="constraintTest">
-    <complexType>
-      <sequence>
-        <element name="manufacturers" type="tns:ManufacturerType"/>
-        <element name="products" type="tns:ProductType"/>
-      </sequence>
-    </complexType>
-
-    <unique name="uniqueTest">
-      <selector xpath="tns:manufacturers/tns:location"/>
-      <field xpath="@district"/>
-    </unique>
-    <unique name="uniqueTest2">
-      <selector xpath="tns:products/tns:productName"/>
-      <field xpath="@id"/>
-    </unique>
-
-    <key name="keyTest">
-      <selector xpath="tns:products/tns:productName"/>
-      <field xpath="@productId"/>
-    </key>
-
-    <keyref name="keyRefTest" refer="tns:keyTest">
-      <selector xpath="tns:manufacturers/tns:location/tns:productName"/>
-      <field xpath="@productId"/>
-    </keyref>
-
-  </element>
-
-  <complexType name="ManufacturerType">
-    <sequence>
-      <element name="location" maxOccurs="unbounded">
-        <complexType>
-          <sequence>
-            <element name="productName" maxOccurs="unbounded">
-              <complexType>
-                <complexContent>
-                  <extension base="string">
-                    <attribute name="productId" type="integer"/>
-                    <attribute name="units" type="integer"/>
-                  </extension>
-                </complexContent>
-              </complexType>
-            </element>
-          </sequence>
-          <attribute name="district" type="integer"/>
-        </complexType>
-      </element>
-    </sequence>
-  </complexType>
-
-  <complexType name="ProductType">
-    <sequence>
-      <element name="productName" maxOccurs="unbounded">
-        <complexType>
-          <simpleContent>
-            <extension base="string">
-              <attribute name="productId" type="integer"/>
-            </extension>
-          </simpleContent>
-        </complexType>
-      </element>
-    </sequence>
-  </complexType>
+  <xsd:element name="constraintTest">
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element name="manufacturers" type="tns:ManufacturerType"/>
+        <xsd:element name="products" type="tns:ProductType"/>
+      </xsd:sequence>
+    </xsd:complexType>
+
+    <xsd:unique name="uniqueTest">
+      <xsd:selector xpath="tns:manufacturers/tns:location"/>
+      <xsd:field xpath="@district"/>
+    </xsd:unique>
+    <xsd:unique name="uniqueTest2">
+      <xsd:selector xpath="tns:products/tns:productName"/>
+      <xsd:field xpath="@productId"/>
+    </xsd:unique>
+
+    <xsd:key name="keyTest">
+      <xsd:selector xpath="tns:products/tns:productName"/>
+      <xsd:field xpath="@productId"/>
+    </xsd:key>
+
+    <xsd:keyref name="keyRefTest" refer="tns:keyTest">
+      <xsd:selector xpath="tns:manufacturers/tns:location/tns:productName"/>
+      <xsd:field xpath="@productId"/>
+    </xsd:keyref>
+
+      <xsd:key name="keyTest2">
+          <xsd:selector xpath="tns:products/tns:productName"/>
+          <xsd:field xpath="@productId"/>
+      </xsd:key>
+
+      <xsd:keyref name="keyRefTest2" refer="tns:keyTest2">
+          <xsd:selector xpath="tns:manufacturers/tns:location/tns:productName"/>
+          <xsd:field xpath="@productId"/>
+      </xsd:keyref>
+
+  </xsd:element>
+
+  <xsd:complexType name="ManufacturerType">
+    <xsd:sequence>
+      <xsd:element name="location" maxOccurs="unbounded">
+        <xsd:complexType>
+          <xsd:sequence>
+            <xsd:element name="productName" maxOccurs="unbounded">
+              <xsd:complexType>
+                <xsd:complexContent>
+                  <xsd:extension base="string">
+                    <xsd:attribute name="productId" type="integer"/>
+                    <xsd:attribute name="units" type="integer"/>
+                  </xsd:extension>
+                </xsd:complexContent>
+              </xsd:complexType>
+            </xsd:element>
+          </xsd:sequence>
+          <xsd:attribute name="district" type="integer"/>
+        </xsd:complexType>
+      </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="ProductType">
+    <xsd:sequence>
+      <xsd:element name="productName" maxOccurs="unbounded">
+        <xsd:complexType>
+          <xsd:simpleContent>
+            <xsd:extension base="string">
+              <xsd:attribute name="productId" type="integer"/>
+            </xsd:extension>
+          </xsd:simpleContent>
+        </xsd:complexType>
+      </xsd:element>
+    </xsd:sequence>
+  </xsd:complexType>
 
-</schema>
\ No newline at end of file
+</xsd:schema>
\ No newline at end of file



Mime
View raw message