You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by jk...@apache.org on 2007/08/24 15:12:52 UTC

svn commit: r569372 - in /incubator/woden/branches/woden65/src/org/apache/woden: ./ internal/ internal/util/dom/

Author: jkaputin
Date: Fri Aug 24 06:12:51 2007
New Revision: 569372

URL: http://svn.apache.org/viewvc?rev=569372&view=rev
Log:
WODEN-65
Initial commit of serialization contribution from
Sagara Gunathunga.

Added:
    incubator/woden/branches/woden65/src/org/apache/woden/WSDLWriter.java   (with props)
    incubator/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java   (with props)
    incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java   (with props)
    incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java   (with props)
    incubator/woden/branches/woden65/src/org/apache/woden/internal/WriterFeatures.java   (with props)
Modified:
    incubator/woden/branches/woden65/src/org/apache/woden/WSDLFactory.java
    incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLFactory.java
    incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLFactory.java
    incubator/woden/branches/woden65/src/org/apache/woden/internal/util/dom/DOMUtils.java

Modified: incubator/woden/branches/woden65/src/org/apache/woden/WSDLFactory.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/WSDLFactory.java?rev=569372&r1=569371&r2=569372&view=diff
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/WSDLFactory.java (original)
+++ incubator/woden/branches/woden65/src/org/apache/woden/WSDLFactory.java Fri Aug 24 06:12:51 2007
@@ -179,6 +179,7 @@
         
         return fFullPropertyFileName;
     }
+    public abstract WSDLWriter newWSDLWriter() throws WSDLException;
     
     public abstract WSDLReader newWSDLReader() throws WSDLException;
     

Added: incubator/woden/branches/woden65/src/org/apache/woden/WSDLWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/WSDLWriter.java?rev=569372&view=auto
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/WSDLWriter.java (added)
+++ incubator/woden/branches/woden65/src/org/apache/woden/WSDLWriter.java Fri Aug 24 06:12:51 2007
@@ -0,0 +1,66 @@
+
+package org.apache.woden;
+
+import java.io.Writer;
+import java.io.OutputStream;
+import org.apache.woden.wsdl20.Description;
+/**
+ * This interface describes a collection of methods
+ * that allow a WSDL model to be written to a writer
+ * in an XML format that follows the WSDL schema.
+ *
+ * Based on wsdl4j WSDLWriter.
+ *
+ *@author Sagara Gunathunga (sagara.gunathunga@gmail.com)
+ */
+public interface WSDLWriter {
+
+    /**
+     * Sets the specified feature to the specified value.
+     * <p>
+     * There are no minimum features that must be supported.
+     * <p>
+     * All feature names must be fully-qualified, Java package style. All
+     * names starting with javax.wsdl. are reserved for features defined
+     * by the JWSDL specification. It is recommended that implementation-
+     * specific features be fully-qualified to match the package name
+     * of that implementation. For example: com.abc.featureName
+     *
+     * @param name the name of the feature to be set.
+     * @param value the value to set the feature to.
+     * @throws IllegalArgumentException if the feature name is not recognized.
+     * @see #getFeature(String)
+     */
+
+    public void setFeature(String name, boolean value)
+    throws IllegalArgumentException;
+
+    /**
+     * Gets the value of the specified feature.
+     *
+     * @param name the name of the feature to get the value of.
+     * @return the value of the feature.
+     * @throws IllegalArgumentException if the feature name is not recognized.
+     * @see #setFeature(String, boolean)
+     */
+
+    public boolean getFeature(String name) throws IllegalArgumentException;
+
+    /**
+     * Write the specified WSDL definition to the specified Writer.
+     *
+     * @param wsdlDef the WSDL definition to be written.
+     * @param sink the Writer to write the xml to.
+     */
+    public void writeWSDL(Description wsdlDes, Writer sink)
+      throws WSDLException;
+    /**
+     * Write the specified WSDL definition to the specified OutputStream.
+     *
+     * @param wsdlDef the WSDL definition to be written.
+     * @param sink the OutputStream to write the xml to.
+     */
+    public void writeWSDL(Description wsdlDes, OutputStream sink)
+      throws WSDLException;
+
+}

