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/02/26 17:15:28 UTC

svn commit: r631272 - in /webservices/woden/branches/woden65: src/org/apache/woden/internal/BaseWSDLWriter.java src/org/apache/woden/internal/DOMWSDLWriter.java test/org/apache/woden/WSDLWriterTest.java

Author: jkaputin
Date: Tue Feb 26 08:15:27 2008
New Revision: 631272

URL: http://svn.apache.org/viewvc?rev=631272&view=rev
Log:
Committed latest patches to woden65 branch.

Added:
    webservices/woden/branches/woden65/test/org/apache/woden/WSDLWriterTest.java   (with props)
Modified:
    webservices/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java
    webservices/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java

Modified: webservices/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java?rev=631272&r1=631271&r2=631272&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/internal/BaseWSDLWriter.java Tue Feb 26 08:15:27 2008
@@ -24,7 +24,6 @@
 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;

Modified: webservices/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java?rev=631272&r1=631271&r2=631272&view=diff
==============================================================================
--- webservices/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java (original)
+++ webservices/woden/branches/woden65/src/org/apache/woden/internal/DOMWSDLWriter.java Tue Feb 26 08:15:27 2008
@@ -26,6 +26,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.woden.WSDLException;
+import org.apache.woden.XMLElement;
 import org.apache.woden.internal.util.dom.DOM2Writer;
 import org.apache.woden.internal.util.dom.DOMUtils;
 import org.apache.woden.internal.wsdl20.Constants;
@@ -53,7 +54,7 @@
 import org.apache.woden.wsdl20.xml.TypesElement;
 import org.apache.woden.wsdl20.xml.WSDLElement;
 import org.apache.woden.xml.XMLAttr;
