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/03/30 06:41:42 UTC

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

Author: ajith
Date: Thu Mar 29 21:41:41 2007
New Revision: 523933

URL: http://svn.apache.org/viewvc?view=rev&rev=523933
Log:
1. Changed the serialization from static to instance driven.
2. Fixed the serializer to have proper extension serialization calls
3. Added a test case to check the extension attributes

Added:
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
Modified:
    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/XmlSchemaSerializer.java
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java
    webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java

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?view=diff&rev=523933&r1=523932&r2=523933
==============================================================================
--- 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 Thu Mar 29 21:41:41 2007
@@ -190,15 +190,21 @@
 
     public Document[] getAllSchemas() {
         try {
-            return XmlSchemaSerializer.serializeSchema(this, true);
+            
+            XmlSchemaSerializer xser = new XmlSchemaSerializer();
+            xser.setExtReg(this.parent.getExtReg());
+            return xser.serializeSchema(this, true);
+
         } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
             throw new XmlSchemaException(e.getMessage());
         }
     }
 
-    private static void serialize_internal(XmlSchema schema, Writer out) {
+    private  void serialize_internal(XmlSchema schema, Writer out) {
         try {
-            Document[] serializedSchemas = XmlSchemaSerializer.serializeSchema(schema, false);
+            XmlSchemaSerializer xser = new XmlSchemaSerializer();
+            xser.setExtReg(this.parent.getExtReg());
+            Document[] serializedSchemas = xser.serializeSchema(schema, false);
             TransformerFactory trFac = TransformerFactory.newInstance();
             Source source = new DOMSource(serializedSchemas[0]);
             Result result = new StreamResult(out);

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=523933&r1=523932&r2=523933
==============================================================================
--- 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 Mar 29 21:41:41 2007
@@ -52,7 +52,7 @@
 
     private static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
 
-    private XmlSchemaSerializer() {
+    XmlSchemaSerializer() {
         docs = new ArrayList();
         schema_ns = new Hashtable();
     }
@@ -75,10 +75,9 @@
      * Array of Documents that include/imported.
      * **********************************************************************
      */
-    public static Document[] serializeSchema(XmlSchema schemaObj,
+    public Document[] serializeSchema(XmlSchema schemaObj,
                                              boolean serializeIncluded) throws XmlSchemaSerializerException {
-        return new XmlSchemaSerializer().serializeSchemaElement(schemaObj,
-                serializeIncluded);
+        return serializeSchemaElement(schemaObj, serializeIncluded);
     }
 
     Document[] serializeSchemaElement(XmlSchema schemaObj,
@@ -190,6 +189,10 @@
         serializeSchemaChild(items, serializedSchema, serializedSchemaDocs,
                 schemaObj, serializeIncluded);
 
+        //process extension elements/attributes
+        processExtensibilityComponents(schemaObj,serializedSchema);
+
+
         serializedSchemaDocs.appendChild(serializedSchema);
         docs.add(serializedSchemaDocs);
 
@@ -356,6 +359,9 @@
             docs.addAll(includeSeri.docs);
         }
 
+        //process includes
+        processExtensibilityComponents(includeObj,includeEl);
+
         return includeEl;
     }
 
@@ -410,6 +416,9 @@
             docs.addAll(importSeri.docs);
         }
 
+         //process extension
+        processExtensibilityComponents(importObj,importEl);
+
         return importEl;
     }
 
@@ -481,6 +490,10 @@
                 redefine.appendChild(attributeGroupRef);
             }
         }
+
+            //process extension
+        processExtensibilityComponents(redefineObj,redefine);
+
         return redefine;
     }
 
@@ -618,6 +631,9 @@
             serializedEl.setAttribute("nillable", "true");
         }
 
+            //process extension
+        processExtensibilityComponents(elementObj,serializedEl);
+
         return serializedEl;
     }
 
@@ -689,6 +705,9 @@
 		   throw new XmlSchemaSerializerException("simple type must be set "
 		   + "with content, either union, restriction or list");*/
 
+            //process extension
+        processExtensibilityComponents(simpleTypeObj,serializedSimpleType);
+
         return serializedSimpleType;
     }
 
@@ -749,6 +768,10 @@
                 serializedRestriction.appendChild(facetEl);
             }
         }
+
+            //process extension
+        processExtensibilityComponents(restrictionObj,serializedRestriction);
+
         return serializedRestriction;
     }
 