Propchange: incubator/woden/branches/woden65/src/org/apache/woden/WSDLWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java?rev=569372&view=auto
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java (added)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java Fri Aug 24 06:12:51 2007
@@ -0,0 +1,230 @@
+
+package org.apache.woden.internal;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.wsdl.Definition;
+import org.apache.woden.ErrorHandler;
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLWriter;
+import org.apache.woden.internal.resolver.SimpleURIResolver;
+import org.apache.woden.internal.util.PropertyUtils;
+import org.apache.woden.resolver.URIResolver;
+import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
+import org.apache.woden.internal.WSDLContext;
+import org.apache.woden.wsdl20.Description;
+import org.w3c.dom.Document;
+import org.apache.woden.internal.wsdl20.Constants;
+
+/**
+ *   This class contains properties and methods common
+ *   to WSDLWriter implementations.
+ *
+ *   TODO Once the OMWSDLWriter implemantation is completed
+ *   this class should be a abstract class.
+ *   @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
+ *
+ */
+ public abstract  class BaseWSDLWriter implements WSDLWriter{
+
+     private String fFactoryImplName = null; //TODO deprecate/remove?
+
+     final protected WSDLContext fWsdlContext;
+     final protected WriterFeatures features;
+
+     public BaseWSDLWriter(WSDLContext wsdlContext){
+         fWsdlContext = wsdlContext;
+         fFactoryImplName = fWsdlContext.wsdlFactory.getClass().getName();
+         features = new WriterFeatures();
+
+     }
+
+     /**
+      * @return Returns the fErrorReporter.
+      */
+     public ErrorReporter getErrorReporter()
+     {
+         return fWsdlContext.errorReporter;
+     }
+
+     /**
+      * Get the cached WSDLFactory if there is one, otherwise
+      * create and cache a new one.
+      *
+      * TODO see setFactoryImplName todo
+      *
+      * @return Returns a.
+      */
+     protected WSDLFactory getFactory() throws WSDLException
+     {
+         return fWsdlContext.wsdlFactory;
+         /*
+         if(fFactory == null)
+         {
+             fFactory = (fFactoryImplName != null)
+                         ? WSDLFactory.newInstance(fFactoryImplName)
+                         : WSDLFactory.newInstance();
+         }
+         return fFactory;
+         */
+     }
+
+     public void setFactoryImplName(String factoryImplName) {
+
+
+
+         fFactoryImplName = factoryImplName;
+     }
+
+     /**
+      * @return the WSDLFactory implementation classname
+      */
+     public String getFactoryImplName() {
+         return fFactoryImplName;
+     }
+
+     public void setExtensionRegistry(ExtensionRegistry extReg)
+     {
+         if(extReg == null) {
+             String msg = fWsdlContext.errorReporter.getFormattedMessage(
+                     "WSDL014", new Object[] {});
+             throw new NullPointerException(msg);
+         }
+
+         fWsdlContext.setExtensionRegistry(extReg);
+     }
+
+     public ExtensionRegistry getExtensionRegistry()
+     {
+         return fWsdlContext.getExtensionRegistry();
+     }
+
+     public void setFeature(String name, boolean value)
+     {
+         if(name == null)
+         {
+             //name must not be null
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL005", null));
+         }
+         try
+         {
+            features.setValue(name, value);
+         }
+         catch(IllegalArgumentException e)
+         {
+            // Feature name is not recognized, so throw an exception.
+             Object[] args = new Object[] {name};
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL006", args));
+         }
+     }
+
+     /**
+      * Returns the on/off setting of the named feature, represented as a boolean.
+      *
+      * @param name the name of the feature to get the value of
+      * @return a boolean representing the on/off state of the named feature
+      * @throws IllegalArgumentException if the feature name is not recognized.
+      */
+     public boolean getFeature(String name)
+     {
+         if(name == null)
+         {
+             //name must not be null
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL005", null));
+         }
+
+         try
+         {
+            return features.getValue(name);
+         }
+         catch(IllegalArgumentException e)
+         {
+            // Feature name is not recognized, so throw an exception.
+             Object[] args = new Object[] {name};
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL006", args));
+         }
+     }
+
+     /**
+      * Set a named property to the specified object.
+      * <p>
+      * All property names should be fully-qualified, Java package style to
+      * avoid name clashes. All names starting with org.apache.woden. are
+      * reserved for properties defined by the Woden implementation.
+      * Properties specific to other implementations should be fully-qualified
+      * to match the package name structure of that implementation.
+      * For example: com.abc.propertyName
+      *
+      * @param name the name of the property to be set
+      * @param value an Object representing the value to set the property to
+      * @throws IllegalArgumentException if the property name is not recognized.
+      */
+
+     public void setProperty(String name, Object value)
+     {
+         if(name == null)
+         {
+             //name must not be null
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL007", null));
+         }
+         else if(name.equals("xyz"))
+         {
+             //TODO determine the required properties and
+             //create an if block for each one to set the value.
+         }
+         else
+         {
+             //property name is not recognized, so throw an exception
+             Object[] args = new Object[] {name};
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL008", args));
+         }
+     }
+
+     /**
+      * Returns the value of the named property.
+      *
+      * @param name the name of the property to get the value of
+      * @return an Object representing the property's value
+      * @throws IllegalArgumentException if the property name is not recognized.
+      */
+     public Object getProperty(String name)
+     {
+         if(name == null)
+         {
+             //name must not be null
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL007", null));
+         }
+
+         //Return the property's value or throw an exception if the property
+         //name is not recognized
+
+         if(name.equals("xyz"))
+         {
+             //TODO determine the required properties and
+             //create an if block for each one to get the value.
+             return null;
+         }
+         else
+         {
+             //property name is not recognized, so throw an exception
+             Object[] args = new Object[] {name};
+             throw new IllegalArgumentException(
+                     fWsdlContext.errorReporter.getFormattedMessage("WSDL008", args));
+         }
+     }
+}

Propchange: incubator/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLFactory.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLFactory.java?rev=569372&r1=569371&r2=569372&view=diff
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLFactory.java (original)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLFactory.java Fri Aug 24 06:12:51 2007
@@ -19,6 +19,7 @@
 import org.apache.woden.WSDLException;
 import org.apache.woden.WSDLFactory;
 import org.apache.woden.WSDLReader;