-import org.apache.ws.commons.schema.XmlSchema;
+import org.w3c.dom.Node;
 
 /**
  * This is a concrete class derived from BaseWSDLWriter
@@ -158,7 +159,7 @@
         printExtensibilityAttributes(desEle.getExtensionAttributes(), desEle, pw);
         printNamespaceDeclarations(namespaces, pw);
         pw.println('>');
-        printDocumentations(desEle.getDocumentationElements(), desEle, pw);
+        printDocumentation(desEle.getDocumentationElements(), desEle, pw);
         printImports(desEle.getImportElements(), desEle, pw);
         printIncludes(desEle.getIncludeElements(), desEle, pw);
         printTypes(desEle.getTypesElement(), desEle, pw);
@@ -233,7 +234,7 @@
                     }
                     printExtensibilityAttributes(importEle.getExtensionAttributes(), importEle, pw);
                     pw.println('>');
-                    printDocumentations(importEle.getDocumentationElements(), des, pw);
+                    printDocumentation(importEle.getDocumentationElements(), des, pw);
                     printExtensibilityElements(importEle.getClass(), importEle.getExtensionElements(), des, pw);
                     pw.println("  </" + tagName + '>');
                 }
@@ -272,7 +273,7 @@
                     }
                     printExtensibilityAttributes(includeEle.getExtensionAttributes(),includeEle, pw);
                     pw.println('>');
-                    printDocumentations(includeEle.getDocumentationElements(), des, pw);
+                    printDocumentation(includeEle.getDocumentationElements(), des, pw);
                     printExtensibilityElements(includeEle.getClass(), includeEle.getExtensionElements(), des, pw);
                     pw.println("  </" + tagName + '>');
                 }
@@ -339,7 +340,7 @@
 
                     printExtensibilityAttributes(intrface.getExtensionAttributes(), intrface, pw);
                     pw.println('>');
-                    printDocumentations(intrface.getDocumentationElements(), des, pw);
+                    printDocumentation(intrface.getDocumentationElements(), des, pw);
                     printOperations(intrface.getInterfaceOperationElements(), des, pw);
                     printExtensibilityElements(intrface.getClass(), intrface.getExtensionElements(), des, pw);
                     pw.println("  </" + tagName + '>');
@@ -402,9 +403,9 @@
 
                     printExtensibilityAttributes(operation.getExtensionAttributes(), operation, pw);
                     pw.println('>');
-                    printDocumentations(operation.getDocumentationElements(), des, pw);
-                    printInterfaceMessageReferenceElement(operation.getInterfaceMessageReferenceElements(),des, pw);
-                    printInterfaceFaultReferenceElements(operation.getInterfaceFaultReferenceElements(),des,pw);
+                    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 + '>');
 
@@ -426,7 +427,7 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printInterfaceMessageReferenceElement( InterfaceMessageReferenceElement[] msgrefs,
+    protected void printInterfaceMessageReferences( InterfaceMessageReferenceElement[] msgrefs,
             DescriptionElement des,
             PrintWriter pw)
               throws WSDLException
@@ -471,10 +472,10 @@
                     DOMUtils.printAttribute(Constants.ATTR_ELEMENT, qtu.getToken(), pw);
                 }
             }
-            
+
             printExtensibilityAttributes(msgRef.getExtensionAttributes(), msgRef, pw);
             pw.println('>');
-            printDocumentations(msgRef.getDocumentationElements(), des, pw);
+            printDocumentation(msgRef.getDocumentationElements(), des, pw);
             printExtensibilityElements(msgRef.getClass(), msgRef.getExtensionElements(), des, pw);
             pw.println("    </" + tagName + '>');
         }
@@ -488,7 +489,7 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printInterfaceFaultReferenceElements(InterfaceFaultReferenceElement[] faulRefs,
+    protected void printInterfaceFaultReferences(InterfaceFaultReferenceElement[] faulRefs,
                                                         DescriptionElement des,
                                                         PrintWriter pw)
                                                         throws WSDLException{
@@ -528,7 +529,7 @@
 
                 printExtensibilityAttributes(faulRef.getExtensionAttributes(), faulRef, pw);
                 pw.println('>');
-                printDocumentations(faulRef.getDocumentationElements(), des, pw);
+                printDocumentation(faulRef.getDocumentationElements(), des, pw);
                 printExtensibilityElements(faulRef.getClass(), faulRef.getExtensionElements(), des, pw);
                 pw.println("    </" + tagName + '>');
             }
@@ -592,16 +593,16 @@
 
                    printExtensibilityAttributes(binding.getExtensionAttributes(), binding, pw);
                    pw.println('>');
-                   printBindingOperationElements(
+                   printBindingOperations(
                            binding.getBindingOperationElements(),des,pw);
 
                 }
 
 
-                printDocumentations(binding.getDocumentationElements(), des, pw);
+                printDocumentation(binding.getDocumentationElements(), des, pw);
                 printExtensibilityElements(binding.getClass(), binding.getExtensionElements(), des, pw);
-                printBindingOperationElements(binding.getBindingOperationElements(), des, pw);
-                printBindingFaultElements(binding.getBindingFaultElements(), des, pw);
+                printBindingOperations(binding.getBindingOperationElements(), des, pw);
+                printBindingFaults(binding.getBindingFaultElements(), des, pw);
                 pw.println("  </" + tagName + '>');
             }
         }
@@ -614,7 +615,7 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printBindingFaultElements(BindingFaultElement[] faults,
+    protected void printBindingFaults(BindingFaultElement[] faults,
                                              DescriptionElement des,
                                              PrintWriter pw)
                                              throws WSDLException{
@@ -653,7 +654,7 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printBindingOperationElements(BindingOperationElement[] operations,
+    protected void printBindingOperations(BindingOperationElement[] operations,
                                                  DescriptionElement des,
                                                  PrintWriter pw)
                                                  throws WSDLException
@@ -725,8 +726,8 @@
 
                 printExtensibilityAttributes(service.getExtensionAttributes(), service, pw);
                 pw.println('>');
-                printEndpoint(service.getEndpointElements(), des, pw);
-                printDocumentations(service.getDocumentationElements(), des, pw);
+                printEndpoints(service.getEndpointElements(), des, pw);
+                printDocumentation(service.getDocumentationElements(), des, pw);
                 printExtensibilityElements(service.getClass(),service.getExtensionElements(), des, pw);
                 pw.println("    </" + tagName + '>');
             }
@@ -740,7 +741,7 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printEndpoint(EndpointElement[] endpoints,
+    protected void printEndpoints(EndpointElement[] endpoints,
                                  DescriptionElement des,
                                  PrintWriter pw)
                                  throws WSDLException
@@ -777,7 +778,7 @@
 
                 printExtensibilityAttributes(endPoint.getExtensionAttributes(), endPoint, pw);
                 pw.println('>');
-                printDocumentations(endPoint.getDocumentationElements(), des, pw);
+                printDocumentation(endPoint.getDocumentationElements(), des, pw);
                 printExtensibilityElements(endPoint.getClass(), endPoint.getExtensionElements(), des, pw);
                 pw.println("    </" + tagName + '>');
             }
@@ -809,8 +810,8 @@
             pw.println('>');
             ExtensionElement[] extElements = types.getExtensionElements();
             printExtensibilityElements(types.getClass(), extElements, des, pw);
-            printImportedSchemaElements(types.getImportedSchemas(),des,pw);
-            printInlinedSchemaElements(types.getInlinedSchemas(),des,pw);
+            printImportedSchemas(types.getImportedSchemas(),des,pw);
+            printInlinedSchemas(types.getInlinedSchemas(),des,pw);
             pw.println("</" + tagName + '>');
         }
     }
@@ -823,18 +824,27 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printInlinedSchemaElements(InlinedSchema[] inlinedSchema,
+    protected void printInlinedSchemas(InlinedSchema[] inlinedSchema,
                                               DescriptionElement des,
                                               PrintWriter pw)
                                               throws WSDLException
     {
-        XmlSchema xs=null;
+       /* previous method
+        *
+        *  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);
-        }
+        }*/
+
+    	for(int i=0;i<inlinedSchema.length;i++){
+    		InlinedSchema schema=inlinedSchema[i];
+    		XMLElement ele=schema.getXMLElement();
+    		DOM2Writer.serializeAsXML(((Node)ele.getSource()), pw);
+
+    	}
     }
 
     /**
@@ -844,16 +854,29 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printImportedSchemaElements(ImportedSchema[] importedSchema,
+    protected void printImportedSchemas(ImportedSchema[] importedSchema,
                                                DescriptionElement des,
                                                PrintWriter pw )
                                                throws WSDLException
     {
-        // TODO Hard coded for XML schema 2000,complete for both 2000 and 2001
+    	 // 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++){
 
+            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);
             DOMUtils.printAttribute(Constants.ATTR_NAMESPACE,
                     importedSchema[i].getNamespace().toString(),
@@ -862,6 +885,7 @@
                     importedSchema[i].getSchemaLocation().toString(),
                     pw);
             pw.print(" />");
+            }
         }
     }
 
@@ -947,7 +971,7 @@
      * @param des corresponding  DescriptionElement.
      * @param pw the Writer to write the xml to.
      */
