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 2008/07/07 18:13:11 UTC

svn commit: r674534 - in /webservices/woden/branches/woden65/src/org/apache/woden/internal: OMWSDLWriter.java util/om/OMUtils.java util/om/OMWriter.java

Author: jkaputin
Date: Mon Jul  7 09:13:10 2008
New Revision: 674534

URL: http://svn.apache.org/viewvc?rev=674534&view=rev
Log:
WODEN-65
Committed Sagara's patch to commence work on the OM serialization. Improve indentation in OMWriter.

Added:
    webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMWriter.java   (with props)
Modified:
    webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java
    webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMUtils.java

Modified: webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java?rev=674534&r1=674533&r2=674534&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/internal/OMWSDLWriter.java Mon Jul  7 09:13:10 2008
@@ -6,10 +6,43 @@
 import java.io.PrintWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMNode;
 import org.apache.woden.WSDLException;
+import org.apache.woden.XMLElement;
+import org.apache.woden.internal.util.om.OMUtils;
+import org.apache.woden.internal.util.om.OMWriter;
+import org.apache.woden.internal.wsdl20.Constants;
+import org.apache.woden.schema.ImportedSchema;
+import org.apache.woden.schema.InlinedSchema;
+import org.apache.woden.types.NamespaceDeclaration;
+import org.apache.woden.types.QNameTokenUnion;
+import org.apache.woden.wsdl20.enumeration.Direction;
+import org.apache.woden.wsdl20.extensions.ExtensionElement;
+import org.apache.woden.wsdl20.extensions.ExtensionRegistry;
+import org.apache.woden.wsdl20.extensions.ExtensionSerializer;
+import org.apache.woden.wsdl20.xml.BindingElement;
+import org.apache.woden.wsdl20.xml.BindingFaultElement;
+import org.apache.woden.wsdl20.xml.BindingOperationElement;
 import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.xml.DocumentationElement;
