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 du...@apache.org on 2006/05/15 18:34:30 UTC
svn commit: r406669 - in /incubator/woden/java: build.properties build.xml
src/org/apache/woden/tool/ src/org/apache/woden/tool/converter/
src/org/apache/woden/tool/converter/Convert.java
src/org/apache/woden/tool/converter/Utils.java
Author: duftler
Date: Mon May 15 09:34:27 2006
New Revision: 406669
URL: http://svn.apache.org/viewcvs?rev=406669&view=rev
Log:
Committed 1st pass at tool to convert from WSDL1.1 to WSDL2.0.
Added the necessary lines to build.xml and build.properties to allow building (requires WSDL4J).
Made a minor change to build.xml to stop Xerces jars from being repeatedly extracted.
Try "java org.apache.woden.tool.converter.Convert" to see command-line usage.
Currently outputs files with the same name as inputted, but with an ".wsdl2" extension.
Can be modified to output Woden classes.
Added:
incubator/woden/java/src/org/apache/woden/tool/
incubator/woden/java/src/org/apache/woden/tool/converter/
incubator/woden/java/src/org/apache/woden/tool/converter/Convert.java
incubator/woden/java/src/org/apache/woden/tool/converter/Utils.java
Modified:
incubator/woden/java/build.properties
incubator/woden/java/build.xml
Modified: incubator/woden/java/build.properties
URL: http://svn.apache.org/viewcvs/incubator/woden/java/build.properties?rev=406669&r1=406668&r2=406669&view=diff
==============================================================================
--- incubator/woden/java/build.properties (original)
+++ incubator/woden/java/build.properties Mon May 15 09:34:27 2006
@@ -25,6 +25,8 @@
AntURL = http://www.apache.org/dist/ant/binaries/apache-ant-1.6.5-bin.zip
AntFile = apache-ant-1.6.5-bin.zip
AntJar = ant.jar
+WSDL4JURL = http://superb-west.dl.sourceforge.net/sourceforge/wsdl4j/wsdl4j-bin-1.5.2.zip
+WSDL4JFile = wsdl4j-bin-1.5.2.zip
! The location of the Woden build home
build.home = ${basedir}
Modified: incubator/woden/java/build.xml
URL: http://svn.apache.org/viewcvs/incubator/woden/java/build.xml?rev=406669&r1=406668&r2=406669&view=diff
==============================================================================
--- incubator/woden/java/build.xml (original)
+++ incubator/woden/java/build.xml Mon May 15 09:34:27 2006
@@ -67,6 +67,8 @@
<echo message="AntURL=${AntURL}" />
<echo message="AntFile=${AntFile}" />
<echo message="AntJar=${AntJar}" />
+ <echo message="WSDL4JURL=${WSDL4JURL}" />
+ <echo message="WSDL4JFile=${WSDL4JFile}" />
<echo message="build.home=${build.home}" />
<echo message="version=${version}" />
<echo message="milestone=${milestone}" />
@@ -107,13 +109,14 @@
<available file="${downloads}/${XmlSchemaFile}" property="XmlSchema.exists" />
<available file="${downloads}/${XercesFile}" property="Xerces.exists" />
<available file="${downloads}/${AntFile}" property="Ant.exists" />
+ <available file="${downloads}/${WSDL4JFile}" property="WSDL4J.exists" />
<antcall target="getXmlSchema" />
<antcall target="getXerces" />
<antcall target="getAnt" />
+ <antcall target="getWSDL4J" />
<antcall target="extractXmlSchema" />
- <antcall target="extractXerces" />
<antcall target="extractAnt" />
<!-- flatten the lib dir -->
@@ -140,6 +143,13 @@
<!-- Get the latest version of Xerces and unzip it -->
<target name="getXerces" unless="Xerces.exists">
<get src="${XercesURL}" dest="${downloads}/${XercesFile}" />
+
+ <unzip src="${downloads}/${XercesFile}" dest="${libraryDir}">
+ <patternset>
+ <include name="**/${XercesJar1}" />
+ <include name="**/${XercesJar2}" />
+ </patternset>
+ </unzip>
</target>
<!-- Get the latest version of Ant and unzip it -->
@@ -147,21 +157,22 @@
<get src="${AntURL}" dest="${downloads}/${AntFile}" />
</target>
- <!-- Copy the XmlSchema file to the lib dir -->
- <target name="extractXmlSchema">
- <copy file="${downloads}/${XmlSchemaFile}" todir="${libraryDir}" />
- </target>
+ <!-- Get the latest version of WSDL4J and unzip it -->
+ <target name="getWSDL4J" unless="WSDL4J.exists">
+ <get src="${WSDL4JURL}" dest="${downloads}/${WSDL4JFile}" />
- <!-- Extract the Xerces jars to the lib dir -->
- <target name="extractXerces">
- <unzip src="${downloads}/${XercesFile}" dest="${libraryDir}">
+ <unzip src="${downloads}/${WSDL4JFile}" dest="${libraryDir}">
<patternset>
- <include name="**/${XercesJar1}" />
- <include name="**/${XercesJar2}" />
+ <include name="**/wsdl4j*.jar" />
</patternset>
</unzip>
</target>
+ <!-- Copy the XmlSchema file to the lib dir -->
+ <target name="extractXmlSchema">
+ <copy file="${downloads}/${XmlSchemaFile}" todir="${libraryDir}" />
+ </target>
+
<!-- Copy the Ant file to the lib dir -->
<target name="extractAnt">
<copy file="${downloads}/${AntFile}" todir="${libraryDir}" />
@@ -171,7 +182,15 @@
This task produces woden.jar. -->
<target name="buildImplAndAPI" depends="init">
<mkdir dir="${build.classes}" />
- <javac sourcepath="" srcdir="${src.home}" destdir="${build.classes}" classpath="${libraryDir}/${XmlSchemaFile};${libraryDir}/${XercesJar1};${libraryDir}/${XercesJar2};${libraryDir}/${AntJar}" />
+ <javac sourcepath=""
+ srcdir="${src.home}"
+ destdir="${build.classes}">
+ <classpath>
+ <fileset dir="${libraryDir}">
+ <include name="**/*.jar"/>
+ </fileset>
+ </classpath>
+ </javac>
<!-- Copy all non Java files. -->
<copy todir="${build.classes}">
<fileset dir="${src.home}">
Added: incubator/woden/java/src/org/apache/woden/tool/converter/Convert.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/tool/converter/Convert.java?rev=406669&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/tool/converter/Convert.java (added)
+++ incubator/woden/java/src/org/apache/woden/tool/converter/Convert.java Mon May 15 09:34:27 2006
@@ -0,0 +1,1593 @@
+package org.apache.woden.tool.converter;
+
+import java.io.*;
+import java.util.*;
+import javax.wsdl.*;
+import javax.wsdl.extensions.*;
+import javax.wsdl.extensions.soap.*;
+import javax.wsdl.factory.*;
+import javax.wsdl.xml.*;
+import javax.xml.namespace.QName;
+
+// We may want to remove these 2 dependencies at some point.
+import com.ibm.wsdl.util.StringUtils;
+import com.ibm.wsdl.util.xml.DOMUtils;
+
+/**
+ * This is a utility to convert WSDL 1.1 documents into WSDL 2.0 documents.
+ *
+ * @author Matthew J. Duftler (duftler@us.ibm.com)
+ */
+public class Convert
+{
+ private static String NS_URI_WSDL_2_0_BASE =
+ "http://www.w3.org/2006/01";
+ private static String NS_URI_WSDL_2_0 =
+ NS_URI_WSDL_2_0_BASE + "/wsdl";
+ private static String NS_URI_WSDL_2_0_SOAP =
+ NS_URI_WSDL_2_0 + "/soap";
+ private static String NS_URI_WSDL_2_0_SOAP_1_1_HTTP =
+ NS_URI_WSDL_2_0_BASE + "/soap11/bindings/HTTP";
+ private static String NS_URI_WSDL_2_0_SOAP_1_2_HTTP =
+ "http://www.w3.org/2003/05/soap/bindings/HTTP";
+ private static String NS_URI_WSDL_1_1 =
+ "http://schemas.xmlsoap.org/wsdl/";
+ private static String NS_URI_WSDL_1_1_SOAP =
+ "http://schemas.xmlsoap.org/wsdl/soap/";
+ private static String NS_URI_WSDL_1_1_SOAP_HTTP =
+ "http://schemas.xmlsoap.org/soap/http";
+ private static String NS_URI_SCHEMA_2001 =
+ "http://www.w3.org/2001/XMLSchema";
+ private static String NS_URI_WSP =
+ "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+ private static Map patternMappings = new HashMap();
+ static
+ {
+ patternMappings.put(OperationType.ONE_WAY, NS_URI_WSDL_2_0 + "/in-only");
+ patternMappings.put(OperationType.REQUEST_RESPONSE, NS_URI_WSDL_2_0 + "/in-out");
+ patternMappings.put(OperationType.SOLICIT_RESPONSE, NS_URI_WSDL_2_0 + "/out-in");
+ patternMappings.put(OperationType.NOTIFICATION, NS_URI_WSDL_2_0 + "/out-only");
+ /*
+ For this to happen, the 1.1 document would've had to omit both the
+ <input> and <output> elements (instead of including them and referring
+ to childless <message>s).
+ */
+ patternMappings.put(null, NS_URI_WSDL_2_0 + "/in-out");
+ }
+
+ public static String COPY = "copy";
+ public static String IGNORE = "ignore";
+
+ private static Map baseExtToBehaviorMap = new HashMap();
+ static
+ {
+ baseExtToBehaviorMap.put(Binding.class.getName() +
+ new QName(NS_URI_WSDL_1_1_SOAP, "binding"),
+ IGNORE);
+ baseExtToBehaviorMap.put(BindingOperation.class.getName() +
+ new QName(NS_URI_WSDL_1_1_SOAP, "operation"),
+ IGNORE);
+ baseExtToBehaviorMap.put(Port.class.getName() +
+ new QName(NS_URI_WSDL_1_1_SOAP, "address"),
+ IGNORE);
+
+ baseExtToBehaviorMap.put(Definition.class.getName() +
+ new QName(NS_URI_WSP, "UsingPolicy"),
+ COPY);
+ baseExtToBehaviorMap.put(Definition.class.getName() +
+ new QName(NS_URI_WSP, "Policy"),
+ COPY);
+
+ // MJD - debug
+ // Need to decide what to do with extension elements found within message.
+// baseExtToBehaviorMap.put(Message.class.getName() +
+// new QName(NS_URI_WSP, "PolicyReference"),
+// COPY);
+ // MJD - debug
+ baseExtToBehaviorMap.put(Operation.class.getName() +
+ new QName(NS_URI_WSP, "PolicyReference"),
+ COPY);
+ baseExtToBehaviorMap.put(Binding.class.getName() +
+ new QName(NS_URI_WSP, "PolicyReference"),
+ COPY);
+ baseExtToBehaviorMap.put(BindingOperation.class.getName() +
+ new QName(NS_URI_WSP, "PolicyReference"),
+ COPY);
+ // MJD - debug
+ // Need to decide what to do with extension elements found within bindingInput.
+// baseExtToBehaviorMap.put(BindingInput.class.getName() +
+// new QName(NS_URI_WSP, "PolicyReference"),
+// COPY);
+ // MJD - debug
+ baseExtToBehaviorMap.put(Service.class.getName() +
+ new QName(NS_URI_WSP, "PolicyReference"),
+ COPY);
+ baseExtToBehaviorMap.put(Port.class.getName() +
+ new QName(NS_URI_WSP, "PolicyReference"),
+ COPY);
+
+ // MJD - debug
+ /*
+ Need to decide how to handle extensibility attributes encountered within
+ faults and parts.
+ */
+ // MJD - debug
+ }
+
+ private Map extToBehaviorMap = baseExtToBehaviorMap;
+
+ public Map getExtToBehaviorMap()
+ {
+ return extToBehaviorMap;
+ }
+
+ public void setExtToBehaviorMap(Map extToBehaviorMap)
+ {
+ this.extToBehaviorMap = extToBehaviorMap;
+ }
+
+ public String convertDefinition(String newTargetNS,
+ Definition def,
+ String targetDir,
+ boolean verbose,
+ boolean overwrite) throws WSDLException,
+ IOException
+ {
+ return convertDefinition(newTargetNS,
+ def,
+ new HashMap(),
+ new HashMap(),
+ new HashMap(),
+ targetDir,
+ verbose,
+ overwrite);
+ }
+
+ private String convertDefinition(String newTargetNS,
+ Definition def,
+ Map opToQNameMap,
+ Map faultToQNameMap,
+ Map defToFileNameMap,
+ String targetDir,
+ boolean verbose,
+ boolean overwrite) throws WSDLException,
+ IOException
+ {
+ String documentBaseURI = def.getDocumentBaseURI();
+ String targetFileName = new File(documentBaseURI).getName() + "2";
+ OutputStream out = Utils.getOutputStream(targetDir,
+ targetFileName,
+ overwrite,
+ verbose);
+ PrintWriter pw = new PrintWriter(out);
+ ExtensionRegistry extReg = def.getExtensionRegistry();
+
+ pw.print("<description");
+
+ String origTargetNamespace = def.getTargetNamespace();
+ String targetNamespace = convertNamespaceDecls(newTargetNS,
+ def.getNamespaces(),
+ pw,
+ def);
+
+ convertExtensions(Definition.class,
+ def,
+ pw,
+ def);
+
+ defToFileNameMap.put(def, targetFileName);
+
+ convertImports(newTargetNS,
+ def.getImports(),
+ pw,
+ def,
+ origTargetNamespace,
+ targetNamespace,
+ opToQNameMap,
+ faultToQNameMap,
+ defToFileNameMap,
+ targetDir,
+ verbose,
+ overwrite);
+ convertTypes(def.getTypes(), pw, def, extReg);
+ convertPortTypes(def.getPortTypes(),
+ pw,
+ def,
+ targetNamespace,
+ opToQNameMap,
+ faultToQNameMap);
+ convertBindings(def.getBindings(),
+ pw,
+ def,
+ origTargetNamespace,
+ targetNamespace,
+ opToQNameMap,
+ faultToQNameMap);
+ convertServices(def.getServices(),
+ pw,
+ def,
+ origTargetNamespace,
+ targetNamespace);
+
+ pw.println("</description>");
+ pw.flush();
+ pw.close();
+
+ return targetFileName;
+ }
+
+ public String convertFile(String newTargetNS,
+ String fileName,
+ String targetDir,
+ boolean verbose,
+ boolean overwrite) throws WSDLException,
+ IOException
+ {
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader reader = factory.newWSDLReader();
+
+ reader.setFeature("javax.wsdl.verbose", verbose);
+
+ Definition def = reader.readWSDL(fileName);
+
+ return convertDefinition(newTargetNS, def, targetDir, verbose, overwrite);
+ }
+
+ private String convertNamespaceDecls(String newTargetNS,
+ Map namespaces,
+ PrintWriter pw,
+ Definition def)
+ {
+ String targetNamespace = newTargetNS != null && !newTargetNS.equals("")
+ ? newTargetNS
+ : def.getTargetNamespace();
+
+ if (targetNamespace == null || targetNamespace.equals(""))
+ {
+ throw new IllegalArgumentException("If the source WSDL v1.1 document " +
+ "does not specify a " +
+ "targetNamespace, you must use the " +
+ "-targetNS command-line argument to " +
+ "specify one.");
+ }
+
+ pw.println(" xmlns=\"" + NS_URI_WSDL_2_0 + "\"");
+ pw.print(" targetNamespace=\"" + targetNamespace + "\"");
+
+ // MJD - debug
+ // These namespace declarations should be reset to their initial value.
+ def.addNamespace("tns", targetNamespace);
+ def.addNamespace("wsoap", NS_URI_WSDL_2_0_SOAP);
+ // MJD - debug
+
+ if (namespaces != null)
+ {
+ Iterator prefixes = namespaces.keySet().iterator();
+
+ while (prefixes.hasNext())
+ {
+ String prefix = (String)prefixes.next();
+
+ if (!prefix.equals("") && !prefix.equals("soap"))
+ {
+ String namespaceURI = def.getNamespace(prefix);
+
+ if (!namespaceURI.equals(NS_URI_WSDL_1_1_SOAP)
+ && !namespaceURI.equals(NS_URI_SCHEMA_2001)
+ && !namespaceURI.equals(NS_URI_WSDL_1_1))
+ {
+ pw.print("\n xmlns:" + prefix + "=\"" + namespaceURI +
+ "\"");
+ }
+ }
+ }
+ }
+
+ // MJD - debug
+// pw.print("\n " +
+// "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+// "\n xsi:schemaLocation=\n" +
+// " \"" + NS_URI_WSDL_2_0 + "\n" +
+// " http://www.w3.org/2006/01/wsdl/wsdl20.xsd\"");
+ // MJD - debug
+
+ pw.println(">");
+
+ return targetNamespace;
+ }
+
+ private void convertExtensionAttrs(AttributeExtensible attrExtensible,
+ PrintWriter pw,
+ Definition def)
+ throws WSDLException
+ {
+ Map extensionAttributes = attrExtensible.getExtensionAttributes();
+ Iterator attrNames = extensionAttributes.keySet().iterator();
+
+ while (attrNames.hasNext())
+ {
+ QName attrName = (QName)attrNames.next();
+ Object attrValue = extensionAttributes.get(attrName);
+ String attrStrValue = null;
+ QName attrQNameValue = null;
+
+ if (attrValue instanceof String)
+ {
+ attrStrValue = (String)attrValue;
+ }
+ else if (attrValue instanceof QName)
+ {
+ attrQNameValue = (QName)attrValue;
+ }
+ else if (attrValue instanceof List)
+ {
+ List attrValueList = (List)attrValue;
+ int size = attrValueList.size();
+
+ if (size > 0)
+ {
+ Object tempAttrVal = attrValueList.get(0);
+
+ if (tempAttrVal instanceof String)
+ {
+ attrStrValue = StringUtils.getNMTokens(attrValueList);
+ }
+ else if (tempAttrVal instanceof QName)
+ {
+ StringBuffer strBuf = new StringBuffer();
+
+ for (int i = 0; i < size; i++)
+ {
+ QName tempQName = (QName)attrValueList.get(i);
+
+ strBuf.append((i > 0 ? " " : "") +
+ DOMUtils.getQualifiedValue(tempQName.getNamespaceURI(),
+ tempQName.getLocalPart(),
+ def));
+ }
+
+ attrStrValue = strBuf.toString();
+ }
+ else
+ {
+ throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+ "Unknown type of extension attribute '" +
+ attrName + "': " +
+ tempAttrVal.getClass().getName());
+ }
+ }
+ else
+ {
+ attrStrValue = "";
+ }
+ }
+ else
+ {
+ throw new WSDLException(WSDLException.CONFIGURATION_ERROR,
+ "Unknown type of extension attribute '" +
+ attrName + "': " +
+ attrValue.getClass().getName());
+ }
+
+ if (attrQNameValue != null)
+ {
+ DOMUtils.printQualifiedAttribute(attrName, attrQNameValue, def, pw);
+ }
+ else
+ {
+ DOMUtils.printQualifiedAttribute(attrName, attrStrValue, def, pw);
+ }
+ }
+ }
+
+ private void convertExtensions(Class parentClass,
+ ElementExtensible elExtensible,
+ PrintWriter pw,
+ Definition def)
+ throws WSDLException
+ {
+ List extElements = elExtensible.getExtensibilityElements();
+
+ if (extElements != null)
+ {
+ ExtensionRegistry extReg = def.getExtensionRegistry();
+ Iterator extIterator = extElements.iterator();
+ String parentClassName = parentClass.getName();
+
+ while (extIterator.hasNext())
+ {
+ ExtensibilityElement extEl = (ExtensibilityElement)extIterator.next();
+ QName elementType = extEl.getElementType();
+ String behavior = (String)extToBehaviorMap.get(parentClassName +
+ elementType);
+
+ if (behavior == null)
+ {
+ throw new IllegalArgumentException("Encountered unknown " +
+ "extension element '" +
+ elementType + "', as a child of " +
+ "a " + parentClassName + ".");
+ }
+ else if (behavior.equals(COPY))
+ {
+ ExtensionSerializer extSer = extReg.querySerializer(parentClass,
+ elementType);
+
+ extSer.marshall(parentClass,
+ elementType,
+ extEl,
+ pw,
+ def,
+ extReg);
+ }
+ else if (behavior.equals(IGNORE))
+ {
+ }
+ else
+ {
+ throw new IllegalArgumentException("Encountered unknown " +
+ "behavior '" + behavior +
+ "' registered for extension " +
+ "element '" + elementType +
+ "', as a child of a " +
+ parentClassName + ".");
+ }
+ }
+ }
+ }
+
+ private void convertImports(String newTargetNS,
+ Map importMap,
+ PrintWriter pw,
+ Definition def,
+ String origTargetNamespace,
+ String targetNamespace,
+ Map opToQNameMap,
+ Map faultToQNameMap,
+ Map defToFileNameMap,
+ String targetDir,
+ boolean verbose,
+ boolean overwrite) throws WSDLException,
+ IOException
+ {
+ Iterator importListIterator = importMap.values().iterator();
+
+ while (importListIterator.hasNext())
+ {
+ List importList = (List)importListIterator.next();
+ Iterator importIterator = importList.iterator();
+
+ while (importIterator.hasNext())
+ {
+ Import _import = (Import)importIterator.next();
+ Definition importedDef = _import.getDefinition();
+ //String importedNamespace = _import.getNamespaceURI();
+ String importedDefTNS = null;
+
+ if (importedDef != null)
+ {
+ importedDefTNS = importedDef.getTargetNamespace();
+
+ /*
+ Since an imported definition was actually resolved, we have to make
+ sure that a targetNamespace was specified, and that it matches the
+ value of the namespace attribute specified on the <import> element.
+ */
+ if (importedDefTNS == null || importedDefTNS.equals(""))
+ {
+ throw new IllegalArgumentException("You cannot <import> WSDL v1.1 " +
+ "documents that do not " +
+ "specify the targetNamespace " +
+ "attribute on the definition " +
+ "element.");
+ }
+ else if (!importedDefTNS.equals(_import.getNamespaceURI()))
+ {
+ throw new IllegalArgumentException("The value of the namespace " +
+ "attribute on the <import> " +
+ "element must match the " +
+ "value of the targetNamespace " +
+ "attribute specified on the " +
+ "document being imported.");
+ }
+ }
+ else
+ {
+ /*
+ Since no definition was resolved, use the value from the namespace
+ attribute on the <import> element.
+ */
+ importedDefTNS = _import.getNamespaceURI();
+
+ if (importedDefTNS == null || importedDefTNS.equals(""))
+ {
+ throw new IllegalArgumentException("You cannot <import> WSDL v1.1 " +
+ "documents wihout either " +
+ "specifying the targetNamespace " +
+ "attribute on the imported " +
+ "definition element or " +
+ "specifying the namespace " +
+ "attribute on the <import> " +
+ "element.");
+ }
+ }
+
+ // Determine whether the -targetNS value should be propagated.
+ if (newTargetNS != null && !newTargetNS.equals(""))
+ {
+ if (importedDefTNS.equals(origTargetNamespace))
+ {
+ importedDefTNS = newTargetNS;
+ }
+ else if (!importedDefTNS.equals(newTargetNS))
+ {
+ newTargetNS = null;
+ }
+ }
+
+ String targetFileName = null;
+ String locationURI = _import.getLocationURI();
+
+ if (locationURI != null
+ && !locationURI.equals("")
+ && importedDef != null)
+ {
+ targetFileName = (String)defToFileNameMap.get(importedDef);
+
+ if (targetFileName == null)
+ {
+ targetFileName = convertDefinition(newTargetNS,
+ importedDef,
+ opToQNameMap,
+ faultToQNameMap,
+ defToFileNameMap,
+ targetDir,
+ verbose,
+ overwrite);
+ }
+ }
+
+ if (importedDefTNS.equals(targetNamespace))
+ {
+ if (targetFileName != null)
+ {
+ pw.print(" <include location=\"" + targetFileName + "\"");
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(_import,
+ pw,
+ def);
+
+ pw.println("/>");
+ }
+ }
+ else
+ {
+ pw.print(" <import namespace=\"" + importedDefTNS + "\"");
+
+ if (targetFileName != null)
+ {
+ pw.print(" location=\"" + targetFileName + "\"");
+ }
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(_import,
+ pw,
+ def);
+
+ pw.println("/>");
+ }
+ }
+ }
+ }
+
+ private void convertTypes(Types types,
+ PrintWriter pw,
+ Definition def,
+ ExtensionRegistry extReg) throws WSDLException
+ {
+ if (types == null)
+ {
+ return;
+ }
+
+ List extElList = types.getExtensibilityElements();
+
+ if (extElList != null && extElList.size() > 0)
+ {
+ pw.println(" <types>");
+
+ Iterator extElIterator = extElList.iterator();
+
+ while (extElIterator.hasNext())
+ {
+ ExtensibilityElement extEl = (ExtensibilityElement)extElIterator.next();
+ QName elementType = extEl.getElementType();
+ ExtensionSerializer extSer = extReg.querySerializer(Types.class,
+ extEl.getElementType());
+
+ extSer.marshall(Types.class, elementType, extEl, pw, def, extReg);
+ }
+
+ pw.println(" </types>");
+ }
+ }
+
+ private void convertPortTypes(Map portTypeMap,
+ PrintWriter pw,
+ Definition def,
+ String targetNamespace,
+ Map opToQNameMap,
+ Map faultToQNameMap)
+ throws WSDLException
+ {
+ if (portTypeMap == null)
+ {
+ return;
+ }
+
+ Iterator portTypes = portTypeMap.values().iterator();
+
+ while (portTypes.hasNext())
+ {
+ PortType portType = (PortType)portTypes.next();
+
+ if (portType.isUndefined())
+ {
+ continue;
+ }
+
+ QName qname = portType.getQName();
+
+ pw.print(" <interface name=\"" + qname.getLocalPart() + "\"");
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(portType,
+ pw,
+ def);
+
+ pw.println(">");
+
+ StringWriter operationsSW = new StringWriter();
+ PrintWriter operationsPW = new PrintWriter(operationsSW);
+ StringWriter faultsSW = new StringWriter();
+ PrintWriter faultsPW = new PrintWriter(faultsSW);
+
+ convertOperations(portType.getOperations(),
+ faultsPW,
+ operationsPW,
+ def,
+ targetNamespace,
+ opToQNameMap,
+ faultToQNameMap);
+
+ faultsPW.flush();
+ pw.print(faultsSW.toString());
+ operationsPW.flush();
+ pw.print(operationsSW.toString());
+
+ pw.println(" </interface>");
+ }
+ }
+
+ private void convertOperations(List operations,
+ PrintWriter faultsPW,
+ PrintWriter operationsPW,
+ Definition def,
+ String targetNamespace,
+ Map opToQNameMap,
+ Map faultToQNameMap)
+ throws WSDLException
+ {
+ if (operations != null && operations.size() > 0)
+ {
+ Set opNameSet = new HashSet();
+ Map newFaultMap = new HashMap();
+ Iterator opIterator = operations.iterator();
+
+ while (opIterator.hasNext())
+ {
+ Operation op = (Operation)opIterator.next();
+ String origOpName = op.getName();
+ String opName = origOpName;
+ int index = 1;
+
+ while (opNameSet.contains(opName))
+ {
+ opName = origOpName + "_" + index++;
+ }
+
+ opNameSet.add(opName);
+ opToQNameMap.put(op, new QName(targetNamespace, opName));
+
+ OperationType opType = op.getStyle();
+
+ operationsPW.println(" <operation name=\"" + opName + "\"");
+ operationsPW.print(" pattern=\"" +
+ patternMappings.get(opType) + "\"");
+ operationsPW.println(">");
+
+ convertExtensions(Operation.class,
+ op,
+ operationsPW,
+ def);
+
+ // MJD - debug
+ // Need to make sure these are called in the proper order.
+ convertInput(op.getInput(), operationsPW, def);
+ convertOutput(op.getOutput(), operationsPW, def);
+ convertFaults(op.getFaults(),
+ faultsPW,
+ operationsPW,
+ def,
+ targetNamespace,
+ newFaultMap,
+ faultToQNameMap);
+ // MJD - debug
+
+ operationsPW.println(" </operation>");
+ }
+ }
+ }
+
+ private void convertFaults(Map faultMap,
+ PrintWriter faultsPW,
+ PrintWriter operationsPW,
+ Definition def,
+ String targetNamespace,
+ Map newFaultMap,
+ Map faultToQNameMap)
+ throws WSDLException
+ {
+ if (faultMap == null)
+ {
+ return;
+ }
+
+ Iterator faults = faultMap.values().iterator();
+
+ while (faults.hasNext())
+ {
+ Fault fault = (Fault)faults.next();
+ String faultName = fault.getName();
+
+ if (faultName == null || faultName.equals(""))
+ {
+ throw new IllegalArgumentException("WSDL v1.1 requires a name to be " +
+ "specified for every fault element.");
+ }
+
+ Message faultMessage = fault.getMessage();
+
+ if (faultMessage == null || faultMessage.isUndefined())
+ {
+ throw new IllegalArgumentException("WSDL v1.1 requires a (defined) " +
+ "message to be specified for " +
+ "every fault element.");
+ }
+
+ List extEls = faultMessage.getExtensibilityElements();
+
+ if (extEls != null && extEls.size() > 0)
+ {
+ throw new IllegalArgumentException("Encountered extensibility " +
+ "elements within a message " +
+ "and cannot determine what to " +
+ "do with them: " + faultMessage);
+ }
+
+ List faultParts = faultMessage.getOrderedParts(null);
+ int size = faultParts.size();
+
+ if (size == 1)
+ {
+ Part part = (Part)faultParts.get(0);
+ QName elementName = part.getElementName();
+
+ if (elementName == null)
+ {
+ throw new IllegalArgumentException("The conversion utility " +
+ "currently supports only " +
+ "doc/lit style.");
+ }
+
+ QName retrievedElName = (QName)newFaultMap.get(faultName);
+ String origFaultName = faultName;
+ int index = 1;
+
+ while (retrievedElName != null
+ && !retrievedElName.equals(elementName))
+ {
+ faultName = origFaultName + "_" + index++;
+ retrievedElName = (QName)newFaultMap.get(faultName);
+ }
+
+ if (retrievedElName == null)
+ {
+ faultsPW.print(" <fault name=\"" + faultName + "\"");
+
+ DOMUtils.printQualifiedAttribute("element",
+ elementName,
+ def,
+ faultsPW);
+
+ faultsPW.println("/>");
+
+ newFaultMap.put(faultName, elementName);
+ }
+
+ QName refQName = new QName(targetNamespace, faultName);
+
+ operationsPW.print(" <outfault");
+
+ DOMUtils.printQualifiedAttribute("ref",
+ refQName,
+ def,
+ operationsPW);
+
+ operationsPW.println(" messageLabel=\"Out\"/>");
+
+ faultToQNameMap.put(fault, refQName);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Encountered a fault " +
+ "message with a number of " +
+ "parts other than 1: " +
+ faultParts);
+ }
+ }
+ }
+
+ private void convertInput(Input input,
+ PrintWriter pw,
+ Definition def) throws WSDLException
+ {
+ if (input != null)
+ {
+ Message inputMsg = input.getMessage();
+
+ if (inputMsg != null)
+ {
+ List extEls = inputMsg.getExtensibilityElements();
+
+ if (extEls != null && extEls.size() > 0)
+ {
+ throw new IllegalArgumentException("Encountered extensibility " +
+ "elements within a message " +
+ "and cannot determine what to " +
+ "do with them: " + inputMsg);
+ }
+
+ List orderedInputParts = inputMsg.getOrderedParts(null);
+ int size = orderedInputParts.size();
+
+ if (size == 1)
+ {
+ Part part = (Part)orderedInputParts.get(0);
+ QName elementName = part.getElementName();
+// String messageLabel = part.getName();
+ String messageLabel = "In";
+
+ pw.print(" <input messageLabel=\"" + messageLabel + "\"");
+
+ DOMUtils.printQualifiedAttribute("element",
+ elementName,
+ def,
+ pw);
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(input,
+ pw,
+ def);
+
+ pw.println("/>");
+ }
+ else if (size == 0)
+ {
+ pw.print(" <input messageLabel=\"In\" element=\"#none\"");
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(input,
+ pw,
+ def);
+
+ pw.println("/>");
+ }
+ else
+ {
+ throw new IllegalArgumentException("Encountered an input " +
+ "message with a number of " +
+ "parts other than 0 or 1: " +
+ orderedInputParts);
+ }
+ }
+ }
+ }
+
+ private void convertOutput(Output output,
+ PrintWriter pw,
+ Definition def) throws WSDLException
+ {
+ if (output != null)
+ {
+ Message outputMsg = output.getMessage();
+
+ if (outputMsg != null)
+ {
+ List extEls = outputMsg.getExtensibilityElements();
+
+ if (extEls != null && extEls.size() > 0)
+ {
+ throw new IllegalArgumentException("Encountered extensibility " +
+ "elements within a message " +
+ "and cannot determine what to " +
+ "do with them: " + outputMsg);
+ }
+
+ List orderedOutputParts = outputMsg.getOrderedParts(null);
+ int size = orderedOutputParts.size();
+
+ if (size == 1)
+ {
+ Part part = (Part)orderedOutputParts.get(0);
+ QName elementName = part.getElementName();
+// String messageLabel = part.getName();
+ String messageLabel = "Out";
+
+ pw.print(" <output messageLabel=\"" + messageLabel + "\"");
+
+ DOMUtils.printQualifiedAttribute("element",
+ elementName,
+ def,
+ pw);
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(output,
+ pw,
+ def);
+
+ pw.println("/>");
+ }
+ else if (size == 0)
+ {
+ pw.print(" <output messageLabel=\"Out\" element=\"#none\"");
+
+ // Attributes are just copied over to the new element.
+ convertExtensionAttrs(output,
+ pw,
+ def);
+
+ pw.println("/>");
+ }
+ else
+ {
+ throw new IllegalArgumentException("Encountered an output " +
+ "message with a number of " +
+ "parts other than 0 or 1: " +
+ orderedOutputParts);
+ }
+ }
+ }
+ }
+
+ private void convertBindings(Map bindingMap,
+ PrintWriter pw,
+ Definition def,
+ String origTargetNamespace,
+ String targetNamespace,
+ Map opToQNameMap,
+ Map faultToQNameMap)
+ throws WSDLException
+ {
+ if (bindingMap == null)
+ {
+ return;
+ }
+
+ Iterator bindings = bindingMap.values().iterator();
+
+ while (bindings.hasNext())
+ {
+ Binding binding = (Binding)bindings.next();
+
+ if (binding.isUndefined())
+ {
+ continue;
+ }
+
+ QName qname = binding.getQName();
+ PortType portType = binding.getPortType();
+
+ // Only convert the binding if the original portType can be resolved.
+ if (portType.isUndefined())
+ {
+ continue;
+ }
+
+ QName portTypeQName = null;
+ Set faultSet = new HashSet();
+ String type = null;
+ // Need to support both 1.1 and 1.2.
+ String soapVersion = "1.1";
+ String soapProtocol = null;
+ List extEls = binding.getExtensibilityElements();
+
+ if (extEls.size() > 0)
+ {
+ ExtensibilityElement extEl = (ExtensibilityElement)extEls.get(0);
+
+ if (extEl instanceof SOAPBinding)
+ {
+ SOAPBinding soapBinding = (SOAPBinding)extEl;
+
+ type = NS_URI_WSDL_2_0_SOAP;
+
+ String transportURI = soapBinding.getTransportURI();
+
+ if (NS_URI_WSDL_1_1_SOAP_HTTP.equals(transportURI))
+ {
+ soapProtocol = NS_URI_WSDL_2_0_SOAP_1_1_HTTP;
+ }
+ }
+ }
+
+ pw.print(" <binding name=\"" + qname.getLocalPart() + "\"");
+
+ if (portType != null)
+ {
+ portTypeQName = portType.getQName();
+
+ if (portTypeQName != null)
+ {
+ String portTypeNS = portTypeQName.getNamespaceURI();
+
+ if (!portTypeNS.equals(targetNamespace)
+ && portTypeNS.equals(origTargetNamespace))
+ {
+ portTypeQName = new QName(targetNamespace,
+ portTypeQName.getLocalPart());
+ }
+
+ pw.print("\n ");
+
+ DOMUtils.printQualifiedAttribute("interface",
+ portTypeQName,
+ def,
+ pw);
+ }
+ }
+
+ if (type != null)
+ {
+ pw.print("\n type=\"" + type + "\"");
+ }
+
+ if (soapVersion != null)
+ {
+ pw.print("\n ");
+
+ DOMUtils.printQualifiedAttribute(new QName(NS_URI_WSDL_2_0_SOAP,
+ "version"),
+ soapVersion,
+ def,
+ pw);
+ }
+
+ if (soapProtocol != null)
+ {
+ pw.print("\n ");
+
+ DOMUtils.printQualifiedAttribute(new QName(NS_URI_WSDL_2_0_SOAP,
+ "protocol"),
+ soapProtocol,
+ def,
+ pw);
+ }
+
+ pw.println(">");
+
+ convertExtensions(Binding.class,
+ binding,
+ pw,
+ def);
+
+ List operations = binding.getBindingOperations();
+ StringWriter operationsSW = new StringWriter();
+ PrintWriter operationsPW = new PrintWriter(operationsSW);
+ Iterator opIterator = operations.iterator();
+
+ while (opIterator.hasNext())
+ {
+ BindingOperation bindingOp = (BindingOperation)opIterator.next();
+ Operation op = bindingOp.getOperation();
+ Map bindingFaultMap = bindingOp.getBindingFaults();
+
+ if (bindingFaultMap != null)
+ {
+ Iterator bindingFaults = bindingFaultMap.values().iterator();
+
+ while (bindingFaults.hasNext())
+ {
+ BindingFault bindingFault = (BindingFault)bindingFaults.next();
+ String faultName = bindingFault.getName();
+
+ if (faultName == null)
+ {
+ List extElList = bindingFault.getExtensibilityElements();
+
+ if (extElList != null)
+ {
+ Iterator extIterator = extElList.iterator();
+
+ while (extIterator.hasNext())
+ {
+ ExtensibilityElement extEl =
+ (ExtensibilityElement)extIterator.next();
+
+ if (extEl instanceof SOAPFault)
+ {
+ SOAPFault soapFault = (SOAPFault)extEl;
+
+ faultName = soapFault.getName();
+ }
+ }
+ }
+ }
+
+ if (faultName == null)
+ {
+ throw new IllegalArgumentException("WSDL v1.1 requires a name " +
+ "to be specified for " +
+ "every wsdl:fault and " +
+ "soap:fault element.");
+ }
+
+ Fault fault = op.getFault(faultName);
+
+ if (fault == null)
+ {
+ throw new IllegalArgumentException("Unable to resolve " +
+ "referenced fault '" +
+ faultName + "'.");
+ }
+
+ QName faultRefType = (QName)faultToQNameMap.get(fault);
+
+ if (faultRefType == null)
+ {
+ throw new IllegalArgumentException("Unable to resolve " +
+ "referenced fault '" +
+ faultName + "'.");
+ }
+ else
+ {
+ faultSet.add(faultRefType);
+ }
+ }
+ }
+
+ QName refType = (QName)opToQNameMap.get(op);
+
+ if (refType == null)
+ {
+ throw new IllegalArgumentException("Unable to resolve referenced " +
+ "operation '" + op.getName() +
+ "'.");
+ }
+
+ String soapActionURI = null;
+ List extElList = bindingOp.getExtensibilityElements();
+
+ if (extElList != null)
+ {
+ Iterator extIterator = extElList.iterator();
+
+ while (extIterator.hasNext())
+ {
+ ExtensibilityElement extEl =
+ (ExtensibilityElement)extIterator.next();
+
+ if (extEl instanceof SOAPOperation)
+ {
+ SOAPOperation soapOp = (SOAPOperation)extEl;
+
+ soapActionURI = soapOp.getSoapActionURI();
+ }
+ }
+ }
+
+ operationsPW.print(" <operation");
+
+ DOMUtils.printQualifiedAttribute("ref",
+ refType,
+ def,
+ operationsPW);
+
+ if (soapActionURI != null)
+ {
+ DOMUtils.printQualifiedAttribute(new QName(NS_URI_WSDL_2_0_SOAP,
+ "action"),
+ soapActionURI,
+ def,
+ operationsPW);
+ }
+
+ operationsPW.println(">");
+
+ convertExtensions(BindingOperation.class,
+ bindingOp,
+ operationsPW,
+ def);
+
+ operationsPW.println(" </operation>");
+ }
+
+ Iterator faultIterator = faultSet.iterator();
+
+ while (faultIterator.hasNext())
+ {
+ QName faultRefType = (QName)faultIterator.next();
+
+ pw.print(" <fault");
+
+ DOMUtils.printQualifiedAttribute("ref",
+ faultRefType,
+ def,
+ pw);
+
+ pw.println("/>");
+ }
+
+ operationsPW.flush();
+ pw.print(operationsSW.toString());
+ pw.println(" </binding>");
+ }
+ }
+
+ private void convertServices(Map serviceMap,
+ PrintWriter pw,
+ Definition def,
+ String origTargetNamespace,
+ String targetNamespace)
+ throws WSDLException
+ {
+ if (serviceMap == null)
+ {
+ return;
+ }
+
+ Set serviceNameSet = new HashSet();
+ Iterator services = serviceMap.values().iterator();
+
+ while (services.hasNext())
+ {
+ Service service = (Service)services.next();
+ QName serviceQName = service.getQName();
+ String origServiceName = null;
+
+ if (serviceQName != null)
+ {
+ origServiceName = serviceQName.getLocalPart();
+ }
+
+ if (origServiceName == null || origServiceName.equals(""))
+ {
+ throw new IllegalArgumentException("WSDL v1.1 requires a name to be " +
+ "specified for every service " +
+ "element.");
+ }
+
+ Map portMap = service.getPorts();
+
+ if (portMap == null || portMap.size() == 0)
+ {
+ // If there are no 1.1 <port>s, we can't define any 2.0 <endpoint>s.
+ return;
+ }
+
+ Map portTypeToPortsMap = new HashMap();
+ Iterator ports = portMap.values().iterator();
+
+ while (ports.hasNext())
+ {
+ Port port = (Port)ports.next();
+ PortType servicePortType = getServicePortType(port);
+
+ // Only convert the port if the original portType can be resolved.
+ if (!servicePortType.isUndefined())
+ {
+ List portList = (List)portTypeToPortsMap.get(servicePortType);
+
+ if (portList == null)
+ {
+ portList = new Vector();
+ portTypeToPortsMap.put(servicePortType, portList);
+ }
+
+ portList.add(port);
+ }
+ }
+
+ String serviceName = origServiceName;
+ Iterator uniquePortTypes = portTypeToPortsMap.keySet().iterator();
+ int index = 0;
+
+ while (uniquePortTypes.hasNext())
+ {
+ if (index > 0 || serviceNameSet.contains(serviceName))
+ {
+ serviceName = origServiceName + "_" + index++;
+
+ while (serviceNameSet.contains(serviceName))
+ {
+ serviceName = origServiceName + "_" + index++;
+ }
+ }
+
+ serviceNameSet.add(serviceName);
+
+ PortType servicePortType = (PortType)uniquePortTypes.next();
+ QName serviceInterfaceType = getServiceInterfaceType(origServiceName,
+ servicePortType,
+ origTargetNamespace,
+ targetNamespace);
+ List portList = (List)portTypeToPortsMap.get(servicePortType);
+
+ pw.println(" <service name=\"" + serviceName + "\"");
+ pw.print(" ");
+
+ DOMUtils.printQualifiedAttribute("interface",
+ serviceInterfaceType,
+ def,
+ pw);
+
+ pw.println(">");
+
+ convertExtensions(Service.class,
+ service,
+ pw,
+ def);
+
+ convertPorts(portList, pw, def, origTargetNamespace, targetNamespace);
+
+ pw.println(" </service>");
+
+ if (index == 0)
+ {
+ index++;
+ }
+ }
+ }
+ }
+
+ private PortType getServicePortType(Port port)
+ {
+ Binding binding = port.getBinding();
+ PortType servicePortType = null;
+
+ if (binding != null)
+ {
+ servicePortType = binding.getPortType();
+ }
+
+ return servicePortType;
+ }
+
+ private QName getServiceInterfaceType(String origServiceName,
+ PortType servicePortType,
+ String origTargetNamespace,
+ String targetNamespace)
+ {
+ QName serviceInterfaceType = null;
+
+ if (servicePortType != null)
+ {
+ serviceInterfaceType = servicePortType.getQName();
+ }
+
+ if (serviceInterfaceType == null)
+ {
+ /*
+ If we can't determine the type of the 1.1 <portType>, we can't define
+ the 2.0 <service>.
+ */
+ throw new IllegalArgumentException("Unable to determine the portType " +
+ "referenced by service '" +
+ origServiceName + "'.");
+ }
+ else
+ {
+ String serviceInterfaceNS = serviceInterfaceType.getNamespaceURI();
+
+ if (!serviceInterfaceNS.equals(targetNamespace)
+ && serviceInterfaceNS.equals(origTargetNamespace))
+ {
+ serviceInterfaceType = new QName(targetNamespace,
+ serviceInterfaceType.getLocalPart());
+ }
+ }
+
+ return serviceInterfaceType;
+ }
+
+ private void convertPorts(List portList,
+ PrintWriter pw,
+ Definition def,
+ String origTargetNamespace,
+ String targetNamespace)
+ throws WSDLException
+ {
+ Iterator ports = portList.iterator();
+
+ while (ports.hasNext())
+ {
+ Port port = (Port)ports.next();
+ String portName = port.getName();
+ Binding binding = port.getBinding();
+ QName bindingQName = null;
+
+ if (binding != null)
+ {
+ bindingQName = binding.getQName();
+ }
+
+ if (bindingQName == null)
+ {
+ /*
+ If we can't determine the type of the 1.1 <binding>, we can't define
+ the 2.0 <endpoint>.
+ */
+ throw new IllegalArgumentException("Unable to determine the type of " +
+ "the binding referenced by port '" +
+ port.getName() + "'.");
+ }
+ else
+ {
+ String bindingNS = bindingQName.getNamespaceURI();
+
+ if (!bindingNS.equals(targetNamespace)
+ && bindingNS.equals(origTargetNamespace))
+ {
+ bindingQName = new QName(targetNamespace,
+ bindingQName.getLocalPart());
+ }
+ }
+
+ String address = null;
+ List extEls = port.getExtensibilityElements();
+
+ if (extEls.size() > 0)
+ {
+ ExtensibilityElement extEl = (ExtensibilityElement)extEls.get(0);
+
+ if (extEl instanceof SOAPAddress)
+ {
+ SOAPAddress soapAddress = (SOAPAddress)extEl;
+
+ address = soapAddress.getLocationURI();
+ }
+ }
+
+ pw.println(" <endpoint name=\"" + portName + "\"");
+ pw.print(" ");
+
+ DOMUtils.printQualifiedAttribute("binding",
+ bindingQName,
+ def,
+ pw);
+
+ if (address != null)
+ {
+ pw.print("\n address=\"" + address + "\"");
+ }
+
+ pw.println(">");
+
+ convertExtensions(Port.class,
+ port,
+ pw,
+ def);
+
+ pw.println(" </endpoint>");
+ }
+ }
+
+ private static void printUsage(String errorMessage)
+ {
+ System.err.println("Error: " + errorMessage + "\n\n" +
+ "Usage:\n\n" +
+ " java " + Convert.class.getName() +
+ " [args]\n\n" +
+ " args:\n\n" +
+ " -wsdl file-or-URL-of-wsdl1.1-document\n" +
+ " [-targetNS new-target-namespace]\n" +
+ " [-dir targetDir] default: .\n" +
+ " [-verbose (on|off)] default: on\n" +
+ " [-overwrite (on|off)] default: off" +
+ " (Overwrite existing files?)");
+
+ System.exit(1);
+ }
+
+ /**
+ * The main entry-point for the conversion utility. The output is sent to
+ * standard out.
+ *<code>
+ *<pre>Usage:</pre>
+ *<p>
+ *<pre> java com.ibm.wsdl.convert.Convert -wsdl wsdl1.1FileName</pre>
+ */
+ public static void main(String[] argv) throws Exception
+ {
+ long startTime = System.currentTimeMillis();
+
+ if (argv.length % 2 != 0)
+ {
+ printUsage("Incorrect number of arguments.");
+ }
+
+ String wsdlDoc = null;
+ String newTargetNS = null;
+ String targetDir = ".";
+ boolean verbose = true;
+ boolean overwrite = false;
+
+ for (int i = 0; i < argv.length; i += 2)
+ {
+ String option = argv[i];
+ String value = argv[i + 1];
+
+ if (option.equals("-wsdl"))
+ {
+ wsdlDoc = value;
+ }
+ else if (option.equals("-targetNS"))
+ {
+ newTargetNS = value;
+ }
+ else if (option.equals("-dir"))
+ {
+ targetDir = value;
+ }
+ else if (option.equals("-verbose"))
+ {
+ verbose = value.equals("on");
+ }
+ else if (option.equals("-overwrite"))
+ {
+ overwrite = value.equals("on");
+ }
+ else
+ {
+ printUsage("Unrecognized argument '" + option + "'.");
+ }
+ }
+
+ if (wsdlDoc != null)
+ {
+ Convert convert = new Convert();
+
+ convert.convertFile(newTargetNS,
+ wsdlDoc,
+ targetDir,
+ verbose,
+ overwrite);
+ }
+ else
+ {
+ printUsage("No WSDL 1.1 document was specified (use the '-wsdl' " +
+ "argument.)");
+ }
+
+ long endTime = System.currentTimeMillis();
+
+ if (verbose)
+ {
+ System.out.println("Done.\n" +
+ "Elapsed time: " + (endTime - startTime) + "ms");
+ }
+ }
+}
+
Added: incubator/woden/java/src/org/apache/woden/tool/converter/Utils.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/tool/converter/Utils.java?rev=406669&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/tool/converter/Utils.java (added)
+++ incubator/woden/java/src/org/apache/woden/tool/converter/Utils.java Mon May 15 09:34:27 2006
@@ -0,0 +1,64 @@
+package org.apache.woden.tool.converter;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * @author Matthew J. Duftler <du...@us.ibm.com>
+ */
+public class Utils
+{
+ public static OutputStream getOutputStream(String root,
+ String name,
+ boolean overwrite,
+ boolean verbose)
+ throws IOException
+ {
+ if (root != null)
+ {
+ File directory = new File(root);
+
+ if (!directory.exists())
+ {
+ if (!directory.mkdirs())
+ {
+ throw new IOException("Failed to create directory '" + root + "'.");
+ }
+ else if (verbose)
+ {
+ System.out.println("Created directory '" +
+ directory.getAbsolutePath() + "'.");
+ }
+ }
+ }
+
+ File file = new File(root, name);
+ String absolutePath = file.getAbsolutePath();
+
+ if (file.exists())
+ {
+ if (!overwrite)
+ {
+ throw new IOException("File '" + absolutePath + "' already exists. " +
+ "Please remove it or enable the " +
+ "-overwrite option.");
+ }
+ else
+ {
+ file.delete();
+
+ if (verbose)
+ {
+ System.out.println("Deleted file '" + absolutePath + "'.");
+ }
+ }
+ }
+
+ if (verbose)
+ {
+ System.out.println("Created file '" + absolutePath + "'.");
+ }
+
+ return new FileOutputStream(absolutePath);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org