Author: mmerz Date: Mon Jan 10 15:04:45 2005 New Revision: 124838 URL: http://svn.apache.org/viewcvs?view=rev&rev=124838 Log: Updated from wsdl code generation
Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/wsdl2ajava.vm Removed: incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm Modified: incubator/beehive/trunk/wsm/build.xml incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java Modified: incubator/beehive/trunk/wsm/build.xml Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/build.xml?view=diff&rev=124838&p1=incubator/beehive/trunk/wsm/build.xml&r1=124837&p2=incubator/beehive/trunk/wsm/build.xml&r2=124838 ============================================================================== --- incubator/beehive/trunk/wsm/build.xml (original) +++ incubator/beehive/trunk/wsm/build.xml Mon Jan 10 15:04:45 2005 @@ -145,6 +145,14 @@ <src path="${runtime.dir}"/> <exclude name="**/axis/**"/> </javac> + + <copy todir="${runtime.classes}" overwrite="true"> + <fileset dir="${runtime.dir}" includes="**/*.template,**/*.vm,META-INF/**"/> + </copy> + <!-- Copy property files into the build --> + <copy todir="${runtime.classes}" overwrite="true"> + <fileset dir="${runtime.dir}" includes="**/*.properties"/> + </copy> </target> <target name="axis" depends="xsd,runtime" if="isJDKOver5"> <!-- makes sure controls.jar has been built --> Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java?view=diff&rev=124838&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java&r1=124837&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java&r2=124838 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadata.java Mon Jan 10 15:04:45 2005 @@ -50,4 +50,5 @@ String getJavaMethodName(); Class getJavaReturnType(); + String getJavaReturnTypeFullName(); } Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java?view=diff&rev=124838&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java&r1=124837&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java&r2=124838 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181MethodMetadataImpl.java Mon Jan 10 15:04:45 2005 @@ -301,4 +301,25 @@ return true; } + + /* (non-Javadoc) + * @see org.apache.beehive.wsm.jsr181.model.Jsr181MethodMetadata#getJavaReturnTypeFullName() + * + * * NOTE THIS METHOD AND SUPPORTING METHOD SHOULD BE MOVED OUT TO A ELEMENT CLASS + * THAT ENCAPSULATES QNAME AND CLASS + + */ + public String getJavaReturnTypeFullName() { + return getClassName(getJavaReturnType()); + } + + + private String getClassName(Class cls) { + if (cls.isArray()) { + return getClassName(cls.getComponentType()) + "[]"; + } + else { + return cls.getName().replace('$', '.'); + } + } } Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java?view=diff&rev=124838&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java&r1=124837&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java&r2=124838 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadata.java Mon Jan 10 15:04:45 2005 @@ -39,4 +39,5 @@ Class getJavaType(); void setJavaType(Class javaType); + String getJavaTypeFullName(); // this should be moved to web service elementtype later. } Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java?view=diff&rev=124838&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java&r1=124837&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java&r2=124838 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181ParameterMetadataImpl.java Mon Jan 10 15:04:45 2005 @@ -113,4 +113,23 @@ setWpHeader(annotation.header()); } } + + /* (non-Javadoc) + * @see org.apache.beehive.wsm.jsr181.model.Jsr181ParameterMetadata#getJavaTypeFullName() + * + * NOTE THIS METHOD AND SUPPORTING METHOD SHOULD BE MOVED OUT TO A ELEMENT CLASS + * THAT ENCAPSULATES QNAME AND CLASS + */ + public String getJavaTypeFullName() { + return getClassName(getJavaType()); + + } + private String getClassName(Class cls) { + if (cls.isArray()) { + return getClassName(cls.getComponentType()) + "[]"; + } + else { + return cls.getName().replace('$', '.'); + } + } } Modified: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java?view=diff&rev=124838&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java&r1=124837&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java&r2=124838 ============================================================================== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java (original) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/model/Jsr181TypeMetadataImpl.java Mon Jan 10 15:04:45 2005 @@ -571,8 +571,7 @@ public String[] getTargetNamespaceParts() { // strip the "http://" from the targetnamespace String namespace=getWsTargetNamespace().substring(7, getWsTargetNamespace().length()); - System.out.println("name space before split: " + namespace + " after split size: " + namespace.split("[\\./]").length); - String[] beforeTranspose = namespace.split("[\\./]"); + String[] beforeTranspose = namespace.split("[\\./]"); String[] res = new String[beforeTranspose.length]; for(int i=0; i<res.length; i++) res[i] = beforeTranspose[res.length - i - 1]; 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=124838&p1=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java&r1=124837&p2=incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java&r2=124838 ============================================================================== --- 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 Mon Jan 10 15:04:45 2005 @@ -18,6 +18,9 @@ */ package org.apache.beehive.wsm.jsr181.wsdl; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.Writer; @@ -30,6 +33,7 @@ import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; /** * @author dmehrtas @@ -56,31 +60,14 @@ */ public void init() throws Exception, ResourceNotFoundException, ParseErrorException, MethodInvocationException { - Properties p = new Properties(); - // p.setProperty("file.resource.loader.path", - // "C:/beehive/trunk/wsm/templates"); - p.setProperty("resource.loader", "class"); - p - .setProperty("class.resource.loader.class", - "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); - p.setProperty("class.resource.loader.cache", "true"); - p.setProperty("class.resource.loader.modificationCheckInterval", "0"); - init(p); - } - /** - * @param p - * @throws Exception - * @throws ResourceNotFoundException - * @throws ParseErrorException - * @throws MethodInvocationException - */ - public void init(Properties p) throws Exception, ResourceNotFoundException, - ParseErrorException, MethodInvocationException { + Properties p = new Properties(); + p.setProperty(VelocityEngine.RESOURCE_LOADER, "class"); + p.setProperty("class." + VelocityEngine.RESOURCE_LOADER + ".class", + ClasspathResourceLoader.class.getName()); ve = new VelocityEngine(); ve.init(p); - - String templateFileName = "templates/wsdl2ajava.vm"; + String templateFileName = "org/apache/beehive/wsm/jsr181/wsdl/wsdl2ajava.vm"; try { template = ve.getTemplate(templateFileName); @@ -106,12 +93,42 @@ } } + public void generateAnnotatedJavaFromWSDL(String wsdlFileName, + String baseSrcDir) throws Exception { + + InputStream wsdl = new FileInputStream(wsdlFileName); + WSDLProcessor processor = new XmlBeanWSDLProcessor(); + Jsr181TypeMetadata om = processor.createObjectModel(wsdl); + String className = om.getWsName(); + String packageName = "web"; // Later see if the target name service is + // better option + String packageDirName = packageName.replaceAll("\\.", "/"); // nop right + // now, + // useful if + // the + // target + // package + // name + + File packageDir = new File(baseSrcDir + "/" + packageDirName); + if (!packageDir.exists()) + packageDir.mkdirs(); + + String fullFilePath = baseSrcDir + "/" + packageDirName + "/" + + className + ".jws"; + + File srcFile = new File(fullFilePath); + srcFile.createNewFile(); + Writer w = new FileWriter(srcFile, false); + generateAnnotatedJavaFromOM(om, w); + } + public void generateAnnotatedJavaFromWSDL(InputStream wsdl, Writer w) throws Exception { - - WSDLProcessor processor = new XmlBeanWSDLProcessor(); - Jsr181TypeMetadata om = processor.createObjectModel(wsdl); - generateAnnotatedJavaFromOM(om, w); + + WSDLProcessor processor = new XmlBeanWSDLProcessor(); + Jsr181TypeMetadata om = processor.createObjectModel(wsdl); + generateAnnotatedJavaFromOM(om, w); } /** @@ -123,13 +140,26 @@ * @throws Exception * @throws IOException */ - public void generateAnnotatedJavaFromOM( Jsr181TypeMetadata om, Writer w) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception, IOException { + public void generateAnnotatedJavaFromOM(Jsr181TypeMetadata om, Writer w) + throws ResourceNotFoundException, ParseErrorException, + MethodInvocationException, Exception, IOException { VelocityContext context = new VelocityContext(); - context.put("webServiceOM", om); - template.merge(context, w); - w.close(); + context.put("webServiceOM", om); + template.merge(context, w); + w.close(); } -} + public static int main(String args[]) throws Exception { + if (args.length < 2) { + System.out + .println("Usage: Wsdl2AJava <wsdlFileName> <base source dir>"); + return (-1); + } + Wsdl2AJava processor = new Wsdl2AJava(); + processor.init(); + processor.generateAnnotatedJavaFromWSDL(args[0], args[1]); + return 0; + } +} Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/wsdl2ajava.vm Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/wsdl2ajava.vm?view=auto&rev=124838 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/wsdl2ajava.vm Mon Jan 10 15:04:45 2005 @@ -0,0 +1,182 @@ + +## +## +## +#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 = SOAPBinding.Style.$sb.style, + use = SOAPBinding.Use.$sb.use, + parameterStyle = SOAPBinding.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 = WebParam.Mode.$param.wpMode, + header = $param.wpHeader +## For now use the hack to get the correct name. later change this to use element -- Daryoush +## )$param.javaType.name $param.wpName#if($ctr < $size), + )$param.javaTypeFullName $param.wpName#if($ctr < $size), +#end +#end +#end +## +## +## +/* +This file is an Annotated java file that that is automatically generated +from wsdl: $webServiceOM.wsWsdlLocation + +*/ +#set($packageName="") +#set($ctr=0) +#set($size=$webServiceOM.targetNamespaceParts.size()) +#foreach( $dirName in $webServiceOM.targetNamespaceParts) +#if($ctr != 0) #set($packageName="$packageName.")#end +#set($ctr=$ctr + 1) +#set($packageName="$packageName$dirName") +#end +## package $packageName; For now just use web as package name + +package web; + +import java.rmi.RemoteException; + +import javax.jws.Oneway; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + + +#webService($webServiceOM.wsName $webServiceOM.wsTargetNamespace $webServiceOM.wsWsdlLocation) +#handlerChain($webServiceOM.hcFileName $webServiceOM.name) +#soapBinding($webServiceOM.soapBinding) +#soapMsgHandlers($webServiceOM.soapHandlers) +public class $webServiceOM.wsName { + +#foreach( $method in $webServiceOM.methods) + /********************************************** + * +#foreach( $param in $method.params) + * @param $param.wpName + * +#end + * @throws java.rmi.RemoteException + * + ***********************************************/ +#webMethod($method) +#results($method) +## For now use the hack to get the correct name. later change this to use element -- Daryoush +## public $method.javaReturnType.name $method.javaMethodName (#if($method.params.size() == 0)) + public $method.javaReturnTypeFullName $method.javaMethodName (#if($method.params.size() == 0)) + #if(!$method.oneWay)throws RemoteException#end {#end +#if($method.params.size() > 0) + +#params($method) +) + #if(!$method.oneWay)throws RemoteException#end { +#end + + //TODO: Implement the method logic here... +#if($method.javaReturnType.name == "void") + return; +#else + return null; +#end + + } + +#end +} + Deleted: /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=auto&rev=124837 ==============================================================================
