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 bi...@apache.org on 2009/04/07 03:36:36 UTC

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

Author: bimargulies
Date: Tue Apr  7 01:36:35 2009
New Revision: 762589

URL: http://svn.apache.org/viewvc?rev=762589&view=rev
Log:
WSCOMMONS-430, WSCOMMONS-458 for Attribute Groups.

Modified:
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java

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?rev=762589&r1=762588&r2=762589&view=diff
==============================================================================
--- 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 Tue Apr  7 01:36:35 2009
@@ -1632,11 +1632,7 @@
             currentSchema.groups.collection.put(group.getQName(), group);
             currentSchema.items.add(group);
         } else if (el.getLocalName().equals("attributeGroup")) {
-            XmlSchemaAttributeGroup group = handleAttributeGroup(currentSchema,
-                    el, schemaEl);
-            currentSchema.attributeGroups.collection.put(group.getQName(),
-                    group);
-            currentSchema.items.add(group);
+            handleAttributeGroup(currentSchema, el, schemaEl);
         } else if (el.getLocalName().equals("attribute")) {
             XmlSchemaAttribute attr = handleAttribute(currentSchema, el,
                     schemaEl, true); // pass true to

Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java?rev=762589&r1=762588&r2=762589&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java Tue Apr  7 01:36:35 2009
@@ -57,10 +57,8 @@
     static final String SCHEMA_NS = XMLConstants.W3C_XML_SCHEMA_NS_URI;
     private static final String UTF_8_ENCODING = "UTF-8";
 
-    XmlSchemaForm attributeFormDefault;
-    XmlSchemaForm elementFormDefault;
 
-    XmlSchemaObjectTable attributeGroups;
+    Map<QName, XmlSchemaAttributeGroup> attributeGroups;
     XmlSchemaObjectTable attributes;
     XmlSchemaObjectTable elements;
     XmlSchemaObjectTable groups;
@@ -76,6 +74,8 @@
     String schemaNamespacePrefix = "";
     XmlSchemaCollection parent;
 
+    private XmlSchemaForm elementFormDefault;
+    private XmlSchemaForm attributeFormDefault;
     private List<XmlSchemaExternal> externals;
     private NamespacePrefixList namespaceContext;
     // keep the encoding of the input
@@ -104,7 +104,7 @@
         items = new XmlSchemaObjectCollection();
         externals = new ArrayList<XmlSchemaExternal>();
         elements = new XmlSchemaObjectTable();
-        attributeGroups = new XmlSchemaObjectTable();
+        attributeGroups = new HashMap<QName, XmlSchemaAttributeGroup>();
         attributes = new XmlSchemaObjectTable();
         groups = new XmlSchemaObjectTable();
         notations = new XmlSchemaObjectTable();
@@ -144,7 +144,7 @@
         attributeFormDefault = value;
     }
 
-    public XmlSchemaObjectTable getAttributeGroups() {
+    public Map<QName, XmlSchemaAttributeGroup> getAttributeGroups() {
         return attributeGroups;
     }
 
@@ -214,7 +214,7 @@
             return null;
         }
 
-        XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)attributeGroups.getItem(name);
+        XmlSchemaAttributeGroup group = attributeGroups.get(name);
         if (deep) {
             if (group == null) {
                 // search the imports

Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java?rev=762589&r1=762588&r2=762589&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java Tue Apr  7 01:36:35 2009
@@ -42,6 +42,8 @@
      */
     public XmlSchemaAttributeGroup(XmlSchema parent) {
         namedDelegate = new XmlSchemaNamedImpl(parent, true);
+        parent.getItems().add(this);
+        // we can't be put in the map until we have a name. Perhaps we should be forced to have a name ?
         attributes = new XmlSchemaObjectCollection();
     }
 
@@ -82,6 +84,10 @@
     }
 
     public void setName(String name) {
+        if (name != null) {
+            namedDelegate.getParent().getAttributeGroups().remove(getQName());
+        }
         namedDelegate.setName(name);
+        namedDelegate.getParent().getAttributeGroups().put(getQName(), this);
     }
 }

Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=762589&r1=762588&r2=762589&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Tue Apr  7 01:36:35 2009
@@ -1560,13 +1560,15 @@
         }
 
         // todo: implement xml:lang,
-        if (schemaObj.attributeFormDefault != null && schemaObj.attributeFormDefault != XmlSchemaForm.NONE) {
+        if (schemaObj.getAttributeFormDefault() != null 
+            && schemaObj.getAttributeFormDefault() != XmlSchemaForm.NONE) {
             serializedSchema.setAttribute("attributeFormDefault", 
-                                          schemaObj.attributeFormDefault.toString());
+                                          schemaObj.getAttributeFormDefault().toString());
         }
 