-    protected void printDocumentations(DocumentationElement[] docEles,
+    protected void printDocumentation(DocumentationElement[] docEles,
                                        DescriptionElement def,
                                        PrintWriter pw)
                                        throws WSDLException
@@ -968,13 +992,15 @@
 
                     //printExtensibilityAttributes(Operation.class, docEles.get, def, pw);
                     pw.println('>');
-
-Object o = docEle.getContent().getSource();
-org.w3c.dom.Element domEl = (org.w3c.dom.Element)o;
-String textContent = domEl.getTextContent();
-                    //String textContent=((org.w3c.dom.Element)
-                    //        docEle.getContent().getSource()).getTextContent();
-                    pw.print(textContent);
+                    Object o = docEle.getContent().getSource();
+                    org.w3c.dom.Element domEl = (org.w3c.dom.Element)o;
+                    /*
+                     * This is not enough to handle DocumentationElement
+                     * with nested DocumentationElements,if it is required
+                     * a recursive method based on getNodeType()
+                     * (org.w3c.dom.Node) can be used to solve this issue.
+                     */
+                    DOM2Writer.serializeAsXML(domEl.getFirstChild(), pw);
                   //  printExtensibilityElements(Operation.class, extElements, def, pw);
                     pw.println("    </" + tagName + '>');
 
@@ -983,21 +1009,4 @@
         }
     }
 
-
-
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+}
\ No newline at end of file

