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/04/06 08:45:43 UTC

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

Author: ajith
Date: Thu Apr  5 23:45:42 2007
New Revision: 526072

URL: http://svn.apache.org/viewvc?view=rev&rev=526072
Log:
1. Fixed the serialization issue mentioned in  https://issues.apache.org/jira/browse/AXIS2-2457. 
2. Added two more test cases to check the problem
3. Fixed the schemaImport null issue   - this should hopfully fix the woden problem

Added:
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java
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/XmlSchemaSerializer.java
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.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?view=diff&rev=526072&r1=526071&r2=526072
==============================================================================
--- 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 Thu Apr  5 23:45:42 2007
@@ -166,6 +166,7 @@
                         el, schemaEl);
                 schema.includes.add(schemaImport);
                 schema.items.add(schemaImport);
+
             } else if (el.getLocalName().equals("group")) {
                 XmlSchemaGroup group = handleGroup(schema, el, schemaEl);
                 schema.groups.collection.put(group.name, group);
@@ -194,9 +195,9 @@
             }
         }
 
-           //add the extesibility components
+        //add the extesibility components
         processExtensibilityComponents(schema,schemaEl);
-        
+
         return schema;
     }
 
@@ -1385,29 +1386,29 @@
         }
 
         if ((keyEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "key")) != null) {
-        	while(keyEl != null) {
-        		element.constraints.add(handleConstraint(keyEl, "Key"));
-        		keyEl = XDOMUtil.getNextSiblingElement(keyEl, "key");
-        	}
+            while(keyEl != null) {
+                element.constraints.add(handleConstraint(keyEl, "Key"));
+                keyEl = XDOMUtil.getNextSiblingElement(keyEl, "key");
+            }
         }
 
         if ((keyrefEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "keyref")) != null) {
-        	while(keyrefEl != null) {
-	            XmlSchemaKeyref keyRef = (XmlSchemaKeyref) handleConstraint(keyrefEl, "Keyref");
-	            if(keyrefEl.hasAttribute("refer")) {
-		            String name = keyrefEl.getAttribute("refer");
-		            keyRef.refer = getRefQName(name, el);
-	            }
-	            element.constraints.add(keyRef);
-	            keyrefEl = XDOMUtil.getNextSiblingElement(keyrefEl, "keyref");
-        	}
+            while(keyrefEl != null) {
+                XmlSchemaKeyref keyRef = (XmlSchemaKeyref) handleConstraint(keyrefEl, "Keyref");
+                if(keyrefEl.hasAttribute("refer")) {
+                    String name = keyrefEl.getAttribute("refer");
+                    keyRef.refer = getRefQName(name, el);
+                }
+                element.constraints.add(keyRef);
+                keyrefEl = XDOMUtil.getNextSiblingElement(keyrefEl, "keyref");
+            }
         }
 
         if ((uniqueEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "unique")) != null) {
-        	while(uniqueEl != null) {
-        		element.constraints.add(handleConstraint(uniqueEl, "Unique"));
-        		uniqueEl = XDOMUtil.getNextSiblingElement(uniqueEl, "unique");
-        	}
+            while(uniqueEl != null) {
+                element.constraints.add(handleConstraint(uniqueEl, "Unique"));
+                uniqueEl = XDOMUtil.getNextSiblingElement(uniqueEl, "unique");
+            }
         }
 
         if (el.hasAttribute("abstract")) {
@@ -1516,6 +1517,13 @@
         }
     }
 
+    /**
+     * Hanlde the import
+     * @param schema
+     * @param importEl
+     * @param schemaEl
+     * @return XmlSchemaObject
+     */
     XmlSchemaImport handleImport(XmlSchema schema, Element importEl,
                                  Element schemaEl) {
 
@@ -1568,7 +1576,7 @@
                                 validator);
             }
         }
