Author: mmerz Date: Wed Dec 15 13:22:14 2004 New Revision: 112020 URL: http://svn.apache.org/viewcvs?view=rev&rev=112020 Log: Initial version of WSDL to Annotated java code generation scripts
Contributor: Daryoush Mehrtash Modified: incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm Modified: incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java?view=diff&rev=112020&p1=incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java&r1=112019&p2=incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java&r2=112020 ============================================================================== --- incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java (original) +++ incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java Wed Dec 15 13:22:14 2004 @@ -26,6 +26,8 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.OutputStreamWriter; +import java.io.StringBufferInputStream; +import java.io.StringWriter; import java.util.Collection; import java.util.List; import java.util.Iterator; @@ -41,6 +43,8 @@ import org.apache.axis.description.OperationDesc; import org.apache.axis.description.ParameterDesc; import org.apache.axis.description.ServiceDesc; +import org.apache.beehive.wsm.jsr181.model.Jsr181MethodMetadataImpl; +import org.apache.beehive.wsm.jsr181.model.Jsr181ParameterMetadataImpl; import org.apache.beehive.wsm.jsr181.model.Jsr181TypeMetadataImpl; import org.apache.beehive.wsm.jsr181.model.SOAPBindingInfo; import org.apache.beehive.wsm.jsr181.model.Jsr181MethodMetadata; @@ -71,11 +75,114 @@ } public void testSrcCodeGeneration() throws Exception { - FileWriter fw = new FileWriter("resultfile.java", false); - FileInputStream fis = new FileInputStream("./wsm/drt/tests/FooWSDL.xml"); + + StringWriter result = new StringWriter(); + //FileInputStream fis = new FileInputStream("./wsm/drt/tests/FooWSDL.xml"); + //StringBufferInputStream sbis = new StringBufferInputStream(theWSDL); + + Jsr181TypeMetadata om = new Jsr181TypeMetadataImpl("myClassName"); + om.setWsName("MyWebService"); + om.setWsTargetNamespace("http://www.mynamespace.org/mywebservice"); + om.setWsWsdlLocation("myWsdlLocation"); + + Jsr181MethodMetadata method1 = new Jsr181MethodMetadataImpl("firstMethod", void.class); + method1.setOneWay(true); + method1.setWmOperationName("myFirstMethodOperationName"); + om.addMethod(method1); + + + Jsr181MethodMetadata method2 = new Jsr181MethodMetadataImpl("secondMethod", String.class); + method2.setOneWay(false); + method2.setWmOperationName("mySecondMethodOperationName"); + Jsr181ParameterMetadata param1 = new Jsr181ParameterMetadataImpl(); + param1.setJavaType(String.class); + param1.setWpName("myStringParam"); + param1.setWpTargetNamespace("http://www.mynamespace.org/myparameters"); + param1.setWpMode(WebParam.Mode.INOUT); + method2.addParam(param1); + method2.setWrName("method2Result"); + method2.setWrTargetNamespace("http://www.mynamespace.org/myresults"); + om.addMethod(method2); + + Jsr181MethodMetadata method3 = new Jsr181MethodMetadataImpl("thirdMethod", String.class); + method3.setOneWay(false); + method3.setWmOperationName("myThirdMethodOperationName"); + Jsr181ParameterMetadata param3_1 = new Jsr181ParameterMetadataImpl(); + param3_1.setJavaType(String.class); + param3_1.setWpName("myStringParam1"); + param3_1.setWpTargetNamespace("http://www.mynamespace.org/myparameters"); + param3_1.setWpMode(WebParam.Mode.INOUT); + method3.addParam(param3_1); + Jsr181ParameterMetadata param3_2 = new Jsr181ParameterMetadataImpl(); + param3_2.setJavaType(String.class); + param3_2.setWpName("myStringParam2"); + param3_2.setWpTargetNamespace("http://www.mynamespace.org/myparameters"); + param3_2.setWpMode(WebParam.Mode.IN); + method3.addParam(param3_2); + method3.setWrName("method3Result"); + method3.setWrTargetNamespace("http://www.mynamespace.org/myresults"); + om.addMethod(method3); + + Wsdl2AJava processor = new Wsdl2AJava(); processor.init(); - processor.generateAnnotatedJavaFromWSDL(fis, fw); + processor.generateAnnotatedJavaFromOM(om, result); + System.out.println("Outputfile: \n" + result.getBuffer().toString()); } + + String theWSDL = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + "<wsdl:definitions targetNamespace=\"http://www.superflaco.com/AnnotationTest\" xmlns:apachesoap=\"http://xml.apache.org/xml-soap\" xmlns:impl=\"http://www.superflaco.com/AnnotationTest\" xmlns:intf=\"http://www.superflaco.com/AnnotationTest\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:wsdlsoap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + + " <!--WSDL created by Apache Axis version: 1.2beta3" + + " Built on Aug 15, 2004 (04:32:00 PDT)-->" + + " <wsdl:message name=\"goHomeResponse\">" + + " <wsdl:part name=\"howdy\" type=\"soapenc:string\"/>" + + " </wsdl:message>" + + " <wsdl:message name=\"goHomeRequest\">" + + " </wsdl:message>" + + " <wsdl:message name=\"GoLocoResponse\">" + + " <wsdl:part name=\"result\" type=\"xsd:boolean\"/>" + + " </wsdl:message>" + + " <wsdl:message name=\"GoLocoRequest\">" + + " <wsdl:part name=\"in0\" type=\"xsd:int\"/>" + + "<wsdl:part name=\"detail\" type=\"soapenc:string\"/>" + + " </wsdl:message>" + + " <wsdl:portType name=\"Abacus\">" + + " <wsdl:operation name=\"GoLoco\" parameterOrder=\"in0 detail\">" + + " <wsdl:input message=\"impl:GoLocoRequest\" name=\"GoLocoRequest\"/>" + + " <wsdl:output message=\"impl:GoLocoResponse\" name=\"GoLocoResponse\"/>" + + " </wsdl:operation>" + + " <wsdl:operation name=\"goHome\">" + + " <wsdl:input message=\"impl:goHomeRequest\" name=\"goHomeRequest\"/>" + + " <wsdl:output message=\"impl:goHomeResponse\" name=\"goHomeResponse\"/>" + + " </wsdl:operation>" + + " </wsdl:portType>" + + " <wsdl:binding name=\"FooSoapBinding\" type=\"impl:Abacus\">" + + " <wsdlsoap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\"/>" + + " <wsdl:operation name=\"GoLoco\">" + + " <wsdlsoap:operation soapAction=\"LocoAction\"/>" + + " <wsdl:input name=\"GoLocoRequest\">" + + " <wsdlsoap:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"http://www.superflaco.com/AnnotationTest\" use=\"encoded\"/>" + + " </wsdl:input>" + + " <wsdl:output name=\"GoLocoResponse\">" + + " <wsdlsoap:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"http://www.superflaco.com/AnnotationTest\" use=\"encoded\"/>" + + " </wsdl:output>" + + " </wsdl:operation>" + + " <wsdl:operation name=\"goHome\">" + + " <wsdlsoap:operation soapAction=\"\"/>" + + " <wsdl:input name=\"goHomeRequest\">" + + " <wsdlsoap:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"http://www.superflaco.com/AnnotationTest\" use=\"encoded\"/>" + + " </wsdl:input>" + + " <wsdl:output name=\"goHomeResponse\">" + + " <wsdlsoap:body encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" namespace=\"http://www.superflaco.com/AnnotationTest\" use=\"encoded\"/>" + + " </wsdl:output>" + + " </wsdl:operation>" + + " </wsdl:binding>" + + " <wsdl:service name=\"Cheetorama\">" + + " <wsdl:port binding=\"impl:FooSoapBinding\" name=\"Foo\">" + + " <wsdlsoap:address location=\"http://localhost:8080/AnnotatedAxis/Foo.jws\"/>" + + " </wsdl:port>" + + " </wsdl:service>" + + "</wsdl:definitions>"; + } Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java?view=diff&rev=112020&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java&r1=112019&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java&r2=112020 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java Wed Dec 15 13:22:14 2004 @@ -20,19 +20,15 @@ */ package org.apache.beehive.wsm.jsr181.wsdl; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; import java.io.Writer; import java.util.Properties; import org.apache.beehive.wsm.jsr181.model.Jsr181TypeMetadata; +import org.apache.beehive.wsm.jsr181.util.VelocityLineFormatter; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; @@ -118,10 +114,26 @@ WSDLProcessor processor = new XmlBeanWSDLProcessor(); Jsr181TypeMetadata om = processor.createObjectModel(wsdl); - VelocityContext context = new VelocityContext(); + generateAnnotatedJavaFromOM(om, w); + } + + /** + * @param w + * @param om + * @throws ResourceNotFoundException + * @throws ParseErrorException + * @throws MethodInvocationException + * @throws Exception + * @throws IOException + */ + public void generateAnnotatedJavaFromOM( Jsr181TypeMetadata om, Writer w) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception, IOException { + VelocityContext context = new VelocityContext(); + context.put("formatter", new VelocityLineFormatter()); context.put("webServiceOM", om); template.merge(context, w); w.close(); } } + + Modified: incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm?view=diff&rev=112020&p1=incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm&r1=112019&p2=incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm&r2=112020 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm (original) +++ incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm Wed Dec 15 13:22:14 2004 @@ -1,46 +1,151 @@ + +## +## +## +#macro(webService $name $targetNamespace $wsdlLocation) [EMAIL PROTECTED] ( + name="$name" + targetNameSpace="$targetNamespace" +#if($wsdlLocation) + wsdlLocation="$wsdlLocation" +#end +) +#end +## +## +## +#macro(handlerChain $fileName $name) +#if( $fileName || $name) [EMAIL PROTECTED] ( + name="$name" + file="$fileName" +) +#end +#end +## +## +## +#macro( soapBinding $sb) [EMAIL PROTECTED] ( + style="$sb.style" + use="$sb.use" + parameterStyle="$sb.parameterStyle" +) +#end +## +## +## +#macro( soapMsgHandlers $handlers) +#if($handlers.size() > 0) [EMAIL PROTECTED] ( +#foreach( $smh in $handlers) + @SOAPMessageHandler ( + name="$smh.name" + className="$snm.className" + roles = { +#foreach($role in $smh.roles) + "$role" +#end + } + headers = { +#foreach($header in $smh.headers) + "$header" +#end + } + initParams = { +#foreach($paramName in $smh.parameterMap.keySet()) + @InitParam( + name="$paramName" + value="$smh.parameterMap.get($paramName)" + ) +#end + } + ) +#end +) +#end +#end +## +## +## +#macro( webMethod $method) + @WebMethod( + operationName="$method.wmOperationName" +#if($method.wmAction) + action="$method.wmAction" +#end + ) + +#end +## +## +## +#macro( results $method) +#if($method.oneWay) + @Oneway +#else + @WebResult( + name="$method.wrName" + targetNamespace="$method.wrTargetNamespace" + ) +#end +#end +## +## +## +#macro(params $method) +#set($size=$method.params.size()) +#set($ctr=0) +#foreach( $param in $method.params) +#set($ctr=$ctr + 1) + @WebParam( + name="$param.wpName" + targetNamespace="$param.wpTargetNamespace" + mode="$param.wpMode" + header="$param.wpHeader" + )$param.javaType $param.wpName#if($ctr < $size), +#end +#end +#end +## +## +## /* This file is an Annotated java file that that is automatically generated from wsdl: $webServiceOM.wsWsdlLocation -Source: wsdl2ajava.vm */ - [EMAIL PROTECTED] { - name="$webServiceOM.wsName" - targetNamspace="$webServiceOM.wsTargetNamespace" - wsdlLocation="$webServiceOM.wsWsdlLocation" - endpointInterface="$webServiceOM.wsEndpointInterface" - } - - +#webService($webServiceOM.wsName $webServiceOM.wsTargetNamespace $webServiceOM.wsWsdlLocation) +#handlerChain($webServiceOM.hcFileName $webServiceOM.name) +#soapBinding($webServiceOM.soapBinding) +#soapMsgHandlers($webServiceOM.soapHandlers) public class $webServiceOM.getWsName()Impl { + #foreach( $method in $webServiceOM.methods) - -/* -Method comments here -*/ - [EMAIL PROTECTED]( operationName="$method.wmOperationName" action="$method.wmAction") [EMAIL PROTECTED]( name="$method.wrName" targetNamespace="$method.wrTargetNamespace" ) -public $method.javaReturnType $method.javaMethodName( + /********************************************** + * +#foreach( $param in $method.params) + * @param $param.wpName + * +#end + * @throws java.rmi.RemoteException + * + ***********************************************/ +#webMethod($method) +#results($method) + public $method.javaReturnType $method.javaMethodName (#if($method.params.size() == 0)) + throws java.rmi.RemoteException {#end +#if($method.params.size() > 0) + +#params($method) +) + throws java.rmi.RemoteException { +#end + + + //TODO: Implement the method logic here... + } -#set($firstIt=1) -#foreach( $param in $method.params) -#if( $firstIt != 1) -, - #end -#set($firstIt=0) - @WebParam( name="$param.wpName" targetNamespace="$param.wpTargetNamespace" mode="$param.wpMode" header="$param.wpHeader) $param.javaType $param.wpName - -#end -) { - - //TODO: Implement the method logic here... -} - #end - - } -
