savara SVN: r167 - in tools/eclipse/trunk/plugins: org.jboss.savara.tools.wsdl and 6 other directories.
by do-not-reply@jboss.org
Author: objectiser
Date: 2010-02-16 16:31:20 -0500 (Tue, 16 Feb 2010)
New Revision: 167
Added:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/plugin.xml
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLBinding.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/soap/
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/soap/SOAPRPCWSDLBinding.java
Removed:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLBinding.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/soap/
Modified:
tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java
tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF
Log:
SAVARA-55 - WSDL can be generated independently of BPEL - in a sub-folder called wsdl.
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-02-16 20:28:13 UTC (rev 166)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -30,7 +30,7 @@
import org.jboss.savara.tools.bpel.model.*;
import org.jboss.savara.tools.bpel.model.component.PartnerLink;
import org.jboss.savara.tools.bpel.util.XMLUtils;
-import org.jboss.savara.tools.wsdl.soap.SOAPRPCWSDLBinding;
+import org.jboss.savara.tools.wsdl.generator.soap.SOAPRPCWSDLBinding;
import org.scribble.contract.model.Contract;
import org.scribble.contract.model.Interface;
import org.scribble.conversation.model.*;
@@ -265,8 +265,8 @@
if (role.getAnnotations().containsKey(Contract.class.getName())) {
javax.wsdl.xml.WSDLWriter writer=
javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();
- org.jboss.savara.tools.wsdl.WSDLGenerator generator=
- new org.jboss.savara.tools.wsdl.WSDLGenerator();
+ org.jboss.savara.tools.wsdl.generator.WSDLGenerator generator=
+ new org.jboss.savara.tools.wsdl.generator.WSDLGenerator();
Contract contract=(Contract)role.getAnnotations().get(Contract.class.getName());
java.util.List<javax.wsdl.Definition> defns=generator.generateDefinitions(contract,
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF 2010-02-16 20:28:13 UTC (rev 166)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF 2010-02-16 21:31:20 UTC (rev 167)
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JBoss SAVARA Tools WSDL Plug-in
-Bundle-SymbolicName: org.jboss.savara.tools.wsdl
+Bundle-SymbolicName: org.jboss.savara.tools.wsdl;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.jboss.savara.tools.wsdl.osgi.Activator
Import-Package: org.osgi.framework;version="1.3.0"
@@ -10,6 +10,12 @@
Require-Bundle: javax.wsdl;bundle-version="1.5.1";visibility:=reexport,
org.scribble.contract.model;bundle-version="0.1.0",
org.apache.commons.logging;bundle-version="1.0.4",
- org.scribble.core;bundle-version="0.1.0"
-Export-Package: org.jboss.savara.tools.wsdl,
- org.jboss.savara.tools.wsdl.soap
+ org.scribble.core;bundle-version="0.1.0",
+ org.eclipse.core.resources,
+ org.eclipse.jface,
+ org.eclipse.ui,
+ org.scribble.eclipse,
+ org.eclipse.core.runtime,
+ org.scribble.conversation.model
+Export-Package: org.jboss.savara.tools.wsdl.generator,
+ org.jboss.savara.tools.wsdl.generator.soap
Added: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/plugin.xml
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/plugin.xml (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/plugin.xml 2010-02-16 21:31:20 UTC (rev 167)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ id="org.jboss.tools.overlord.cdl.bpel.object.contribution"
+ objectClass="org.eclipse.core.resources.IFile"
+ nameFilter="*.cdm">
+ <menu
+ id="org.jboss.savara.tools.menu"
+ label="Savara"
+ path="additions">
+ <separator name="group1"/>
+ </menu>
+ <menu
+ id="generate.menu"
+ label="Generate"
+ path="org.jboss.savara.tools.menu/additions">
+ <separator name="group2"/>
+ </menu>
+ <action
+ label="WSDL"
+ class="org.jboss.savara.tools.wsdl.actions.GenerateAction"
+ menubarPath="org.jboss.savara.tools.menu/generate.menu/group2"
+ enablesFor="1"
+ id="org.jboss.savara.tools.wsdl.actions.GenerateAction">
+ </action>
+ </objectContribution>
+ </extension>
+
+</plugin>
Deleted: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLBinding.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLBinding.java 2010-02-16 20:28:13 UTC (rev 166)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLBinding.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -1,89 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.jboss.savara.tools.wsdl;
-
-/**
- * This interface is used to establish binding information on a
- * WSDL definition.
- *
- */
-public interface WSDLBinding {
-
- /**
- * This method returns the name of the WSDL binding implementation.
- *
- * @return The WSDL binding
- */
- public String getName();
-
- /**
- * This method initializes the WSDL definition for the binding.
- *
- * @param defn The definition
- */
- public void initDefinition(javax.wsdl.Definition defn);
-
- /**
- * This method adds WSDL binding information to the port binding.
- *
- * @param defn The definition
- * @param binding The port type
- */
- public void updateBinding(javax.wsdl.Definition defn, javax.wsdl.Binding binding);
-
- /**
- * This method adds WSDL binding information to the operation.
- *
- * @param defn The definition
- * @param operation The operation
- */
- public void updateOperation(javax.wsdl.Definition defn, javax.wsdl.BindingOperation operation);
-
- /**
- * This method adds WSDL binding information to the input.
- *
- * @param defn The definition
- * @param input The input
- */
- public void updateInput(javax.wsdl.Definition defn, javax.wsdl.BindingInput input);
-
- /**
- * This method adds WSDL binding information to the output.
- *
- * @param defn The definition
- * @param output The output
- */
- public void updateOutput(javax.wsdl.Definition defn, javax.wsdl.BindingOutput output);
-
- /**
- * This method adds WSDL binding information to the fault.
- *
- * @param defn The definition
- * @param fault The fault
- */
- public void updateFault(javax.wsdl.Definition defn, javax.wsdl.BindingFault fault);
-
- /**
- * This method adds WSDL binding information to the fault.
- *
- * @param defn The definition
- * @param port The port
- */
- public void updatePort(javax.wsdl.Definition defn, javax.wsdl.Port port);
-
-}
Deleted: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java 2010-02-16 20:28:13 UTC (rev 166)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -1,476 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.jboss.savara.tools.wsdl;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.scribble.contract.model.FaultDetails;
-import org.scribble.contract.model.Namespace;
-import org.scribble.contract.model.RequestResponseMEP;
-import org.scribble.model.TypeReference;
-
-/**
- * This class generates a WSDL definition from a Contract model.
- *
- */
-public class WSDLGenerator {
-
- public static final String BINDING_SUFFIX = "Binding";
-
- private static Log logger = LogFactory.getLog(WSDLGenerator.class);
-
- public WSDLGenerator() {
- }
-
- /**
- * This method generates a WSDL definition from a Scribble contract model.
- *
- * @param contract The contract model
- * @param wsdlBinding The WSDL binding to use, or null if no binding
- * @return The WSDL definition
- */
- public java.util.List<javax.wsdl.Definition> generateDefinitions(org.scribble.contract.model.Contract contract,
- WSDLBinding wsdlBinding) {
- java.util.List<javax.wsdl.Definition> ret=new java.util.Vector<javax.wsdl.Definition>();
-
- try {
- // Create definition for contract's target namespace
- javax.wsdl.Definition main=getDefinition(ret, contract, contract.getNamespace(), wsdlBinding);
-
- // If no definition, then return
- if (main == null) {
- return(ret);
- }
-
- // Create service
- javax.wsdl.Service service=main.createService();
- service.setQName(new javax.xml.namespace.QName(contract.getNamespace(),
- contract.getName()+"Service"));
-
- main.addService(service);
-
- // Define a port type per interface
- for (int i=0; i < contract.getInterfaces().size(); i++) {
- javax.wsdl.PortType portType=
- createPortType(ret, contract, contract.getInterfaces().get(i),
- wsdlBinding);
-
- javax.wsdl.Binding binding=
- createBinding(ret, contract, contract.getInterfaces().get(i),
- portType, wsdlBinding);
-
- // Create service port for interface
- javax.wsdl.Port port=main.createPort();
-
- port.setName(contract.getInterfaces().get(i).getName()+"Port");
- port.setBinding(binding);
-
- service.addPort(port);
-
- if (wsdlBinding != null) {
- wsdlBinding.updatePort(main, port);
- }
- }
-
- } catch(Exception e) {
- logger.error("Failed to generate WSDL", e);
- }
-
- return(ret);
- }
-
- /**
- * This method returns the definition associated with the supplied target namespace.
- *
- * @param wsdls The list of current WSDL definitions
- * @param contract The contract
- * @param targetNamespace The target namespace
- * @param wsdlBinding The WSDL binding to use, or null if no binding
- * @return The WSDL definition for the target namespace, or null if unable to find or create
- */
- protected javax.wsdl.Definition getDefinition(java.util.List<javax.wsdl.Definition> wsdls,
- org.scribble.contract.model.Contract contract, String targetNamespace,
- WSDLBinding wsdlBinding) {
- javax.wsdl.Definition ret=null;
-
- if (targetNamespace != null) {
- for (int i=0; ret == null && i < wsdls.size(); i++) {
- ret = wsdls.get(i);
-
- if (ret.getTargetNamespace() == null ||
- ret.getTargetNamespace().equals(targetNamespace) == false) {
- ret = null;
- }
- }
-
- if (ret == null) {
- ret = createDefinition(contract, targetNamespace);
-
- if (ret != null) {
-
- // Initialize definition using the WSDL binding
- if (wsdlBinding != null) {
- wsdlBinding.initDefinition(ret);
- }
-
- wsdls.add(ret);
- }
- }
- }
-
- return(ret);
- }
-
- /**
- * This method creates a new WSDL definition associated with the supplied
- * target namespace.
- *
- * @param contract The contract
- * @param targetNamespace The target namespace
- * @return The WSDL definition
- */
- protected javax.wsdl.Definition createDefinition(org.scribble.contract.model.Contract contract,
- String targetNamespace) {
- javax.wsdl.Definition ret=null;
-
- try {
- javax.wsdl.factory.WSDLFactory fact=
- javax.wsdl.factory.WSDLFactory.newInstance();
-
- ret = fact.newDefinition();
-
- // Set details on the definition
- if (contract.getName() != null) {
- ret.setQName(new javax.xml.namespace.QName(contract.getName()));
- }
- ret.setTargetNamespace(targetNamespace);
-
- // Set up namespace mappings
- for (int i=0; i < contract.getNamespaces().size(); i++) {
- Namespace ns=contract.getNamespaces().get(i);
-
- ret.addNamespace(ns.getPrefix(), ns.getURI());
- }
-
- } catch(Exception e) {
- logger.error("Failed to create WSDL definition for target namespace '"+targetNamespace+"'", e);
- }
-
- return(ret);
- }
-
- /**
- * This method generates a port type, using the supplied WSDL definition,
- * based on the information in the supplied interface definition.
- *
- * @param wsdls The list of current WSDL definitions
- * @param contract The contract
- * @param intf The interface model
- * @return The WSDL port type
- */
- public javax.wsdl.PortType createPortType(java.util.List<javax.wsdl.Definition> wsdls,
- org.scribble.contract.model.Contract contract,
- org.scribble.contract.model.Interface intf,
- WSDLBinding wsdlBinding) {
- javax.wsdl.PortType ret=null;
-
- if (intf != null) {
- javax.wsdl.Definition defn=getDefinition(wsdls, contract, intf.getNamespace(), wsdlBinding);
-
- if (defn != null) {
- ret = defn.createPortType();
- ret.setUndefined(false);
-
- if (intf.getName() != null) {
- ret.setQName(new javax.xml.namespace.QName(intf.getNamespace(), intf.getName()));
- }
-
- for (int i=0; i < intf.getMessageExchangePatterns().size(); i++) {
- createOperation(wsdls, contract, ret,
- intf.getMessageExchangePatterns().get(i), wsdlBinding);
- }
-
- // Only add portType to definition if they have atleast one operation
- if (ret != null && ret.getOperations().size() > 0) {
- defn.addPortType(ret);
- }
- }
- }
-
- return(ret);
- }
-
- /**
- * This method generates a port type binding, using the supplied WSDL definition,
- * based on the information in the supplied interface definition.
- *
- * @param wsdls The list of current WSDL definitions
- * @param contract The contract
- * @param intf The interface model
- * @param portType The port type
- * @return The WSDL port type binding
- */
- public javax.wsdl.Binding createBinding(java.util.List<javax.wsdl.Definition> wsdls,
- org.scribble.contract.model.Contract contract,
- org.scribble.contract.model.Interface intf,
- javax.wsdl.PortType portType,
- WSDLBinding wsdlBinding) {
- javax.wsdl.Binding ret=null;
-
- if (intf != null) {
- javax.wsdl.Definition defn=getDefinition(wsdls, contract, intf.getNamespace(), wsdlBinding);
-
- if (defn != null) {
- ret = defn.createBinding();
- ret.setUndefined(false);
-
- // Check if WSDL binding details
- if (wsdlBinding != null) {
- wsdlBinding.updateBinding(defn, ret);
- }
-
- if (intf.getName() != null) {
- ret.setQName(new javax.xml.namespace.QName(intf.getNamespace(),
- intf.getName()+BINDING_SUFFIX));
- }
-
- ret.setPortType(portType);
-
- for (int i=0; i < intf.getMessageExchangePatterns().size(); i++) {
- createBindingOperation(wsdls, contract, ret,
- intf.getMessageExchangePatterns().get(i), wsdlBinding);
- }
-
- // Only add portType to definition if they have atleast one operation
- if (ret != null && ret.getBindingOperations().size() > 0) {
- defn.addBinding(ret);
- }
- }
- }
-
- return(ret);
- }
-
- /**
- * This method generates an operation, using the supplied WSDL definition,
- * based on the information in the supplied message exchange pattern.
- *
- * @param wsdls The list of current WSDL definitions
- * @param contract The contract
- * @param portType The port type
- * @param mep The message exchange pattern
- * @return The WSDL operation
- */
- public javax.wsdl.Operation createOperation(java.util.List<javax.wsdl.Definition> wsdls,
- org.scribble.contract.model.Contract contract, javax.wsdl.PortType portType,
- org.scribble.contract.model.MessageExchangePattern mep,
- WSDLBinding wsdlBinding) {
- javax.wsdl.Operation ret=null;
-
- javax.wsdl.Definition defn=null;
-
- if (portType != null) {
- defn = getDefinition(wsdls, contract, portType.getQName().getNamespaceURI(), wsdlBinding);
- }
-
- if (defn != null && mep != null) {
- ret = defn.createOperation();
- ret.setUndefined(false);
-
- ret.setName(mep.getOperation());
-
- javax.wsdl.Message mesg=getMessage(wsdls, contract, mep.getTypes(), wsdlBinding);
-
- if (mesg != null) {
- javax.wsdl.Input input=defn.createInput();
- input.setMessage(mesg);
- ret.setInput(input);
- }
-
- // Check if a request/response MEP
- if (mep instanceof RequestResponseMEP) {
- RequestResponseMEP rr=(RequestResponseMEP)mep;
-
- javax.wsdl.Message om=getMessage(wsdls, contract, rr.getResponseTypes(), wsdlBinding);
- if (om != null) {
- javax.wsdl.Output output=defn.createOutput();
- output.setMessage(om);
- ret.setOutput(output);
- }
-
- // Generate fault details
- if (rr.getFaultDetails() != null) {
- for (int i=0; i < rr.getFaultDetails().size(); i++) {
- FaultDetails fd=rr.getFaultDetails().get(i);
-
- javax.wsdl.Message fm=getMessage(wsdls, contract, fd.getTypes(), wsdlBinding);
- if (fm != null) {
- javax.wsdl.Fault fault=defn.createFault();
- fault.setName(fd.getName());
- fault.setMessage(fm);
-
- ret.addFault(fault);
- }
- }
- }
- }
-
- portType.addOperation(ret);
- }
-
- return(ret);
- }
-
- /**
- * This method generates a binding operation, using the supplied WSDL definition,
- * based on the information in the supplied message exchange pattern.
- *
- * @param wsdls The list of current WSDL definitions
- * @param contract The contract
- * @param binding The port type binding
- * @param mep The message exchange pattern
- * @return The WSDL binding operation
- */
- public javax.wsdl.BindingOperation createBindingOperation(java.util.List<javax.wsdl.Definition> wsdls,
- org.scribble.contract.model.Contract contract, javax.wsdl.Binding binding,
- org.scribble.contract.model.MessageExchangePattern mep,
- WSDLBinding wsdlBinding) {
- javax.wsdl.BindingOperation ret=null;
-
- javax.wsdl.Definition defn=null;
-
- if (binding != null) {
- defn = getDefinition(wsdls, contract, binding.getQName().getNamespaceURI(), wsdlBinding);
- }
-
- if (defn != null && mep != null) {
- ret = defn.createBindingOperation();
- //ret.setUndefined(false);
-
- // Check if WSDL operation details
- if (wsdlBinding != null) {
- wsdlBinding.updateOperation(defn, ret);
- }
-
- ret.setName(mep.getOperation());
-
- javax.wsdl.Message mesg=getMessage(wsdls, contract, mep.getTypes(), wsdlBinding);
-
- if (mesg != null) {
- javax.wsdl.BindingInput input=defn.createBindingInput();
-
- // Check if WSDL operation details
- if (wsdlBinding != null) {
- wsdlBinding.updateInput(defn, input);
- }
-
- ret.setBindingInput(input);
- }
-
- // Check if a request/response MEP
- if (mep instanceof RequestResponseMEP) {
- RequestResponseMEP rr=(RequestResponseMEP)mep;
-
- javax.wsdl.Message om=getMessage(wsdls, contract, rr.getResponseTypes(), wsdlBinding);
- if (om != null) {
- javax.wsdl.BindingOutput output=defn.createBindingOutput();
-
- // Check if WSDL operation details
- if (wsdlBinding != null) {
- wsdlBinding.updateOutput(defn, output);
- }
-
- ret.setBindingOutput(output);
- }
-
- // Generate fault details
- if (rr.getFaultDetails() != null) {
- for (int i=0; i < rr.getFaultDetails().size(); i++) {
- FaultDetails fd=rr.getFaultDetails().get(i);
-
- javax.wsdl.Message fm=getMessage(wsdls, contract, fd.getTypes(), wsdlBinding);
- if (fm != null) {
- javax.wsdl.BindingFault fault=defn.createBindingFault();
- fault.setName(fd.getName());
-
- // Check if WSDL operation details
- if (wsdlBinding != null) {
- wsdlBinding.updateFault(defn, fault);
- }
-
- ret.addBindingFault(fault);
- }
- }
- }
- }
-
- binding.addBindingOperation(ret);
- }
-
- return(ret);
- }
-
- /**
- * This method returns a message, using the supplied WSDL definition,
- * based on the information supplied in the list of type references. If
- * a single type reference is supplied, this will be the message type,
- * if multiple type references are supplied, then these will be considered
- * the message parts.<p>
- * <p>
- * The returned message will be part of the supplied definition. If it
- * does not exist prior to the call to this method, then it will be
- * created and added to the definition upon returning the message.
- *
- * @param wsdls The list of current WSDL definitions
- * @param contract The contract
- * @param types The list of type references
- * @return The WSDL message
- */
- public javax.wsdl.Message getMessage(java.util.List<javax.wsdl.Definition> wsdls,
- org.scribble.contract.model.Contract contract,
- java.util.List<TypeReference> types,
- WSDLBinding wsdlBinding) {
- javax.wsdl.Message ret=null;
-
- if (types != null && types.size() > 0) {
- javax.xml.namespace.QName qname=null;
- javax.wsdl.Definition defn=null;
-
- if (types.size() == 1) {
- TypeReference ref=types.get(0);
- qname = new javax.xml.namespace.QName(ref.getNamespace(),ref.getLocalpart());
-
- defn = getDefinition(wsdls, contract, ref.getNamespace(), wsdlBinding);
- } else {
- throw new UnsupportedOperationException("Currently only supports single type reference");
- }
-
- if (qname != null &&
- (ret = defn.getMessage(qname)) == null) {
- ret = defn.createMessage();
- ret.setUndefined(false);
-
- ret.setQName(qname);
-
- defn.addMessage(ret);
- }
- }
-
- return(ret);
- }
-}
Added: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/actions/GenerateAction.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.actions;
+
+import org.apache.commons.logging.*;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.jboss.savara.tools.wsdl.generator.GeneratorUtil;
+import org.jboss.savara.tools.wsdl.generator.soap.SOAPRPCWSDLBinding;
+
+import org.scribble.contract.model.Contract;
+import org.scribble.contract.model.Interface;
+import org.scribble.conversation.model.ConversationModel;
+import org.scribble.eclipse.util.*;
+import org.scribble.extensions.RegistryFactory;
+import org.scribble.model.ModelReference;
+import org.scribble.model.admin.DefaultModelListener;
+import org.scribble.model.admin.ModelInfo;
+import org.scribble.model.admin.ModelRepository;
+
+/**
+ * This class implements the action to generate the choreography
+ * as a set of WSDL definition.
+ */
+public class GenerateAction implements IObjectActionDelegate {
+
+ private static final String CANNOT_GENERATE = "Choreography has errors, so cannot generate";
+
+ public GenerateAction() {
+ }
+
+ /**
+ * This method implements the action's run method.
+ *
+ * @param action The action
+ */
+ public void run(IAction action) {
+ if (m_selection instanceof StructuredSelection) {
+ StructuredSelection sel=(StructuredSelection)m_selection;
+
+ IResource res=(IResource)sel.getFirstElement();
+
+ if (res instanceof IFile) {
+
+ if (ResourceUtil.hasErrors(res) == false) {
+
+ generateWSDL((IFile)res);
+
+ } else {
+ warn(CANNOT_GENERATE);
+ }
+ }
+ }
+ }
+
+ /**
+ * This method generates the WSDL associated
+ * with the supplied file resource.
+ *
+ * @param res The file
+ */
+ protected void generateWSDL(IFile res) {
+ ModelReference ref=
+ org.scribble.eclipse.model.admin.OSGIModelRepository.createReference(res);
+ ConversationModel conversationModel=null;
+ java.util.List<ModelReference> localModelRefs=null;
+
+ if (ref != null) {
+ ModelRepository mrep=(ModelRepository)
+ RegistryFactory.getRegistry().getExtension(
+ ModelRepository.class, null);
+
+ if (mrep != null) {
+ java.util.List<ModelInfo> models=mrep.getModels(ref,
+ new DefaultModelListener());
+
+ for (int i=0; conversationModel == null &&
+ i < models.size(); i++) {
+ if (models.get(i).getModel() instanceof ConversationModel) {
+ conversationModel = (ConversationModel)
+ models.get(i).getModel();
+
+ localModelRefs = conversationModel.getLocalModels(ref);
+ }
+ }
+ }
+ }
+
+ if (conversationModel == null) {
+ logger.error("Unable to load model used to generate " +
+ "the BPEL artefacts", null);
+ } else if (localModelRefs != null) {
+ for (ModelReference mref : localModelRefs) {
+
+ try {
+ generateWSDL(conversationModel, mref, res);
+ } catch(Exception e) {
+ logger.error("Failed to generate WSDL for '"+res+"'", e);
+ }
+ }
+ }
+ }
+
+ protected void generateWSDL(ConversationModel cm, ModelReference ref, IResource cdmResource) throws Exception {
+
+ if (ref.getAnnotations().containsKey(Contract.class.getName())) {
+ javax.wsdl.xml.WSDLWriter writer=
+ javax.wsdl.factory.WSDLFactory.newInstance().newWSDLWriter();
+ org.jboss.savara.tools.wsdl.generator.WSDLGenerator generator=
+ new org.jboss.savara.tools.wsdl.generator.WSDLGenerator();
+ Contract contract=(Contract)ref.getAnnotations().get(Contract.class.getName());
+
+ java.util.List<javax.wsdl.Definition> defns=generator.generateDefinitions(contract,
+ new SOAPRPCWSDLBinding());
+
+ // Check if contract has atleast one message exchange pattern
+ boolean f_hasMEP=false;
+
+ for (int i=0; f_hasMEP == false && i < contract.getInterfaces().size(); i++) {
+ Interface intf=contract.getInterfaces().get(i);
+ f_hasMEP = (intf.getMessageExchangePatterns().size() > 0);
+ }
+
+ for (int i=defns.size()-1; i >= 0; i--) {
+ javax.wsdl.Definition defn=defns.get(i);
+
+ // Check if definition has a port type
+ if (defn.getPortTypes().size() > 0 || defn.getMessages().size() > 0
+ || (f_hasMEP && defn.getServices().size() > 0)) {
+ String num="";
+ if (i > 0) {
+ num += i;
+ }
+
+ String filename=cm.getModelName().getName()+"_"+ref.getLocatedRole()+num+".wsdl";
+
+ if (i > 0) {
+ javax.wsdl.Import imp=defns.get(0).createImport();
+
+ imp.setDefinition(defn);
+ imp.setNamespaceURI(defn.getTargetNamespace());
+ imp.setLocationURI(filename);
+
+ defns.get(0).addImport(imp);
+ }
+
+ java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream();
+
+ writer.writeWSDL(defn, baos);
+
+ byte[] b=baos.toByteArray();
+
+ baos.close();
+
+ IPath wsdlPath=cdmResource.getParent().getFullPath().append(
+ new Path("wsdl")).append(filename);
+
+ IFile wsdlFile=cdmResource.getProject().getWorkspace().getRoot().getFile(wsdlPath);
+ GeneratorUtil.createParentFolder(wsdlFile);
+ wsdlFile.create(null, true,
+ new org.eclipse.core.runtime.NullProgressMonitor());
+
+ wsdlFile.setContents(new java.io.ByteArrayInputStream(b), true, false,
+ new org.eclipse.core.runtime.NullProgressMonitor());
+ }
+ }
+ }
+ }
+
+
+ /**
+ * This method indicates that the selection has changed.
+ *
+ * @param action The action
+ * @param selection The selection
+ */
+ public void selectionChanged(IAction action,
+ ISelection selection) {
+ m_selection = selection;
+ }
+
+ /**
+ * This method sets the currently active workbench part.
+ *
+ * @param action The action
+ * @param targetPart The active workbench part
+ */
+ public void setActivePart(IAction action,
+ IWorkbenchPart targetPart) {
+ m_targetPart = targetPart;
+ }
+
+ /**
+ * This method is used to report a warning.
+ *
+ * @param mesg The warning message
+ */
+ public void warn(String mesg) {
+
+ MessageBox mbox=new MessageBox(m_targetPart.getSite().getShell(),
+ SWT.ICON_WARNING|SWT.OK);
+ mbox.setMessage(mesg);
+ mbox.open();
+ }
+
+ private static Log logger = LogFactory.getLog(GenerateAction.class);
+
+ private ISelection m_selection=null;
+ private IWorkbenchPart m_targetPart=null;
+}
Added: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/GeneratorUtil.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.generator;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * This class provides general utility functions for
+ * use when generating artefacts.
+ */
+public class GeneratorUtil {
+
+ /**
+ * This method checks whether the parent folder exists,
+ * and if not attempts to create it.
+ *
+ * @param res The current resource
+ */
+ public static void createParentFolder(IResource res) {
+
+ if (res.getParent() instanceof IFolder) {
+ IFolder parent=(IFolder)res.getParent();
+
+ if (parent.exists() == false) {
+ createParentFolder(parent);
+
+ try {
+ parent.create(true, true,
+ new org.eclipse.core.runtime.NullProgressMonitor());
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+}
Copied: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLBinding.java (from rev 162, tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLBinding.java)
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLBinding.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLBinding.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.generator;
+
+/**
+ * This interface is used to establish binding information on a
+ * WSDL definition.
+ *
+ */
+public interface WSDLBinding {
+
+ /**
+ * This method returns the name of the WSDL binding implementation.
+ *
+ * @return The WSDL binding
+ */
+ public String getName();
+
+ /**
+ * This method initializes the WSDL definition for the binding.
+ *
+ * @param defn The definition
+ */
+ public void initDefinition(javax.wsdl.Definition defn);
+
+ /**
+ * This method adds WSDL binding information to the port binding.
+ *
+ * @param defn The definition
+ * @param binding The port type
+ */
+ public void updateBinding(javax.wsdl.Definition defn, javax.wsdl.Binding binding);
+
+ /**
+ * This method adds WSDL binding information to the operation.
+ *
+ * @param defn The definition
+ * @param operation The operation
+ */
+ public void updateOperation(javax.wsdl.Definition defn, javax.wsdl.BindingOperation operation);
+
+ /**
+ * This method adds WSDL binding information to the input.
+ *
+ * @param defn The definition
+ * @param input The input
+ */
+ public void updateInput(javax.wsdl.Definition defn, javax.wsdl.BindingInput input);
+
+ /**
+ * This method adds WSDL binding information to the output.
+ *
+ * @param defn The definition
+ * @param output The output
+ */
+ public void updateOutput(javax.wsdl.Definition defn, javax.wsdl.BindingOutput output);
+
+ /**
+ * This method adds WSDL binding information to the fault.
+ *
+ * @param defn The definition
+ * @param fault The fault
+ */
+ public void updateFault(javax.wsdl.Definition defn, javax.wsdl.BindingFault fault);
+
+ /**
+ * This method adds WSDL binding information to the fault.
+ *
+ * @param defn The definition
+ * @param port The port
+ */
+ public void updatePort(javax.wsdl.Definition defn, javax.wsdl.Port port);
+
+}
Copied: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java (from rev 162, tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java)
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/WSDLGenerator.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -0,0 +1,476 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.generator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.scribble.contract.model.FaultDetails;
+import org.scribble.contract.model.Namespace;
+import org.scribble.contract.model.RequestResponseMEP;
+import org.scribble.model.TypeReference;
+
+/**
+ * This class generates a WSDL definition from a Contract model.
+ *
+ */
+public class WSDLGenerator {
+
+ public static final String BINDING_SUFFIX = "Binding";
+
+ private static Log logger = LogFactory.getLog(WSDLGenerator.class);
+
+ public WSDLGenerator() {
+ }
+
+ /**
+ * This method generates a WSDL definition from a Scribble contract model.
+ *
+ * @param contract The contract model
+ * @param wsdlBinding The WSDL binding to use, or null if no binding
+ * @return The WSDL definition
+ */
+ public java.util.List<javax.wsdl.Definition> generateDefinitions(org.scribble.contract.model.Contract contract,
+ WSDLBinding wsdlBinding) {
+ java.util.List<javax.wsdl.Definition> ret=new java.util.Vector<javax.wsdl.Definition>();
+
+ try {
+ // Create definition for contract's target namespace
+ javax.wsdl.Definition main=getDefinition(ret, contract, contract.getNamespace(), wsdlBinding);
+
+ // If no definition, then return
+ if (main == null) {
+ return(ret);
+ }
+
+ // Create service
+ javax.wsdl.Service service=main.createService();
+ service.setQName(new javax.xml.namespace.QName(contract.getNamespace(),
+ contract.getName()+"Service"));
+
+ main.addService(service);
+
+ // Define a port type per interface
+ for (int i=0; i < contract.getInterfaces().size(); i++) {
+ javax.wsdl.PortType portType=
+ createPortType(ret, contract, contract.getInterfaces().get(i),
+ wsdlBinding);
+
+ javax.wsdl.Binding binding=
+ createBinding(ret, contract, contract.getInterfaces().get(i),
+ portType, wsdlBinding);
+
+ // Create service port for interface
+ javax.wsdl.Port port=main.createPort();
+
+ port.setName(contract.getInterfaces().get(i).getName()+"Port");
+ port.setBinding(binding);
+
+ service.addPort(port);
+
+ if (wsdlBinding != null) {
+ wsdlBinding.updatePort(main, port);
+ }
+ }
+
+ } catch(Exception e) {
+ logger.error("Failed to generate WSDL", e);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the definition associated with the supplied target namespace.
+ *
+ * @param wsdls The list of current WSDL definitions
+ * @param contract The contract
+ * @param targetNamespace The target namespace
+ * @param wsdlBinding The WSDL binding to use, or null if no binding
+ * @return The WSDL definition for the target namespace, or null if unable to find or create
+ */
+ protected javax.wsdl.Definition getDefinition(java.util.List<javax.wsdl.Definition> wsdls,
+ org.scribble.contract.model.Contract contract, String targetNamespace,
+ WSDLBinding wsdlBinding) {
+ javax.wsdl.Definition ret=null;
+
+ if (targetNamespace != null) {
+ for (int i=0; ret == null && i < wsdls.size(); i++) {
+ ret = wsdls.get(i);
+
+ if (ret.getTargetNamespace() == null ||
+ ret.getTargetNamespace().equals(targetNamespace) == false) {
+ ret = null;
+ }
+ }
+
+ if (ret == null) {
+ ret = createDefinition(contract, targetNamespace);
+
+ if (ret != null) {
+
+ // Initialize definition using the WSDL binding
+ if (wsdlBinding != null) {
+ wsdlBinding.initDefinition(ret);
+ }
+
+ wsdls.add(ret);
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method creates a new WSDL definition associated with the supplied
+ * target namespace.
+ *
+ * @param contract The contract
+ * @param targetNamespace The target namespace
+ * @return The WSDL definition
+ */
+ protected javax.wsdl.Definition createDefinition(org.scribble.contract.model.Contract contract,
+ String targetNamespace) {
+ javax.wsdl.Definition ret=null;
+
+ try {
+ javax.wsdl.factory.WSDLFactory fact=
+ javax.wsdl.factory.WSDLFactory.newInstance();
+
+ ret = fact.newDefinition();
+
+ // Set details on the definition
+ if (contract.getName() != null) {
+ ret.setQName(new javax.xml.namespace.QName(contract.getName()));
+ }
+ ret.setTargetNamespace(targetNamespace);
+
+ // Set up namespace mappings
+ for (int i=0; i < contract.getNamespaces().size(); i++) {
+ Namespace ns=contract.getNamespaces().get(i);
+
+ ret.addNamespace(ns.getPrefix(), ns.getURI());
+ }
+
+ } catch(Exception e) {
+ logger.error("Failed to create WSDL definition for target namespace '"+targetNamespace+"'", e);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method generates a port type, using the supplied WSDL definition,
+ * based on the information in the supplied interface definition.
+ *
+ * @param wsdls The list of current WSDL definitions
+ * @param contract The contract
+ * @param intf The interface model
+ * @return The WSDL port type
+ */
+ public javax.wsdl.PortType createPortType(java.util.List<javax.wsdl.Definition> wsdls,
+ org.scribble.contract.model.Contract contract,
+ org.scribble.contract.model.Interface intf,
+ WSDLBinding wsdlBinding) {
+ javax.wsdl.PortType ret=null;
+
+ if (intf != null) {
+ javax.wsdl.Definition defn=getDefinition(wsdls, contract, intf.getNamespace(), wsdlBinding);
+
+ if (defn != null) {
+ ret = defn.createPortType();
+ ret.setUndefined(false);
+
+ if (intf.getName() != null) {
+ ret.setQName(new javax.xml.namespace.QName(intf.getNamespace(), intf.getName()));
+ }
+
+ for (int i=0; i < intf.getMessageExchangePatterns().size(); i++) {
+ createOperation(wsdls, contract, ret,
+ intf.getMessageExchangePatterns().get(i), wsdlBinding);
+ }
+
+ // Only add portType to definition if they have atleast one operation
+ if (ret != null && ret.getOperations().size() > 0) {
+ defn.addPortType(ret);
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method generates a port type binding, using the supplied WSDL definition,
+ * based on the information in the supplied interface definition.
+ *
+ * @param wsdls The list of current WSDL definitions
+ * @param contract The contract
+ * @param intf The interface model
+ * @param portType The port type
+ * @return The WSDL port type binding
+ */
+ public javax.wsdl.Binding createBinding(java.util.List<javax.wsdl.Definition> wsdls,
+ org.scribble.contract.model.Contract contract,
+ org.scribble.contract.model.Interface intf,
+ javax.wsdl.PortType portType,
+ WSDLBinding wsdlBinding) {
+ javax.wsdl.Binding ret=null;
+
+ if (intf != null) {
+ javax.wsdl.Definition defn=getDefinition(wsdls, contract, intf.getNamespace(), wsdlBinding);
+
+ if (defn != null) {
+ ret = defn.createBinding();
+ ret.setUndefined(false);
+
+ // Check if WSDL binding details
+ if (wsdlBinding != null) {
+ wsdlBinding.updateBinding(defn, ret);
+ }
+
+ if (intf.getName() != null) {
+ ret.setQName(new javax.xml.namespace.QName(intf.getNamespace(),
+ intf.getName()+BINDING_SUFFIX));
+ }
+
+ ret.setPortType(portType);
+
+ for (int i=0; i < intf.getMessageExchangePatterns().size(); i++) {
+ createBindingOperation(wsdls, contract, ret,
+ intf.getMessageExchangePatterns().get(i), wsdlBinding);
+ }
+
+ // Only add portType to definition if they have atleast one operation
+ if (ret != null && ret.getBindingOperations().size() > 0) {
+ defn.addBinding(ret);
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method generates an operation, using the supplied WSDL definition,
+ * based on the information in the supplied message exchange pattern.
+ *
+ * @param wsdls The list of current WSDL definitions
+ * @param contract The contract
+ * @param portType The port type
+ * @param mep The message exchange pattern
+ * @return The WSDL operation
+ */
+ public javax.wsdl.Operation createOperation(java.util.List<javax.wsdl.Definition> wsdls,
+ org.scribble.contract.model.Contract contract, javax.wsdl.PortType portType,
+ org.scribble.contract.model.MessageExchangePattern mep,
+ WSDLBinding wsdlBinding) {
+ javax.wsdl.Operation ret=null;
+
+ javax.wsdl.Definition defn=null;
+
+ if (portType != null) {
+ defn = getDefinition(wsdls, contract, portType.getQName().getNamespaceURI(), wsdlBinding);
+ }
+
+ if (defn != null && mep != null) {
+ ret = defn.createOperation();
+ ret.setUndefined(false);
+
+ ret.setName(mep.getOperation());
+
+ javax.wsdl.Message mesg=getMessage(wsdls, contract, mep.getTypes(), wsdlBinding);
+
+ if (mesg != null) {
+ javax.wsdl.Input input=defn.createInput();
+ input.setMessage(mesg);
+ ret.setInput(input);
+ }
+
+ // Check if a request/response MEP
+ if (mep instanceof RequestResponseMEP) {
+ RequestResponseMEP rr=(RequestResponseMEP)mep;
+
+ javax.wsdl.Message om=getMessage(wsdls, contract, rr.getResponseTypes(), wsdlBinding);
+ if (om != null) {
+ javax.wsdl.Output output=defn.createOutput();
+ output.setMessage(om);
+ ret.setOutput(output);
+ }
+
+ // Generate fault details
+ if (rr.getFaultDetails() != null) {
+ for (int i=0; i < rr.getFaultDetails().size(); i++) {
+ FaultDetails fd=rr.getFaultDetails().get(i);
+
+ javax.wsdl.Message fm=getMessage(wsdls, contract, fd.getTypes(), wsdlBinding);
+ if (fm != null) {
+ javax.wsdl.Fault fault=defn.createFault();
+ fault.setName(fd.getName());
+ fault.setMessage(fm);
+
+ ret.addFault(fault);
+ }
+ }
+ }
+ }
+
+ portType.addOperation(ret);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method generates a binding operation, using the supplied WSDL definition,
+ * based on the information in the supplied message exchange pattern.
+ *
+ * @param wsdls The list of current WSDL definitions
+ * @param contract The contract
+ * @param binding The port type binding
+ * @param mep The message exchange pattern
+ * @return The WSDL binding operation
+ */
+ public javax.wsdl.BindingOperation createBindingOperation(java.util.List<javax.wsdl.Definition> wsdls,
+ org.scribble.contract.model.Contract contract, javax.wsdl.Binding binding,
+ org.scribble.contract.model.MessageExchangePattern mep,
+ WSDLBinding wsdlBinding) {
+ javax.wsdl.BindingOperation ret=null;
+
+ javax.wsdl.Definition defn=null;
+
+ if (binding != null) {
+ defn = getDefinition(wsdls, contract, binding.getQName().getNamespaceURI(), wsdlBinding);
+ }
+
+ if (defn != null && mep != null) {
+ ret = defn.createBindingOperation();
+ //ret.setUndefined(false);
+
+ // Check if WSDL operation details
+ if (wsdlBinding != null) {
+ wsdlBinding.updateOperation(defn, ret);
+ }
+
+ ret.setName(mep.getOperation());
+
+ javax.wsdl.Message mesg=getMessage(wsdls, contract, mep.getTypes(), wsdlBinding);
+
+ if (mesg != null) {
+ javax.wsdl.BindingInput input=defn.createBindingInput();
+
+ // Check if WSDL operation details
+ if (wsdlBinding != null) {
+ wsdlBinding.updateInput(defn, input);
+ }
+
+ ret.setBindingInput(input);
+ }
+
+ // Check if a request/response MEP
+ if (mep instanceof RequestResponseMEP) {
+ RequestResponseMEP rr=(RequestResponseMEP)mep;
+
+ javax.wsdl.Message om=getMessage(wsdls, contract, rr.getResponseTypes(), wsdlBinding);
+ if (om != null) {
+ javax.wsdl.BindingOutput output=defn.createBindingOutput();
+
+ // Check if WSDL operation details
+ if (wsdlBinding != null) {
+ wsdlBinding.updateOutput(defn, output);
+ }
+
+ ret.setBindingOutput(output);
+ }
+
+ // Generate fault details
+ if (rr.getFaultDetails() != null) {
+ for (int i=0; i < rr.getFaultDetails().size(); i++) {
+ FaultDetails fd=rr.getFaultDetails().get(i);
+
+ javax.wsdl.Message fm=getMessage(wsdls, contract, fd.getTypes(), wsdlBinding);
+ if (fm != null) {
+ javax.wsdl.BindingFault fault=defn.createBindingFault();
+ fault.setName(fd.getName());
+
+ // Check if WSDL operation details
+ if (wsdlBinding != null) {
+ wsdlBinding.updateFault(defn, fault);
+ }
+
+ ret.addBindingFault(fault);
+ }
+ }
+ }
+ }
+
+ binding.addBindingOperation(ret);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns a message, using the supplied WSDL definition,
+ * based on the information supplied in the list of type references. If
+ * a single type reference is supplied, this will be the message type,
+ * if multiple type references are supplied, then these will be considered
+ * the message parts.<p>
+ * <p>
+ * The returned message will be part of the supplied definition. If it
+ * does not exist prior to the call to this method, then it will be
+ * created and added to the definition upon returning the message.
+ *
+ * @param wsdls The list of current WSDL definitions
+ * @param contract The contract
+ * @param types The list of type references
+ * @return The WSDL message
+ */
+ public javax.wsdl.Message getMessage(java.util.List<javax.wsdl.Definition> wsdls,
+ org.scribble.contract.model.Contract contract,
+ java.util.List<TypeReference> types,
+ WSDLBinding wsdlBinding) {
+ javax.wsdl.Message ret=null;
+
+ if (types != null && types.size() > 0) {
+ javax.xml.namespace.QName qname=null;
+ javax.wsdl.Definition defn=null;
+
+ if (types.size() == 1) {
+ TypeReference ref=types.get(0);
+ qname = new javax.xml.namespace.QName(ref.getNamespace(),ref.getLocalpart());
+
+ defn = getDefinition(wsdls, contract, ref.getNamespace(), wsdlBinding);
+ } else {
+ throw new UnsupportedOperationException("Currently only supports single type reference");
+ }
+
+ if (qname != null &&
+ (ret = defn.getMessage(qname)) == null) {
+ ret = defn.createMessage();
+ ret.setUndefined(false);
+
+ ret.setQName(qname);
+
+ defn.addMessage(ret);
+ }
+ }
+
+ return(ret);
+ }
+}
Copied: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/soap/SOAPRPCWSDLBinding.java (from rev 162, tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/soap/SOAPRPCWSDLBinding.java)
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/soap/SOAPRPCWSDLBinding.java (rev 0)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/generator/soap/SOAPRPCWSDLBinding.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.savara.tools.wsdl.generator.soap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.savara.tools.wsdl.generator.WSDLBinding;
+
+/**
+ * This interface is used to establish binding information on a
+ * WSDL definition.
+ *
+ */
+public class SOAPRPCWSDLBinding implements WSDLBinding {
+ private static Log logger = LogFactory.getLog(SOAPRPCWSDLBinding.class);
+
+ /**
+ * This method returns the name of the WSDL binding implementation.
+ *
+ * @return The WSDL binding
+ */
+ public String getName() {
+ return("SOAP RPC");
+ }
+
+ /**
+ * This method initializes the WSDL definition for the binding.
+ *
+ * @param defn The definition
+ */
+ public void initDefinition(javax.wsdl.Definition defn) {
+ defn.addNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+ }
+
+ /**
+ * This method adds WSDL binding information to the port binding.
+ *
+ * @param defn The definition
+ * @param binding The port type
+ */
+ public void updateBinding(javax.wsdl.Definition defn, javax.wsdl.Binding binding) {
+ try {
+ javax.wsdl.extensions.soap.SOAPBinding sb=(javax.wsdl.extensions.soap.SOAPBinding)
+ defn.getExtensionRegistry().createExtension(javax.wsdl.Binding.class,
+ new javax.xml.namespace.QName("http://schemas.xmlsoap.org/wsdl/soap/", "binding"));
+ sb.setStyle("rpc");
+ sb.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+ binding.addExtensibilityElement(sb);
+ } catch(Exception e) {
+ logger.error("Failed to add SOAP binding", e);
+ }
+ }
+
+ /**
+ * This method adds WSDL binding information to the operation.
+ *
+ * @param defn The definition
+ * @param operation The operation
+ */
+ public void updateOperation(javax.wsdl.Definition defn, javax.wsdl.BindingOperation operation) {
+ try {
+ javax.wsdl.extensions.soap.SOAPOperation soap=(javax.wsdl.extensions.soap.SOAPOperation)
+ defn.getExtensionRegistry().createExtension(javax.wsdl.BindingOperation.class,
+ new javax.xml.namespace.QName("http://schemas.xmlsoap.org/wsdl/soap/", "operation"));
+ soap.setStyle("rpc");
+ soap.setSoapActionURI("");
+ operation.addExtensibilityElement(soap);
+ } catch(Exception e) {
+ logger.error("Failed to add SOAP operation", e);
+ }
+ }
+
+ /**
+ * This method adds WSDL binding information to the input.
+ *
+ * @param defn The definition
+ * @param input The input
+ */
+ public void updateInput(javax.wsdl.Definition defn, javax.wsdl.BindingInput input) {
+ try {
+ javax.wsdl.extensions.soap.SOAPBody soap=(javax.wsdl.extensions.soap.SOAPBody)
+ defn.getExtensionRegistry().createExtension(javax.wsdl.BindingInput.class,
+ new javax.xml.namespace.QName("http://schemas.xmlsoap.org/wsdl/soap/", "body"));
+ soap.setUse("literal");
+ soap.setNamespaceURI(defn.getTargetNamespace());
+ input.addExtensibilityElement(soap);
+ } catch(Exception e) {
+ logger.error("Failed to add SOAP body to input", e);
+ }
+ }
+
+ /**
+ * This method adds WSDL binding information to the output.
+ *
+ * @param defn The definition
+ * @param output The output
+ */
+ public void updateOutput(javax.wsdl.Definition defn, javax.wsdl.BindingOutput output) {
+ try {
+ javax.wsdl.extensions.soap.SOAPBody soap=(javax.wsdl.extensions.soap.SOAPBody)
+ defn.getExtensionRegistry().createExtension(javax.wsdl.BindingOutput.class,
+ new javax.xml.namespace.QName("http://schemas.xmlsoap.org/wsdl/soap/", "body"));
+ soap.setUse("literal");
+ soap.setNamespaceURI(defn.getTargetNamespace());
+ output.addExtensibilityElement(soap);
+ } catch(Exception e) {
+ logger.error("Failed to add SOAP body to output", e);
+ }
+ }
+
+ /**
+ * This method adds WSDL binding information to the fault.
+ *
+ * @param defn The definition
+ * @param fault The fault
+ */
+ public void updateFault(javax.wsdl.Definition defn, javax.wsdl.BindingFault fault) {
+ try {
+ javax.wsdl.extensions.soap.SOAPFault soap=(javax.wsdl.extensions.soap.SOAPFault)
+ defn.getExtensionRegistry().createExtension(javax.wsdl.BindingFault.class,
+ new javax.xml.namespace.QName("http://schemas.xmlsoap.org/wsdl/soap/", "fault"));
+ soap.setUse("literal");
+ soap.setNamespaceURI(defn.getTargetNamespace());
+ soap.setName(fault.getName());
+
+ fault.addExtensibilityElement(soap);
+ } catch(Exception e) {
+ logger.error("Failed to add SOAP body to fault", e);
+ }
+ }
+
+ /**
+ * This method adds WSDL binding information to the fault.
+ *
+ * @param defn The definition
+ * @param port The port
+ */
+ public void updatePort(javax.wsdl.Definition defn, javax.wsdl.Port port) {
+ try {
+ javax.wsdl.extensions.soap.SOAPAddress soap=(javax.wsdl.extensions.soap.SOAPAddress)
+ defn.getExtensionRegistry().createExtension(javax.wsdl.Port.class,
+ new javax.xml.namespace.QName("http://schemas.xmlsoap.org/wsdl/soap/", "address"));
+ soap.setLocationURI("http://localhost:8080/"+defn.getQName().getLocalPart()+"Service");
+
+ port.addExtensibilityElement(soap);
+ } catch(Exception e) {
+ logger.error("Failed to add SOAP address to port", e);
+ }
+ }
+
+}
Modified: tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java
===================================================================
--- tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java 2010-02-16 20:28:13 UTC (rev 166)
+++ tools/eclipse/trunk/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java 2010-02-16 21:31:20 UTC (rev 167)
@@ -17,7 +17,7 @@
*/
package org.jboss.savara.tools.wsdl.tests;
-import org.jboss.savara.tools.wsdl.WSDLGenerator;
+import org.jboss.savara.tools.wsdl.generator.WSDLGenerator;
import org.scribble.contract.model.*;
import org.scribble.model.TypeReference;