Author: ajith
Date: Thu Mar 29 22:00:35 2007
New Revision: 523937

URL: http://svn.apache.org/viewvc?view=rev&rev=523937
Log:
1. Added a test case for custom element serialization
2. Changed some of the comments and method names so that things make sense

Added:
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
Modified:
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java?view=diff&rev=523937&r1=523936&r2=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java
 Thu Mar 29 22:00:35 2007
@@ -8,7 +8,7 @@
 import javax.xml.namespace.QName;
 
 /**
- * Custome attribute deserializer for our test custom attribute
+ * Custom attribute deserializer for our test custom attribute
  */
 public class CustomAttributeDeserializer implements ExtensionDeserializer {
 

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java?view=diff&rev=523937&r1=523936&r2=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
 Thu Mar 29 22:00:35 2007
@@ -17,13 +17,11 @@
 import java.io.ByteArrayInputStream;
 
 /**
- * @author : Ajith Ranabahu
- *         Date: Mar 29, 2007
- *         Time: 10:05:54 PM
+ * Test class to do a full parsing run with the extensions
  */
 public class CustomExtensionSerializerTest extends TestCase {
 
-    public void testDeserialization() throws Exception {
+    public void testSerialization() throws Exception {
         //set the system property for the custom extension registry
         System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
                 CustomExtensionRegistry.class.getName());
@@ -39,6 +37,7 @@
         assertNotNull(schema);
 
         //now serialize it to a byte stream
+        //and build a new document out of it
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         schema.write(baos);
 

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java?view=diff&rev=523937&r1=523936&r2=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java
 Thu Mar 29 22:00:35 2007
@@ -8,9 +8,7 @@
 import javax.xml.namespace.QName;
 
 /**
- * @author : Ajith Ranabahu
- *         Date: Mar 29, 2007
- *         Time: 9:12:19 PM
+ * Custom element deserializer
  */
 public class CustomElementDeserializer implements ExtensionDeserializer {
     /**

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java?view=diff&rev=523937&r1=523936&r2=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java
 Thu Mar 29 22:00:35 2007
@@ -3,11 +3,15 @@
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
 import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Attr;
+
+import java.util.Map;
+
+import tests.customext.attrib.CustomAttribute;
 
 /**
- * @author : Ajith Ranabahu
- *         Date: Mar 29, 2007
- *         Time: 9:30:07 PM
+ * Custom element serializer
  */
 public class CustomElementSerializer implements ExtensionSerializer {
     /**
@@ -20,6 +24,16 @@
      *                     serialization mechanism is to create a DOM tree 
first and serialize it
      */
     public void serialize(XmlSchemaObject schemaObject, Class classOfType, 
Node domNode) {
-        //To change body of implemented methods use File | Settings | File 
Templates.
+       Map metaInfoMap = schemaObject.getMetaInfoMap();
+       CustomElement customElt = 
(CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
+
+        Element elt = (Element)domNode;
+        Element extElt = 
elt.getOwnerDocument().createElementNS(CustomElement.CUSTOM_ELT_QNAME.getNamespaceURI(),
+                                                             
CustomElement.CUSTOM_ELT_QNAME.getLocalPart());
+        extElt.setAttribute("prefix",customElt.getPrefix());
+        extElt.setAttribute("suffix",customElt.getSuffix());
+
+        elt.appendChild(extElt);
+
     }
 }

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java?view=diff&rev=523937&r1=523936&r2=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
 Thu Mar 29 22:00:35 2007
@@ -13,9 +13,7 @@
 import java.util.Map;
 
 /**
- * @author : Ajith Ranabahu
- *         Date: Mar 29, 2007
- *         Time: 9:33:17 PM
+ * Test class to run through the full cycle of build-check
  */
 public class CustomExtElementDeserializerTest extends TestCase {
 

Added: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java?view=auto&rev=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
 (added)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
 Thu Mar 29 22:00:35 2007
@@ -0,0 +1,69 @@
+package tests.customext.elt;
+
+import org.apache.ws.commons.schema.constants.Constants;
+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;
+
+import tests.Resources;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+/**
+ *  Test class to run through the full cycle of build-serialize-build-check
+ */
+public class CustomExtElementSerializerTest extends TestCase {
+
+
+    public void testSerialization() throws Exception {
+        //set the system property for the custom extension registry
+        System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+                CustomExtensionRegistry.class.getName());
+
+        //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);
+
+        //now serialize it to a byte stream
+        //and build a new document out of it
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        schema.write(baos);
+        Document doc2 = documentBuilderFactory.newDocumentBuilder().
+                parse(new ByteArrayInputStream(baos.toByteArray()));
+
+        schema = schemaCol.read(doc2,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);
+
+            CustomElement customElt = 
(CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
+            assertNotNull(customElt);
+
+        }
+
+        //remove our system property
+        
System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
+
+    }
+}

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java?view=diff&rev=523937&r1=523936&r2=523937
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java
 Thu Mar 29 22:00:35 2007
@@ -3,9 +3,7 @@
 import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
 
 /**
- * @author : Ajith Ranabahu
- *         Date: Mar 29, 2007
- *         Time: 9:21:40 PM
+ * Custom extension registry
  */
 public class CustomExtensionRegistry extends ExtensionRegistry {
 



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

Reply via email to