@@ -822,6 +845,9 @@
 //            serializedFacet.appendChild(annotation);
 //        }
 
+            //process extension
+        processExtensibilityComponents(facetObj,serializedFacet);
+
         return serializedFacet;
     }
 
@@ -936,6 +962,9 @@
         if (attrColl.getCount() > 0)
             setupAttr(doc, attrColl, schema, serializedComplexType);
 
+            //process extension
+        processExtensibilityComponents(complexTypeObj,serializedComplexType);
+
         return serializedComplexType;
     }
 
@@ -1006,6 +1035,10 @@
                 sequence.appendChild(any);
             }
         }
+
+            //process extension
+        processExtensibilityComponents(sequenceObj,sequence);
+
         return sequence;
     }
 
@@ -1134,6 +1167,10 @@
                     attribute.setAttribute(nodeName, value);
             }
         }
+
+            //process extension
+        processExtensibilityComponents(attributeObj,attribute);
+
         return attribute;
     }
 
@@ -1226,6 +1263,10 @@
                 }
             }
         }
+
+            //process extension
+        processExtensibilityComponents(choiceObj,choice);
+
         return choice;
     }
 
@@ -1279,6 +1320,9 @@
             }
         }
 
+            //process extension
+        processExtensibilityComponents(allObj,allEl);
+
         return allEl;
     }
 
@@ -1325,6 +1369,10 @@
             Element annotation = serializeAnnotation(doc, listObj.annotation, schema);
             list.appendChild(annotation);
         }
+
+            //process extension
+        processExtensibilityComponents(listObj,list);
+
         return list;
     }
 
@@ -1380,6 +1428,10 @@
                     schema);
             union.appendChild(annotation);
         }
+
+            //process extension
+        processExtensibilityComponents(unionObj,union);
+
         return union;
     }
 
@@ -1438,6 +1490,9 @@
             anyEl.appendChild(annotation);
         }
 
+            //process extension
+        processExtensibilityComponents(anyObj,anyEl);
+
         return anyEl;
     }
 
@@ -1494,6 +1549,9 @@
             group.appendChild(all);
         }
 
+            //process extension
+        processExtensibilityComponents(groupObj,group);
+
         return group;
     }
 
@@ -1561,6 +1619,9 @@
             groupRef.appendChild(annotation);
         }
 
+            //process extension
+        processExtensibilityComponents(groupRefObj,groupRef);
+
         return groupRef;
     }
 
@@ -1610,6 +1671,10 @@
                     + "must be restriction or extension");
 
         simpleContent.appendChild(content);
+
+            //process extension
+        processExtensibilityComponents(simpleContentObj,simpleContent);
+
         return simpleContent;
     }
 
@@ -1670,6 +1735,9 @@
 
         complexContent.appendChild(content);
 
+            //process extension
+        processExtensibilityComponents(complexContentObj,complexContent);
+
         return complexContent;
     }
 
@@ -1740,6 +1808,10 @@
                 constraint.appendChild(field);
             }
         }
+
+            //process extension
+        processExtensibilityComponents(constraintObj,constraint);
+
         return constraint;
     }
 
@@ -1779,6 +1851,8 @@
                     selectorObj.annotation, schema);
             selector.appendChild(annotation);
         }
+            //process extension
+        processExtensibilityComponents(selectorObj,selector);
         return selector;
     }
 
@@ -1817,6 +1891,9 @@
             field.appendChild(annotation);
         }
 
+            //process extension
+        processExtensibilityComponents(fieldObj,field);
+
         return field;
     }
 
@@ -1868,6 +1945,9 @@
             }
         }
 
+            //process extension
+        processExtensibilityComponents(annotationObj,annotation);
+
         return annotation;
     }
 
@@ -1917,6 +1997,9 @@
             }
         }
 
+            //process extension
+        processExtensibilityComponents(appInfoObj,appInfoEl);
+
         return appInfoEl;
     }
 
@@ -1970,6 +2053,9 @@
                 }
             }
         }
+            //process extension
+        processExtensibilityComponents(documentationObj,documentationEl);
+
         return documentationEl;
     }
 
@@ -2047,6 +2133,10 @@
                     (XmlSchemaFacet) facets.getItem(i), schema);
             restriction.appendChild(facet);
         }