Added: webservices/woden/branches/woden65/test/org/apache/woden/WSDLWriterTest.java
URL: http://svn.apache.org/viewvc/webservices/woden/branches/woden65/test/org/apache/woden/WSDLWriterTest.java?rev=631272&view=auto
==============================================================================
--- webservices/woden/branches/woden65/test/org/apache/woden/WSDLWriterTest.java (added)
+++ webservices/woden/branches/woden65/test/org/apache/woden/WSDLWriterTest.java Tue Feb 26 08:15:27 2008
@@ -0,0 +1,131 @@
+/**
+ * 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;
+
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+
+import junit.framework.TestCase;
+
+/**
+ * Testcase to test WSDLWriter interface.
+ *
+ * @author sagara Gunathunga
+ *
+ */
+public class WSDLWriterTest extends TestCase {
+
+	    private String finputWsdlPath = null;
+	    private String foutputWsdlPath = null;
+	    private Description fDescription = null;
+	    private WSDLFactory FWSDLFactory=null;
+	    private WSDLReader fReader=null;
+	    private WSDLWriter fWriter=null;
+
+	    private final String inputPath="org/apache/woden/primer-hotelReservationService.wsdl";
+	    //change this path according to the local file system.
+	    private final String outputPath="c:/out.wsdl";
+
+	    protected void setUp() throws Exception {
+	        super.setUp();
+	        finputWsdlPath =inputPath;
+	        foutputWsdlPath = outputPath;
+	        FWSDLFactory=WSDLFactory.newInstance();
+	    }
+
+
+	    protected void tearDown() throws Exception {
+	        super.tearDown();
+	        finputWsdlPath = null;
+	        foutputWsdlPath = null;
+	        fDescription = null;
+	        FWSDLFactory=null;
+	        fReader=null;
+	        fWriter=null;
+	    }
+
+
+	    /**
+		 * Test method for {@link org.apache.woden.WSDLWriter#writeWSDL(org.apache.woden.wsdl20.xml.DescriptionElement, java.io.Writer)}.
+		 */
+		public void testWriteWSDLDescriptionElementWriter() {
+			try {
+	            fReader=FWSDLFactory.newWSDLReader();
+	            fWriter=FWSDLFactory.newWSDLWriter();
+	            FileWriter fFileWriter=new FileWriter(foutputWsdlPath);
+	            URL wsdlInputURL = getClass().getClassLoader().getResource(inputPath);
+	            DescriptionElement descElem = (DescriptionElement)fReader.readWSDL(wsdlInputURL.toString());
+	            assertNotNull("DescriptionElement can not  be null", descElem);
+	            fDescription=descElem.toComponent();
+	            fWriter.writeWSDL(descElem, fFileWriter);
+	            fFileWriter.flush();
+	            fFileWriter.close();
+	            DescriptionElement outDescElem = (DescriptionElement)fReader.readWSDL(foutputWsdlPath);
+	            assertNotNull("DescriptionElement can not  be null", outDescElem);
+	            assertEquals("Two Description component should be same ",
+	            		  outDescElem.toComponent(), fDescription);
+
+	        } catch (WSDLException e) {
+
+	            fail("Can not instantiate the WSDLReader or WSDLWriter object.");
+	        }catch (IOException e) {
+
+	            fail("Can not access the specified file");
+	        }
+		}
+
+		/**
+		 * Test method for {@link org.apache.woden.WSDLWriter#writeWSDL(org.apache.woden.wsdl20.xml.DescriptionElement, java.io.OutputStream)}.
+		 */
+		public void testWriteWSDLDescriptionElementOutputStream() {
+			try {
+		        fReader=FWSDLFactory.newWSDLReader();
+		        fWriter=FWSDLFactory.newWSDLWriter();
+		        FileOutputStream fFileStream=new FileOutputStream(foutputWsdlPath);
+		        URL wsdlInputURL = getClass().getClassLoader().getResource(inputPath);
+		        DescriptionElement descElem = (DescriptionElement)fReader.readWSDL(wsdlInputURL.toString());
+		        assertNotNull("DescriptionElement can not  be null", descElem);
+		        fDescription=descElem.toComponent();
+		        fWriter.writeWSDL(descElem, fFileStream);
+		        DescriptionElement outDescElem = (DescriptionElement)fReader.readWSDL(foutputWsdlPath);
+		        assertNotNull("DescriptionElement can not  be null", outDescElem);
+		        assertEquals("Two Description component should be same",
+		        		  outDescElem.toComponent(), fDescription);
+
+		    } catch (WSDLException e) {
+
+		        fail("Can not instantiate the WSDLReader or WSDLWriter object.");
+		    }catch (IOException e) {
+
+		        fail("Can not access the specified file");
+		    }
+		    }
+
+
+
+		}
+
+
+
+
+
+

Propchange: webservices/woden/branches/woden65/test/org/apache/woden/WSDLWriterTest.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