Author: dims
Date: Sun May 21 20:28:45 2006
New Revision: 408555

URL: http://svn.apache.org/viewvc?rev=408555&view=rev
Log:
Fix for WSCOMMONS-31 from Brent Ulbricht - NPE in SchemaBuilder when using 
redefine

Added:
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine1.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine2.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine3.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine4.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine5.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine6.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine7.xsd
    webservices/commons/trunk/modules/XmlSchema/test-resources/redefine8.xsd
    webservices/commons/trunk/modules/XmlSchema/test/tests/RedefineTest.java
Modified:
    
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaRedefine.java

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaRedefine.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaRedefine.java?rev=408555&r1=408554&r2=408555&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaRedefine.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaRedefine.java
 Sun May 21 20:28:45 2006
@@ -1,55 +1,58 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * 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.
- */
-
-package org.apache.ws.commons.schema;
-
-/**
- * Allows simple and complex types, groups, and attribute groups from
- * external schema files to be redefined in the current schema. This
- * class provides versioning for the schema elements. Represents the
- * World Wide Web Consortium (W3C) redefine element.
- */
-
-public class XmlSchemaRedefine extends XmlSchemaExternal {
-
-    /**
-     * Creates new XmlSchemaRedefine
-     */
-    public XmlSchemaRedefine() {
-        items = new XmlSchemaObjectCollection();
-    }
-
-    XmlSchemaObjectTable attributeGroups, groups, schemaTypes;
-
-    public XmlSchemaObjectTable getAttributeGroup() {
-        return attributeGroups;
-    }
-
-    public XmlSchemaObjectTable getGroup() {
-        return groups;
-    }
-
-    XmlSchemaObjectCollection items;
-
-    public XmlSchemaObjectCollection getItems() {
-        return items;
-    }
-
-    public XmlSchemaObjectTable getSchemaTypes() {
-        return schemaTypes;
-    }
-
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Allows simple and complex types, groups, and attribute groups from
+ * external schema files to be redefined in the current schema. This
+ * class provides versioning for the schema elements. Represents the
+ * World Wide Web Consortium (W3C) redefine element.
+ */
+
+public class XmlSchemaRedefine extends XmlSchemaExternal {
+
+    /**
+     * Creates new XmlSchemaRedefine
+     */
+    public XmlSchemaRedefine() {
+        items = new XmlSchemaObjectCollection();
+        schemaTypes = new XmlSchemaObjectTable();
+        groups = new XmlSchemaObjectTable();
+        attributeGroups = new XmlSchemaObjectTable();
+    }
+
+    XmlSchemaObjectTable attributeGroups, groups, schemaTypes;
+
+    public XmlSchemaObjectTable getAttributeGroup() {
+        return attributeGroups;
+    }
+
+    public XmlSchemaObjectTable getGroup() {
+        return groups;
+    }
+
+    XmlSchemaObjectCollection items;
+
+    public XmlSchemaObjectCollection getItems() {
+        return items;
+    }
+
+    public XmlSchemaObjectTable getSchemaTypes() {
+        return schemaTypes;
+    }
+
+}

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine1.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine1.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine1.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine1.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,34 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+  
+  <complexType name="person">
+    <sequence>
+      <element name="firstname" type="string"/>
+      <element name="lastname" type="string"/>
+    </sequence>
+  </complexType>
+
+  <element name="customer" type="tns:person"/>
+
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine2.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine2.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine2.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine2.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,39 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+
+  <redefine schemaLocation="test-resources/redefine1.xsd">
+    <complexType name="person">
+      <complexContent>
+        <extension base="tns:person">
+          <sequence>
+            <element name="id" type="string"/>
+          </sequence>
+        </extension>
+      </complexContent>
+    </complexType>
+  </redefine>
+
+  <element name="vip" type="tns:person"/>
+
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine3.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine3.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine3.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine3.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,28 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+  
+  <xsd:simpleType name="drinksize">
+    <xsd:restriction base="xsd:integer"/>
+  </xsd:simpleType>
+          
+  <xsd:element name="size" type="drinksize"/>
+
+</xsd:schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine4.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine4.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine4.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine4.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,36 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+
+  <redefine schemaLocation="test-resources/redefine3.xsd">
+    <simpleType name="drinksize">
+      <restriction base="tns:drinksize">
+        <minInclusive value="1"/>
+        <maxInclusive value="3"/>
+      </restriction>
+    </simpleType>
+  </redefine>
+          
+  <element name="childsizedrink" type="tns:drinksize"/>
+
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine5.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine5.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine5.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine5.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,33 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+  
+  <group name="PrologGroup">
+    <sequence>
+      <element name="date" type="string"/>
+      <element name="author" type="string"/>
+      <element name="defect" type="integer"/>
+    </sequence>
+  </group>
+          
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine6.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine6.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine6.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine6.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,34 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+
+  <redefine schemaLocation="test-resources/redefine5.xsd">
+    <group name="PrologGroup">
+      <sequence>
+        <group ref="tns:PrologGroup"/>
+        <element name="description" type="string"/>
+      </sequence>
+    </group>
+  </redefine>
+
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine7.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine7.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine7.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine7.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,31 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+  
+  <attributeGroup name="AttribGroup">
+    <attribute name="type" type="string"/>
+    <attribute name="units" type="string"/>
+    <attribute name="serialId" type="string"/>
+  </attributeGroup>
+          
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test-resources/redefine8.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/redefine8.xsd?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/redefine8.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/redefine8.xsd 
Sun May 21 20:28:45 2006
@@ -0,0 +1,32 @@
+<!--
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+-->
+
+<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";>
+
+  <redefine schemaLocation="test-resources/redefine7.xsd">
+    <attributeGroup name="AttribGroup">
+      <attribute name="type" type="string"/>
+      <attribute name="units" type="string"/>
+    </attributeGroup>
+  </redefine>
+
+</schema>
\ No newline at end of file

Added: webservices/commons/trunk/modules/XmlSchema/test/tests/RedefineTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/RedefineTest.java?rev=408555&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/RedefineTest.java 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/RedefineTest.java 
Sun May 21 20:28:45 2006
@@ -0,0 +1,459 @@
+package tests;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.xml.namespace.QName;
+
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaObjectTable;
+import org.apache.ws.commons.schema.XmlSchemaRedefine;
+import org.apache.ws.commons.schema.XmlSchemaComplexType;
+import org.apache.ws.commons.schema.XmlSchemaParticle;
+import org.apache.ws.commons.schema.XmlSchemaContentModel;
+import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
+import org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaGroup;
+import org.apache.ws.commons.schema.XmlSchemaGroupRef;
+import org.apache.ws.commons.schema.XmlSchemaAttributeGroup;
+import org.apache.ws.commons.schema.XmlSchemaAttribute;
+
+/*
+ * Copyright 2004,2005 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.
+ * 
+ * @author Brent Ulbricht 
+ */
+public class RedefineTest extends TestCase {
+
+    /**
+     * This method will test a complex type redefine.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testComplexTypeRedefine() throws Exception {
+
+        /*
+        redefine1.xsd
+        -----------------
+        
+        <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";>
+  
+          <complexType name="person">
+            <sequence>
+              <element name="firstname" type="string"/>
+              <element name="lastname" type="string"/>
+            </sequence>
+          </complexType>
+
+          <element name="customer" type="tns:person"/>
+
+        </schema>
+        
+                         
+        redefine2.xsd
+        -----------------
+        
+        <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";>
+
+          <redefine schemaLocation="test-resources/redefine1.xsd">
+            <complexType name="person">
+              <complexContent>
+                <extension base="tns:person">
+                  <sequence>
+                    <element name="id" type="string"/>
+                  </sequence>
+                </extension>
+              </complexContent>
+            </complexType>
+          </redefine>
+
+          <element name="vip" type="tns:person"/>
+
+        </schema>
+        */
+
+        InputStream is = new FileInputStream("test-resources/redefine2.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaObjectTable xsot = schema.getElements();
+        assertEquals(1, xsot.getCount());
+
+        XmlSchemaElement xse = null;
+        for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+            xse = (XmlSchemaElement)i.next();
+        }
+        assertEquals("vip", xse.getName());
+        assertEquals(new QName("http://soapinterop.org/types";,
+                               "person"),
+                     xse.getSchemaTypeName());
+
+        XmlSchemaObjectCollection xsoc = schema.getIncludes();
+        assertEquals(1, xsoc.getCount());
+        
+        XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+        xsot = xsr.getSchemaTypes();
+        assertEquals(1, xsot.getCount());
+
+        for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+            QName qname = (QName)i.next();
+            assertEquals(new QName("http://soapinterop.org/types";,
+                                   "person"), qname);
+        }
+
+        XmlSchemaComplexType xsct = null;
+        for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+            xsct = (XmlSchemaComplexType)i.next();
+        }
+        assertNotNull(xsct);
+
+        XmlSchemaContentModel xscm = xsct.getContentModel();
+        assertNotNull(xscm);
+
+        XmlSchemaComplexContentExtension xscce =
+            (XmlSchemaComplexContentExtension)xscm.getContent();
+        assertEquals(new QName("http://soapinterop.org/types";,
+                               "person"),
+                     xscce.getBaseTypeName());
+
+        XmlSchemaSequence xsp = (XmlSchemaSequence)xscce.getParticle();
+        assertNotNull(xsp);
+
+        XmlSchemaObjectCollection c = xsp.getItems();
+        assertEquals(1, c.getCount());
+
+        xse = null;
+        for (int i = 0; i < c.getCount(); i++) {
+            xse = (XmlSchemaElement)c.getItem(i);
+        }
+        assertEquals("id", xse.getName());
+        assertEquals(new QName("http://www.w3.org/2001/XMLSchema";,
+                               "string"),
+                     xse.getSchemaTypeName());
+
+    }
+
+    /**
+     * This method will test a simple type redefine.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testSimpleTypeRedefine() throws Exception {
+        /*
+        
+        redefine3.xsd
+        -----------------
+        
+        <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";>
+  
+          <simpleType name="drinksize">
+            <restriction base="integer"/>
+          </simpleType>
+          
+          <element name="size" type="tns:drinksize"/>
+
+        </schema>
+        
+                                                  
+        redefine4.xsd
+        -----------------
+        
+        <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";>
+
+          <redefine schemaLocation="test-resources/redefine3.xsd">
+            <simpleType name="drinksize">
+              <restriction base="tns:drinksize">
+                <minInclusive value="1"/>
+                <maxInclusive value="3"/>
+              </restriction>
+            </simpleType>
+          </redefine>
+          
+          <element name="childsizedrink" type="tns:drinksize"/>
+
+        </schema>
+        */
+
+        InputStream is = new FileInputStream("test-resources/redefine4.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaObjectTable xsot = schema.getElements();
+        assertEquals(1, xsot.getCount());
+
+        XmlSchemaElement xse = null;
+        for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+            xse = (XmlSchemaElement)i.next();
+        }
+        assertEquals("childsizedrink", xse.getName());
+        assertEquals(new QName("http://soapinterop.org/types";,
+                               "drinksize"),
+                     xse.getSchemaTypeName());
+
+        XmlSchemaObjectCollection xsoc = schema.getIncludes();
+        assertEquals(1, xsoc.getCount());
+        
+        XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+        xsot = xsr.getSchemaTypes();
+        assertEquals(1, xsot.getCount());
+
+        for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+            QName qname = (QName)i.next();
+            assertEquals(new QName("http://soapinterop.org/types";,
+                                   "drinksize"), qname);
+        }
+
+        XmlSchemaSimpleType xsst = null;
+        for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+            xsst = (XmlSchemaSimpleType)i.next();
+        }
+        assertNotNull(xsst);
+
+        XmlSchemaSimpleTypeRestriction xsstr =
+            (XmlSchemaSimpleTypeRestriction)xsst.getContent();
+        assertEquals(new QName("http://soapinterop.org/types";,
+                               "drinksize"),
+                     xsstr.getBaseTypeName());
+
+        xsoc = xsstr.getFacets();
+
+        Set s = new HashSet();
+        s.add(XmlSchemaMinInclusiveFacet.class.getName());
+        s.add(XmlSchemaMaxInclusiveFacet.class.getName());
+        for (Iterator i  = xsoc.getIterator(); i.hasNext(); ) {
+            Object o = i.next();
+            assertTrue(s.remove(o.getClass().getName()));
+            if (o instanceof XmlSchemaMinInclusiveFacet) {
+                assertEquals("1", ((XmlSchemaMinInclusiveFacet)o).getValue());
+            } else if (o instanceof XmlSchemaMaxInclusiveFacet) {
+                assertEquals("3", ((XmlSchemaMaxInclusiveFacet)o).getValue());
+            } else {
+                fail("Unexpected object encountered: "
+                     + o.getClass().getName());
+            }
+        }
+
+        assertTrue("The set should have been empty, but instead contained: "
+                   + s + ".",
+                   s.isEmpty());
+
+    }
+
+    /**
+     * This method will test a group redefine.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testGroupRedefine() throws Exception {
+
+        /*
+        redefine5.xsd
+        -----------------
+        
+        <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";>
+  
+          <group name="PrologGroup">
+            <sequence>
+              <element name="date" type="string"/>
+              <element name="author" type="string"/>
+              <element name="defect" type="integer"/>
+            </sequence>
+          </group>
+          
+        </schema>
+
+
+        redefine6.xsd
+        -----------------
+
+        <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";>
+
+          <redefine schemaLocation="redefine5.xsd">
+            <group name="PrologGroup">
+              <sequence>
+                <group ref="tns:PrologGroup"/>
+                <element name="description" type="string"/>
+              </sequence>
+            </group>
+          </redefine>
+
+        </schema>
+        */
+
+        InputStream is = new FileInputStream("test-resources/redefine6.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaObjectCollection xsoc = schema.getIncludes();
+        assertEquals(1, xsoc.getCount());
+        
+        XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+        XmlSchemaObjectTable xsot = xsr.getGroup();
+        assertEquals(1, xsot.getCount());
+
+        for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+            assertEquals("PrologGroup", (String)i.next());
+        }
+
+        XmlSchemaGroup xsg = null;
+        for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+            xsg = (XmlSchemaGroup)i.next();
+        }
+
+        XmlSchemaSequence xss = (XmlSchemaSequence)xsg.getParticle();
+
+        xsoc = xss.getItems();
+        assertEquals(2, xsoc.getCount());
+        
+        Set s = new HashSet();
+        s.add(XmlSchemaGroupRef.class.getName());
+        s.add(XmlSchemaElement.class.getName());
+        for (Iterator i  = xsoc.getIterator(); i.hasNext(); ) {
+            Object o = i.next();
+            assertTrue(s.remove(o.getClass().getName()));
+            if (o instanceof XmlSchemaGroupRef) {
+                assertEquals(new QName("http://soapinterop.org/types";,
+                                       "PrologGroup"),
+                             ((XmlSchemaGroupRef)o).getRefName());
+            } else if (o instanceof XmlSchemaElement) {
+                assertEquals("description", ((XmlSchemaElement)o).getName());
+            } else {
+                fail("Unexpected object encountered: "
+                     + o.getClass().getName());
+            }
+        }
+
+        assertTrue("The set should have been empty, but instead contained: "
+                   + s + ".",
+                   s.isEmpty());
+
+    }
+
+    /**
+     * This method will test a attribute group redefine.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testAttributeGroupRedefine() throws Exception {
+
+        /*
+        redefine7.xsd
+        -----------------
+        
+        <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";>
+  
+          <attributeGroup name="AttribGroup">
+            <attribute name="type" type="string"/>
+            <attribute name="units" type="string"/>
+            <attribute name="serialId" type="string"/>
+          </attributeGroup>
+          
+        </schema>
+
+
+        redefine8.xsd
+        -----------------
+
+        <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";>
+
+          <redefine schemaLocation="redefine7.xsd">
+            <attributeGroup name="AttribGroup">
+              <attribute name="type" type="string"/>
+              <attribute name="units" type="string"/>
+            </attributeGroup>
+          </redefine>
+
+        </schema>
+        */
+
+        InputStream is = new FileInputStream("test-resources/redefine8.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaObjectCollection xsoc = schema.getIncludes();
+        assertEquals(1, xsoc.getCount());
+        
+        XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+        XmlSchemaObjectTable xsot = xsr.getAttributeGroup();
+        assertEquals(1, xsot.getCount());
+
+        for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+            assertEquals("AttribGroup", (String)i.next());
+        }
+
+        XmlSchemaAttributeGroup xsag = null;
+        for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+            xsag = (XmlSchemaAttributeGroup)i.next();
+        }
+        assertEquals("AttribGroup", xsag.getName());
+        xsoc = xsag.getAttributes();
+
+        Set s = new HashSet();
+        s.add("type");
+        s.add("units");
+        for (Iterator i  = xsoc.getIterator(); i.hasNext(); ) {
+            XmlSchemaAttribute xsa = (XmlSchemaAttribute)i.next();
+            assertTrue(s.remove(xsa.getName()));
+        }
+
+        assertTrue("The set should have been empty, but instead contained: "
+                   + s + ".",
+                   s.isEmpty());
+        
+    }
+
+
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to