+
+            //process extension
+        processExtensibilityComponents(restrictionObj,restriction);
+
         return restriction;
     }
 
@@ -2119,6 +2209,9 @@
             extension.appendChild(anyAttribute);
         }
 
+            //process extension
+        processExtensibilityComponents(extensionObj,extension);
+
         return extension;
     }
 
@@ -2204,6 +2297,9 @@
             restriction.appendChild(anyAttribute);
         }
 
+            //process extension
+        processExtensibilityComponents(restrictionObj,restriction);
+
         return restriction;
     }
 
@@ -2284,6 +2380,9 @@
             extension.appendChild(anyAttribute);
         }
 
+            //process extension
+        processExtensibilityComponents(extensionObj,extension);
+
         return extension;
     }
 
@@ -2333,6 +2432,9 @@
             anyAttribute.appendChild(annotation);
         }
 
+            //process extension
+        processExtensibilityComponents(anyAttributeObj,anyAttribute);
+
         return anyAttribute;
     }
 
@@ -2380,6 +2482,10 @@
                     attributeGroupObj.annotation, schema);
             attributeGroupRef.appendChild(annotation);
         }
+
+            //process extension
+        processExtensibilityComponents(attributeGroupObj,attributeGroupRef);
+
         return attributeGroupRef;
     }
 
@@ -2446,6 +2552,9 @@
             attributeGroup.appendChild(anyAttribute);
         }
 
+            //process extension
+        processExtensibilityComponents(attributeGroupObj,attributeGroup);
+
         return attributeGroup;
     }
 
@@ -2604,7 +2713,27 @@
             Map metaInfoMap = schemaObject.getMetaInfoMap();
             if (metaInfoMap!=null && !metaInfoMap.isEmpty()) {
                 //get the extra objects and call the respective deserializers
+                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)
+                            );
+                        }
+
+
 
+                    }
+
+                }
 
             }
 

Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java?view=diff&rev=523933&r1=523932&r2=523933
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java Thu Mar 29 21:41:41 2007
@@ -3,6 +3,10 @@
 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;
 
 /**
  * serializer for the custom attribute
@@ -19,6 +23,13 @@
      *                     serialization mechanism is to create a DOM tree first and serialize it
      */
     public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
+        Map metaInfoMap = schemaObject.getMetaInfoMap();
+        CustomAttribute att = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
 
+        Element elt = (Element)domNode;
+        Attr att1 = elt.getOwnerDocument().createAttributeNS(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getNamespaceURI(),
+                                                             CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getLocalPart());
+        att1.setValue(att.getPrefix() + ":" + att.getSuffix());
+        elt.setAttributeNodeNS(att1);
     }
 }

Modified: webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java?view=diff&rev=523933&r1=523932&r2=523933
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java Thu Mar 29 21:41:41 2007
@@ -18,7 +18,7 @@
 public class CustomExtDeserializerTest extends TestCase {
 
 
-    public void testSimpleTypeSchemaGeneration() throws Exception {
+    public void testDeserialization() throws Exception {
             //set the system property for the custom extension registry
             System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
                     CustomExtensionRegistry.class.getName());

Added: 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=auto&rev=523933
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java Thu Mar 29 21:41:41 2007
@@ -0,0 +1,72 @@
+package tests.customext.attrib;
+
+import junit.framework.TestCase;
+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;
+
+/**
+ * @author : Ajith Ranabahu
+ *         Date: Mar 29, 2007
+ *         Time: 10:05:54 PM
+ */
+public class CustomExtensionSerializerTest extends TestCase {
+
+    public void testDeserialization() 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 doc1 = documentBuilderFactory.newDocumentBuilder().
+                parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(doc1,null);
+        assertNotNull(schema);
+
+        //now serialize it to a byte stream
+        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);
+
+            CustomAttribute customAttrib = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
+            assertNotNull(customAttrib);
+
+        }
+
+
+        //remove our system property
+        System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
+
+    }
+
+}

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=523933&r1=523932&r2=523933
==============================================================================
--- 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 21:41:41 2007
@@ -20,7 +20,7 @@
 public class CustomExtElementDeserializerTest extends TestCase {
 
 
-    public void testSimpleTypeSchemaGeneration() throws Exception {
+    public void testDeserialization() throws Exception {
             //set the system property for the custom extension registry
             System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
                     CustomExtensionRegistry.class.getName());



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