Author: mmerz Date: Fri Dec 10 17:45:29 2004 New Revision: 111565 URL: http://svn.apache.org/viewcvs?view=rev&rev=111565 Log: Added wsdl 2 java
Contributor: Daryoush Mehrtash Added: incubator/beehive/trunk/wsm/drt/tests/AddressBookWSDL.xml 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/ incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm Added: incubator/beehive/trunk/wsm/drt/tests/AddressBookWSDL.xml Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/drt/tests/AddressBookWSDL.xml?view=auto&rev=111565 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/wsm/drt/tests/AddressBookWSDL.xml Fri Dec 10 17:45:29 2004 @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="UTF-8"?> +<wsdl:definitions targetNamespace="http://beehive.apache.org/AddressBook" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://beehive.apache.org/AddressBook" xmlns:intf="http://beehive.apache.org/AddressBook" xmlns:tns1="http://sample.beehive.apache.org" 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.2RC2 +Built on Nov 16, 2004 (12:19:44 EST)--> + <wsdl:types> + <schema elementFormDefault="qualified" targetNamespace="http://beehive.apache.org/AddressBook" xmlns="http://www.w3.org/2001/XMLSchema"> + <import namespace="http://sample.beehive.apache.org"/> + <element name="addEntry"> + <complexType> + <sequence> + <element name="in0" type="xsd:string"/> + <element name="in1" type="tns1:Address"/> + </sequence> + </complexType> + </element> + <element name="addEntryResponse"> + <complexType/> + </element> + <element name="getAddressFromName"> + <complexType> + <sequence> + <element name="in0" type="xsd:string"/> + </sequence> + </complexType> + </element> + <element name="getAddressFromNameResponse"> + <complexType> + <sequence> + <element name="result" type="tns1:Address"/> + </sequence> + </complexType> + </element> + </schema> + <schema elementFormDefault="qualified" targetNamespace="http://sample.beehive.apache.org" xmlns="http://www.w3.org/2001/XMLSchema"> + <complexType name="Phone"> + <sequence> + <element name="areaCode" type="xsd:int"/> + <element name="exchange" nillable="true" type="xsd:string"/> + <element name="number" nillable="true" type="xsd:string"/> + </sequence> + </complexType> + <complexType name="StateType"> + <sequence> + <element name="state" nillable="true" type="xsd:string"/> + </sequence> + </complexType> + <complexType name="Address"> + <sequence> + <element name="city" nillable="true" type="xsd:string"/> + <element name="phoneNumber" nillable="true" type="tns1:Phone"/> + <element name="state" nillable="true" type="tns1:StateType"/> + <element name="streetName" nillable="true" type="xsd:string"/> + <element name="streetNum" type="xsd:int"/> + <element name="zip" type="xsd:int"/> + </sequence> + </complexType> + </schema> + </wsdl:types> + + <wsdl:message name="addEntryRequest"> + + <wsdl:part element="impl:addEntry" name="parameters"/> + + </wsdl:message> + + <wsdl:message name="addEntryResponse"> + + <wsdl:part element="impl:addEntryResponse" name="parameters"/> + + </wsdl:message> + + <wsdl:message name="getAddressFromNameResponse"> + + <wsdl:part element="impl:getAddressFromNameResponse" name="parameters"/> + + </wsdl:message> + + <wsdl:message name="getAddressFromNameRequest"> + + <wsdl:part element="impl:getAddressFromName" name="parameters"/> + + </wsdl:message> + + <wsdl:portType name="Service"> + + <wsdl:operation name="addEntry"> + + <wsdl:input message="impl:addEntryRequest" name="addEntryRequest"/> + + <wsdl:output message="impl:addEntryResponse" name="addEntryResponse"/> + + </wsdl:operation> + + <wsdl:operation name="getAddressFromName"> + + <wsdl:input message="impl:getAddressFromNameRequest" name="getAddressFromNameRequest"/> + + <wsdl:output message="impl:getAddressFromNameResponse" name="getAddressFromNameResponse"/> + + </wsdl:operation> + + </wsdl:portType> + + <wsdl:binding name="ServiceSoapBinding" type="impl:Service"> + + <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + + <wsdl:operation name="addEntry"> + + <wsdlsoap:operation soapAction=""/> + + <wsdl:input name="addEntryRequest"> + + <wsdlsoap:body use="literal"/> + + </wsdl:input> + + <wsdl:output name="addEntryResponse"> + + <wsdlsoap:body use="literal"/> + + </wsdl:output> + + </wsdl:operation> + + <wsdl:operation name="getAddressFromName"> + + <wsdlsoap:operation soapAction=""/> + + <wsdl:input name="getAddressFromNameRequest"> + + <wsdlsoap:body use="literal"/> + + </wsdl:input> + + <wsdl:output name="getAddressFromNameResponse"> + + <wsdlsoap:body use="literal"/> + + </wsdl:output> + + </wsdl:operation> + + </wsdl:binding> + + <wsdl:service name="ServiceService"> + + <wsdl:port binding="impl:ServiceSoapBinding" name="Service"> + + <wsdlsoap:address location="http://localhost:8080/AddressBook/web/Service.jws"/> + + </wsdl:port> + + </wsdl:service> + +</wsdl:definitions> Added: 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=auto&rev=111565 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/wsm/drt/tests/org/apache/beehive/wsm/jsr181/wsdl/WSDL2AnnotatedJavaTest.java Fri Dec 10 17:45:29 2004 @@ -0,0 +1,81 @@ +/* + * XmlBeanWSDLProcessorTest.java + * + * Copyright 2001-2004 The Apache Software Foundation. + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Original author: Daryoush Mehrtash + */ +package org.apache.beehive.wsm.jsr181.wsdl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.OutputStreamWriter; +import java.util.Collection; +import java.util.List; +import java.util.Iterator; +import java.util.Properties; + +import javax.jws.WebParam; +import javax.jws.soap.SOAPBinding; +import javax.wsdl.OperationType; + +import junit.framework.TestCase; +import org.apache.axis.constants.Style; +import org.apache.axis.constants.Use; +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.Jsr181TypeMetadataImpl; +import org.apache.beehive.wsm.jsr181.model.SOAPBindingInfo; +import org.apache.beehive.wsm.jsr181.model.Jsr181MethodMetadata; +import org.apache.beehive.wsm.jsr181.model.Jsr181ParameterMetadata; +import org.apache.beehive.wsm.jsr181.model.Jsr181TypeMetadata; +import org.apache.beehive.wsm.jsr181.processor.reflection.WsmReflectionAnnotationProcessor; +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; +import org.apache.velocity.exception.ResourceNotFoundException; + +/******************************************************************************* + * + * + * @author Daryoush Mehrtash + */ +public class WSDL2AnnotatedJavaTest extends TestCase { + + + + public void setUp() throws Exception { + } + + public void tearDown() { + } + + public void testSrcCodeGeneration() throws Exception { + FileWriter fw = new FileWriter("resultfile.java", false); + FileInputStream fis = new FileInputStream("./tests/FooWSDL.xml"); + Wsdl2AJava processor = new Wsdl2AJava(); + processor.init(); + processor.generateAnnotatedJavaFromWSDL(fis, fw); + + } +} Added: 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=auto&rev=111565 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/jsr181/wsdl/Wsdl2AJava.java Fri Dec 10 17:45:29 2004 @@ -0,0 +1,127 @@ +/* + * Wsdl2AJava.java + * + * Copyright 2004 BEA Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * Original author: Daryoush Mehrtash + */ +package org.apache.beehive.wsm.jsr181.wsdl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +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.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; +import org.apache.velocity.exception.ResourceNotFoundException; + +/** + * @author dmehrtas + * + */ +public class Wsdl2AJava { + + VelocityEngine ve = null; + Template template = null; + + /** + * @throws Exception + * + */ + public Wsdl2AJava() throws Exception { + super(); + } + + /** + * @throws Exception + * @throws ResourceNotFoundException + * @throws ParseErrorException + * @throws MethodInvocationException + */ + 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 { + ve = new VelocityEngine(); + ve.init(p); + + String templateFileName = "templates/wsdl2ajava.vm"; + + try { + template = ve.getTemplate(templateFileName); + } catch (ResourceNotFoundException e) { + // couldn't find the template + System.out.println("Failed to find the tempate file: " + + templateFileName + " in classpath: " + + System.getProperty("java.class.path")); + e.printStackTrace(); + throw e; + } catch (ParseErrorException e) { + // syntax error : problem parsing the template + e.printStackTrace(); + throw e; + } catch (MethodInvocationException e) { + // something invoked in the template + // threw an exception + e.printStackTrace(); + throw e; + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + public void generateAnnotatedJavaFromWSDL(InputStream wsdl, Writer w) + throws Exception { + + WSDLProcessor processor = new XmlBeanWSDLProcessor(); + Jsr181TypeMetadata om = processor.createObjectModel(wsdl); + VelocityContext context = new VelocityContext(); + context.put("webServiceOM", om); + template.merge(context, w); + w.close(); + } + +} Added: 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=111565 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/wsm/src/runtime/templates/wsdl2ajava.vm Fri Dec 10 17:45:29 2004 @@ -0,0 +1,46 @@ +/* +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" + } + + +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( + +#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 + + +} + +