+import org.apache.woden.WSDLWriter;
 import org.apache.woden.internal.wsdl20.DescriptionImpl;
 import org.apache.woden.internal.wsdl20.extensions.PopulatedExtensionRegistry;
 import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
@@ -40,6 +41,11 @@
     
     public WSDLReader newWSDLReader() throws WSDLException {
         return new DOMWSDLReader(fWsdlContext);
+    }
+    
+//  Returns an DOMWSDLWriter
+    public  WSDLWriter newWSDLWriter() throws WSDLException{
+        return new DOMWSDLWriter(fWsdlContext);
     }
     
     public DescriptionElement newDescription() {

Added: incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java?rev=569372&view=auto
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java (added)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java Fri Aug 24 06:12:51 2007
@@ -0,0 +1,719 @@
+package org.apache.woden.internal;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import org.apache.woden.wsdl20.*;
+import org.apache.woden.wsdl20.xml.*;
+import org.apache.woden.xml.XMLAttr;
+import org.apache.woden.wsdl20.extensions.*;
+import org.apache.woden.WSDLException;
+import org.apache.woden.schema.ImportedSchema;
+import org.apache.woden.schema.InlinedSchema;
+import org.apache.woden.internal.wsdl20.Constants;
+import  org.apache.ws.commons.schema.XmlSchema;
+import org.apache.woden.wsdl20.enumeration.Direction;
+import org.apache.woden.internal.util.dom.DOM2Writer;
+import org.apache.woden.internal.util.dom.DOMUtils;
+import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
+
+/**
+ * WSDLWriter implemantation based on DOM
+ *
+ * @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
+ */
+
+public class DOMWSDLWriter extends BaseWSDLWriter
+{
+    public DOMWSDLWriter(WSDLContext wsdlContext)
+    {
+        super(wsdlContext);
+
+    }
+
+    public void writeWSDL(Description wsdlDes, Writer sink)
+        throws WSDLException {
+
+        PrintWriter pw = new PrintWriter(sink);
+        String javaEncoding = (sink instanceof OutputStreamWriter)
+                              ? ((OutputStreamWriter)sink).getEncoding()
+                              : null;
+        String xmlEncoding = DOM2Writer.java2XMLEncoding(javaEncoding);
+        if (xmlEncoding == null)
+       {
+           throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+                   "Unsupported Java encoding for writing " +
+                   "wsdl file: '" + javaEncoding + "'.");
+       }
+        pw.println(Constants.XML_DECL_START +
+               xmlEncoding +
+               Constants.XML_DECL_END);
+        printDescription(wsdlDes, pw);
+    }
+
+    public void writeWSDL(Description wsdlDes, OutputStream sink)
+        throws WSDLException {
+
+        Writer writer = null;
+        try{
+            writer = new OutputStreamWriter(sink, "UTF8");
+
+        }catch (UnsupportedEncodingException e){
+            e.printStackTrace();
+            writer = new OutputStreamWriter(sink);
+        }
+        writeWSDL(wsdlDes, writer);
+    }
+
+    protected void printDescription(Description def, PrintWriter pw)
+        throws WSDLException {
+
+        if (def == null){
+            return;
+        }
+        DescriptionElement desEle=def.toElement();
+        if (DOMUtils.getPrefix(Constants.NS_URI_WSDL20,desEle) == null){
+
+            String prefix = "wsdl";
+            int subscript = 0;
+            while (def.toElement().getNamespace(prefix) != null){
+                prefix = "wsdl" + subscript++;
+            }
+            try{
+                desEle.addNamespace(prefix, new URI(Constants.NS_URI_WSDL20));
+            }catch(URISyntaxException  exp){
+                // TODO
+            }
+        }
+        String tagName =DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                Constants.ELEM_DESCRIPTION, desEle);
+        pw.print('<' + tagName);
+        String targetNamespace = desEle.getTargetNamespace().toString();
+        Map namespaces = desEle.getNamespaces();
+        DOMUtils.printAttribute(Constants.ATTR_TARGET_NAMESPACE,
+                                targetNamespace,
+                                pw);
+         //TODO
+        //printExtensibilityAttributes(DescriptionElement.class, desEle, def, pw);
+
+        printNamespaceDeclarations(namespaces, pw);
+        pw.println('>');
+
+        printImports(desEle.getImportElements(), desEle, pw);
+
+        printIncludes(desEle.getIncludeElements(), desEle, pw);
+
+        printTypes(desEle.getTypesElement(), desEle, pw);
+
+        printInterfaces(desEle.getInterfaceElements(), desEle, pw);
+
+        printBindings(desEle.getBindingElements(), desEle, pw);
+
+        printServices(desEle.getServiceElements(), desEle, pw);
+
+       //TODO
+       // printExtensibilityElements(Definition.class, extElements, def, pw);
+
+        pw.println("</" + tagName + '>');
+        pw.flush();
+    }
+
+    protected void printNamespaceDeclarations(Map namespaces, PrintWriter pw)
+        throws WSDLException {
+
+        if (namespaces != null){
+            Set keys = namespaces.keySet();
+            Iterator keyIterator = keys.iterator();
+            while (keyIterator.hasNext()){
+                String prefix = (String)keyIterator.next();
+                if (prefix == null){
+                    prefix = "";
+                }
+                DOMUtils.printAttribute(Constants.ATTR_XMLNS +
+                        (!prefix.equals("") ? ":" + prefix : ""),
+                        (String)namespaces.get(prefix).toString(),
+                        pw);
+            }
+        }
+
+    }
+
+    protected void printImports(ImportElement[] imports,
+                                DescriptionElement des,
+                                PrintWriter pw)
+                                throws WSDLException
+    {
+            //      TODO
+
+    }
+
+    protected void printIncludes(IncludeElement[] imports,
+                                 DescriptionElement des,
+                                 PrintWriter pw)
+                                 throws WSDLException
+     {
+              //      TODO
+
+
+    }
+
+    protected void printInterfaces(InterfaceElement[] intrfaces,
+                                   DescriptionElement des,
+                                   PrintWriter pw)
+                                   throws WSDLException
+     {
+        if (intrfaces != null){
+            String tagName =
+                DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                           Constants.ELEM_INTERFACE,
+                           des);
+            for(int ind=0;ind<intrfaces.length;ind++){
+                InterfaceElement intrface = intrfaces[ind];
+                if (intrface!=null){
+                    pw.print("  <" + tagName);
+                    QName name = intrface.getName();
+                    if (name != null){
+                        DOMUtils.printAttribute(Constants.ATTR_NAME,
+                                name.getLocalPart(),
+                                pw);
+                    }
+                    // TODO
+                    // printExtensibilityAttributes(InterfaceElement.class, portType, des, pw);
+
+                    pw.println('>');
+
+                    // TODO
+                    //printDocumentation(portType.getDocumentationElement(), def, pw);
+
+
+                    printOperations(intrface.getInterfaceOperationElements(), des, pw);
+
+                    // TODO
+                    // printExtensibilityElements(PortType.class, extElements, def, pw);
+
+                    pw.println("  </" + tagName + '>');
+                }
+            }
+        }
+     }
+
+    protected void printOperations(InterfaceOperationElement[] operations,
+                                   DescriptionElement def,
+                                   PrintWriter pw)
+                                   throws WSDLException
+     {
+        if (operations != null){
+
+            String tagName =
+                DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                          Constants.ELEM_OPERATION,
+                          def);
+            for(int ind=0;ind<operations.length;ind++){
+
+                InterfaceOperationElement operation =operations[ind] ;
+                if (operation!=null){
+
+                    pw.print("    <" + tagName);
+                    DOMUtils.printAttribute(Constants.ATTR_NAME,
+                             operation.getName().getLocalPart(),
+                             pw);
+
+                    //TODO
+                    // printExtensibilityAttributes(Operation.class, operation, def, pw);
+
+                    pw.println('>');
+
+                    //TODO
+                   //printDocumentation(operation.getDocumentationElement(), def, pw);
+
+                    printInterfaceMessageReferenceElement(operation.getInterfaceMessageReferenceElements(),def, pw);
+
+
+                    printInterfaceFaultReferenceElements(operation.getInterfaceFaultReferenceElements(),def,pw);
+
+
+                    // TODO
+                    // printExtensibilityElements(Operation.class, extElements, def, pw);
+
+                    pw.println("    </" + tagName + '>');
+
+                }
+
+            }
+
+
+        }
+
+
+
+     }
+
+    protected void printInterfaceMessageReferenceElement( InterfaceMessageReferenceElement[] msgrefs,
+            DescriptionElement des,
+            PrintWriter pw)
+              throws WSDLException
+     {
+
+        for(int ind=0;ind<msgrefs.length;ind++){
+            InterfaceMessageReferenceElement msgRef=msgrefs[ind];
+            if(msgRef!=null){
+
+                String tagName =null;
+                Direction msgDirection=msgRef.getDirection();
+                if(msgDirection==Direction.IN){
+                    tagName=DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                             Constants.ELEM_INPUT,
+                             des);
+                }else if(msgDirection==Direction.OUT){
+                    tagName=DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                             Constants.ELEM_OUTPUT,
+                             des);            }
+
+            pw.print("      <" + tagName);
+            String msglable=msgRef.getMessageLabel().toString();
+            DOMUtils.printAttribute(Constants.ATTR_MESSAGE_LABEL, msglable, pw);
+            QName attrQName=msgRef.getElementName();
+            String attrName=
+                DOMUtils.getQualifiedValue(des.getNamespace(attrQName.getPrefix()).toString(),
+                    attrQName.getLocalPart(), des);
+            DOMUtils.printAttribute(Constants.ATTR_ELEMENT, attrName, pw);
+
+            // TODO
+            //printExtensibilityAttributes(Input.class, input, def, pw);
+
+            pw.println('>');
+
+
+            // TODO
+            // printDocumentation(input.getDocumentationElement(), def, pw);
+
+
+            // TODO
+            // printExtensibilityElements(Input.class, extElements, def, pw);
+
+            pw.println("    </" + tagName + '>');
+        }
+      }
+    }
+
+    protected void printInterfaceFaultReferenceElements(InterfaceFaultReferenceElement[] faulRefs,
+                                                        DescriptionElement des,
+                                                        PrintWriter pw)
+                                                        throws WSDLException{
+        for(int ind=0;ind<faulRefs.length;ind++){
+
+            InterfaceFaultReferenceElement faulRef=faulRefs[ind];
+            if(faulRef!=null){
+
+                String tagName =null;
+                Direction msgDirection=faulRef.getDirection();
+                if(msgDirection==Direction.IN){
+                    tagName=DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                            Constants.ELEM_INFAULT,
+                            des);
+                }else if(msgDirection==Direction.OUT){
+
+                    tagName=DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                            Constants.ELEM_OUTFAULT,
+                            des);
+
+                }
+
+                pw.print("      <" + tagName);
+
+                String msglable=faulRef.getMessageLabel().toString();
+
+                DOMUtils.printAttribute(Constants.ATTR_MESSAGE_LABEL, msglable, pw);
+
+
+                QName attrQName=faulRef.getRef();
+                String attrName=
+                    DOMUtils.getQualifiedValue(des.getNamespace(attrQName.getPrefix()).toString(),
+                        attrQName.getLocalPart(),
+                          des);
+                DOMUtils.printAttribute(Constants.ATTR_ELEMENT, attrName, pw);
+
+               // TODO
+               // printExtensibilityAttributes(Input.class, input, def, pw);
+
+               pw.println('>');
+
+               // TODO
+               // printDocumentation(input.getDocumentationElement(), def, pw);
+
+              // TODO
+              //printExtensibilityElements(Input.class, extElements, def, pw);
+
+              pw.println("    </" + tagName + '>');
+            }
+
+
+
+        }
+
+
+    }
+
+    protected void printBindings(BindingElement[] bindings,
+                                 DescriptionElement def,
+                                 PrintWriter pw)
+                                 throws WSDLException
+    {
+        String tagName =
+            DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                        Constants.ELEM_BINDING,
+                        def);
+        for(int ind=0;ind<bindings.length;ind++){
+
+            BindingElement binding=bindings[ind];
+            if (bindings != null){
+
+                pw.print("  <" + tagName);
+                QName name = binding.getName();
+                if (name != null){
+                    DOMUtils.printAttribute(Constants.ATTR_NAME,
+                            name.getLocalPart(),
+                            pw);
+                }
+
+                InterfaceElement intrface = binding.getInterfaceElement();
+                if (intrface != null){
+
+                    DOMUtils.printQualifiedAttribute(Constants.ATTR_INTERFACE,
+                            intrface.getName(),
+                            def,
+                            pw);
+                    DOMUtils.printAttribute(Constants.ATTR_TYPE,
+                            binding.getType().toString(),
+                            pw);
+
+
+
+                   // TODO write seralization to handle wsoap:protocol attribute
+                   // e.g. wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP"
+                   pw.println('>');
+                   printBindingOperationElements(
+                           binding.getBindingOperationElements(),def,pw);
+
+                }
+
+                // TODO
+                // printDocumentation(binding.getDocumentationElement(), def, pw);
+
+
+                // TODO
+                // printExtensibilityElements(Binding.class, extElements, def, pw);
+
+
+                // printBindingOperationElements(binding.getBindingOperationElements(), def, pw);
+                // printBindingFaultElements(binding.getBindingFaultElements(), def, pw);
+
+                pw.println("  </" + tagName + '>');
+            }
+        }
+    }
+
+    protected void printBindingFaultElements(BindingFaultElement[] faults,
+                                             DescriptionElement def,
+                                             PrintWriter pw)
+                                             throws WSDLException{
+        // TODO
+
+    }
+
+    protected void printBindingOperationElements(BindingOperationElement[] operations,
+                                                 DescriptionElement def,
+                                                 PrintWriter pw)
+                                                 throws WSDLException
+     {
+
+        if (operations != null){
+
+            String tagName =
+                DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                          Constants.ELEM_OPERATION,
+                          def);
+            for(int ind=0;ind<operations.length;ind++){
+
+                BindingOperationElement operation =operations[ind] ;
+                if (operation!=null){
+
+                    pw.print("    <" + tagName);
+                    DOMUtils.printQualifiedAttribute(Constants.ATTR_REF,
+                             operation.getRef(),
+                             def,
+                             pw);
+
+                    //TODO write serialization to handle wsoap:mep attrubute
+                    // e.g. wsoap:mep="http://www.w3.org/2003/05/soap/mep/request-response
+
+                    pw.println("/>");
+
+                }
+            }
+
+
+        }
+
+     }
+
+    protected void printServices(ServiceElement[] services,
+                                 DescriptionElement def,
+                                 PrintWriter pw)
+                                 throws WSDLException
+     {
+        String tagName =
+            DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                        Constants.ELEM_SERVICE,
+                        def);
+        for(int ind=0;ind<services.length;ind++){
+
+            ServiceElement service=services[ind];
+            if(service!=null){
+
+                pw.print("  <" + tagName);
+                QName name = service.getName();
+                if (name != null){
+                    DOMUtils.printAttribute(Constants.ATTR_NAME,
+                            name.getLocalPart(),
+                            pw);
+                }
+                QName interName = service.getInterfaceName();
+                if (name != null){
+
+                    DOMUtils.printQualifiedAttribute(Constants.ATTR_INTERFACE,
+                            interName,def, pw);
+                }
+
+                // TODO
+                // printExtensibilityAttributes(Service.class, service, def, pw);
+
+                pw.println('>');
+
+                printEndpoint(service.getEndpointElements(), def, pw);
+            }
+        }
+     }
+
+    protected void printEndpoint(EndpointElement[] endpoints,
+                                 DescriptionElement des,
+                                 PrintWriter pw)
+                                 throws WSDLException
+      {
+        String tagName =
+            DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                                       Constants.ELEM_ENDPOINT,
+                                       des);
+        for(int ind=0;ind<endpoints.length;ind++){
+
+            EndpointElement endPoint=endpoints[ind];
+            if(endPoint!=null){
+
+                pw.print("    <" + tagName);
+                DOMUtils.printAttribute(Constants.ATTR_NAME,
+                        endPoint.getName().toString(), pw);
+                BindingElement binding =endPoint.getBindingElement();
+                if (binding != null){
+                    DOMUtils.printQualifiedAttribute(Constants.ATTR_BINDING,
+                            binding.getName(),
+                            des,
+                            pw);
+                }
+
+                // TODO
+                // printExtensibilityAttributes(Port.class, port, def, pw);
+                pw.println('>');
+                // TODO
+                // printDocumentation(endPoint.addDocumentationElement(), des, pw);
+                // TODO
+                // printExtensibilityElements(Endpoint.class, extElements, des, pw);
+                pw.println("    </" + tagName + '>');
+            }
+        }
+      }
+
+    protected void printTypes(TypesElement types,
+                              DescriptionElement des,
+                              PrintWriter pw)
+                              throws WSDLException
+    {
+        if (types != null){
+
+
+            String tagName =
+                DOMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                                           Constants.ELEM_TYPES,
+                                           des);
+            pw.print("<" + tagName);
+            printExtensibilityAttributes(types.getClass(), types, des, pw);
+            pw.println('>');
+            ExtensionElement[] extElements = types.getExtensionElements();
+            printExtensibilityElements(types.getClass(), extElements, des, pw);
+            printImportedSchemaElements(types.getImportedSchemas(),des,pw);
+            printInlinedSchemaElements(types.getInlinedSchemas(),des,pw);
+            pw.println("</" + tagName + '>');
+        }
+    }
+
+
+    protected void printInlinedSchemaElements(InlinedSchema inlinedSchema[],
+                                              DescriptionElement des,
+                                              PrintWriter pw)
+                                              throws WSDLException
+    {
+        XmlSchema xs=null;
+        // TODO used XmlSchema serialiser.Cause extra info like
+        // attributeFormDefault="unqualified" elementFormDefault="unqualified" ..etc
+        for(int i=0;i<inlinedSchema.length;i++){
+            xs=inlinedSchema[i].getSchemaDefinition();
+            xs.write(pw);
+        }
+    }
+
+    protected void printImportedSchemaElements(ImportedSchema importedSchema[],
+                                               DescriptionElement des,
+                                               PrintWriter pw )
+                                               throws WSDLException
+    {
+        // TODO Hard coded for XML schema 2000,complete for both 2000 and 2001
+        String tagname=DOMUtils.getQualifiedValue(Constants.TYPE_XSD_2001,
+                                                  Constants.ELEM_IMPORT,des);
+        for(int i=0;i<importedSchema.length;i++){
+
+            pw.println("<"+tagname);
+            DOMUtils.printAttribute(Constants.ATTR_NAMESPACE,
+                    importedSchema[i].getNamespace().toString(),
+                    pw);
+            DOMUtils.printAttribute(Constants.ATTR_LOCATION,
+                    importedSchema[i].getSchemaLocation().toString(),
+                    pw);
+            pw.print(" />");
+        }
+    }
+
+    protected void printExtensibilityElements(Class parentType,
+                                              ExtensionElement[] extensibilityElements,
+                                              DescriptionElement def,
+                                              PrintWriter pw)
+                                              throws WSDLException
+      {
+
+        if (extensibilityElements != null){
+
+            for(int ind=0;ind<extensibilityElements.length;ind++){
+
+                ExtensionElement ext =extensibilityElements[ind];
+                QName elementType = ext.getExtensionType();
+                ExtensionRegistry extReg = fWsdlContext.getExtensionRegistry();
+                if (extReg == null){
+
+                    throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+                            "No ExtensionRegistry set for this " +
+                            "Definition, so unable to serialize a '" +
+                            elementType +
+                            "' element in the context of a '" +
+                            parentType.getName() + "'.");
+                }
+                ExtensionSerializer extSer = extReg.querySerializer(parentType,
+                        elementType);
+                extSer.marshall(parentType, elementType, ext, pw, def, extReg);
+            }
+        }
+      }
+
+    protected void printExtensibilityAttributes(Class parentType,
+                                                AttributeExtensible attrExt,
+                                                DescriptionElement def,
+                                                PrintWriter pw)
+                                                throws WSDLException
+    {
+
+        XMLAttr[] extensionAttributes=attrExt.getExtensionAttributes();
+        //Map extensionAttributes = attrExt.getExtensionAttributes()
+        for(int index=0;index<extensionAttributes.length;index++){
+
+            QName attrName = (QName)extensionAttributes[index].getAttributeType();
+            Object attrValue = extensionAttributes[index].getContent();
+            String attrStrValue = null;
+            QName attrQNameValue = null;
+
+            if (attrValue instanceof String){
+
+                attrStrValue = (String)attrValue;
+            }
+            else if (attrValue instanceof QName){
+
+                attrQNameValue = (QName)attrValue;
+            }
+            else if (attrValue instanceof List){
+
+                List attrValueList = (List)attrValue;
+                int size = attrValueList.size();
+                if (size > 0){
+
+                    Object tempAttrVal = attrValueList.get(0);
+                    if (tempAttrVal instanceof String){
+
+                        //attrStrValue = StringUtils.getNMTokens(attrValueList);
+                    }
+                    else if (tempAttrVal instanceof QName){
+                        StringBuffer strBuf = new StringBuffer();
+                        for (int i = 0; i < size; i++){
+
+                            QName tempQName = (QName)attrValueList.get(i);
+                            strBuf.append((i > 0 ? " " : "") +
+                            DOMUtils.getQualifiedValue(tempQName.getNamespaceURI(),
+                                             tempQName.getLocalPart(),
+                                             def));
+                        }
+                        attrStrValue = strBuf.toString();
+                    }else{
+
+                        throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+                                "Unknown type of extension attribute '" +
+                                attrName + "': " +
+                                tempAttrVal.getClass().getName());
+                    }
+                }
+                else{
+                    attrStrValue = "";
+                }
+            }
+            else{
+                throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+                        "Unknown type of extension attribute '" +
+                        attrName + "': " +
+                        attrValue.getClass().getName());
+            }
+            if (attrQNameValue != null){
+                DOMUtils.printQualifiedAttribute(attrName, attrQNameValue, def, pw);
+            }
+            else{
+                DOMUtils.printQualifiedAttribute(attrName, attrStrValue, def, pw);
+            }
+        }
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+

