[Carbon-dev] svn commit r17123 - in
trunk/carbon-components/wsdlconverter: .
org.wso2.carbon.modules.wsdlconverter
org.wso2.carbon.modules.wsdlconverter/src
org.wso2.carbon.modules.wsdlconverter/src/main
org.wso2.carbon.modules.wsdlconverter/src/main/java
org.wso2.carbon.modules.wsdlconverter/src/main/java/org
org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2
org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter
org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/internal
org.wso2.carbon.modules.wsdlconverter/src/main/resources
org.wso2.carbon.modules.wsdlconverter/src/main/resources/web
svn at wso2.org
svn at wso2.org
Fri May 16 04:52:15 PDT 2008
Author: channa
Date: Fri May 16 04:52:15 2008
New Revision: 17123
Log:
Adding basic structure of wsdlconverter bundle. WIP.
Added:
trunk/carbon-components/wsdlconverter/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/pom.xml
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/Util.java
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/WSDLConverter.java
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/internal/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/internal/Activator.java
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/wsdl11to20.xsl
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/divs.html
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/js.html
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/wsdlconverter.js
trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/wsdlconverter.xsl
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/pom.xml
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/pom.xml Fri May 16 04:52:15 2008
@@ -0,0 +1,150 @@
+<!--
+ ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
+ ~
+ ~ Licensed 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>carbon-parent</artifactId>
+ <version>SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.wso2.carbon.wsdlconverter</artifactId>
+ <packaging>bundle</packaging>
+ <version>SNAPSHOT</version>
+ <name>WSO2 Carbon - WSDL Converter</name>
+ <description>This is the core module of the project.</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.core</artifactId>
+ </dependency>
+
+ <!-- Start of OSGi dependencies with Felix -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.main</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>javax.servlet</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.foundation</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>org.eclipse.equinox.http.servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>org.eclipse.equinox.http.helper</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>org.eclipse.equinox.jsp.jasper</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>org.apache.jasper</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>javax.servlet.jsp</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.wso2.utils</groupId>
+ <artifactId>wso2utils</artifactId>
+ <version>SNAPSHOT</version>
+ </dependency>
+
+ <!-- End of OGi dependencies -->
+ </dependencies>
+
+ <build>
+
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${pom.artifactId}</Bundle-Name>
+ <Bundle-Version>1.0.0</Bundle-Version>
+ <Bundle-Activator>org.wso2.carbon.wsdlconverter.internal.Activator
+ </Bundle-Activator>
+ <Private-Package>org.wso2.carbon.wsdlconverter.internal</Private-Package>
+ <Import-Package>
+ javax.servlet;version="2.4.0",
+ javax.servlet.http;version="2.4.0",
+ javax.servlet.resources;version="2.4.0",
+ org.eclipse.equinox.http.helper,
+ org.eclipse.equinox.jsp.jasper,
+ *;resolution:=optional
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+
+
+ </plugins>
+ </build>
+
+
+</project>
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/Util.java
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/Util.java Fri May 16 04:52:15 2008
@@ -0,0 +1,261 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.transform.*;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+
+/**
+ * Utility class for the project
+ */
+public class Util {
+
+ private static Log log = LogFactory.getLog(Util.class);
+
+ /**
+ * This will return location of the file written to the system filesystem.
+ *
+ * @param url WSDL location
+ * @return String file absolute path
+ * @throws AxisFault will be thrown
+ */
+ public static String writeWSDLToFileSystem(String url) throws AxisFault {
+ return writeWSDLToFileSystemHelpler(url).getAbsolutePath();
+ }
+
+ /**
+ * This will return an InputStream for the written file into the filesystem.
+ *
+ * @param url WSDL location
+ * @return InputStream of the file
+ * @throws IOException will be thrown
+ */
+ public static InputStream writeWSDLToStream(String url) throws IOException {
+ return new FileInputStream(writeWSDLToFileSystemHelpler(url));
+ }
+
+ /**
+ * Return the generic wsdl11to20.xsl as an input stream
+ *
+ * @return InputStream
+ * @throws AxisFault will be thrown
+ */
+ public static InputStream getConverterXSLStream() throws AxisFault {
+ InputStream inXSLTStream = Util.class.getClassLoader()
+ .getResourceAsStream("org/wso2/wsdlconverter/wsdl11to20.xsl");
+ if (inXSLTStream == null) {
+ inXSLTStream = Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream("org/wso2/wsdlconverter/wsdl11to20.xsl");
+ }
+ if (inXSLTStream == null) {
+ String e = Util.class.getName() + " wsdl11to20.xsl cannot be located.";
+ log.error(e);
+ throw new AxisFault(e);
+ }
+ return inXSLTStream;
+ }
+
+ /**
+ * Transformation helper.
+ *
+ * @param xmlIn XML
+ * @param xslIn XSL
+ * @param result Result
+ * @param classLoader classloader
+ * @throws TransformerException will be thrown
+ * @throws IllegalAccessException will be thrown
+ * @throws ClassNotFoundException will be thrown
+ * @throws InstantiationException will be thrown
+ */
+ public static void transform(Source xmlIn, Source xslIn, Result result, ClassLoader classLoader)
+ throws TransformerException, IllegalAccessException, InstantiationException,
+ ClassNotFoundException {
+ transform(xmlIn, xslIn, result, null, classLoader);
+ }
+
+ /**
+ * Transform based on parameters
+ *
+ * @param xmlIn XML
+ * @param xslIn XSL
+ * @param result Result
+ * @param paramMap Parameter map
+ * @param classLoader classloader
+ * @throws TransformerException will be thrown
+ * @throws IllegalAccessException will be thrown
+ * @throws InstantiationException will be thrown
+ * @throws ClassNotFoundException will be thrown
+ */
+ public static void transform(Source xmlIn, Source xslIn, Result result, Map paramMap,
+ ClassLoader classLoader)
+ throws TransformerException, ClassNotFoundException, IllegalAccessException,
+ InstantiationException {
+ try {
+ Class providerClass =
+ Class.forName("net.sf.saxon.TransformerFactoryImpl", false, classLoader);
+ TransformerFactory transformerFactory =
+ (TransformerFactory) providerClass.newInstance();
+ Transformer transformer = transformerFactory.newTransformer(xslIn);
+ if (paramMap != null) {
+ Set set = paramMap.keySet();
+ for (Iterator iterator = set.iterator(); iterator.hasNext();) {
+ String key = (String) iterator.next();
+ String value = (String) paramMap.get(key);
+ transformer.setParameter(key, value);
+ }
+ }
+ transformer.transform(xmlIn, result);
+ } catch (TransformerException e) {
+ log.error(e.getMessage(), e);
+ throw e;
+ } catch (ClassNotFoundException e) {
+ log.error(e.getMessage(), e);
+ throw e;
+ } catch (IllegalAccessException e) {
+ log.error(e.getMessage(), e);
+ throw e;
+ } catch (InstantiationException e) {
+ log.error(e.getMessage(), e);
+ throw e;
+ }
+
+ }
+
+ /**
+ * Get generic location to write a file with the given suffix.
+ *
+ * @param suffix should be given with dot; ex: .xml, .wsdl
+ * @return
+ */
+ public static FileInfo getOutputFileLocation(String suffix) {
+ String uuid = String.valueOf(System.currentTimeMillis() + Math.random());
+ String extraFileLocation =
+ MessageContext.
+ getCurrentMessageContext().
+ getConfigurationContext().getProperty("WORK_DIR") +
+ File.separator +
+ "extra" +
+ File.separator +
+ uuid + File.separator;
+ File dirs = new File(extraFileLocation);
+ if (!dirs.exists()) {
+ dirs.mkdirs();
+ }
+ File outFile = new File(extraFileLocation, uuid + suffix);
+ return new FileInfo(uuid, outFile);
+ }
+
+ /**
+ * Helper method to write the WSDL file to the filesytem.
+ *
+ * @param url WSDL location
+ * @return File object
+ * @throws AxisFault will be thrown
+ */
+ public static File writeWSDLToFileSystemHelpler(String url) throws AxisFault {
+ try {
+ URL wsdlURL = new URL(url);
+ URLConnection connection = wsdlURL.openConnection();
+ HttpURLConnection uconn;
+ if (connection instanceof HttpURLConnection) {
+ uconn = (HttpURLConnection) connection;
+ } else {
+ String msg = "Unable to process given URL. " +
+ "Only HTTP protocol is currently supported.";
+ log.error(msg);
+ throw new AxisFault(msg);
+ }
+ uconn.setRequestMethod("GET");
+ uconn.setAllowUserInteraction(false);
+ uconn.setDefaultUseCaches(false);
+ uconn.setDoInput(true);
+ uconn.setDoOutput(false);
+ uconn.setInstanceFollowRedirects(true);
+ uconn.setUseCaches(false);
+ uconn.connect();
+ InputStream inStrm = uconn.getInputStream();
+ BufferedInputStream bIn = new BufferedInputStream(inStrm);
+ File outFile = getOutputFileLocation(".xml").getFile();
+ FileOutputStream out = new FileOutputStream(outFile);
+ // Transfer bytes from in to out
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = bIn.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ bIn.close();
+ inStrm.close();
+ uconn.disconnect();
+ out.close();
+ return outFile;
+ } catch (IllegalArgumentException e) {
+ String msg = "URL provided is invalid. " + e.getMessage() +
+ ". Please use a valid URL";
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ } catch (MalformedURLException e) {
+ String msg = "URL provided is invalid. " + e.getMessage() +
+ ". Please use a valid URL";
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ } catch (FileNotFoundException e) {
+ String msg = "File provied is invalid. " + e.getMessage() +
+ ". Please use a valid file.";
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ } catch (IOException e) {
+ String msg = "Problems has encountered in connection. " + e.getMessage() +
+ ". Please check the connection and try this again.";
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ }
+
+ }
+
+ /**
+ * Class that holds uuid and file info.
+ */
+ public static class FileInfo {
+
+ private String uuid;
+ private File file;
+
+ public FileInfo(String uuid, File file) {
+ this.uuid = uuid;
+ this.file = file;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public File getFile() {
+ return file;
+ }
+ }
+}
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/WSDLConverter.java
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/WSDLConverter.java Fri May 16 04:52:15 2008
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.wsdlconverter;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.Util;
+import org.wso2.utils.WSO2Constants;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.*;
+import java.util.Hashtable;
+import java.util.Map;
+
+/**
+ * Tools that will be used to convert WSDL 1.1 document into WSDL 2.0 document.
+ */
+public class WSDLConverter {
+
+ private static Log log = LogFactory.getLog(WSDLConverter.class);
+
+ /**
+ * This will convert a given WSDL v1.1 document to WSDL v2.0
+ *
+ * @param fileId - id to the path of the wsdl 1.1 document
+ * @return path of the equivalent wsdl 2.0 document
+ * @throws AxisFault return an AxisFault
+ */
+ public String convert(String fileId) throws AxisFault {
+ String wsdl11FilePath = getFilePathFromFileId(fileId);
+ return convertWSDL11ToWSDL20(wsdl11FilePath);
+ }
+
+ /**
+ * @param url any valid URL that can be recognize by URL object
+ * @return String
+ * @throws AxisFault AxisFault wrapper will be thrown
+ */
+ public String convertFromURL(String url) throws AxisFault {
+ try {
+ return convertWSDL11ToWSDL20(Util.writeWSDLToFileSystem(url));
+ } catch (AxisFault e) {
+ throw e;
+ }
+ }
+
+
+ private String convertWSDL11ToWSDL20(String wsdl11FilePath) throws AxisFault {
+ try {
+ InputStream inXSLTStream = Util.getConverterXSLStream();
+ InputStream inXMLStream = new FileInputStream(new File(wsdl11FilePath));
+ Source xmlSource = new StreamSource(inXMLStream);
+ Source xsltSource = new StreamSource(inXSLTStream);
+ String uuid = String.valueOf(System.currentTimeMillis() + Math.random());
+ if (File.separatorChar == '\\') {
+ wsdl11FilePath = wsdl11FilePath.replace('\\','/');
+ }
+ int lastIndex = wsdl11FilePath.lastIndexOf('/');
+ String filePath = wsdl11FilePath.substring(0, lastIndex);
+ File outFile = new File(filePath, uuid + ".xml");
+ OutputStream out = new FileOutputStream(outFile);
+ Result wsdlResult = new StreamResult(out);
+ ClassLoader classLoader =
+ MessageContext.getCurrentMessageContext().getAxisService().getClassLoader();
+ Util.transform(xmlSource, xsltSource, wsdlResult, classLoader);
+ ConfigurationContext configCtx =
+ MessageContext.getCurrentMessageContext().getConfigurationContext();
+ Map fileResourcesMap =
+ (Map) configCtx.getProperty(WSO2Constants.FILE_RESOURCE_MAP);
+ if (fileResourcesMap == null) {
+ fileResourcesMap = new Hashtable();
+ configCtx.setProperty(WSO2Constants.FILE_RESOURCE_MAP, fileResourcesMap);
+ }
+ fileResourcesMap.put(uuid, outFile.getAbsolutePath());
+ return WSO2Constants.ContextPaths.DOWNLOAD_PATH + "?id=" + uuid;
+ } catch (FileNotFoundException e) {
+ String msg = "File provided cannot be found. " + e.getMessage() +
+ ". Please select a valid file.";
+ log.error(e.getMessage(), e);
+ throw new AxisFault(msg);
+ } catch (TransformerConfigurationException e) {
+ String msg = "Problem has occured during the process of transformation. " + e.getMessage();
+ log.error(e.getMessage(), e);
+ throw new AxisFault(msg);
+ } catch (TransformerException e) {
+ String msg = "Problem has occured during the process of transformation. " + e.getMessage();
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ } catch (IllegalAccessException e) {
+ String msg = "IllegalAccessException. " + e.getMessage();
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ } catch (ClassNotFoundException e) {
+ String msg = "ClassNotFoundException. " + e.getMessage();
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ } catch (InstantiationException e) {
+ String msg = "InstantiationException. " + e.getMessage();
+ log.error(msg, e);
+ throw new AxisFault(msg);
+ }
+ }
+
+ protected String getTargetFileLocation(String wsdl11FilePath) throws AxisFault {
+ File file = new File(wsdl11FilePath);
+ if (file.isFile()) {
+ String name = file.getName();
+ String wsdlFileName = name.substring(0, name.lastIndexOf(".")) + "-wsdl20.wsdl";
+ return file.getParent() + File.separator + wsdlFileName;
+ } else {
+ String s = "File path does not refers to a file";
+ log.error(s);
+ throw new AxisFault(s);
+ }
+ }
+
+ private String getFilePathFromFileId(String fileId) {
+ ConfigurationContext configCtx =
+ MessageContext.getCurrentMessageContext().getConfigurationContext();
+ Map fileResMap =
+ (Map) configCtx.getProperty(WSO2Constants.FILE_RESOURCE_MAP);
+ return (String) fileResMap.get(fileId);
+ }
+
+}
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/internal/Activator.java
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/internal/Activator.java Fri May 16 04:52:15 2008
@@ -0,0 +1,54 @@
+package org.wso2.carbon.tryit.internal;
+
+import javax.servlet.Servlet;
+
+import org.eclipse.equinox.http.helper.ContextPathServletAdaptor;
+import org.eclipse.equinox.http.helper.BundleEntryHttpContext;
+import org.eclipse.equinox.jsp.jasper.JspServlet;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+
+public class Activator implements BundleActivator {
+
+ /**
+ * Starts the bundle, getting a service reference, creating a new servlet instance and mapping
+ * the context to the 'tryit' path.
+ *
+ * @param context
+ * @throws Exception
+ */
+ public void start(BundleContext context) throws Exception {
+
+ ServiceReference reference = context
+ .getServiceReference(HttpService.class.getName());
+ if (reference == null) {
+ throw new Exception("An instance of HttpService is not available");
+ }
+ final HttpService httpService = (HttpService) context
+ .getService(reference);
+ try {
+
+ HttpContext commonContext = new BundleEntryHttpContext(context
+ .getBundle(), "/web");
+
+ Servlet adaptedJspServlet1 = new ContextPathServletAdaptor(
+ new JspServlet(context.getBundle(), "/web"), "/wsdlconverter");
+ httpService.registerServlet("/wsdlconverter/*.jsp", adaptedJspServlet1,
+ null, commonContext);
+ httpService.registerResources("/wsdlconverter", "/", commonContext);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void stop(BundleContext arg0) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+}
+
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/wsdl11to20.xsl
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/java/org/wso2/wsdlconverter/wsdl11to20.xsl Fri May 16 04:52:15 2008
@@ -0,0 +1,774 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:transform version="2.0"
+ xmlns="http://www.w3.org/ns/wsdl"
+ xmlns:w11="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:w11soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:w11http="http://schemas.xmlsoap.org/wsdl/http/"
+ xmlns:w11mime="http://schemas.xmlsoap.org/wsdl/mime/"
+ xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/"
+ xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:wsdli="http://www.w3.org/ns/wsdl-instance"
+ xmlns:wsdlx="http://www.w3.org/ns/wsdl-extensions"
+ xmlns:wrpc="http://www.w3.org/ns/wsdl/rpc"
+ xmlns:wsoap="http://www.w3.org/ns/wsdl/soap"
+ xmlns:whttp="http://www.w3.org/ns/wsdl/http"
+ exclude-result-prefixes='w11 w11soap w11http w11mime soap11 soapenc11
+ xs xsi wsoap whttp wrpc wsdli wsdlx'>
+
+ <xsl:strip-space elements="*"/>
+
+ <xsl:output method="xml" media-type="application/xhtml+xml"
+ omit-xml-declaration='yes' encoding='utf-8' indent='yes'/>
+
+ <xsl:template match="/">
+ <xsl:apply-templates select='w11:definitions' />
+ </xsl:template>
+
+ <xsl:template name="converter-doc">
+
+ <xsl:text>
+ </xsl:text>
+ <xsl:comment>
+
+ Documentation at:
+ http://esw.w3.org/topic/WsdlConverter
+
+ To report problems, please refer to:
+ http://esw.w3.org/topic/WsdlConverterFeedback
+
+ Generated by the WSDL converter version:
+ 2006-02-20
+
+ </xsl:comment>
+ <xsl:text>
+ </xsl:text>
+ </xsl:template>
+
+ <xsl:variable name='type' select='/w11:definitions/w11:binding[1]'/>
+ <xsl:variable name='qname'
+ select='resolve-QName($type/@type, $type)'/>
+
+ <xsl:template match="w11:definitions">
+ <description targetNamespace="{@targetNamespace}" >
+ <!-- creating namespace declarations -->
+ <xsl:namespace name='{prefix-from-QName($qname)}'
+ select='namespace-uri-from-QName($qname)' />
+
+ <xsl:call-template name="converter-doc"/>
+
+ <xsl:apply-templates select='w11:documentation'/>
+
+ <xsl:choose>
+ <xsl:when test='not(w11:types)'>
+ <types>
+ <xsl:apply-templates select='/w11:definitions/w11:import' mode='types'/>
+ <xsl:apply-templates select='//w11soap:body' mode="rpctypes"/>
+ <xsl:call-template name="httpUrlReplacementSchemaDecl"/>
+ </types>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:apply-templates select="w11:types"/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:apply-templates select='*[not((local-name()="import"
+ or local-name()="documentation"
+ or local-name()="types")
+ and namespace-uri()="http://schemas.xmlsoap.org/wsdl/")]' />
+ </description>
+ </xsl:template>
+
+ <xsl:template name="resolve-soaprpc-element-localname">
+
+ <xsl:param name="msg"/>
+ <xsl:choose>
+ <xsl:when test="local-name($msg) = 'input'">
+ <xsl:value-of select="$msg/../@name"/>
+ </xsl:when>
+ <xsl:when test="local-name($msg) = 'output'">
+ <!-- @@@ Not 100% sure about this one -->
+ <xsl:value-of select="concat(../../@name, 'Response')"/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <!-- @@@ I don't think that we can do anything for faults -->
+ <xsl:value-of select="'#any'"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match='w11soap:body' mode="rpctypes">
+ <xsl:variable name="soapbody" select="."/>
+
+ <xsl:if test="$soapbody/../../@style = 'rpc'
+ or $soapbody/../../../w11soap:binding/@style = 'rpc'">
+ <xsl:variable name='message_name' select='resolve-QName(../@message, ..)'/>
+ <xsl:variable name='message'
+ select='/w11:definitions/w11:message[QName(/w11:definitions/@targetNamespace, @name) eq $message_name]'/>
+ <xsl:variable name="parts" select="tokenize($soapbody/@parts, '\s+')"/>
+ <xsl:variable name="usestypes">
+ <xsl:call-template name="message-is-using-types">
+ <xsl:with-param name="parts" select="$parts"/>
+ <xsl:with-param name="message" select="$message"/>
+ <xsl:with-param name="name" select="current()"/>
+
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:if test="not($usestypes='true')">
+ <xsl:variable name="localName">
+ <xsl:call-template name="resolve-soaprpc-element-localname">
+ <xsl:with-param name="msg" select=".."/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:if test="$localName != '#any'">
+
+ <xs:schema targetNamespace="{@namespace}">
+ <xs:element name="{$localName}">
+ <xs:complexType>
+ <xs:sequence>
+ <xsl:for-each select="$parts">
+ <xsl:variable name="part"
+ select="$message/w11:part[@name = current()]"/>
+ <xsl:variable name="element"
+ select="resolve-QName($part/@element, $part)"/>
+ <xs:element ref="{$element}">
+ <xsl:namespace name='{prefix-from-QName($element)}'
+ select='namespace-uri-from-QName($element)'/>
+
+ </xs:element>
+ </xsl:for-each>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </xsl:if>
+ </xsl:if>
+ </xsl:if>
+
+ </xsl:template>
+
+ <xsl:template match='w11:definitions/w11:import'>
+ <xsl:choose>
+ <xsl:when test='@location and doc-available(@location)'>
+ <xsl:variable name='nodes' select='doc(@location)' />
+ <xsl:choose>
+ <xsl:when test='$nodes/w11:definitions'>
+ <import namespace="{@namespace}" location="{@location}" />
+
+ </xsl:when>
+ <xsl:when test='$nodes/xs:schema'>
+ <!-- move to wsdl20:description/wsdl20:types
+ see match=wsdl20:description/wsdl20:types
+ and match=wsdl20:description/wsdl20:portType-->
+ </xsl:when>
+ <xsl:when test='count($nodes) = 0'>
+ <import namespace="{@namespace}" location="{@location}" />
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- No WSDL 2.0 components found at <xsl:value-of
+ select='@location' /> in namespace <xsl:value-of
+ select='@namespace' /> -->
+
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <import namespace="{@namespace}" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match='w11:definitions/w11:import' mode='types'>
+ <!-- check if an WSDL 1.1 import was about XSD -->
+ <xsl:if test='@location and doc-available(@location)
+ and doc(@location)/xs:schema'>
+ <!-- move to wsdl20:description/wsdl20:types -->
+ <xs:import namespace="{@namespace}" schemaLocation="{@location}" />
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match='w11:types'>
+
+ <types>
+ <xsl:apply-templates select='/w11:definitions/w11:import' mode='types'/>
+ <xsl:apply-templates select='xs:schema' />
+ <xsl:apply-templates select='*[not(local-name()="schema"
+ and namespace-uri()="http://www.w3.org/2001/XMLSchema")]' />
+ <xsl:apply-templates select='//w11soap:body' mode="rpctypes"/>
+ <xsl:call-template name="httpUrlReplacementSchemaDecl"/>
+ </types>
+ </xsl:template>
+
+ <xsl:template name="httpUrlReplacementSchemaDecl">
+ <!-- Convert message parts with using types that are used in an HTTP binding -->
+ <!-- FIXME: currently only works with input; how about output? -->
+ <xsl:for-each select="//w11:message">
+ <xsl:variable name="themessage" select="."/>
+ <xsl:variable name="message_name" select="QName(/w11:definitions/@targetNamespace, @name)"/>
+ <xsl:variable name="operation" select="//w11:portType/w11:operation[resolve-QName(w11:input/@message, .) = $message_name]" />
+ <xsl:for-each select="$operation">
+ <xsl:variable name="operation_name" select="@name"/>
+
+ <xsl:variable name="porttype_name" select="QName(/w11:definitions/@targetNamespace, ../@name)"/>
+ <xsl:variable name="bound_to_http">
+ <xsl:for-each select="//w11:binding[resolve-QName(@type, .) = $porttype_name]/w11:operation[@name = $operation_name]">
+ <xsl:if test="../w11http:binding">
+ <xsl:text>y</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:if test="contains($bound_to_http, 'y')">
+ <xs:schema targetNamespace="{concat(/w11:definitions/@targetNamespace, 'GEN')}">
+ <xs:documentation>
+ The following is made up by the translation script.
+ It's not clear how well this is going to work.
+ </xs:documentation>
+
+ <xs:element name="{$operation_name}">
+ <xs:complexType>
+ <xsl:for-each select="$themessage/w11:part">
+ <xs:element name="{@name}" type="{@type}"/>
+ </xsl:for-each>
+
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template match='w11:message'>
+
+<!-- <xsl:comment>MESSAGE:<xsl:value-of select='@name' /></xsl:comment> -->
+ </xsl:template>
+
+ <xsl:template match='w11:portType'>
+ <interface name='{@name}'>
+ <xsl:apply-templates select='w11:documentation' />
+ <xsl:apply-templates select='*[not(local-name()="documentation"
+ and namespace-uri()="http://schemas.xmlsoap.org/wsdl/")]' />
+ </interface>
+ </xsl:template>
+
+ <xsl:template match='w11:portType/w11:operation'>
+ <xsl:apply-templates select='w11:fault' />
+ <xsl:variable name='name' select='@name'/>
+ <operation name='{$name}'>
+ <xsl:variable name='ios' select='*[(local-name()="input"
+ or local-name()="output"
+ or local-name()="fault")
+ and namespace-uri()="http://schemas.xmlsoap.org/wsdl/"]' />
+ <!-- pattern is not optional in WSDL 2.0 -->
+ <xsl:variable name='pattern'>
+ <xsl:choose>
+ <xsl:when test='count($ios) = 1
+ and $ios/self::w11:input'>
+
+ <!-- One-Way Operation -->
+ <xsl:text>http://www.w3.org/ns/wsdl/in-only</xsl:text>
+ </xsl:when>
+ <xsl:when test='count($ios) = 2
+ and $ios/self::w11:input
+ and $ios/self::w11:fault'>
+ <xsl:text>http://www.w3.org/ns/wsdl/robust-in-only</xsl:text>
+ </xsl:when>
+ <xsl:when test='count($ios) = 1
+ and $ios/self::w11:output'>
+ <!-- Notification Operation -->
+
+ <xsl:text>http://www.w3.org/ns/wsdl/out-only</xsl:text>
+ </xsl:when>
+ <xsl:when test='count($ios) = 2
+ and $ios/self::w11:output
+ and $ios/self::w11:fault'>
+ <xsl:text>http://www.w3.org/ns/wsdl/robust-out-only</xsl:text>
+ </xsl:when>
+ <xsl:when test='count($ios/self::w11:input) = 1
+ and count($ios/self::w11:output) = 1
+ and $ios/self::w11:output[preceding-sibling::w11:input]'>
+ <!-- Request-Response Operation -->
+ <xsl:text>http://www.w3.org/ns/wsdl/in-out</xsl:text>
+
+ </xsl:when>
+ <xsl:when test='count($ios/self::w11:output) = 1
+ and count($ios/self::w11:input) = 1
+ and $ios/self::w11:input[preceding-sibling::w11:output]'>
+ <!-- Solicit-Response Operation -->
+ <xsl:text>http://www.w3.org/ns/wsdl/out-in</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>http://www.w3.org/2006/02/undefined</xsl:text>
+ </xsl:otherwise>
+
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:attribute name='pattern'>
+ <xsl:value-of select='$pattern' />
+ </xsl:attribute>
+ <xsl:if test='count(../w11:operation[@name=$name]) > 1'>
+ <!-- WSDL 1.1 operation/@name are unique according to
+ the WS-I Basic profile but input/output are -->
+ <documentation>
+ ERROR: duplicate name for the operation
+ </documentation>
+
+ </xsl:if>
+ <xsl:apply-templates select='w11:documentation' />
+
+ <xsl:for-each select='$ios'>
+ <xsl:choose>
+ <xsl:when test='self::w11:input or self::w11:output'>
+ <xsl:apply-templates select='.' />
+ </xsl:when>
+ <xsl:when test='self::w11:fault'>
+
+ <xsl:choose>
+ <xsl:when test='$pattern = "http://www.w3.org/ns/wsdl/out-in"
+ or $pattern = "http://www.w3.org/ns/wsdl/out-opt-in"'>
+ <xsl:apply-templates select='.' mode='infault'/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select='.' mode='outfault'/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+
+ </xsl:choose>
+ </xsl:for-each>
+ </operation>
+ </xsl:template>
+
+ <xsl:template match='w11:portType/w11:operation/w11:input
+ |w11:portType/w11:operation/w11:output
+ |w11:portType/w11:operation/w11:fault'>
+ <xsl:element name='{local-name()}' namespace='http://www.w3.org/ns/wsdl'>
+ <xsl:call-template name='resolve-elementType' />
+ </xsl:element>
+
+ </xsl:template>
+
+ <xsl:template match='w11:fault' mode='infault'>
+ <xsl:variable name='prefix'>
+ <xsl:value-of select='prefix-from-QName($qname)'/>
+ </xsl:variable>
+
+ <infault ref='{$prefix}:{@name}'>
+ <xsl:namespace name='{prefix}' select='/w11:definitions/@targetNamespace' />
+ </infault>
+
+ </xsl:template>
+
+ <xsl:template match='w11:fault' mode='outfault'>
+ <xsl:variable name='prefix'>
+ <xsl:value-of select='prefix-from-QName($qname)'/>
+ </xsl:variable>
+
+ <outfault ref='{$prefix}:{@name}'>
+ <xsl:namespace name='{$prefix}' select='/w11:definitions/@targetNamespace' />
+ </outfault>
+
+ </xsl:template>
+
+ <xsl:template match='w11:fault' mode='binding'>
+ <xsl:variable name='prefix'>
+ <xsl:value-of select='prefix-from-QName($qname)'/>
+ </xsl:variable>
+
+ <fault ref='{$prefix}:{@name}'>
+ <xsl:namespace name='{$prefix}' select='/w11:definitions/@targetNamespace' />
+ </fault>
+
+ </xsl:template>
+
+ <xsl:template name='resolve-elementType-attrs'>
+ <!-- This template is called by resolve-elementType to set attribute values -->
+ <xsl:param name="element"/>
+ <xsl:param name="faultname"/>
+ <xsl:choose>
+ <xsl:when test='self::w11:fault'>
+ <xsl:attribute name='name'>
+
+ <xsl:value-of select='$faultname' />
+ </xsl:attribute>
+ <xsl:attribute name='element'><xsl:value-of select="$element"/></xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:attribute name='element'><xsl:value-of select="$element"/></xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="message-is-using-types">
+ <xsl:param name="parts"/>
+ <xsl:param name="message"/>
+ <xsl:param name="name"/>
+ <xsl:variable name="usestypes">
+ <xsl:for-each select="$parts">
+ <xsl:variable name="bodypart" select="$message/w11:part[@name eq $name]"/>
+ <xsl:if test='$bodypart/@type
+ and not($bodypart/@element)'>
+
+ <xsl:value-of select="'y'"/>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="contains($usestypes, 'y')">
+ <xsl:value-of select="true()"/>
+ </xsl:when>
+ <xsl:otherwise>
+
+ <xsl:value-of select="false()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name='resolve-elementType'>
+ <xsl:variable name='message_name' select='resolve-QName(@message, .)'/>
+ <xsl:variable name='message'
+ select='/w11:definitions/w11:message[QName(/w11:definitions/@targetNamespace, @name) eq $message_name]'/>
+ <xsl:variable name="portType_name"
+ select="QName(/w11:definitions/@targetNamespace, ../../@name)"/>
+ <xsl:variable name="operation_name" select="../@name"/>
+
+ <xsl:variable name="bound_operation" select="//w11:binding[resolve-QName(@type, current()) = $portType_name]/w11:operation[@name=$operation_name]"/>
+ <!-- FIXME: this has a good chance of breaking if the message is bound more than once -->
+ <!-- FIXME: Only running tests on one operation, and will fail if @message is missing on input -->
+ <xsl:variable name="soapbody" select="$bound_operation/w11:input[resolve-QName(@message, current())=$message_name]/w11soap:body|$bound_operation/w11:output[resolve-QName(@message, current())=$message_name]/w11soap:body"/>
+ <xsl:variable name="parts" select="tokenize($soapbody/@parts, '\s+')"/>
+ <xsl:choose>
+ <!-- Is this SOAP RPC? -->
+ <xsl:when test="$soapbody/../../@style = 'rpc'
+ or $soapbody/../../../w11soap:binding/@style = 'rpc'">
+ <!-- Check that all parts are defined with elements -->
+
+ <xsl:variable name="usestypes">
+ <xsl:call-template name="message-is-using-types">
+ <xsl:with-param name="parts" select="$parts"/>
+ <xsl:with-param name="message" select="$message"/>
+ <xsl:with-param name="name" select="current()"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="not($usestypes='true')">
+ <!-- This is the case; we can be precise -->
+
+ <xsl:variable name="localName">
+ <xsl:call-template name="resolve-soaprpc-element-localname">
+ <xsl:with-param name="msg" select="."/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="elementType">
+ <xsl:choose>
+ <xsl:when test="$localName = '#any'">
+ <xsl:value-of select="$localName"/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:value-of select="QName($soapbody/@namespace,
+ concat('bodyns:',$localName))" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:if test="$localName != '#any'">
+ <xsl:namespace name="bodyns"
+ select="$soapbody/@namespace" />
+ </xsl:if>
+ <xsl:call-template name='resolve-elementType-attrs'>
+
+ <xsl:with-param name='element' select="$elementType"/>
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name='resolve-elementType-attrs'>
+ <xsl:with-param name='element' select="'#any'"/>
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <!-- Is this a simple case? One part defined as an element -->
+ <xsl:when test='count($message/w11:part) = 1
+ and not($message/w11:part/@type)
+ and $message/w11:part/@element'>
+ <!-- Simple case when a message has only one part defined as an element -->
+ <xsl:variable name='elementType'
+ select='resolve-QName($message/w11:part/@element, $message/w11:part)'/>
+ <xsl:namespace name='{prefix-from-QName($elementType)}'
+ select='namespace-uri-from-QName($elementType)'/>
+ <xsl:call-template name='resolve-elementType-attrs'>
+
+ <xsl:with-param name='element' select="$elementType"/>
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+ </xsl:when>
+ <!-- Is there more than one part? -->
+ <xsl:when test='count($message/w11:part) > 1'>
+ <!-- Case where there's more than one part -->
+ <xsl:variable name="httpUrlReplacement">
+ <xsl:for-each select="$bound_operation">
+
+ <xsl:if test="w11:input[resolve-QName(@message, current())=$message_name]/w11http:urlReplacement or w11:input/w11http:urlReplacement">
+ <xsl:text>y</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <xsl:choose>
+ <!-- Is the message bound to SOAP? -->
+ <xsl:when test="$soapbody">
+
+ <xsl:choose>
+ <!-- FIXME - BIG FAT WARNING: this is assuming that
+ there's only one binding of the interface In case
+ this isn't the case, we have to hope that the same
+ part is going to be bound to the body, otherwise
+ the assumptions made here are going to be wrong -->
+ <xsl:when test="count($parts) = 1">
+ <!-- ... but only one is the body, and is defined as
+ an element -->
+ <xsl:variable name="bodypart" select="$message/w11:part[@name = $parts]"/>
+ <xsl:if test='not($bodypart/@type)
+ and $bodypart/@element'>
+ <xsl:variable name='elementType'
+ select='resolve-QName($bodypart/@element, $bodypart)'/>
+ <xsl:namespace name='{prefix-from-QName($elementType)}'
+ select='namespace-uri-from-QName($elementType)'/>
+ <xsl:call-template name='resolve-elementType-attrs'>
+
+ <xsl:with-param name='element' select="$elementType"/>
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name='resolve-elementType-attrs'>
+ <xsl:with-param name='element' select="'#any'"/>
+ <xsl:with-param name='faultname' select="@name"/>
+
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <!-- Is the message bound to HTTP with URL replacement? -->
+ <xsl:when test="contains($httpUrlReplacement, 'y')">
+ <xsl:namespace name="convertns"
+ select="concat(/w11:definitions/@targetNamespace, 'GEN')" />
+ <xsl:call-template name='resolve-elementType-attrs'>
+ <xsl:with-param name='element' select="concat('convertns:', ../@name)"/>
+
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+ </xsl:when>
+ <!-- No, the message is not bound to SOAP nor to HTTP, we don't make any assumptions -->
+ <xsl:otherwise>
+ <xsl:call-template name='resolve-elementType-attrs'>
+ <xsl:with-param name='element' select="'#any'"/>
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name='resolve-elementType-attrs'>
+ <xsl:with-param name='element' select="'#any'"/>
+ <xsl:with-param name='faultname' select="@name"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="http-serialization">
+ <xsl:param name="binding-msg-ref"/>
+ <xsl:param name="attrib"/>
+ <xsl:variable name="mime" select="$binding-msg-ref/w11mime:content"/>
+ <xsl:if test="count($mime) = 1 and $mime/@type">
+ <xsl:attribute name="{$attrib}">
+
+ <xsl:value-of select="$mime/@type"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="count($mime) > 1">
+ <xsl:attribute name="{$attrib}">*/*</xsl:attribute>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match='w11:binding'>
+
+ <binding name='{@name}' interface='{@type}'>
+ <xsl:variable name='qname' select='resolve-QName(@type, .)' />
+ <xsl:namespace name='{prefix-from-QName($qname)}' select='namespace-uri-from-QName($qname)'/>
+ <xsl:if test='w11soap:binding'>
+ <xsl:attribute name='type'>http://www.w3.org/ns/wsdl/soap</xsl:attribute>
+ <xsl:attribute name='version' namespace='http://www.w3.org/ns/wsdl/soap'>1.1</xsl:attribute>
+ <xsl:attribute name='protocol' namespace='http://www.w3.org/ns/wsdl/soap'>
+ <xsl:choose>
+
+ <xsl:when test='w11soap:binding/@transport = "http://schemas.xmlsoap.org/soap/http"'>
+ <xsl:text>http://www.w3.org/2006/01/soap11/bindings/HTTP/</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select='w11soap:binding/@transport'/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+
+ </xsl:if>
+ <xsl:if test='w11http:binding'>
+ <xsl:attribute name='type'>http://www.w3.org/ns/wsdl/http</xsl:attribute>
+ <xsl:attribute name='methodDefault' namespace='http://www.w3.org/ns/wsdl/http'>
+ <xsl:value-of select="w11http:binding/@verb" />
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates select='/w11:definitions[@targetNamespace = namespace-uri-from-QName($qname)]
+ /w11:portType[@name = local-name-from-QName($qname)]/w11:operation/w11:fault'
+ mode='binding'/>
+
+ <xsl:apply-templates select='*[not(local-name()="binding"
+ and (namespace-uri() = "http://schemas.xmlsoap.org/wsdl/soap/"
+ or namespace-uri() = "http://schemas.xmlsoap.org/wsdl/http/"))]' />
+ </binding>
+ </xsl:template>
+
+ <xsl:template match="w11:binding/w11:operation">
+ <xsl:variable name='prefix'>
+ <xsl:value-of select='prefix-from-QName($qname)'/>
+ </xsl:variable>
+
+ <operation ref='{$prefix}:{@name}'>
+
+ <xsl:namespace name='{$prefix}' select='/w11:definitions/@targetNamespace' />
+ <!-- SOAP Binding -->
+ <xsl:variable name='action' select='w11soap:operation/@soapAction'/>
+ <xsl:if test='$action != ""'>
+ <!--
+ @@@ Unsure about this test:
+ http://lists.w3.org/Archives/Public/public-ws-desc-comments/2006Feb/0000.html
+ -->
+ <xsl:attribute name='soapAction' namespace='http://www.w3.org/ns/wsdl/soap'>
+ <xsl:value-of select='$action'/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="../w11soap:binding">
+ <xsl:if test="w11:input/w11soap:header or w11:output/w11soap:header">
+ <xsl:apply-templates select="*" mode="binding"/>
+ </xsl:if>
+ </xsl:if>
+ <!-- HTTP Binding -->
+ <xsl:if test="../w11http:binding">
+ <xsl:call-template name="http-serialization">
+ <xsl:with-param name="binding-msg-ref" select="w11:input"/>
+
+ <xsl:with-param name="attrib" select="'inputSerialization'"/>
+ </xsl:call-template>
+ <xsl:call-template name="http-serialization">
+ <xsl:with-param name="binding-msg-ref" select="w11:output"/>
+ <xsl:with-param name="attrib" select="'outputSerialization'"/>
+ </xsl:call-template>
+ </xsl:if>
+ <xsl:if test="w11http:operation/@location">
+ <xsl:choose>
+
+ <xsl:when test="w11:input/w11http:urlReplacement">
+ <xsl:attribute name='location' namespace='http://www.w3.org/ns/wsdl/http'>
+ <xsl:value-of select="translate(w11http:operation/@location, '()', '{}')"/>
+ </xsl:attribute>
+ <xsl:attribute name='ignoreUncited' namespace='http://www.w3.org/ns/wsdl/http'>
+ <xsl:text>true</xsl:text>
+ </xsl:attribute>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:attribute name='location' namespace='http://www.w3.org/ns/wsdl/http'>
+ <xsl:value-of select="w11http:operation/@location"/>
+ </xsl:attribute>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:if>
+ </operation>
+ </xsl:template>
+
+ <xsl:template match="w11:input|w11:output" mode="binding">
+ <!-- We're not specifying @messageLabel here because it is not needed for the MEPs
+ that we handle -->
+ <xsl:element name='{local-name()}' namespace='http://www.w3.org/ns/wsdl'>
+ <xsl:variable name="messageName"
+ select="local-name-from-QName(resolve-QName(current()/w11soap:header/@message, current()/w11soap:header))"/>
+ <xsl:variable name="partName"
+ select="current()/w11soap:header/@part" />
+ <xsl:variable name="elementName"
+ select="//w11:message[@name=$messageName]/w11:part[@name=$partName]/@element" />
+ <!-- FIXME: Not handling types -->
+ <xsl:if test="$elementName">
+
+ <wsoap:header required="true">
+ <xsl:variable name="element" select="resolve-QName($elementName, //w11:message[@name=$messageName]/w11:part[@name=$partName])"/>
+ <xsl:namespace name='{prefix-from-QName($element)}'
+ select='namespace-uri-from-QName($element)'/>
+ <xsl:attribute name="element">
+ <xsl:value-of select="$element"/>
+ </xsl:attribute>
+ </wsoap:header>
+ </xsl:if>
+ </xsl:element>
+
+ </xsl:template>
+
+ <xsl:template match='w11:service'>
+ <service name='{@name}'>
+ <xsl:variable name='binding_qname' select='resolve-QName(w11:port[1]/@binding, w11:port[1])'/>
+ <xsl:variable name='binding' select='/w11:definitions[@targetNamespace = namespace-uri-from-QName($binding_qname)]
+ /w11:binding[@name = local-name-from-QName($binding_qname)]' />
+ <xsl:variable name='interface' select='resolve-QName($binding/@type, $binding)' />
+ <xsl:attribute name='interface'>
+ <xsl:value-of select='$interface' />
+
+ </xsl:attribute>
+ <xsl:namespace name='{prefix-from-QName($interface)}' select='namespace-uri-from-QName($interface)'/>
+ <xsl:apply-templates select='*' />
+ </service>
+ </xsl:template>
+
+ <xsl:template match='w11:port'>
+ <endpoint name='{@name}' binding='{@binding}'>
+ <xsl:variable name='qname' select='resolve-QName(@binding, .)' />
+
+ <xsl:namespace name='{prefix-from-QName($qname)}' select='namespace-uri-from-QName($qname)'/>
+ <xsl:if test='w11soap:address'>
+ <xsl:attribute name="address">
+ <xsl:value-of select='w11soap:address/@location'/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test='w11http:address'>
+ <xsl:attribute name="address">
+ <xsl:value-of select='w11http:address/@location'/>
+
+ </xsl:attribute>
+ </xsl:if>
+ </endpoint>
+ </xsl:template>
+
+ <xsl:template match='w11:documentation'>
+ <documentation>
+ <xsl:apply-templates select='*|@*|text()' />
+ </documentation>
+
+ </xsl:template>
+
+ <xsl:template match="*|@*|text()">
+ <xsl:copy>
+ <xsl:apply-templates select='*|@*|text()' />
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:transform>
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/divs.html
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/divs.html Fri May 16 04:52:15 2008
@@ -0,0 +1,2 @@
+<div id="divWSDLConverterTool" style="display:none;"></div>
+<div id="divTryitTool" style="display:none;"></div>
\ No newline at end of file
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/js.html
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/js.html Fri May 16 04:52:15 2008
@@ -0,0 +1 @@
+<script language="javascript" src="extensions/tools_wc/js/wsdlconverter.js"></script>
\ No newline at end of file
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/wsdlconverter.js
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/wsdlconverter.js Fri May 16 04:52:15 2008
@@ -0,0 +1,109 @@
+/**
+ * This js has the tools related js functions
+ */
+
+if (typeof wso2 == "undefined") {
+ var wso2 = {};
+}
+if (typeof wso2.tool == "undefined") {
+ wso2.tool = {};
+}
+
+wso2.tool.WC = {
+ validateAndSubmit : function() {
+ try {
+ var objForm = document.getElementById('wsdl11FormID');
+ var inputObj = document.getElementById('filename');
+ if (inputObj.value == "") {
+ wso2.wsf.Util.alertWarning('Please Select a WSDL of Version 1.1');
+ return false;
+ }
+ objForm.action = "fileupload/*";
+ FileExcutor.execute = this.wcserviceClient;
+ objForm.submit();
+ return true;
+ } catch(e) {
+ wso2.wsf.Util.alertWarning('You have selected an invalid WSDL document.');
+ }
+ },
+
+ validateAndSubmitURL : function() {
+ var inputObj = document.getElementById('wsdl11URL');
+ if (inputObj.value == "") {
+ wso2.wsf.Util.alertWarning('WSDL 1.1 URL cannot be empty.');
+ return false;
+ }
+ var bodyXml = '<req:convertFromURL xmlns:req="http://org.wso2.wsf/tools">\n' +
+ '<url><![CDATA[' + inputObj.value + ']]></url>\n' +
+ '</req:convertFromURL>\n';
+ var callURL = wso2.wsf.Util.getServerURL() + "/" + "WSDLConverter" ;
+ wso2.wsf.Util.cursorWait();
+ new wso2.wsf.WSRequest(callURL, "urn:convertFromURL", bodyXml, wcserviceClientCallback, [1]);
+
+ },
+
+ validateAndSubmitTryit : function() {
+ var inputObj = document.getElementById('tryitFileName');
+ if (inputObj.value == "") {
+ wso2.wsf.Util.alertWarning('Please Select a WSDL of Version 1.1 or 2.0');
+ return false;
+ }
+ var bodyXml = '<req:generateAJAXApp xmlns:req="http://org.wso2.wsf/tools">\n' +
+ '<url><![CDATA[' + inputObj.value + ']]></url>\n' +
+ '<hostName><![CDATA['+ HOST+']]></hostName>\n' +
+ '</req:generateAJAXApp>\n';
+ var callURL = wso2.wsf.Util.getServerURL() + "/" + "GenericAJAXClient" ;
+ wso2.wsf.Util.cursorWait();
+ new wso2.wsf.WSRequest(callURL, "urn:generateAJAXApp", bodyXml, wcserviceClientCallback, [2]);
+
+ },
+
+ showWC : function() {
+ this.showHelper("wsdlconverter","divWSDLConverterTool");
+ },
+
+ showTryit : function() {
+ this.showHelper("tryit", "divTryitTool");
+ document.tryitWSDLFileUploda.tryitFileName.focus();
+ },
+
+ showHelper : function(documentName, divName) {
+ var tmpTransformationNode;
+ if (window.XMLHttpRequest && !wso2.wsf.Util.isIE()) {
+ tmpTransformationNode =
+ document.implementation.createDocument("", documentName, null);
+ } else if (window.ActiveXObject) {
+ tmpTransformationNode = new ActiveXObject("Microsoft.XmlDom");
+ var sXml = "<"+documentName+"></"+documentName+">";
+ tmpTransformationNode.loadXML(sXml);
+ }
+ var objDiv = document.getElementById(divName);
+ var xsltHelperObj = new wso2.wsf.XSLTHelper();
+ xsltHelperObj.transform(objDiv, tmpTransformationNode, "extensions/tools_wc/xslt/wsdlconverter.xsl", true);
+ wso2.wsf.Util.showOnlyOneMain(objDiv);
+ },
+
+ wcserviceClient : function(uuid) {
+ var bodyXml = '<req:convertRequest xmlns:req="http://org.wso2.wsf/tools">\n' +
+ '<fileId>' + uuid + '</fileId>\n' +
+ '</req:convertRequest>\n';
+ var callURL = wso2.wsf.Util.getServerURL() + "/" + "WSDLConverter" ;
+ wso2.wsf.Util.cursorWait();
+ new wso2.wsf.WSRequest(callURL, "urn:convert", bodyXml, wcserviceClientCallback);
+ }
+}
+
+function wcserviceClientCallback() {
+ var data = this.req.responseXML;
+ var responseTextValue = data.getElementsByTagName("return")[0].firstChild.nodeValue;
+ var openBaseURL = "http://" + HOST +
+ (HTTP_PORT != 80 ? (":" + HTTP_PORT + ROOT_CONTEXT) : ROOT_CONTEXT);
+ window.open(openBaseURL + responseTextValue);
+ if (this.params) {
+ if (this.params == 1) {
+ wso2.tool.WC.showWC();
+ } else if (this.params == 2) {
+ wso2.tool.WC.showTryit();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/wsdlconverter.xsl
==============================================================================
--- (empty file)
+++ trunk/carbon-components/wsdlconverter/org.wso2.carbon.modules.wsdlconverter/src/main/resources/web/wsdlconverter.xsl Fri May 16 04:52:15 2008
@@ -0,0 +1,109 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:ns="http://org.wso2.wsf/tools">
+ <xsl:output method="html"/>
+
+ <xsl:template match="wsdlconverter">
+ <div>
+ <h2>WSDL Converter</h2>
+ </div>
+ <fieldset style="border:none;">
+ <div id="formset">
+ <div>
+ <form action="fileupload/*"
+ id="wsdl11FormID"
+ method="post"
+ name="wsdlUpload"
+ enctype="multipart/form-data"
+ target="globalIFrame">
+ <xsl:attribute name="onSubmit">
+ javascript:
+ return wso2.tool.WC.validateAndSubmit();
+ </xsl:attribute>
+ <fieldset>
+ <legend>Select WSDL 1.1 document</legend>
+ <div>
+ <label>Select WSDL</label>
+ <input type="file" id="filename" name="filename" size="50"/>
+ <br/>
+ <div class="buttonrow">
+ <input type="submit" id="wcButtonId" value="Convert WSDL 1.1 --> 2.0 ">
+ <xsl:attribute name="onclick">
+ javascript:
+ return wso2.tool.WC.validateAndSubmit();
+ </xsl:attribute>
+ </input>
+ </div>
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ <div>
+ <form method="POST"
+ name="wsdl11URLForm"
+ target="globalIFrame">
+ <xsl:attribute name="onSubmit">
+ javascript:
+ wso2.tool.WC.validateAndSubmitURL();
+ return false;
+ </xsl:attribute>
+ <fieldset>
+ <legend>Enter type WSDL 1.1 document URL</legend>
+ <div>
+ <label>Enter URL</label>
+ <input type="text" id="wsdl11URL" name="wsdl11URL" size="50"/>
+ <br/>
+ <div class="buttonrow">
+ <input type="submit" id="wcURLButtonId" value="Convert WSDL 1.1 --> 2.0 ">
+ <xsl:attribute name="onclick">
+ javascript:
+ wso2.tool.WC.validateAndSubmitURL();
+ return false;
+ </xsl:attribute>
+ </input>
+ </div>
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ </div>
+ </fieldset>
+ </xsl:template>
+
+ <xsl:template match="tryit">
+ <div>
+ <h2>Try It</h2>
+ </div>
+ <fieldset style="border:none;">
+ <div id="formset">
+ <form id="tryitFormId"
+ method="post"
+ name="tryitWSDLFileUploda"
+ target="globalIFrame">
+ <xsl:attribute name="onSubmit">
+ javascript:
+ wso2.tool.WC.validateAndSubmitTryit();
+ return false;
+ </xsl:attribute>
+ <fieldset>
+ <legend>Enter WSDL 1.1 or 2.0 document location</legend>
+ <div>
+ <label>Enter URL</label>
+ <input type="text" id="tryitFileName" name="tryitFileName" size="50"/>
+ <br/>
+ <div class="buttonrow">
+ <input type="submit" id="tryitButtonId" value="Try It">
+ <xsl:attribute name="onclick">
+ javascript:
+ wso2.tool.WC.validateAndSubmitTryit();
+ return false;
+ </xsl:attribute>
+ </input>
+ </div>
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ </fieldset>
+ </xsl:template>
+
+</xsl:stylesheet>
More information about the Carbon-dev
mailing list