You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by aj...@apache.org on 2007/05/22 08:29:14 UTC

svn commit: r540446 - in /webservices/commons/trunk/modules/XmlSchema/src: main/java/org/apache/ws/commons/schema/ test/java/tests/ test/test-resources/

Author: ajith
Date: Mon May 21 23:29:13 2007
New Revision: 540446

URL: http://svn.apache.org/viewvc?view=rev&rev=540446
Log:
1. fixed the Jira 73 (https://issues.apache.org/jira/browse/WSCOMMONS-73)
 i. added code to populate the min/max occurences in relevant particles
 ii. Added / modified the test cases to test it

The test cases need to be improved further!!!!

Added:
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SequenceTest.java
    webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/sequence.xsd
Modified:
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java
    webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/choice.xsd

Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java?view=diff&rev=540446&r1=540445&r2=540446
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java Mon May 21 23:29:13 2007
@@ -916,6 +916,11 @@
                                              Element schemaEl) {
 
         XmlSchemaSequence sequence = new XmlSchemaSequence();
+
+        //handle min and max occurences
+        sequence.minOccurs = getMinOccurs(sequenceEl);
+        sequence.maxOccurs = getMaxOccurs(sequenceEl);
+
         for (Element el = XDOMUtil.getFirstChildElementNS(sequenceEl, XmlSchema.SCHEMA_NS)
                 ; el != null;
                   el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
@@ -1026,6 +1031,10 @@
 
         XmlSchemaAll all = new XmlSchemaAll();
 
+          //handle min and max occurences
+        all.minOccurs = getMinOccurs(allEl);
+        all.maxOccurs = getMaxOccurs(allEl);
+
         for (Element el = XDOMUtil.getFirstChildElementNS(allEl, XmlSchema.SCHEMA_NS);
              el != null; el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
 
@@ -1046,6 +1055,7 @@
         XmlSchemaGroup group = new XmlSchemaGroup();
         group.name = new QName(schema.getTargetNamespace(),groupEl.getAttribute("name"));
 
+
         for (Element el = XDOMUtil.getFirstChildElementNS(groupEl,
                 XmlSchema.SCHEMA_NS);
              el != null;
@@ -1139,6 +1149,9 @@
                                              Element groupEl, Element schemaEl) {
 
         XmlSchemaGroupRef group = new XmlSchemaGroupRef();
+        
+        group.maxOccurs  = getMaxOccurs(groupEl);
+        group.minOccurs  = getMinOccurs(groupEl);
 
         Element annotationEl = XDOMUtil.getFirstChildElementNS(groupEl,
                 XmlSchema.SCHEMA_NS,

Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java?view=diff&rev=540446&r1=540445&r2=540446
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ChoiceTest.java Mon May 21 23:29:13 2007
@@ -55,8 +55,11 @@
         </schema>
         */
 
-        QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
-                                        "computer");
+        QName computerElementQname = new QName("http://soapinterop.org/types",
+                                        "computer");      
+        QName mbElementQname = new QName("http://soapinterop.org/types",
+                                        "motherboard");
+        
         InputStream is = new FileInputStream(Resources.asURI("choice.xsd"));
         XmlSchemaCollection schemaCol = new XmlSchemaCollection();
         XmlSchema schema = schemaCol.read(new StreamSource(is), null);
@@ -65,7 +68,7 @@
                                       "machine");
         XmlSchemaElement elem = schemaCol.getElementByQName(WRONG_QNAME);
         assertNull(elem);
-        elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+        elem = schemaCol.getElementByQName(computerElementQname);
         assertEquals("computer", elem.getName());
         assertEquals(new QName("http://soapinterop.org/types", "computer"),
                      elem.getQName());
@@ -101,6 +104,23 @@
         assertTrue("The set should have been empty, but instead contained: "
                    + s + ".",
                    s.isEmpty());
+
+        //test min and max occurs
+        elem = schemaCol.getElementByQName(mbElementQname);
+        assertEquals("motherboard", elem.getName());
+        assertEquals(new QName("http://soapinterop.org/types", "motherboard"),
+                     elem.getQName());
+
+        cType = (XmlSchemaComplexType)elem.getSchemaType();
+        assertNotNull(cType);
+
+        choice = (XmlSchemaChoice)cType.getParticle();
+        assertNotNull(choice);
+
+        //values from the XML file
+        assertEquals(choice.getMinOccurs(),1);
+        assertEquals(choice.getMaxOccurs(),6);
+
     }
 
 }

Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SequenceTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SequenceTest.java?view=auto&rev=540446
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SequenceTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/SequenceTest.java Mon May 21 23:29:13 2007
@@ -0,0 +1,88 @@
+package tests;
+
+import junit.framework.TestCase;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.ws.commons.schema.*;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.
+ *
+ */
+public class SequenceTest extends TestCase {
+
+    /**
+     * This method will test the sequence - the min and max occurences.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testChoice() throws Exception {
+
+        /*
+        <schema xmlns="http://www.w3.org/2001/XMLSchema"
+                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+                xmlns:tns="http://soapinterop.org/types"
+                targetNamespace="http://soapinterop.org/types">
+
+           <element name="computer">
+            <complexType>
+              <sequence minOccurs="4" maxOccurs="50">
+                <element name="desktop" type="string"/>
+                <element name="laptop" type="string"/>
+              </sequence>
+            </complexType>
+          </element>
+
+        </schema>
+        */
+
+        QName computerElementQname = new QName("http://soapinterop.org/types",
+                                        "computer");
+
+
+        InputStream is = new FileInputStream(Resources.asURI("sequence.xsd"));
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        QName WRONG_QNAME = new QName("http://soapinterop.org/types",
+                                      "machine");
+        XmlSchemaElement elem = schemaCol.getElementByQName(WRONG_QNAME);
+        assertNull(elem);
+        elem = schemaCol.getElementByQName(computerElementQname);
+        assertEquals("computer", elem.getName());
+        assertEquals(new QName("http://soapinterop.org/types", "computer"),
+                     elem.getQName());
+
+        XmlSchemaComplexType cType = (XmlSchemaComplexType)elem.getSchemaType();
+        assertNotNull(cType);
+
+        XmlSchemaSequence sequence = (XmlSchemaSequence)cType.getParticle();
+        assertNotNull(sequence);
+
+        //values from the XML file
+        assertEquals(sequence.getMinOccurs(),4);
+        assertEquals(sequence.getMaxOccurs(),50);
+
+    }
+
+}

Modified: webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/choice.xsd
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/choice.xsd?view=diff&rev=540446&r1=540445&r2=540446
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/choice.xsd (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/choice.xsd Mon May 21 23:29:13 2007
@@ -29,4 +29,13 @@
     </complexType>
   </element>
 
+    <element name="motherboard">
+    <complexType>
+      <choice minOccurs="1" maxOccurs="6">
+        <element name="PCI" type="string"/>
+        <element name="ISA" type="string"/>
+        <element name="USB" type="string"/>
+      </choice>
+    </complexType>
+  </element>
 </schema>

Added: webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/sequence.xsd
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/sequence.xsd?view=auto&rev=540446
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/sequence.xsd (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/sequence.xsd Mon May 21 23:29:13 2007
@@ -0,0 +1,33 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+        xmlns:tns="http://soapinterop.org/types"
+        targetNamespace="http://soapinterop.org/types">
+
+  <element name="computer">
+    <complexType>
+      <sequence minOccurs="4" maxOccurs="50">
+        <element name="desktop" type="string"/>
+        <element name="laptop" type="string"/>
+      </sequence>
+    </complexType>
+  </element>
+
+
+</schema>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org