Propchange: incubator/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLFactory.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLFactory.java?rev=569372&r1=569371&r2=569372&view=diff
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLFactory.java (original)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLFactory.java Fri Aug 24 06:12:51 2007
@@ -19,6 +19,7 @@
 import org.apache.woden.WSDLException;
 import org.apache.woden.WSDLFactory;
 import org.apache.woden.WSDLReader;
+import org.apache.woden.WSDLWriter;
 import org.apache.woden.internal.wsdl20.DescriptionImpl;
 import org.apache.woden.internal.wsdl20.extensions.PopulatedExtensionRegistry;
 import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
@@ -38,6 +39,13 @@
     public WSDLReader newWSDLReader() throws WSDLException {
         return new OMWSDLReader(fWsdlContext);
     }
+    
+//  Returns an DOMWSDLWriter
+    public  WSDLWriter newWSDLWriter() throws WSDLException{
+        return new OMWSDLWriter(fWsdlContext);
+    }
+    
+    
 
     public DescriptionElement newDescription() {
         return new DescriptionImpl(fWsdlContext);

Added: incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java?rev=569372&view=auto
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java (added)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java Fri Aug 24 06:12:51 2007
@@ -0,0 +1,39 @@
+
+package org.apache.woden.internal;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.woden.WSDLException;
+import org.apache.woden.wsdl20.Description;
+
+/**
+ * @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
+ *
+ */
+public class OMWSDLWriter extends BaseWSDLWriter{
+
+    public OMWSDLWriter(WSDLContext wsdlContext)throws WSDLException{
+        super(wsdlContext);
+    }
+
+    public void setFeature(String name, boolean value)
+    throws IllegalArgumentException{
+        //TO-DO
+    }
+
+
+
+    public void writeWSDL(Description wsdlDes, Writer sink)
+    throws WSDLException{
+
+    }
+
+    public void writeWSDL(Description wsdlDes, OutputStream sink){
+
+    }
+}

Propchange: incubator/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/woden/branches/woden65/src/org/apache/woden/internal/WriterFeatures.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/WriterFeatures.java?rev=569372&view=auto
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/WriterFeatures.java (added)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/WriterFeatures.java Fri Aug 24 06:12:51 2007
@@ -0,0 +1,66 @@
+package org.apache.woden.internal;
+
+import java.util.Hashtable;
+import org.apache.woden.WSDLWriter;
+
+/**
+ * This class contains all supported Woden writer features .
+ *
+ * TODO Decide this is necessary or not?
+ * determine the required features (e.g. org.apache.woden.verbose) and
+ * create an ID for each value.
+ */
+public class WriterFeatures {
+
+    /**
+     * This hashtable contains the values for the features.
+     */
+    protected Hashtable values = new Hashtable();
+
+    private Boolean on = new Boolean(true);
+    private Boolean off = new Boolean(false);
+
+    public WriterFeatures()
+    {
+
+    }
+
+    /**
+     * Get the value for the given feature.
+     * @param featureId The ID of the feature for which the value is requested.
+     * @return true if the feature is enabled, false otherwise.
+     * @throws IllegalArgumentException if the feature is not supported.
+     */
+    public boolean getValue(String featureId) throws IllegalArgumentException
+    {
+      Boolean value = (Boolean)values.get(featureId);
+      if(value == null)
+      {
+        throw new IllegalArgumentException("The feature " + featureId + " is not supported.");
+      }
+      return value.booleanValue();
+    }
+
+    /**
+     * Set the value of the given feature
+     * @param featureId The ID of the feature to set.
+     * @param value The value to set for the feature.
+     * @throws IllegalArgumentException if the feature is not supported.
+     */
+    public void setValue(String featureId, boolean value) throws IllegalArgumentException
+    {
+        // Check if the feature is supported.
+        if(!values.containsKey(featureId))
+        {
+            throw new IllegalArgumentException("The feature " + featureId + " is not supported.");
+        }
+        if(value)
+        {
+            values.put(featureId, on);
+        }
+        else
+        {
+            values.put(featureId, off);
+        }
+    }
+}

Propchange: incubator/woden/branches/woden65/src/org/apache/woden/internal/WriterFeatures.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/woden/branches/woden65/src/org/apache/woden/internal/util/dom/DOMUtils.java
URL: http://svn.apache.org/viewvc/incubator/woden/branches/woden65/src/org/apache/woden/internal/util/dom/DOMUtils.java?rev=569372&r1=569371&r2=569372&view=diff
==============================================================================
--- incubator/woden/branches/woden65/src/org/apache/woden/internal/util/dom/DOMUtils.java (original)
+++ incubator/woden/branches/woden65/src/org/apache/woden/internal/util/dom/DOMUtils.java Fri Aug 24 06:12:51 2007
@@ -21,6 +21,8 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Vector;
+import java.util.Map;
+import java.io.PrintWriter;
 
 import javax.xml.namespace.QName;
 
@@ -551,7 +553,7 @@
     throw wsdlExc;
   }
 