+import org.apache.woden.wsdl20.xml.EndpointElement;
+import org.apache.woden.wsdl20.xml.ImportElement;
+import org.apache.woden.wsdl20.xml.IncludeElement;
+import org.apache.woden.wsdl20.xml.InterfaceElement;
+import org.apache.woden.wsdl20.xml.InterfaceFaultReferenceElement;
+import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement;
+import org.apache.woden.wsdl20.xml.InterfaceOperationElement;
+import org.apache.woden.wsdl20.xml.ServiceElement;
+import org.apache.woden.wsdl20.xml.TypesElement;
+import org.apache.woden.wsdl20.xml.WSDLElement;
+import org.apache.woden.xml.XMLAttr;
+
 
 /**
  * @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
@@ -17,23 +50,625 @@
  */
 public class OMWSDLWriter extends BaseWSDLWriter{
 
-    public OMWSDLWriter(WSDLContext wsdlContext)throws WSDLException{
+    public OMWSDLWriter(WSDLContext wsdlContext)
+    {
         super(wsdlContext);
+
     }
 
-    public void setFeature(String name, boolean value)
-    throws IllegalArgumentException{
-        //TO-DO
+
+    /**
+     * This method write the specified WSDL Description to
+     * the specified Writer.
+     *
+     * @param wsdlDes the WSDL Description to be written.
+     * @param sink the Writer to write the xml to.
+     */
+    public void writeWSDL(DescriptionElement wsdlDes, Writer sink)
+        throws WSDLException {
+
+        PrintWriter pw = new PrintWriter(sink);
+        String javaEncoding = (sink instanceof OutputStreamWriter)
+                              ? ((OutputStreamWriter)sink).getEncoding()
+                              : null;
+        String xmlEncoding = OMWriter.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(DescriptionElement wsdlDes, Writer sink)
-    throws WSDLException{
+    /**
+     * This method write the specified WSDL Description to
+     * the specified Writer.
+     *
+     * @param wsdlDes the WSDL Description to be written.
+     * @param sink the OutputStream to write the xml to.
+     */
+    public void writeWSDL(DescriptionElement 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);
+    }
+
+
+    /**
+     * Write the specified WSDL DescriptionElement and it's
+     * child elements to  the specified Writer.
+     *
+     * @param desEle the WSDL Description to be written.
+     * @param sink the Writer to write the xml to.
+     */
+    protected void printDescription(DescriptionElement desEle, PrintWriter pw)
+        throws WSDLException {
+
+        if (desEle == null){
+            return;
+        }
+        if (desEle.getNamespacePrefix(Constants.NS_URI_WSDL20) == null){
+            String prefix = "wsdl";
+            int subscript = 0;
+            while (desEle.getNamespaceURI(prefix) != null){
+                prefix = "wsdl" + subscript++;
+            }
+            desEle.addNamespace(prefix, Constants.NS_URI_WSDL20);
+        }
+        String tagName =OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                Constants.ELEM_DESCRIPTION, desEle);
+        pw.print('<' + tagName);
+        String targetNamespace = desEle.getTargetNamespace().toString();
+        NamespaceDeclaration[] namespaces = desEle.getDeclaredNamespaces();
+        OMUtils.printAttribute(Constants.ATTR_TARGET_NAMESPACE,
+                                targetNamespace,
+                                pw);
+
+        printExtensibilityAttributes(desEle.getExtensionAttributes(), desEle, pw);
+        printNamespaceDeclarations(namespaces, pw);
+        pw.println('>');
+        printDocumentation(desEle.getDocumentationElements(), desEle, pw);
+        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);
+        printExtensibilityElements(desEle.getClass(), desEle.getExtensionElements(), desEle, pw);
+        pw.println("</" + tagName + '>');
+        pw.flush();
+    }
+
+
+    /**
+     * Serialize  the namespace declarations of the  WSDL Description.
+     *
+     * @param namespaces a java.util.Map contains namespace of WSDL Description.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printNamespaceDeclarations(NamespaceDeclaration[] namespaces, PrintWriter pw)
+        throws WSDLException {
+        
+        if (namespaces != null) {
+            int len = namespaces.length;
+            for (int i = 0; i < len; i++) {
+                String prefix = namespaces[i].getPrefix();
+                if (prefix == null) {
+                    prefix = "";
+                }
+                OMUtils.printAttribute(Constants.ATTR_XMLNS
+                        + (!prefix.equals("") ? ":" + prefix : ""),
+                        namespaces[i].getNamespaceURI().toString(), pw);
+            }
+        }
+
+
+    }
+
+
+    /**
+     * Serialize  the ImportElements of the  WSDL element model.
+     *
+     * @param imports an array of ImportElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printImports(ImportElement[] imports,
+                                DescriptionElement des,
+                                PrintWriter pw)
+                                throws WSDLException
+    {   
+        
+        if (imports != null){
+            String tagName =
+                OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                           Constants.ELEM_IMPORT,
+                           des);
+            for(int ind=0;ind<imports.length;ind++){
+                ImportElement importEle = imports[ind];
+                if (importEle!=null){
+                    pw.print("  <" + tagName);
+
+                    String namespace = importEle.getNamespace().toString();
+                    if (namespace != null){
+                        OMUtils.printAttribute(Constants.ATTR_NAMESPACE,
+                                namespace,
+                                pw);
+                    }
+                    String location = importEle.getLocation().toString();
+                    if (location != null){
+                        OMUtils.printAttribute(Constants.ATTR_LOCATION,
+                                location,
+                                pw);
+                    }
+                    printExtensibilityAttributes(importEle.getExtensionAttributes(), importEle, pw);
+                    pw.println('>');
+                    printDocumentation(importEle.getDocumentationElements(), des, pw);
+                    printExtensibilityElements(importEle.getClass(), importEle.getExtensionElements(), des, pw);
+                    pw.println("  </" + tagName + '>');
+                }
+            }
+        }
+
+    }
+
+    /**
+     * Serialize  the IncludeElements of the  WSDL element model.
+     *
+     * @param imports an array of IncludeElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printIncludes(IncludeElement[] includes,
+                                 DescriptionElement des,
+                                 PrintWriter pw)
+                                 throws WSDLException
+     {
+        if (includes != null){
+            String tagName =
+                OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                           Constants.ELEM_INCLUDE,
+                           des);
+            for(int ind=0;ind<includes.length;ind++){
+                IncludeElement includeEle = includes[ind];
+                if (includeEle!=null){
+                    pw.print("  <" + tagName);
+
+                    String location = includeEle.getLocation().toString();
+                    if (location != null){
+                        OMUtils.printAttribute(Constants.ATTR_LOCATION,
+                                location,
+                                pw);
+                    }
+                    printExtensibilityAttributes(includeEle.getExtensionAttributes(),includeEle, pw);
+                    pw.println('>');
+                    printDocumentation(includeEle.getDocumentationElements(), des, pw);
+                    printExtensibilityElements(includeEle.getClass(), includeEle.getExtensionElements(), des, pw);
+                    pw.println("  </" + tagName + '>');
+                }
+            }
+        }
+
+    }
+
+
+    /**
+     * Serialize  the InterfaceElements of the  WSDL element model.
+     *
+     * @param intrfaces an array of intrfacesElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printInterfaces(InterfaceElement[] intrfaces,
+                                   DescriptionElement des,
+                                   PrintWriter pw)
+                                   throws WSDLException
+     {      
+        if (intrfaces != null){
+            String tagName =
+                OMUtils.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){
+                        OMUtils.printAttribute(Constants.ATTR_NAME,
+                                name.getLocalPart(),
+                                pw);
+                    }
+
+                    QName[] extendedInterfaces = intrface.getExtendedInterfaceNames();
+                    for(int i=0;i<extendedInterfaces.length;i++){
+                        if(extendedInterfaces[i]!=null){
+
+                            OMUtils.printQualifiedAttribute(
+                                    Constants.ATTR_EXTENDS,
+                                    extendedInterfaces[i],
+                                    des, pw);
+                        }
+                    }
+
+                    URI[] styleDefaults = intrface.getStyleDefault();
+                    for(int i=0;i<styleDefaults.length;i++){
+
+                        URI styleDefault=styleDefaults[i];
+
+                        if(styleDefault!=null){
+
+                            OMUtils.printAttribute(
+                                    Constants.ATTR_STYLE_DEFAULT,
+                                    styleDefault.toString(),
+                                    pw);
+                        }
+                    }
+
+
+                    printExtensibilityAttributes(intrface.getExtensionAttributes(), intrface, pw);
+                    pw.println('>');
+                    printDocumentation(intrface.getDocumentationElements(), des, pw);
+                    printOperations(intrface.getInterfaceOperationElements(), des, pw);
+                    printExtensibilityElements(intrface.getClass(), intrface.getExtensionElements(), des, pw);
+                    pw.println("  </" + tagName + '>');
+                }
+            }
+        }        
+
+     }
+
+    /**
+     * Serialize  the InterfaceOperationElements of the  WSDL element model.
+     *
+     * @param operations an array of InterfaceOperationElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printOperations(InterfaceOperationElement[] operations,
+                                   DescriptionElement des,
+                                   PrintWriter pw)
+                                   throws WSDLException
+     {
+        if (operations != null){
+
+            String tagName =
+                OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                          Constants.ELEM_OPERATION,
+                          des);
+            for(int ind=0;ind<operations.length;ind++){
+
+                InterfaceOperationElement operation =operations[ind] ;
+                if (operation!=null){
+
+                    pw.print("    <" + tagName);
+
+                    QName name=operation.getName();
+                    if(name!=null){
+                        OMUtils.printAttribute(Constants.ATTR_NAME,
+                                name.getLocalPart(),
+                                pw);
+                    }
 
+                    URI pattern=operation.getPattern();
+                    if(pattern!=null){
+                        OMUtils.printAttribute(Constants.ATTR_PATTERN,
+                                pattern.toString(),
+                                pw);
+                    }
+
+                    URI[] styles=operation.getStyle();
+                    for(int i=0;i<styles.length;i++){
+                        if(styles[i]!=null){
+
+                            OMUtils.printAttribute(
+                                    Constants.ATTR_STYLE,
+                                    styles[i].toString(),
+                                    pw);
+                        }
+                    }
+
+                    printExtensibilityAttributes(operation.getExtensionAttributes(), operation, pw);
+                    pw.println('>');
+                    printDocumentation(operation.getDocumentationElements(), des, pw);
+                    printInterfaceMessageReferences(operation.getInterfaceMessageReferenceElements(),des, pw);
+                    printInterfaceFaultReferences(operation.getInterfaceFaultReferenceElements(),des,pw);
+                    printExtensibilityElements(operation.getClass(), operation.getExtensionElements(), des, pw);
+                    pw.println("    </" + tagName + '>');
+
+                }
+
+            }
+
+
+        }
+
+
+     }
+
+    /**
+     * Serialize  the InterfaceMessageReferenceElements of the  WSDL element model.
+     *
+     * @param msgrefs an array of InterfaceMessageReferenceElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printInterfaceMessageReferences( InterfaceMessageReferenceElement[] msgrefs,
+            DescriptionElement des,
+            PrintWriter pw)
+              throws WSDLException
+     {
+        //TODO     
+          
+    }
+
+    /**
+     * Serialize  the InterfaceFaultReferenceElements of the  WSDL element model.
+     *
+     * @param faulRefs an array of InterfaceFaultReferenceElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printInterfaceFaultReferences(InterfaceFaultReferenceElement[] faulRefs,
+                                                        DescriptionElement des,
+                                                        PrintWriter pw)
+                                                        throws WSDLException{
+        //TODO
+    }
+
+    /**
+     * Serialize  the printBindings of the  WSDL element model.
+     *
+     * @param bindings an array of printBindings.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printBindings(BindingElement[] bindings,
+                                 DescriptionElement des,
+                                 PrintWriter pw)
+                                 throws WSDLException
+    {
+        //TODO
+      
+    }
+
+    /**
+     * Serialize  the BindingFaultElements of the  WSDL element model.
+     *
+     * @param faults an array of BindingFaultElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printBindingFaults(BindingFaultElement[] faults,
+                                             DescriptionElement des,
+                                             PrintWriter pw)
+                                             throws WSDLException{
+        //TODO
+       
+
+    }
+
+    /**
+     * Serialize  the BindingOperationElements of the  WSDL element model.
+     *
+     * @param operations an array of BindingOperationElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printBindingOperations(BindingOperationElement[] operations,
+                                                 DescriptionElement des,
+                                                 PrintWriter pw)
+                                                 throws WSDLException
+     {
+        //TODO      
+
+     }
+
+    /**
+     * Serialize  the ServiceElements of the  WSDL element model.
+     *
+     * @param services an array of ServiceElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printServices(ServiceElement[] services,
+                                 DescriptionElement des,
+                                 PrintWriter pw)
+                                 throws WSDLException
+     {
+        //TODO
+       
+     }
+
+    /**
+     * Serialize  the EndpointElements of the  WSDL element model.
+     *
+     * @param endpoints an array of IncludeElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printEndpoints(EndpointElement[] endpoints,
+                                 DescriptionElement des,
+                                 PrintWriter pw)
+                                 throws WSDLException
+      {
+        //TODO    
+      }
+
+    /**
+     * Serialize  the TypesElements of the  WSDL element model.
+     *
+     *
+     * @param types an array of TypesElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printTypes(TypesElement types,
+                              DescriptionElement des,
+                              PrintWriter pw)
+                              throws WSDLException
+    {
+        if (types != null) {
+
+            String tagName = OMUtils.getQualifiedValue(Constants.NS_URI_WSDL20,
+                    Constants.ELEM_TYPES, des);
+            pw.print("<" + tagName);
+            printExtensibilityAttributes(types.getExtensionAttributes(),types,pw);
+            pw.println('>');
+            ExtensionElement[] extElements = types.getExtensionElements();
+            printExtensibilityElements(types.getClass(), extElements, des,pw);
+            printImportedSchemas(types.getImportedSchemas(), des, pw);
+            printInlinedSchemas(types.getInlinedSchemas(), des, pw);
+            pw.println("</" + tagName + '>');
+        }
+       
+    }
+
+
+    /**
+     * Serialize  the InlinedSchemas of the  WSDL element model.
+     *
+     * @param inlinedSchema an array of InlinedSchemas.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printInlinedSchemas(InlinedSchema[] inlinedSchema,
+                                              DescriptionElement des,
+                                              PrintWriter pw)
+                                              throws WSDLException
+    {
+        /*
+         * previous method
+         * 
+         * XmlSchema xs=null; 
+         * like // attributeFormDefault="unqualified"
+         * elementFormDefault="unqualified" ..etc for(int i=0;i<inlinedSchema.length;i++){
+         * xs=inlinedSchema[i].getSchemaDefinition(); xs.write(pw); }
+         */
+
+        for (int i = 0; i < inlinedSchema.length; i++) {
+            InlinedSchema schema = inlinedSchema[i];
+            XMLElement ele = schema.getXMLElement();
+            //System.out.println("xxxxxxxxxx "+  schema.getXMLElement().getSource().getClass().getName());
+            OMWriter.serializeAsXML((OMNode)ele.getSource(), pw);
+
+        }
+       
     }
 
-    public void writeWSDL(DescriptionElement wsdlDes, OutputStream sink){
+    /**
+     * Serialize  the ImportedSchemas of the  WSDL element model.
+     *
+     * @param importedSchema an array of ImportedSchemas.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printImportedSchemas(ImportedSchema[] importedSchema,
+                                               DescriptionElement des,
+                                               PrintWriter pw )
+                                               throws WSDLException
+    {
+        // TODO Hard coded for XML schema 2000,complete for both 2000 and 2001
+        String tagname=OMUtils.getQualifiedValue(Constants.TYPE_XSD_2001,
+                                                  Constants.ELEM_IMPORT,des);
+        for(int i=0;i<importedSchema.length;i++){
 
+            ImportedSchema schema=importedSchema[i];
+            String ns=schema.getNamespace().toString();
+
+            /*
+             * This  ignore the schema import if it's for
+             *  the W3C schema for XML Schema.
+             */
+            if(Constants.TYPE_XSD_2001.equals(ns)){
+
+                // to be removed
+
+            }else{
+
+            pw.println("<"+tagname);
+            OMUtils.printAttribute(Constants.ATTR_NAMESPACE,
+                    importedSchema[i].getNamespace().toString(),
+                    pw);
+            OMUtils.printAttribute(Constants.ATTR_LOCATION,
+                    importedSchema[i].getSchemaLocation().toString(),
+                    pw);
+            pw.print(" />");
+            }
+        }
+        
     }
