Author: bimargulies
Date: Fri Dec  5 15:30:29 2008
New Revision: 723923

URL: http://svn.apache.org/viewvc?rev=723923&view=rev
Log:
WSCOMMONS-411. Add accessors to allow more selective serialization.

Modified:
    
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
    
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java

Modified: 
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java?rev=723923&r1=723922&r2=723923&view=diff
==============================================================================
--- 
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
 (original)
+++ 
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
 Fri Dec  5 15:30:29 2008
@@ -19,6 +19,7 @@
 
 package org.apache.ws.commons.schema;
 
+import 
org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
 import org.apache.ws.commons.schema.constants.Constants;
 import org.apache.ws.commons.schema.utils.NamespaceContextOwner;
 import org.apache.ws.commons.schema.utils.NamespacePrefixList;
@@ -34,23 +35,21 @@
 import java.util.Iterator;
 import java.util.Stack;
 
-
+// Ancient history, year unknown:-)
+//Oct 15th - momo - initial impl
+//Oct 17th - vidyanand - add SimpleType + element
+//Oct 18th - momo - add ComplexType
+//Oct 19th - vidyanand - handle external
+//Dec 6th - Vidyanand - changed RuntimeExceptions thrown to XmlSchemaExceptions
+//Jan 15th - Vidyanand - made changes to SchemaBuilder.handleElement to look 
for an element ref.
+//Feb 20th - Joni - Change the getXmlSchemaFromLocation schema
+//         variable to name s.
+//Feb 21th - Joni - Port to XMLDomUtil and Tranformation.
 /**
  * Contains the definition of a schema. All XML Schema definition language 
(XSD)
  * elements are children of the schema element. Represents the World Wide Web
  * Consortium (W3C) schema element
  */
-
-// Oct 15th - momo - initial impl
-// Oct 17th - vidyanand - add SimpleType + element
-// Oct 18th - momo - add ComplexType
-// Oct 19th - vidyanand - handle external
-// Dec 6th - Vidyanand - changed RuntimeExceptions thrown to 
XmlSchemaExceptions
-// Jan 15th - Vidyanand - made changes to SchemaBuilder.handleElement to look 
for an element ref.
-// Feb 20th - Joni - Change the getXmlSchemaFromLocation schema
-//            variable to name s.
-// Feb 21th - Joni - Port to XMLDomUtil and Tranformation.
-
 public class XmlSchema extends XmlSchemaAnnotated implements 
NamespaceContextOwner {
     private static final String UTF_8_ENCODING = "UTF-8";
        static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";;
@@ -626,11 +625,24 @@
 
         return true;
     }
+    
+    /**
+     * Retrieve a DOM tree for this one schema, independent of any included or 
+     * related schemas.
+     * @return The DOM document.
+     * @throws XmlSchemaSerializerException
+     */
+    public Document getSchemaDocument() throws XmlSchemaSerializerException {
+        XmlSchemaSerializer xser = new XmlSchemaSerializer();
+        xser.setExtReg(this.parent.getExtReg());
+        return xser.serializeSchema(this, false)[0];
+    }
+    
     public String getInputEncoding() {
         return inputEncoding;
     }
     
-     public String toString() {
+    public String toString() {
         return super.toString() + "[" + logicalTargetNamespace + "]";
     }
 }

Modified: 
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?rev=723923&r1=723922&r2=723923&view=diff
==============================================================================
--- 
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
 (original)
+++ 
webservices/commons/branches/modules/XmlSchema/1_4_X_BRANCH/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
 Fri Dec  5 15:30:29 2008
@@ -19,28 +19,54 @@
 
 package org.apache.ws.commons.schema;
 
-import org.apache.ws.commons.schema.constants.Constants;
-import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
-import org.apache.ws.commons.schema.utils.NamespacePrefixList;
-import org.w3c.dom.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import java.util.*;
-public class XmlSchemaSerializer {
 
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.w3c.dom.Attr;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Convert from the XML Schema class representation to the standard
+ * XML representation. 
+  */
+public class XmlSchemaSerializer {
+       
     /**
      * Extension registry for the serializer
-     *  */
+     */
 
     private ExtensionRegistry extReg;
 
+    /**
+     * Get the registry of extensions for this serializer.
+     * @return the registry.
+     */
     public ExtensionRegistry getExtReg() {
         return extReg;
     }
 
+    /**
+     * Set the registry of extensions for this serializer.
+     * @param extReg the registry.
+     */
     public void setExtReg(ExtensionRegistry extReg) {
         this.extReg = extReg;
     }
@@ -55,28 +81,22 @@
 
     private static final String XMLNS_NAMESPACE_URI = 
"http://www.w3.org/2000/xmlns/";;
 
-    XmlSchemaSerializer() {
+    /**
+     * Create a new serializer.
+     */
+    public XmlSchemaSerializer() {
         docs = new ArrayList();
         schema_ns = new Hashtable();
     }
 
     /**
-     * *********************************************************************
-     * Document[]  serializeSchema(XmlSchema schemaObj,
-     * boolean serializeIncluded)
-     * <p/>
-     * Serialize XmlSchema object pass back the document containing a schema
-     * element as its root.
-     * <p/>
-     * Parameter:
-     * schemaObj - Schema object to serialize.
-     * serialzeIncluded - whether to serialize the included(imported)
-     * schema or not. pass true for serialize all included
-     * schema.
-     * <p/>
-     * Return:
-     * Array of Documents that include/imported.
-     * **********************************************************************
+     * Serialize an entire schema, returning an array of DOM Documents, one 
per XSL file. 
+     * @param schemaObj The XML Schema.
+     * @param serializeIncluded whether to create DOM trees for any included 
or imported 
+     * schemas.
+     * @return Documents. If serializeIncluded is false, the array with have 
one entry.
+     * The main document is always first.
+     * @throws XmlSchemaSerializerException
      */
     public Document[] serializeSchema(XmlSchema schemaObj,
                                              boolean serializeIncluded) throws 
XmlSchemaSerializerException {
@@ -2666,13 +2686,20 @@
         }
     }
 
+    /**
+     * Exception class used for serialization problems.
+     */
     public static class XmlSchemaSerializerException extends Exception {
 
         /**
                 * 
                 */
                private static final long serialVersionUID = 1L;
-
+               
+               /**
+                * Standard constructor with a message.
+                * @param msg the message.
+                */
                public XmlSchemaSerializerException(String msg) {
             super(msg);
         }
@@ -2680,14 +2707,14 @@
 
 
     /**
-     * A generic method to process the extra attributes and the the extra
+     * A generic method to process the extra attributes and the extra
      * elements present within the schema.
-     * What are considered extensions are  child elements with non schema 
namespace
-     * and child attributes with any namespace
+     * What are considered extensions are child elements with non schema 
namespace
+     * and child attributes with any namespace.
      * @param schemaObject
      * @param parentElement
      */
-    private void processExtensibilityComponents(XmlSchemaObject 
schemaObject,Element parentElement){
+    private void processExtensibilityComponents(XmlSchemaObject schemaObject, 
Element parentElement) {
 
         if (extReg!=null){
             Map metaInfoMap = schemaObject.getMetaInfoMap();


Reply via email to