-  /*
+
   public static void printAttribute(String name,
                                     String value,
                                     PrintWriter pw)
@@ -561,15 +563,15 @@
       pw.print(' ' + name + "=\"" + cleanString(value) + '\"');
     }
   }
-  */
+
 
   /**
    * Prints attributes with qualified names.
    */
-  /*
+
   public static void printQualifiedAttribute(QName name,
                                              String value,
-                                             Definition def,
+                                             DescriptionElement desEle,
                                              PrintWriter pw)
                                                throws WSDLException
   {
@@ -577,7 +579,7 @@
     {
       printAttribute(getQualifiedValue(name.getNamespaceURI(),
                                        name.getLocalPart(),
-                                       def),
+                                       desEle),
                      value,
                      pw);
     }
@@ -585,7 +587,7 @@
 
   public static void printQualifiedAttribute(QName name,
                                              QName value,
-                                             Definition def,
+                                             DescriptionElement desEle,
                                              PrintWriter pw)
                                                throws WSDLException
   {
@@ -593,17 +595,17 @@
     {
       printAttribute(getQualifiedValue(name.getNamespaceURI(),
                                        name.getLocalPart(),
-                                       def),
+                                       desEle),
                      getQualifiedValue(value.getNamespaceURI(),
                                        value.getLocalPart(),
-                                       def),
+                                       desEle),
                      pw);
     }
   }
 
   public static void printQualifiedAttribute(String name,
                                              QName value,
-                                             Definition def,
+                                             DescriptionElement desEle,
                                              PrintWriter pw)
                                                throws WSDLException
   {
@@ -612,21 +614,21 @@
       printAttribute(name,
                      getQualifiedValue(value.getNamespaceURI(),
                                        value.getLocalPart(),
-                                       def),
+                                       desEle),
                      pw);
     }
   }
 
   public static String getQualifiedValue(String namespaceURI,
                                          String localPart,
-                                         Definition def)
+                                         DescriptionElement desEle)
                                            throws WSDLException
   {
     String prefix = null;
 
     if (namespaceURI != null && !namespaceURI.equals(""))
     {
-      prefix = getPrefix(namespaceURI, def);
+      prefix = getPrefix(namespaceURI, desEle);
     }
 
     return ((prefix != null && !prefix.equals(""))
@@ -635,21 +637,39 @@
   }
 
   public static String getPrefix(String namespaceURI,
-                                 Definition def)
+                                 DescriptionElement desEle)
                                    throws WSDLException
   {
-    String prefix = def.getPrefix(namespaceURI);
+      String prefix =null;
+      Map nsm=desEle.getNamespaces();
+      java.util.Iterator entryIterator = nsm.entrySet().iterator();
 
-    if (prefix == null)
-    {
-      throw new WSDLException(WSDLException.OTHER_ERROR,
-                              "Can't find prefix for '" + namespaceURI +
-                              "'. Namespace prefixes must be set on the" +
-                              " Definition object using the " +
-                              "addNamespace(...) method.");
-    }
 
-    return prefix;
+      while (entryIterator.hasNext())
+      {
+          Map.Entry entry = (Map.Entry)entryIterator.next();
+          String currPrefix = (String)entry.getKey();
+          String assocNamespaceURI = entry.getValue().toString();
+
+          if(namespaceURI.equals(assocNamespaceURI)){
+
+              prefix=currPrefix;
+
+          }
+      }
+
+      if (prefix == null)
+      {
+          throw new WSDLException(WSDLException.OTHER_ERROR,
+                  "Can't find prefix for '" + namespaceURI +
+                  "'. Namespace prefixes must be set on the" +
+                  " Definition object using the " +
+                  "addNamespace(...) method.");
+
+      }
+
+
+      return prefix;
   }
 
   public static String cleanString(String orig)
@@ -719,7 +739,7 @@
 
     return strBuf.toString();
   }
-  */
-  
+
+
 }
 



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