+
+    /**
+     * Serialize  the ExtensibilityElements of the  WSDL element model.
+     *
+     * @param parentType  parent class of the ExtensibilityElements.
+     * @param extensibilityElements an array of ExtensibilityElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printExtensibilityElements(Class parentType,
+                                              ExtensionElement[] extensibilityElements,
+                                              DescriptionElement def,
+                                              PrintWriter pw)
+                                              throws WSDLException{
+        //TODO
+      
+
+    }
+
+
+
+    /**
+     * Serialize  the printExtensibilityAttributess of the  WSDL element model.
+     *
+     * @param attrExts an array of XMLAttrs.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printExtensibilityAttributes(
+                                      XMLAttr[] attrExts,
+                                      WSDLElement ownerElem,
+                                      PrintWriter pw)
+                                      throws WSDLException
+       {
+        //TODO
+           
+    }
+
+
+
+    /**
+     * Serialize  the DocumentationElements of the  WSDL element model.
+     *
+     * @param docEles an array of DocumentationElements.
+     * @param des corresponding  DescriptionElement.
+     * @param pw the Writer to write the xml to.
+     */
+    protected void printDocumentation(DocumentationElement[] docEles,
+                                       DescriptionElement def,
+                                       PrintWriter pw)
+                                       throws WSDLException
+    {
+        //TODO
+        
+    }
+       
+           
+
+
 }

