Change XmlSchemaAnnotation to use List<> instead of XmlSchemaCollection. Introduce common parent class for appInfo and documentation.


git-svn-id: https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/XmlSchema@764346 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java b/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
index c0856d0..a718797 100644
--- a/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
+++ b/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
@@ -231,7 +231,8 @@
      * add it to annotation collection

      */

     XmlSchemaAnnotation handleAnnotation(Element annotEl) {

-        XmlSchemaObjectCollection content = new XmlSchemaObjectCollection();

+        XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();

+        List<XmlSchemaAnnotationItem> content = annotation.getItems();

         XmlSchemaAppInfo appInfoObj;

         XmlSchemaDocumentation docsObj;

 

@@ -256,9 +257,6 @@
             }

         }

 

-        XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();

-        annotation.items = content;

-

         // process extra attributes and elements

         processExtensibilityComponents(annotation, annotEl);

         return annotation;

diff --git a/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java b/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java
index f015821..c5e7c53 100644
--- a/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java
+++ b/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java
@@ -19,21 +19,24 @@
 

 package org.apache.ws.commons.schema;

 

+import java.util.ArrayList;

+import java.util.List;

+

 /**

  * Defines an annotation. Represents the World Wide Web Consortium (W3C) annotation element.

  */

 

 public class XmlSchemaAnnotation extends XmlSchemaObject {

-    XmlSchemaObjectCollection items;

+    private List<XmlSchemaAnnotationItem> items;

 

     /**

      * Creates new XmlSchemaAnnotation

      */

     public XmlSchemaAnnotation() {

-        items = new XmlSchemaObjectCollection();

+        items = new ArrayList<XmlSchemaAnnotationItem>();

     }

 

-    public XmlSchemaObjectCollection getItems() {

+    public List<XmlSchemaAnnotationItem> getItems() {

         return items;

     }

 }

diff --git a/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotationItem.java b/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotationItem.java
new file mode 100644
index 0000000..57be325
--- /dev/null
+++ b/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotationItem.java
@@ -0,0 +1,28 @@
+/**
+ * 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.ws.commons.schema;
+
+/**
+ * Common base class of the items that can live inside an annotation.
+ */
+public class XmlSchemaAnnotationItem
+    extends XmlSchemaObject {
+
+}
diff --git a/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java b/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java
index e91cf17..a86e6b3 100644
--- a/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java
+++ b/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java
@@ -28,7 +28,7 @@
 

 // Jan 24 2002 - Joni - Change the Node into NodeList

 

-public class XmlSchemaAppInfo extends XmlSchemaObject {

+public class XmlSchemaAppInfo extends XmlSchemaAnnotationItem {

 

     /**

      * Provides the source of the application information.

diff --git a/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java b/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java
index 8f5e545..d363d1f 100644
--- a/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java
+++ b/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java
@@ -26,7 +26,7 @@
  * Wide Web Consortium (W3C) documentation element.

  */

 

-public class XmlSchemaDocumentation extends XmlSchemaObject {

+public class XmlSchemaDocumentation extends XmlSchemaAnnotationItem {

 

 

     /**

diff --git a/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java b/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
index 4ce2b09..5b5ec32 100644
--- a/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
+++ b/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
@@ -203,11 +203,11 @@
         Element annotation = createNewElement(doc, "annotation", schema.getSchemaNamespacePrefix(),
                                               XmlSchema.SCHEMA_NS);
 
-        XmlSchemaObjectCollection contents = annotationObj.items;
-        int contentLength = contents.getCount();
+        List<XmlSchemaAnnotationItem> contents = annotationObj.getItems();
+        int contentLength = contents.size();
 
         for (int i = 0; i < contentLength; i++) {
-            XmlSchemaObject obj = contents.getItem(i);
+            XmlSchemaObject obj = contents.get(i);
 
             if (obj instanceof XmlSchemaAppInfo) {
                 XmlSchemaAppInfo appinfo = (XmlSchemaAppInfo)obj;
diff --git a/src/test/java/tests/AnnotationDeepTest.java b/src/test/java/tests/AnnotationDeepTest.java
index 28c4fa8..4da54e5 100644
--- a/src/test/java/tests/AnnotationDeepTest.java
+++ b/src/test/java/tests/AnnotationDeepTest.java
@@ -20,6 +20,7 @@
 
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.util.List;
 
 import javax.xml.transform.stream.StreamSource;
 
@@ -32,9 +33,9 @@
 
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAnnotation;
+import org.apache.ws.commons.schema.XmlSchemaAnnotationItem;
 import org.apache.ws.commons.schema.XmlSchemaAppInfo;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
 
 public class AnnotationDeepTest extends TestCase {
     
@@ -76,8 +77,8 @@
         
         XmlSchemaAnnotation annotation = schema.getAnnotation();
         assertTrue("annotation is retrieved ok", null != annotation);
-        XmlSchemaObjectCollection items = annotation.getItems();
-        assertEquals("Annotation contains an appinfo and yet this fails", 1, items.getCount());
+        List<XmlSchemaAnnotationItem> items = annotation.getItems();
+        assertEquals("Annotation contains an appinfo and yet this fails", 1, items.size());
 
     }
 
@@ -119,9 +120,9 @@
         
         XmlSchemaAnnotation annotation = schema.getAnnotation();
         assertTrue("annotation is retrieved ok", null != annotation);
-        XmlSchemaObjectCollection items = annotation.getItems();
-        assertTrue(items.getItem(0) instanceof XmlSchemaAppInfo);
-        XmlSchemaAppInfo appInfo = (XmlSchemaAppInfo) items.getItem(0);
+        List<XmlSchemaAnnotationItem> items = annotation.getItems();
+        assertTrue(items.get(0) instanceof XmlSchemaAppInfo);
+        XmlSchemaAppInfo appInfo = (XmlSchemaAppInfo) items.get(0);
         NodeList markup = appInfo.getMarkup();
         assertTrue("The markup exists", null != markup);
         Node node = markup.item(1);
diff --git a/src/test/java/tests/AnnotationTest.java b/src/test/java/tests/AnnotationTest.java
index 886de7e..823eab5 100644
--- a/src/test/java/tests/AnnotationTest.java
+++ b/src/test/java/tests/AnnotationTest.java
@@ -21,6 +21,7 @@
 import java.io.FileInputStream;

 import java.io.InputStream;

 import java.util.HashSet;

+import java.util.List;

 import java.util.Set;

 

 import javax.xml.namespace.QName;

@@ -31,11 +32,11 @@
 

 import org.apache.ws.commons.schema.XmlSchema;

 import org.apache.ws.commons.schema.XmlSchemaAnnotation;

+import org.apache.ws.commons.schema.XmlSchemaAnnotationItem;

 import org.apache.ws.commons.schema.XmlSchemaAppInfo;

 import org.apache.ws.commons.schema.XmlSchemaCollection;

 import org.apache.ws.commons.schema.XmlSchemaDocumentation;

 import org.apache.ws.commons.schema.XmlSchemaObject;

-import org.apache.ws.commons.schema.XmlSchemaObjectCollection;

 import org.apache.ws.commons.schema.XmlSchemaSimpleType;

 

 import org.junit.Assert;

@@ -69,13 +70,13 @@
         XmlSchemaAnnotation xsa = simpleType.getAnnotation();

         assertNotNull(xsa);

 

-        XmlSchemaObjectCollection col = xsa.getItems();

-        assertEquals(1, col.getCount());

+        List<XmlSchemaAnnotationItem> col = xsa.getItems();

+        assertEquals(1, col.size());

 

         Set<String> s = new HashSet<String>();

         s.add(XmlSchemaDocumentation.class.getName());

-        for (int i = 0; i < col.getCount(); i++) {

-            XmlSchemaObject o = col.getItem(i);

+        for (int i = 0; i < col.size(); i++) {

+            XmlSchemaObject o = col.get(i);

             if (o instanceof XmlSchemaAppInfo) {

                 fail("The appinfo element did not contain a source"

                      + " attribute or any content, so this element" + " was not exptected to be found.");

@@ -121,13 +122,13 @@
         XmlSchemaAnnotation xsa = simpleType.getAnnotation();

         assertNotNull(xsa);

 

-        XmlSchemaObjectCollection col = xsa.getItems();

-        assertEquals(1, col.getCount());

+        List<XmlSchemaAnnotationItem> col = xsa.getItems();

+        assertEquals(1, col.size());

 

         Set<String> s = new HashSet<String>();

         s.add(XmlSchemaAppInfo.class.getName());

-        for (int i = 0; i < col.getCount(); i++) {

-            XmlSchemaObject o = col.getItem(i);

+        for (int i = 0; i < col.size(); i++) {

+            XmlSchemaObject o = col.get(i);

             if (o instanceof XmlSchemaAppInfo) {

                 assertEquals("http://test/source/appinfo", ((XmlSchemaAppInfo)o).getSource());

                 NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();

@@ -171,8 +172,8 @@
         XmlSchemaAnnotation xsa = simpleType.getAnnotation();

         assertNotNull(xsa);

 

-        XmlSchemaObjectCollection col = xsa.getItems();

-        assertEquals(0, col.getCount());

+        List<XmlSchemaAnnotationItem> col = xsa.getItems();

+        assertEquals(0, col.size());

 

     }

 

@@ -202,14 +203,14 @@
         XmlSchemaAnnotation xsa = simpleType.getAnnotation();

         assertNotNull(xsa);

 

-        XmlSchemaObjectCollection col = xsa.getItems();

-        assertEquals(2, col.getCount());

+        List<XmlSchemaAnnotationItem> col = xsa.getItems();

+        assertEquals(2, col.size());

 

         Set<String> s = new HashSet<String>();

         s.add(XmlSchemaAppInfo.class.getName());

         s.add(XmlSchemaDocumentation.class.getName());

-        for (int i = 0; i < col.getCount(); i++) {

-            XmlSchemaObject o = col.getItem(i);

+        for (int i = 0; i < col.size(); i++) {

+            XmlSchemaObject o = col.get(i);

             if (o instanceof XmlSchemaAppInfo) {

                 assertEquals("http://test/source/appinfo", ((XmlSchemaAppInfo)o).getSource());

                 NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();

@@ -254,14 +255,14 @@
         XmlSchema schema = schemaCol.read(new StreamSource(is));

 

         XmlSchemaAnnotation xsa = schema.getAnnotation();

-        XmlSchemaObjectCollection col = xsa.getItems();

-        assertEquals(2, col.getCount());

+        List<XmlSchemaAnnotationItem> col = xsa.getItems();

+        assertEquals(2, col.size());

 

         Set<String> s = new HashSet<String>();

         s.add(XmlSchemaAppInfo.class.getName());

         s.add(XmlSchemaDocumentation.class.getName());

-        for (int i = 0; i < col.getCount(); i++) {

-            XmlSchemaObject o = col.getItem(i);

+        for (int i = 0; i < col.size(); i++) {

+            XmlSchemaObject o = col.get(i);

             if (o instanceof XmlSchemaAppInfo) {

                 assertEquals("http://test101/source/appinfo", ((XmlSchemaAppInfo)o).getSource());

                 NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();

diff --git a/src/test/java/tests/NotationTest.java b/src/test/java/tests/NotationTest.java
index 077d759..b02d149 100644
--- a/src/test/java/tests/NotationTest.java
+++ b/src/test/java/tests/NotationTest.java
@@ -22,6 +22,7 @@
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -33,6 +34,7 @@
 
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAnnotation;
+import org.apache.ws.commons.schema.XmlSchemaAnnotationItem;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaDocumentation;
 import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -117,11 +119,11 @@
             XmlSchemaNotation xsn = e.getValue();
             String name = xsn.getName();
             XmlSchemaAnnotation xsa = xsn.getAnnotation();
-            XmlSchemaObjectCollection col = xsa.getItems();
-            assertEquals(1, col.getCount());
+            List<XmlSchemaAnnotationItem> col = xsa.getItems();
+            assertEquals(1, col.size());
             XmlSchemaDocumentation xsd = null;
-            for (int k = 0; k < col.getCount(); k++) {
-                xsd = (XmlSchemaDocumentation)col.getItem(k);
+            for (int k = 0; k < col.size(); k++) {
+                xsd = (XmlSchemaDocumentation)col.get(k);
             }
             if ("teamMascot".equals(name)) {
                 assertEquals("http://www.team.com/graphics/teamMascot", xsn.getPublic());