-        return (schemaImport.schema == null) ? null : schemaImport;
+        return  schemaImport;
     }
 
     /**
@@ -1885,7 +1893,7 @@
 
                     if (namespaceURI!= null &&
                             !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI))
-                      //does not belong to the schema namespace
+                    //does not belong to the schema namespace
                     {
                         QName qName = new QName(namespaceURI,name);
                         extReg.deserializeExtension(schemaObject,qName,extElement);

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?view=diff&rev=526072&r1=526071&r2=526072
==============================================================================
--- 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 Thu Apr  5 23:45:42 2007
@@ -2716,22 +2716,7 @@
                 Iterator keysIt = metaInfoMap.keySet().iterator();
                 while (keysIt.hasNext()) {
                     Object key =  keysIt.next();
-                    if (!Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES.equals(key)){  //skip external attributes
-                        extReg.serializeExtension(schemaObject,metaInfoMap.get(key).getClass(),parentElement);
-                    }else{
-                       Map externalAttribs = (Map)metaInfoMap.get(key);
-                       //external attribs are as DOM attrib objects
-                       Iterator domeAtts = externalAttribs.values().iterator();
-                        while (domeAtts.hasNext()) {
-                            Attr attr = (Attr) domeAtts.next();
-                            parentElement.setAttributeNode(
-                                   (Attr) parentElement.getOwnerDocument().importNode(attr,true)
-                            );
-                        }
-
-
-
-                    }
+                    extReg.serializeExtension(schemaObject,metaInfoMap.get(key).getClass(),parentElement);
 
                 }
 

Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java?view=diff&rev=526072&r1=526071&r2=526072
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java Thu Apr  5 23:45:42 2007
@@ -4,6 +4,8 @@
 import org.apache.ws.commons.schema.constants.Constants;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Attr;
 
 import java.util.Iterator;
 import java.util.Map;
@@ -30,16 +32,11 @@
         Document parentDoc = node.getOwnerDocument();
         if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
             Map attribMap  = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
-            for(Iterator it = attribMap.keySet().iterator();it.hasNext();){
-                Object key = it.next();
-                Object value = attribMap.get(key);
-                // this comparison may not be the most ideal but lets keep it for now
-                if (value.getClass().equals(classOfType)){
-//                   Attr newAtt =
+           for(Iterator it = attribMap.values().iterator();it.hasNext();){
+                if (node.getNodeType()==Node.ELEMENT_NODE){
+                    ((Element)node).setAttributeNodeNS((Attr)parentDoc.importNode((Node)it.next(),true));
                 }
 
-                node.appendChild(
-                        parentDoc.importNode((Node)it.next(),true));
             }
         }
 

Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java?view=auto&rev=526072
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java Thu Apr  5 23:45:42 2007
@@ -0,0 +1,70 @@
+package tests.ext;
+
+import junit.framework.TestCase;
+
+import java.util.Map;
+import java.util.Iterator;
+
+import tests.Resources;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * Test the custom extension dserialization without any specialized
+ * hooks
+ */
+public class PlainExtensionDeserializerTest extends TestCase {
+
+     public void testDeserialization() throws Exception {
+
+           //create a DOM document
+           DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+           documentBuilderFactory.setNamespaceAware(true);
+           Document doc = documentBuilderFactory.newDocumentBuilder().
+                   parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+           XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+           XmlSchema schema = schemaCol.read(doc,null);
+           assertNotNull(schema);
+
+          // get the elements and check whether their annotations are properly
+          // populated
+           Iterator values = schema.getElements().getValues();
+           while (values.hasNext()) {
+               XmlSchemaElement elt =  (XmlSchemaElement) values.next();
+               assertNotNull(elt);
+               Map metaInfoMap = elt.getMetaInfoMap();
+               assertNotNull(metaInfoMap);
+
+           }
+     }
+
+
+    public void testDeserialization1() throws Exception {
+
+           //create a DOM document
+           DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+           documentBuilderFactory.setNamespaceAware(true);
+           Document doc = documentBuilderFactory.newDocumentBuilder().
+                   parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
+
+           XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+           XmlSchema schema = schemaCol.read(doc,null);
+           assertNotNull(schema);
+
+          // get the elements and check whether their annotations are properly
+          // populated
+           Iterator values = schema.getElements().getValues();
+           while (values.hasNext()) {
+               XmlSchemaElement elt =  (XmlSchemaElement) values.next();
+               assertNotNull(elt);
+               Map metaInfoMap = elt.getMetaInfoMap();
+               assertNotNull(metaInfoMap);
+
+           }
+     }
+}

Added: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java?view=auto&rev=526072
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java Thu Apr  5 23:45:42 2007
@@ -0,0 +1,52 @@
+package tests.ext;
+
+import junit.framework.TestCase;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import tests.Resources;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * try writing the schemas after they are built
+ */
+public class PlainExtensionSerializerTest extends TestCase {
+
+     public void testSerialization() throws Exception {
+
+           //create a DOM document
+           DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+           documentBuilderFactory.setNamespaceAware(true);
+           Document doc = documentBuilderFactory.newDocumentBuilder().
+                   parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+           XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+           XmlSchema schema = schemaCol.read(doc,null);
+           assertNotNull(schema);
+
+           schema.write(new ByteArrayOutputStream());
+     }
+
+
+    public void testSerialization1() throws Exception {
+
+           //create a DOM document
+           DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+           documentBuilderFactory.setNamespaceAware(true);
+           Document doc = documentBuilderFactory.newDocumentBuilder().
+                   parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
+
+           XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+           XmlSchema schema = schemaCol.read(doc,null);
+           assertNotNull(schema);
+
+           schema.write(new ByteArrayOutputStream());
+     }
+}



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