Modified: webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMUtils.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMUtils.java?rev=674534&r1=674533&r2=674534&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMUtils.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMUtils.java Mon Jul  7 09:13:10 2008
@@ -19,16 +19,20 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Iterator;
 
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.woden.WSDLException;
+import org.apache.woden.wsdl20.xml.WSDLElement;
 import org.xml.sax.InputSource;
 
 /**
@@ -108,4 +112,110 @@
         return new InputSource(inputStream);
     }
     
+    public static String getQualifiedValue(URI namespaceURI, String localPart,
+            WSDLElement elem) throws WSDLException {
+        String prefix = null;
+
+        if (namespaceURI != null && !namespaceURI.toString().equals("")) {
+            prefix = elem.getNamespacePrefix(namespaceURI);
+        }
+
+        String qv = ((prefix != null && !prefix.equals("")) ? prefix + ":" : "")
+                + localPart;
+
+        return qv;
+    }
+    
+    public static void printAttribute(String name, String value, PrintWriter pw) {
+        if (value != null) {
+            pw.print(' ' + name + "=\"" + cleanString(value) + '\"');
+        }
+    }
+    
+    public static String cleanString(String orig) {
+        if (orig == null) {
+            return "";
+        }
+
+        StringBuffer strBuf = new StringBuffer();
+        char[] chars = orig.toCharArray();
+        boolean inCDATA = false;
+
+        for (int i = 0; i < chars.length; i++) {
+            if (!inCDATA) {
+                switch (chars[i]) {
+                case '&':
+                    strBuf.append("&amp;");
+                    break;
+                case '\"':
+                    strBuf.append("&quot;");
+                    break;
+                case '\'':
+                    strBuf.append("&apos;");
+                    break;
+                case '<': {
+                    if (chars.length >= i + 9) {
+                        String tempStr = new String(chars, i, 9);
+
+                        if (tempStr.equals("<![CDATA[")) {
+                            strBuf.append(tempStr);
+                            i += 8;
+                            inCDATA = true;
+                        } else {
+                            strBuf.append("&lt;");
+                        }
+                    } else {
+                        strBuf.append("&lt;");
+                    }
+                }
+                    break;
+                case '>':
+                    strBuf.append("&gt;");
+                    break;
+                default:
+                    strBuf.append(chars[i]);
+                    break;
+                }
+            } else {
+                strBuf.append(chars[i]);
+
+                if (chars[i] == '>' && chars[i - 1] == ']'
+                        && chars[i - 2] == ']') {
+                    inCDATA = false;
+                }
+            }
+        }
+
+        return strBuf.toString();
+    }
+
+    public static String getQualifiedValue(String namespaceURI,
+            String localPart, WSDLElement elem) throws WSDLException {
+        URI nsUri = null;
+        if (namespaceURI != null) {
+            try {
+                nsUri = new URI(namespaceURI);
+            } catch (URISyntaxException e) {
+                // TODO handle this correctly
+                throw new RuntimeException(e);
+            }
+        }
+        return getQualifiedValue(nsUri, localPart, elem);
+    }
+    
+    public static void printQualifiedAttribute(String name,
+            QName value,
+            WSDLElement elem,
+            PrintWriter pw)
+              throws WSDLException {
+        if (value != null)
+            {
+            printAttribute(name,getQualifiedValue(value.getNamespaceURI(),
+                    value.getLocalPart(),elem),pw);
+            }
+        }
+
+
+
+    
 }
\ No newline at end of file

Added: webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMWriter.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMWriter.java?rev=674534&view=auto
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMWriter.java (added)
+++ webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMWriter.java Mon Jul  7 09:13:10 2008
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0 
+ * 
+ * Unless required by applicable law or agreed to in writing, software 
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License.
+ */
+package org.apache.woden.internal.util.om;
+
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.axiom.om.OMNode;
+import org.apache.woden.internal.util.ObjectRegistry;
+import org.apache.woden.internal.wsdl20.Constants;
+
+
+/**
+ * @author Sagara Gunathunga (sagara.gunathunga@gmail.com)
+ *
+ */
+public class OMWriter {
+    /**
+     * The namespaceURI represented by the prefix <code>xmlns</code>.
+     */
+    private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
+
+    /**
+     * The namespaceURI represented by the prefix <code>xml</code>.
+     */
+    private static String NS_URI_XML = "http://www.w3.org/XML/1998/namespace";
+
+    private static Map xmlEncodingMap = new HashMap();
+
+    static
+    {
+        xmlEncodingMap.put(null, Constants.XML_DECL_DEFAULT);
+        xmlEncodingMap.put(System.getProperty("file.encoding"),
+                Constants.XML_DECL_DEFAULT);
+        xmlEncodingMap.put("UTF8", "UTF-8");
+        xmlEncodingMap.put("UTF-16", "UTF-16");
+        xmlEncodingMap.put("UnicodeBig", "UTF-16");
+        xmlEncodingMap.put("UnicodeLittle", "UTF-16");
+        xmlEncodingMap.put("ASCII", "US-ASCII");
+        xmlEncodingMap.put("ISO8859_1", "ISO-8859-1");
+        xmlEncodingMap.put("ISO8859_2", "ISO-8859-2");
+        xmlEncodingMap.put("ISO8859_3", "ISO-8859-3");
+        xmlEncodingMap.put("ISO8859_4", "ISO-8859-4");
+        xmlEncodingMap.put("ISO8859_5", "ISO-8859-5");
+        xmlEncodingMap.put("ISO8859_6", "ISO-8859-6");
+        xmlEncodingMap.put("ISO8859_7", "ISO-8859-7");
+        xmlEncodingMap.put("ISO8859_8", "ISO-8859-8");
+        xmlEncodingMap.put("ISO8859_9", "ISO-8859-9");
+        xmlEncodingMap.put("ISO8859_13", "ISO-8859-13");
+        xmlEncodingMap.put("ISO8859_15_FDIS", "ISO-8859-15");
+        xmlEncodingMap.put("GBK", "GBK");
+        xmlEncodingMap.put("Big5", "Big5");
+    }
+
+
+
+    public static String java2XMLEncoding(String javaEnc)
+    {
+        return (String)xmlEncodingMap.get(javaEnc);
+    }
+
+    public static void serializeAsXML(OMNode node, Writer writer)
+    {
+
+        ObjectRegistry namespaceStack = new ObjectRegistry();
+
+        namespaceStack.register("xml", NS_URI_XML);
+
+        PrintWriter pw = new PrintWriter(writer);
+        String javaEncoding = (writer instanceof OutputStreamWriter)
+        ? ((OutputStreamWriter) writer).getEncoding()
+                : null;
+
+        print(node, namespaceStack, pw, java2XMLEncoding(javaEncoding));
+    }
+
+
+    private static void print(OMNode node, ObjectRegistry namespaceStack,
+            PrintWriter out, String xmlEncoding) {
+        /**
+         * check this  correct with DOM2Writer method 
+         */
+        if (node == null) {
+            return;
+        }
+        try{
+            node.serialize(out);
+        }catch(Exception e){
+            e.printStackTrace();
+        }  
+    }
+
+
+
+}

Propchange: webservices/woden/branches/woden65/src/org/apache/woden/internal/util/om/OMWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native



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