-        if (schemaObj.elementFormDefault != null && schemaObj.elementFormDefault != XmlSchemaForm.NONE) {
-            serializedSchema.setAttribute("elementFormDefault", schemaObj.elementFormDefault.toString());
+        if (schemaObj.getElementFormDefault() != null 
+            && schemaObj.getElementFormDefault() != XmlSchemaForm.NONE) {
+            serializedSchema.setAttribute("elementFormDefault", schemaObj.getElementFormDefault().toString());
         }
 
         if (schemaObj.getAnnotation() != null) {

Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java?rev=762589&r1=762588&r2=762589&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/AttributeGroupTest.java Tue Apr  7 01:36:35 2009
@@ -22,6 +22,7 @@
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.Iterator;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 import javax.xml.transform.stream.StreamSource;
@@ -34,7 +35,6 @@
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
-import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -56,7 +56,8 @@
  * limitations under the License.
  *
  */
-public class AttributeGroupTest extends Assert {
+public class AttributeGroupTest
+    extends Assert {
 
     /**
      * This method will test the list.
@@ -90,48 +91,40 @@
         XmlSchemaObjectCollection c = t.getAttributes();
         for (Iterator i = c.getIterator(); i.hasNext();) {
             XmlSchemaAttributeGroupRef agrn = (XmlSchemaAttributeGroupRef)i.next();
-            assertEquals(new QName("http://soapinterop.org/types", "department"), 
-                         agrn.getRef().getTargetQName());
+            assertEquals(new QName("http://soapinterop.org/types", "department"), agrn.getRef()
+                .getTargetQName());
         }
 
-        XmlSchemaObjectTable attG = schema.getAttributeGroups();
+        Map<QName, XmlSchemaAttributeGroup> attG = schema.getAttributeGroups();
         assertNotNull(attG);
-        assertEquals(1, attG.getCount());
+        assertEquals(1, attG.size());
 
-        for (Iterator i = attG.getNames(); i.hasNext();) {
-            assertEquals("department", ((QName)i.next()).getLocalPart());
+        for (QName name : attG.keySet()) {
+            assertEquals("department", name.getLocalPart());
         }
 
-        for (Iterator i = attG.getValues(); i.hasNext();) {
-            Object obj1 = i.next();
-            if (obj1 instanceof XmlSchemaAttributeGroup) {
-                assertEquals("department", ((XmlSchemaAttributeGroup)obj1).getName());
-                XmlSchemaObjectCollection attributes = ((XmlSchemaAttributeGroup)obj1).getAttributes();
-                assertNotNull(attributes);
-                assertEquals(2, attributes.getCount());
-                for (Iterator j = attributes.getIterator(); j.hasNext();) {
-                    XmlSchemaAttribute obj2 = (XmlSchemaAttribute)j.next();
-                    String name = obj2.getName();
-                    if ("id".equals(name)) {
-                        assertEquals(new QName("http://soapinterop.org/types", "id"), obj2.getQName());
-                        assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"), obj2
-                            .getSchemaTypeName());
-                    } else if ("name".equals(name)) {
-                        assertEquals(new QName("http://soapinterop.org/types", "name"), obj2.getQName());
-                        assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"), obj2
-                            .getSchemaTypeName());
-                    } else {
-                        fail("The name \"" + name + "\" should not have been found " + "for an attribute.");
+        for (XmlSchemaAttributeGroup group : attG.values()) {
+            assertEquals("department", group.getName());
+            XmlSchemaObjectCollection attributes = group.getAttributes();
+            assertNotNull(attributes);
+            assertEquals(2, attributes.getCount());
+            for (Iterator j = attributes.getIterator(); j.hasNext();) {
+                XmlSchemaAttribute obj2 = (XmlSchemaAttribute)j.next();
+                String name = obj2.getName();
+                if ("id".equals(name)) {
+                    assertEquals(new QName("http://soapinterop.org/types", "id"), obj2.getQName());
+                    assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"), obj2
+                        .getSchemaTypeName());
+                } else if ("name".equals(name)) {
+                    assertEquals(new QName("http://soapinterop.org/types", "name"), obj2.getQName());
+                    assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"), obj2
+                        .getSchemaTypeName());
+                } else {
+                    fail("The name \"" + name + "\" should not have been found " + "for an attribute.");
 
-                    }
                 }
-            } else {
-                fail("There should have been one instance of the " + "class "
-                     + XmlSchemaAttributeGroup.class.getName() + " , but instead "
-                     + obj1.getClass().getName() + " was" + " found.");
             }
         }
 
     }
-
 }