antelder 2003/03/20 07:46:36
Added: java/src/org/apache/wsif/tools/tojava
WSIFJavaGeneratorFactory.java
WSIFJavaBindingWriter.java WSIFEmitter.java
WSIFJavaTestCaseWriter.java
WSIFJavaServiceWriter.java
JavaBindingGenerator.java
java/src/org/apache/wsif/tools WSDL2Java.java Java2WSDL.java
Removed: java/src/org/apache/wsif/wsdl/gen WSIFJavaBindingWriter.java
WSIFJavaTestCaseWriter.java
WSIFJavaServiceWriter.java WSIFEmitter.java
WSIFJavaGeneratorFactory.java
java/src/org/apache/wsif/wsdl WSDL2Java.java
Log:
Add Java2WSDL tool and move tooling from wsdl package to org.apache.wsif.tools
Revision Changes Path
1.1
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaGeneratorFactory.java
Index: WSIFJavaGeneratorFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools.tojava;
import javax.wsdl.Binding;
import javax.wsdl.Service;
import org.apache.axis.wsdl.gen.Generator;
import org.apache.axis.wsdl.symbolTable.BindingEntry;
import org.apache.axis.wsdl.symbolTable.ServiceEntry;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.apache.axis.wsdl.toJava.JavaGeneratorFactory;
import org.apache.axis.wsdl.toJava.JavaServiceWriter;
/**
* WSIFJavaGeneratorFactory
*
* WSIF version of the AXIS JavaGeneratorFactory that overrides
* the service and binding generators to use the WSIF
* versions of the JavaServiceWriter and JavaBindingWriter.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class WSIFJavaGeneratorFactory extends JavaGeneratorFactory {
public Generator getGenerator(Service service, SymbolTable symbolTable) {
Generator writer =
new WSIFJavaServiceWriter(emitter, service, symbolTable);
ServiceEntry sEntry = symbolTable.getServiceEntry(service.getQName());
serviceWriters.addStuff(writer, sEntry, symbolTable);
return serviceWriters;
} // getGenerator
public Generator getGenerator(Binding binding, SymbolTable symbolTable) {
Generator writer =
new WSIFJavaBindingWriter(emitter, binding, symbolTable);
BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
bindingWriters.addStuff(writer, bEntry, symbolTable);
return bindingWriters;
} // getGenerator
}
1.1
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaBindingWriter.java
Index: WSIFJavaBindingWriter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools.tojava;
import java.io.IOException;
import javax.wsdl.Binding;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.apache.axis.wsdl.toJava.Emitter;
import org.apache.axis.wsdl.toJava.JavaBindingWriter;
/**
* WSIFJavaBindingWriter
*
* WSIF version of the AXIS JavaBindingWriter that overrides
* the generate method to only generate the interface. The
* AXIS version also generates stub, skeleton, and implementation
* files which are not required by WSIF.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class WSIFJavaBindingWriter extends JavaBindingWriter {
/**
* Constructor.
*/
public WSIFJavaBindingWriter(
Emitter emitter,
Binding binding,
SymbolTable symbolTable) {
super(emitter, binding, symbolTable);
} // ctor
/**
* Write all the binding bindings:
* - interfaceWriter only
* (but only if required by stub testcase)
*/
public void generate() throws IOException {
setGenerators();
if (interfaceWriter != null) {
if (((WSIFEmitter)emitter).isTestcaseGenStubs()) {
interfaceWriter.generate();
}
}
} // generate
}
1.1
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFEmitter.java
Index: WSIFEmitter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools.tojava;
import org.apache.axis.wsdl.toJava.Emitter;
/**
* WSIFEmitter
*
* WSIF version of the AXIS Emitter that uses the WSIF
* version of JavaGeneratorFactory.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class WSIFEmitter extends Emitter {
protected boolean testcaseGenDII = false;
protected boolean testcaseGenStubs = true;
/**
* Constructor
*/
public WSIFEmitter() {
WSIFJavaGeneratorFactory factory = new WSIFJavaGeneratorFactory();
setFactory(factory);
factory.setEmitter(this);
}
/**
* Returns the testcaseGenDII.
* @return boolean
*/
public boolean isTestcaseGenDII() {
return testcaseGenDII;
}
/**
* Returns the testcaseGenStubs.
* @return boolean
*/
public boolean isTestcaseGenStubs() {
return testcaseGenStubs;
}
/**
* Sets the testcaseGenDII.
* @param testcaseGenDII The testcaseGenDII to set
*/
public void setTestcaseGenDII(boolean testcaseGenDII) {
this.testcaseGenDII = testcaseGenDII;
}
/**
* Sets the testcaseGenStubs.
* @param testcaseGenStubs The testcaseGenStubs to set
*/
public void setTestcaseGenStubs(boolean testcaseGenStubs) {
this.testcaseGenStubs = testcaseGenStubs;
}
}
1.1
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaTestCaseWriter.java
Index: WSIFJavaTestCaseWriter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools.tojava;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Input;
import javax.wsdl.Operation;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.xml.namespace.QName;
import org.apache.axis.utils.JavaUtils;
import org.apache.axis.wsdl.symbolTable.BindingEntry;
import org.apache.axis.wsdl.symbolTable.PortTypeEntry;
import org.apache.axis.wsdl.symbolTable.ServiceEntry;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.apache.axis.wsdl.toJava.Emitter;
import org.apache.axis.wsdl.toJava.JavaClassWriter;
import org.apache.axis.wsdl.toJava.Utils;
import org.apache.wsif.WSIFException;
import org.apache.wsif.providers.ProviderUtils;
import org.apache.wsif.util.WSIFUtils;
/**
* WSIFJavaTestCaseWriter
*
* WSIF version of the AXIS JavaTestCaseWriter that
* generates a WSIF JUnit testcase program source.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class WSIFJavaTestCaseWriter extends JavaClassWriter {
protected ServiceEntry sEntry;
protected SymbolTable symbolTable;
protected String indent;
protected static final String TAB = " ";
/**
* Constructor.
*/
protected WSIFJavaTestCaseWriter(
Emitter emitter,
ServiceEntry sEntry,
SymbolTable symbolTable) {
super(emitter, sEntry.getName() + "TestCase", "testCase");
this.sEntry = sEntry;
this.symbolTable = symbolTable;
}
/**
* Write the body of the TestCase file.
* For each port in the service get the portType
* and call writePortTypeTestCode.
*/
protected void writeFileBody(PrintWriter pw) throws IOException {
indent = TAB;
writeTestConstructor(pw);
skipLines(pw, 1);
writeTestSuite(pw);
ArrayList donePortTypes = new ArrayList();
Service service = sEntry.getService();
Map portMap = service.getPorts();
HashMap diiPortTypeMethods = new HashMap();
HashMap stubPortTypeMethods = new HashMap();
/* for each port in the service, get the portType
* used by its binding, and if hasn't already been
* done for another port then write a portType method */
for (Iterator i = portMap.values().iterator(); i.hasNext();) {
Port p = (Port) i.next();
Binding binding = p.getBinding();
BindingEntry bEntry =
symbolTable.getBindingEntry(binding.getQName());
PortType portType = binding.getPortType();
if (donePortTypes.contains(portType)) {
continue;
}
donePortTypes.add(portType);
String portName = p.getName();
if (!JavaUtils.isJavaId(portName)) {
portName = Utils.xmlNameToJavaClass(portName);
}
PortTypeEntry ptEntry =
symbolTable.getPortTypeEntry(portType.getQName());
if (((WSIFEmitter) emitter).isTestcaseGenDII()) {
writeComment(pw, p.getDocumentationElement());
String methodName =
writeDIITestPortType(
pw,
service,
portName,
portType,
ptEntry);
diiPortTypeMethods.put(portType, methodName);
}
if (((WSIFEmitter) emitter).isTestcaseGenStubs()) {
writeComment(pw, p.getDocumentationElement());
String methodName =
writeStubTestPortType(
pw,
service,
portName,
portType,
ptEntry);
stubPortTypeMethods.put(portType, methodName);
}
}
/* for each port in the service write a JUnit test
* method to call the portType method for the port. */
for (Iterator i = portMap.values().iterator(); i.hasNext();) {
Port p = (Port) i.next();
Binding binding = p.getBinding();
PortType portType = binding.getPortType();
if (((WSIFEmitter) emitter).isTestcaseGenDII()) {
writeTestMethod(
pw,
(String) diiPortTypeMethods.get(portType),
p.getName());
}
if (((WSIFEmitter) emitter).isTestcaseGenStubs()) {
writeTestMethod(
pw,
(String) stubPortTypeMethods.get(portType),
p.getName());
}
}
writeMainMethod(pw);
} // writeFileBody
/**
* Write the header comments.
* (Overriden to make WSIF specific)
*/
protected void writeHeaderComments(PrintWriter pw) throws IOException {
String localFile = getFileName();
int lastSepChar = localFile.lastIndexOf(File.separatorChar);
if (lastSepChar >= 0) {
localFile = localFile.substring(lastSepChar + 1);
}
pw.println("/**");
pw.println(" * " + localFile);
pw.println(" *");
pw.println(" * This file was auto-generated from WSDL");
pw.println(" * by the Apache WSIF WSDL2Java emitter.");
pw.println(" */");
pw.println();
} // writeHeaderComments
/**
* Write the package declaration statement.
* (Overriden so it can add the imports as well)
*/
protected void writePackage(PrintWriter pw) throws IOException {
if (getPackage() != null) {
pw.println("package " + getPackage() + ";");
pw.println();
}
writeImports(pw);
skipLines(pw, 1);
} // writePackage
/**
* Write the import statements.
*/
protected void writeImports(PrintWriter pw) throws IOException {
pw.println("import java.rmi.RemoteException;");
pw.println("import java.util.Iterator;");
skipLines(pw, 1);
pw.println("import junit.framework.Test;");
pw.println("import junit.framework.TestCase;");
pw.println("import junit.framework.TestSuite;");
pw.println("import junit.textui.TestRunner;");
skipLines(pw, 1);
pw.println("import org.apache.wsif.WSIFConstants;");
pw.println("import org.apache.wsif.WSIFException;");
pw.println("import org.apache.wsif.WSIFMessage;");
pw.println("import org.apache.wsif.WSIFOperation;");
pw.println("import org.apache.wsif.WSIFPort;");
pw.println("import org.apache.wsif.WSIFService;");
pw.println("import org.apache.wsif.WSIFServiceFactory;");
}
/**
* Returns "extends junit.framework.TestCase ".
*/
protected String getExtendsText() {
return "extends TestCase ";
} // getExtendsText
/**
* Write the constructor.
*/
protected void writeTestConstructor(PrintWriter pw) throws IOException {
addNewCodeLine(pw, "public " + getClassName() + "(String name) {");
tabIn();
addNewCodeLine(pw, "super(name);");
tabOut();
addNewCodeLine(pw, "}");
}
/**
* Write the JUnit suite method.
*/
protected void writeTestSuite(PrintWriter pw) throws IOException {
addNewCodeLine(pw, "public static Test suite() {");
tabIn();
addNewCodeLine(
pw,
"return new TestSuite(" + getClassName() + ".class);");
tabOut();
addNewCodeLine(pw, "}");
}
/**
* Write the testPortType method using stubs
*/
protected String writeStubTestPortType(
PrintWriter pw,
Service service,
String portName,
PortType portType,
PortTypeEntry ptEntry)
throws IOException {
QName serviceName = service.getQName();
QName portTypeName = portType.getQName();
String methodName = "doit" + "Stub" + portTypeName.getLocalPart();
addNewCodeLine(
pw,
"protected void " + methodName + "(String portName) {");
tabIn();
addNewCodeLine(pw, "try {");
tabIn();
addNewCodeLine(
pw,
"WSIFServiceFactory factory = WSIFServiceFactory.newInstance();");
skipLines(pw, 1);
addNewCodeLine(pw, "WSIFService service =");
tabIn();
addNewCodeLine(pw, "factory.getService(");
tabIn();
addNewCodeLine(
pw,
"\"" + emitter.getWSDLURI().replace('\\', '/') + "\",");
addNewCodeLine(pw, "\"" + serviceName.getNamespaceURI() + "\",");
addNewCodeLine(pw, "\"" + serviceName.getLocalPart() + "\",");
addNewCodeLine(pw, "\"" + portTypeName.getNamespaceURI() + "\",");
addNewCodeLine(pw, "\"" + portTypeName.getLocalPart() + "\");");
tabOut();
tabOut();
skipLines(pw, 1);
String seiName = getSEIName(portType);
addNewCodeLine(pw, seiName);
addCode(pw, " stub =");
tabIn();
addNewCodeLine(pw, "(");
addCode(pw, seiName);
addCode(pw, ") service.getStub(portName, ");
addCode(pw, seiName);
addCode(pw, ".class);");
tabOut();
skipLines(pw, 1);
for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
Operation op = (Operation) i.next();
String javaOpName = Utils.xmlNameToJavaClass(op.getName());
String opMethodName = "executeOp" + javaOpName;
if (isOverloaded(portType, op)) {
opMethodName += getInMsgName(op);
}
addNewCodeLine(pw, opMethodName + "(stub);");
}
skipLines(pw, 1);
tabOut();
addNewCodeLine(pw, "} catch (Exception ex) {");
tabIn();
addNewCodeLine(pw, "ex.printStackTrace();");
addNewCodeLine(pw, "assertTrue(\"");
addCode(pw, methodName);
addCode(pw, " got exception: \" + ex.getLocalizedMessage(), false);");
tabOut();
addNewCodeLine(pw, "}");
tabOut();
addNewCodeLine(pw, "}");
skipLines(pw, 1);
for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
Operation op = (Operation) i.next();
writeStubOperationMethod(pw, seiName, portType, op);
}
return methodName;
}
/**
* Write the executeOp method using stubs
*/
protected void writeStubOperationMethod(
PrintWriter pw,
String seiName,
PortType portType,
Operation op) {
addNewCodeLine(pw, "protected void ");
String javaOpName = Utils.xmlNameToJavaClass(op.getName());
String opMethodName = "executeOp" + javaOpName;
if (isOverloaded(portType, op)) {
opMethodName += getInMsgName(op);
}
addCode(pw, opMethodName);
addCode(pw, "(");
addCode(pw, seiName);
addCode(pw, " stub) throws RemoteException {");
skipLines(pw, 1);
tabIn();
ArrayList params = new ArrayList();
Input in = op.getInput();
if (in != null && in.getMessage() != null) {
List parts = in.getMessage().getOrderedParts(null);
unwrapIfWrapped(
emitter.getCurrentDefinition(),
parts,
op.getName());
addNewCodeLine(
pw,
"// TODO: change these params to required values");
int parameterCounter = 0;
for (Iterator i = parts.iterator(); i.hasNext();) {
Part p = (Part) i.next();
QName type = ProviderUtils.getPartType(p);
String className = Utils.getJavaLocalName(getClassName(type));
String paramName = "p" + parameterCounter++;
params.add(paramName);
addNewCodeLine(
pw,
className
+ " "
+ paramName
+ " = "
+ getTypeInitialiser(type)
+ ";");
}
skipLines(pw, 1);
}
String returnPartName = null;
String returnClassName = "";
Output out = op.getOutput();
if (out != null
&& out.getMessage() != null
&& out.getMessage().getParts().size() > 0) {
List parts = out.getMessage().getOrderedParts(null);
unwrapIfWrapped(
emitter.getCurrentDefinition(),
parts,
op.getName() + "Response");
Part p = (Part) parts.get(0);
returnPartName = p.getName();
if (JavaUtils.isJavaKeyword(returnPartName)) {
returnPartName = "_" + returnPartName;
}
QName type = ProviderUtils.getPartType(p);
returnClassName = Utils.getJavaLocalName(getClassName(type));
addNewCodeLine(pw, returnClassName);
addCode(pw, " ");
addCode(pw, returnPartName);
addCode(pw, " = stub.");
addCode(pw, lowercaseFirst(op.getName()));
addCode(pw, "(");
} else {
addNewCodeLine(pw, "stub.");
addCode(pw, lowercaseFirst(op.getName()));
addCode(pw, "(");
}
for (Iterator i = params.iterator(); i.hasNext();) {
String paramName = (String) i.next();
addCode(pw, paramName);
if (i.hasNext()) {
addCode(pw, ", ");
}
}
addCode(pw, ");");
skipLines(pw, 1);
if (returnPartName != null) {
addNewCodeLine(pw, "System.out.println(\"operation '");
addCode(pw, op.getName());
addCode(pw, "' returned: \" + ");
addCode(pw, returnPartName);
addCode(pw, ");");
skipLines(pw, 1);
addNewCodeLine(pw, "// TODO: test return parts here");
if (Character.isLowerCase(returnClassName.charAt(0))) {
addNewCodeLine(pw, "// assertTrue(\"operation ");
} else {
addNewCodeLine(pw, "assertTrue(\"operation ");
}
addCode(pw, op.getName());
addCode(pw, " returned null!!\", ");
addCode(pw, returnPartName);
addCode(pw, " != null);");
}
tabOut();
addNewCodeLine(pw, "}");
skipLines(pw, 1);
}
/**
* Write the testPortType method using the WSIF DII
*/
protected String writeDIITestPortType(
PrintWriter pw,
Service service,
String portName,
PortType portType,
PortTypeEntry ptEntry)
throws IOException {
QName serviceName = service.getQName();
QName portTypeName = portType.getQName();
String methodName = "doit" + "DII" + portTypeName.getLocalPart();
skipLines(pw, 1);
addNewCodeLine(pw, "protected void ");
addCode(pw, methodName);
addCode(pw, "(String portName) {");
tabIn();
addNewCodeLine(pw, "try {");
tabIn();
addNewCodeLine(
pw,
"WSIFServiceFactory factory = WSIFServiceFactory.newInstance();");
addNewCodeLine(pw, "factory.setFeature(");
tabIn();
addNewCodeLine(pw, "WSIFConstants.WSIF_FEATURE_AUTO_MAP_TYPES,");
addNewCodeLine(pw, "new Boolean(true));");
tabOut();
skipLines(pw, 1);
addNewCodeLine(pw, "WSIFService service =");
tabIn();
addNewCodeLine(pw, "factory.getService(");
tabIn();
addNewCodeLine(
pw,
"\"" + emitter.getWSDLURI().replace('\\', '/') + "\",");
addNewCodeLine(pw, "\"" + serviceName.getNamespaceURI() + "\",");
addNewCodeLine(pw, "\"" + serviceName.getLocalPart() + "\",");
addNewCodeLine(pw, "\"" + portTypeName.getNamespaceURI() + "\",");
addNewCodeLine(pw, "\"" + portTypeName.getLocalPart() + "\");");
tabOut();
tabOut();
skipLines(pw, 1);
addNewCodeLine(pw, "WSIFPort port = service.getPort(portName);");
skipLines(pw, 1);
for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
Operation op = (Operation) i.next();
String opMethodName = "executeOp" + capitalizeFirst(op.getName());
if (isOverloaded(portType, op)) {
opMethodName += getInMsgName(op);
}
addNewCodeLine(pw, opMethodName + "(port);");
}
skipLines(pw, 1);
tabOut();
addNewCodeLine(pw, "} catch (Exception ex) {");
tabIn();
addNewCodeLine(pw, "ex.printStackTrace();");
addNewCodeLine(pw, "assertTrue(\"");
addCode(pw, methodName);
addCode(pw, " got exception: \" + ex.getLocalizedMessage(), false);");
tabOut();
addNewCodeLine(pw, "}");
tabOut();
addNewCodeLine(pw, "}");
skipLines(pw, 1);
for (Iterator i = portType.getOperations().iterator(); i.hasNext();) {
Operation op = (Operation) i.next();
writeDIIOperationMethod(pw, portType, op);
}
return methodName;
}
/**
* Write the executeOp method using the WSIF DII
*/
protected void writeDIIOperationMethod(
PrintWriter pw,
PortType portType,
Operation op) {
addNewCodeLine(pw, "protected void ");
String opMethodName = "executeOp" + capitalizeFirst(op.getName());
boolean overloaded = isOverloaded(portType, op);
if (overloaded) {
opMethodName += getInMsgName(op);
}
addCode(pw, opMethodName);
addCode(pw, "(WSIFPort wsifPort) throws WSIFException {");
skipLines(pw, 1);
tabIn();
addNewCodeLine(pw, "WSIFOperation op = wsifPort.createOperation(");
if (overloaded) {
tabIn();
addNewCodeLine(pw, "\"");
addCode(pw, op.getName());
addCode(pw, "\",");
addNewCodeLine(pw, "\"");
addCode(pw, getInMsgName(op));
addCode(pw, "\",");
addNewCodeLine(pw, "null);");
tabOut();
} else {
addCode(pw, "\"");
addCode(pw, op.getName());
addCode(pw, "\");");
}
skipLines(pw, 1);
addNewCodeLine(pw, "WSIFMessage inMsg = op.createInputMessage();");
addNewCodeLine(pw, "WSIFMessage outMsg = op.createOutputMessage();");
addNewCodeLine(pw, "WSIFMessage faultMsg = op.createFaultMessage();");
skipLines(pw, 1);
Input in = op.getInput();
if (in != null && in.getMessage() != null) {
List parts = in.getMessage().getOrderedParts(null);
unwrapIfWrapped(
emitter.getCurrentDefinition(),
parts,
op.getName());
addNewCodeLine(pw, "// TODO: change these parameter values");
int parameterCounter = 0;
for (Iterator i = parts.iterator(); i.hasNext();) {
Part p = (Part) i.next();
QName type = ProviderUtils.getPartType(p);
String className = Utils.getJavaLocalName(getClassName(type));
String paramName = "p" + parameterCounter++;
addNewCodeLine(
pw,
className
+ " "
+ paramName
+ " = "
+ getTypeInitialiser(type)
+ ";");
String setType;
if (Character.isLowerCase(className.charAt(0))) {
setType = capitalizeFirst(className);
} else {
setType = "Object";
}
addNewCodeLine(pw, "inMsg.set");
addCode(pw, setType);
addCode(pw, "Part(\"");
addCode(pw, p.getName());
addCode(pw, "\", " + paramName + ");");
skipLines(pw, 1);
}
}
addNewCodeLine(pw, "boolean success =");
tabIn();
addNewCodeLine(
pw,
"op.executeRequestResponseOperation(inMsg, outMsg, faultMsg);");
tabOut();
skipLines(pw, 1);
addNewCodeLine(pw, "if (success) {");
tabIn();
addNewCodeLine(
pw,
"System.out.println(\"operation '"
+ op.getName()
+ "' successfull:\");");
Output out = op.getOutput();
if (out != null && out.getMessage() != null) {
List parts = out.getMessage().getOrderedParts(null);
unwrapIfWrapped(
emitter.getCurrentDefinition(),
parts,
op.getName() + "Response");
int parameterCounter = 0;
for (Iterator i = parts.iterator(); i.hasNext();) {
Part p = (Part) i.next();
QName type = ProviderUtils.getPartType(p);
String className = Utils.getJavaLocalName(getClassName(type));
String paramName = "r" + parameterCounter++;
String getType;
String cast;
if (Character.isLowerCase(className.charAt(0))) {
getType = capitalizeFirst(className);
cast = "";
} else {
getType = "Object";
cast = "(" + className + ")";
}
addNewCodeLine(
pw,
className
+ " "
+ paramName
+ " = "
+ cast
+ " outMsg.get"
+ getType
+ "Part(\""
+ p.getName()
+ "\");");
addNewCodeLine(
pw,
"System.out.println(\""
+ p.getName()
+ ": \" + "
+ paramName
+ ");");
}
}
skipLines(pw, 1);
addNewCodeLine(pw, "// TODO: add tests for return parts here");
skipLines(pw, 1);
tabOut();
addNewCodeLine(pw, "} else {");
tabIn();
addNewCodeLine(
pw,
"System.err.println(\"operation '"
+ op.getName()
+ "' returned a fault:\");");
addNewCodeLine(
pw,
"for (Iterator i = faultMsg.getPartNames(); i.hasNext();) {");
tabIn();
addNewCodeLine(
pw,
"System.err.println(faultMsg.getObjectPart((String) i.next()));");
tabOut();
addNewCodeLine(pw, "}");
addNewCodeLine(pw, "assertTrue(\"");
addCode(pw, opMethodName);
addCode(pw, " returned a fault!!\", false);");
tabOut();
addNewCodeLine(pw, "}");
tabOut();
addNewCodeLine(pw, "}");
skipLines(pw, 1);
}
/**
* Write the JUnit test method
*/
protected void writeTestMethod(
PrintWriter pw,
String methodName,
String portName)
throws IOException {
String testMethodname = "test" + capitalizeFirst(methodName) + portName;
addNewCodeLine(pw, "public void " + testMethodname + "() {");
tabIn();
addNewCodeLine(pw, methodName + "(\"" + portName + "\");");
tabOut();
addNewCodeLine(pw, "}");
skipLines(pw, 1);
} // writeTestMethod
/**
* Write the main method
*/
protected void writeMainMethod(PrintWriter pw) throws IOException {
addNewCodeLine(pw, "public static void main(String[] args) {");
tabIn();
addNewCodeLine(pw, "TestRunner.run(suite());");
tabOut();
addNewCodeLine(pw, "}");
skipLines(pw, 1);
} // writeMainMethod
/**
* Capatalise the first character of a String
*/
protected static String capitalizeFirst(String name) {
StringBuffer sb = new StringBuffer(name);
if (sb.length() > 0) {
sb.setCharAt(0, (char) ((sb.charAt(0) & (char) 223)));
}
return sb.toString();
}
/**
* Lowercase the first character of a String
*/
protected static String lowercaseFirst(String name) {
StringBuffer sb = new StringBuffer(name);
if (sb.length() > 0) {
sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
}
return sb.toString();
}
/**
* Gets the fully qualified Java class name from a QName
*/
protected static String getClassName(QName type) {
String className = "";
Map types = WSIFUtils.getSimpleTypesMap();
Object o = types.get(type);
if (o != null) {
className = (String) o;
} else {
className =
Utils.makePackageName(type.getNamespaceURI())
+ "."
+ Utils.xmlNameToJavaClass(type.getLocalPart());
}
return className;
}
/**
* Unwraps a WSDL message if required
*/
protected void unwrapIfWrapped(
Definition def,
List parts,
String operationName) {
if (!emitter.isNowrap()) {
Part p = ProviderUtils.getWrapperPart(parts, operationName);
if (p != null) {
List unwrappedParts;
try {
unwrappedParts = ProviderUtils.unWrapPart(p, def);
} catch (WSIFException e) {
throw new RuntimeException(
"exception unwrapping operation "
+ operationName
+ ": "
+ e.getLocalizedMessage());
}
int i = parts.indexOf(p);
parts.remove(i);
parts.addAll(i, unwrappedParts);
}
}
}
/**
* Gets the name of a WSDL operation's input message
*/
protected String getInMsgName(Operation op) {
String inMsgName = "";
Input inMsg = op.getInput();
if (inMsg != null) {
inMsgName = inMsg.getName();
}
return inMsgName;
}
/**
* Tests if the operation is overloaded in the portType
*/
protected boolean isOverloaded(PortType pt, Operation op) {
boolean overloaded = false;
String opName = op.getName();
for (Iterator i = pt.getOperations().iterator();
!overloaded && i.hasNext();
) {
Operation o2 = (Operation) i.next();
if (!op.equals(o2) && opName.equals(o2.getName())) {
overloaded = true;
}
}
return overloaded;
}
/**
* Gets the initiliser for a type
*/
protected String getTypeInitialiser(QName type) {
String s = "";
String className = Utils.getJavaLocalName(getClassName(type));
if ("int".equals(className)) {
s = "0";
} else if ("short".equals(className)) {
s = "0";
} else if ("boolean".equals(className)) {
s = "false";
} else if ("byte".equals(className)) {
s = "0";
} else if ("long".equals(className)) {
s = "0";
} else if ("double".equals(className)) {
s = "0";
} else if ("float".equals(className)) {
s = "0";
} else if ("char".equals(className)) {
s = "''";
} else {
s = "new " + className + "()";
}
return s;
}
/**
* Gets the Service Endpoint Interface name for a WSDL portType
*/
protected String getSEIName(PortType portType) {
return capitalizeFirst(
Utils.getJavaLocalName(getClassName(portType.getQName())));
}
/**
* Start a new line of code correctly indented
*/
protected void addNewCodeLine(PrintWriter pw, String line) {
pw.println();
pw.print(indent);
pw.print(line);
}
/**
* add code to an already started code line
*/
protected void addCode(PrintWriter pw, String lineFragment) {
pw.print(lineFragment);
}
/**
* Insert some blank lines into the output
*/
protected void skipLines(PrintWriter pw, int lines) {
for (int i = 0; i < lines; i++) {
pw.println();
}
}
/**
* Indent all subsequent code by one tab space
*/
protected void tabIn() {
indent += TAB;
}
/**
* Un-indent all subsequent code by one tab space
*/
protected void tabOut() {
if (indent.length() >= TAB.length()) {
indent = indent.substring(0, indent.length() - TAB.length());
}
}
} // class JavaTestCase
1.1
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/WSIFJavaServiceWriter.java
Index: WSIFJavaServiceWriter.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools.tojava;
import javax.wsdl.Service;
import org.apache.axis.wsdl.symbolTable.ServiceEntry;
import org.apache.axis.wsdl.symbolTable.SymbolTable;
import org.apache.axis.wsdl.toJava.Emitter;
import org.apache.axis.wsdl.toJava.JavaServiceWriter;
/**
* WSIFJavaServiceWriter
*
* WSIF version of the AXIS JavaServiceWriter that suppresses
* the use of the serviceIfaceWritter and serviceImpWriter as
* these are not required by WSIF, and use the WSIF version
* of the JavaTestCaseWriter.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class WSIFJavaServiceWriter extends JavaServiceWriter {
/**
* Constructor.
*/
public WSIFJavaServiceWriter(
Emitter emitter,
Service service,
SymbolTable symbolTable) {
super(emitter, service, symbolTable);
ServiceEntry sEntry = symbolTable.getServiceEntry(service.getQName());
if (sEntry.isReferenced()) {
serviceIfaceWriter = null;
serviceImplWriter = null;
if (emitter.isTestCaseWanted()) {
testCaseWriter =
new WSIFJavaTestCaseWriter(emitter, sEntry, symbolTable);
}
}
} // ctor
}
1.1
xml-axis-wsif/java/src/org/apache/wsif/tools/tojava/JavaBindingGenerator.java
Index: JavaBindingGenerator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools.tojava;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Input;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.xml.namespace.QName;
import org.apache.wsif.wsdl.extensions.format.FormatBindingConstants;
import org.apache.wsif.wsdl.extensions.format.TypeMap;
import org.apache.wsif.wsdl.extensions.format.TypeMapping;
import org.apache.wsif.wsdl.extensions.java.JavaAddress;
import org.apache.wsif.wsdl.extensions.java.JavaBinding;
import org.apache.wsif.wsdl.extensions.java.JavaBindingConstants;
import org.apache.wsif.wsdl.extensions.java.JavaOperation;
import com.ibm.wsdl.BindingOperationImpl;
import com.ibm.wsdl.PortImpl;
/**
* Utility to add a WSIF Java binding to a WSDL4J definition
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class JavaBindingGenerator {
public static void addJAVABinding(Definition def) {
addJavaNamespace(def);
Map m = def.getPortTypes();
for (Iterator i = m.keySet().iterator(); i.hasNext();) {
QName portTypeName = (QName) i.next();
PortType p = (PortType) m.get(portTypeName);
Binding b = makeBinding(def, p);
def.addBinding(b);
Map s = def.getServices();
Object o = s.keySet().iterator().next();
Service service = (Service) s.get(o);
addJavaServicePort(service, b);
}
}
protected static void addJavaNamespace(Definition def) {
def.addNamespace("java", JavaBindingConstants.NS_URI_JAVA);
def.addNamespace("format", FormatBindingConstants.NS_URI_FORMAT);
}
protected static Binding makeBinding(Definition def, PortType p) {
Binding binding = def.createBinding();
binding.setPortType(p);
QName qn =
new QName(
p.getQName().getNamespaceURI(),
p.getQName().getLocalPart() + "JAVABinding");
binding.setQName(qn);
JavaBinding jb = makeJavaBinding(p);
binding.addExtensibilityElement(jb);
TypeMapping formatTypeMapping = makeFormatTypeMapping();
binding.addExtensibilityElement(formatTypeMapping);
addOperations(binding, p);
binding.setUndefined(false);
return binding;
}
protected static JavaBinding makeJavaBinding(PortType p) {
JavaBinding javaBinding = new JavaBinding();
return javaBinding;
}
/**
* <format:typeMapping encoding="Java" style="Java">
* <format:typeMap typeName="typens:type" formatType="package.class" />
*</format:typeMapping>
* TODO: get types automatically from WSDL
*/
protected static TypeMapping makeFormatTypeMapping() {
TypeMapping formatTypeMapping = new TypeMapping();
formatTypeMapping.setEncoding("Java");
formatTypeMapping.setStyle("Java");
TypeMap tm = new TypeMap();
tm.setTypeName(new QName("http://www.w3.org/2001/XMLSchema", "string"));
tm.setFormatType("java.lang.String");
formatTypeMapping.addMap(tm);
return formatTypeMapping;
}
protected static void addOperations(Binding b, PortType p) {
for (Iterator i = p.getOperations().iterator(); i.hasNext();) {
Operation op = (Operation) i.next();
BindingOperationImpl bo = new BindingOperationImpl();
bo.setName(op.getName());
JavaOperation javaOp = makeJavaOperation(op);
bo.addExtensibilityElement(javaOp);
b.addBindingOperation(bo);
}
}
protected static JavaOperation makeJavaOperation(Operation op) {
JavaOperation javaOp = new JavaOperation();
javaOp.setMethodName(op.getName());
javaOp.setMethodType("Instance");
Input input = op.getInput();
Message msg = input.getMessage();
List parts = msg.getOrderedParts(null);
String partList = "";
for (int j = 0; j < parts.size(); j++) {
partList += ((Part) parts.get(j)).getName();
if (j < parts.size()) {
partList += " ";
}
}
javaOp.setParameterOrder(partList);
Output output = op.getOutput();
msg = output.getMessage();
parts = msg.getOrderedParts(null);
if (parts.size() > 0) {
Part part = (Part) parts.get(0);
String partName = part.getName();
javaOp.setReturnPart(partName);
}
return javaOp;
}
protected static void addJavaServicePort(Service s, Binding b) {
Port p = new PortImpl();
QName bindingName = b.getQName();
p.setName(bindingName.getLocalPart());
p.setBinding(b);
JavaAddress ja = new JavaAddress();
ja.setClassName("your.target.class.here");
p.addExtensibilityElement(ja);
s.addPort(p);
}
}
1.1 xml-axis-wsif/java/src/org/apache/wsif/tools/WSDL2Java.java
Index: WSDL2Java.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools;
import org.apache.axis.utils.CLOption;
import org.apache.axis.utils.CLOptionDescriptor;
import org.apache.axis.wsdl.gen.Parser;
import org.apache.axis.wsdl.gen.WSDL2;
import org.apache.wsif.tools.tojava.WSIFEmitter;
/**
* WSIF WSDL2Java Utility program
*
* Generates Java source for the service endpoint interface,
* any complex types, and a WSIF testcase.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class WSDL2Java extends org.apache.axis.wsdl.WSDL2Java {
protected static final int TESTCASE_OPT = 't';
protected static final CLOptionDescriptor[] wsifCLOptions =
new CLOptionDescriptor[] {
new CLOptionDescriptor(
"testCase <stubs | DII | both | none>",
CLOptionDescriptor.ARGUMENT_OPTIONAL,
TESTCASE_OPT,
"emit a JUnit testcase class for the web service."
+ " Optionally specify if the testcase will use the"
+ " WSIF DII, stubs, or both. The default is to use stubs.")};
/**
* Constructor
*/
public WSDL2Java() {
removeOption("testCase");
removeOption("server-side");
removeOption("skeletonDeploy");
removeOption("deployScope");
addOptions(wsifCLOptions);
}
protected void parseOption(CLOption option) {
switch (option.getId()) {
case TESTCASE_OPT :
if (parseTestcaseOption(option)) {
break;
} else {
System.err.println("invalid testcase option: " + option);
printUsage();
}
default :
super.parseOption(option);
}
}
protected boolean parseTestcaseOption(CLOption option) {
boolean valid = true;
String arg = option.getArgument();
((WSIFEmitter) parser).setTestCaseWanted(true);
if ("DII".equalsIgnoreCase(arg)) {
((WSIFEmitter) parser).setTestcaseGenDII(true);
((WSIFEmitter) parser).setTestcaseGenStubs(false);
} else if ("stubs".equalsIgnoreCase(arg)) {
((WSIFEmitter) parser).setTestcaseGenStubs(true);
((WSIFEmitter) parser).setTestcaseGenDII(false);
} else if ("both".equalsIgnoreCase(arg)) {
((WSIFEmitter) parser).setTestcaseGenStubs(true);
((WSIFEmitter) parser).setTestcaseGenDII(true);
} else if ("none".equalsIgnoreCase(arg)) {
((WSIFEmitter) parser).setTestCaseWanted(false);
((WSIFEmitter) parser).setTestcaseGenStubs(false);
((WSIFEmitter) parser).setTestcaseGenDII(false);
} else if (arg == null || arg.length() < 1) {
((WSIFEmitter) parser).setTestcaseGenStubs(true);
((WSIFEmitter) parser).setTestcaseGenDII(false);
} else {
valid = false;
}
return valid;
}
/**
* Override createParser to use the WSIF version of Emitter.
*/
protected Parser createParser() {
return new WSIFEmitter();
}
/**
* Main
*/
public static void main(String args[]) {
WSDL2Java w2j = new WSDL2Java();
w2j.run(args);
}
}
1.1 xml-axis-wsif/java/src/org/apache/wsif/tools/Java2WSDL.java
Index: Java2WSDL.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.wsif.tools;
import org.apache.axis.utils.CLUtil;
import org.apache.axis.utils.Messages;
/**
* WSIF Java2WSDL Utility program
*
* Generates WSDL source files from a Java class.
* For now this changes nothing that the AXIS Java2WSDL does,
* it just lets people use org.apache.wsif.tools.Java2WSDL
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ant Elder</a>
*/
public class Java2WSDL extends org.apache.axis.wsdl.Java2WSDL {
/**
* Constructor
*/
public Java2WSDL() {
super();
}
// /**
// * Instantiate an Emitter
// */
// protected Emitter createEmitter() {
// return new WSIFEmitter();
// }
/**
* printUsage
* print usage information and quit.
* TODO: See bugzilla 18067 to not use hard coded class name
*/
protected void printUsage() {
String lSep = System.getProperty("line.separator");
StringBuffer msg = new StringBuffer();
msg.append("Java2WSDL "
+ Messages.getMessage("j2wemitter00")).append(lSep);
msg.append(Messages.getMessage("j2wusage00",
// "java " + Java2WSDL.class.getName() + " [options]
class-of-portType")).append(lSep);
"java " + getClass().getName() + " [options]
class-of-portType")).append(lSep);
msg.append(Messages.getMessage("j2woptions00")).append(lSep);
msg.append(CLUtil.describeOptions(options).toString());
msg.append(Messages.getMessage("j2wdetails00")).append(lSep);
System.out.println(msg.toString());
}
/**
* Main
*
* For arg details see:
*
http://cvs.apache.org/viewcvs.cgi/~checkout~/xml-axis/java/docs/reference.html#Java2WSDL
*/
public static void main(String args[]) {
Java2WSDL java2wsdl = new Java2WSDL();
System.exit(java2wsdl.run(args));
}
}