Author: objectiser
Date: 2009-10-13 16:40:30 -0400 (Tue, 13 Oct 2009)
New Revision: 43
Modified:
trunk/tools/eclipse/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java
Log:
Added import statement for main wsdl, and port type bindings (currently without soap
extensions).
Modified:
trunk/tools/eclipse/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java
===================================================================
---
trunk/tools/eclipse/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2009-10-12
21:27:38 UTC (rev 42)
+++
trunk/tools/eclipse/plugins/org.jboss.savara.tools.bpel/src/java/org/jboss/savara/tools/bpel/generator/Generator.java 2009-10-13
20:40:30 UTC (rev 43)
@@ -218,11 +218,24 @@
java.util.List<javax.wsdl.Definition>
defns=generator.generateDefinitions(contract);
- for (int i=0; i < defns.size(); i++) {
+ 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) {
+ if (defn.getPortTypes().size() > 0 || defn.getMessages().size() > 0) {
+ String filename=localcm.getModelName().getName()+"_"+
+ role.getName()+i+".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);
Modified:
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java
===================================================================
---
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java 2009-10-12
21:27:38 UTC (rev 42)
+++
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java 2009-10-13
20:40:30 UTC (rev 43)
@@ -30,6 +30,7 @@
*/
public class WSDLGenerator {
+ public static final String SOAP_BINDING_SUFFIX = "SOAPBinding";
private static Log logger = LogFactory.getLog(WSDLGenerator.class);
public WSDLGenerator() {
@@ -51,6 +52,8 @@
// Define a port type per interface
for (int i=0; i < contract.getInterfaces().size(); i++) {
createPortType(ret, contract, contract.getInterfaces().get(i));
+
+ createBinding(ret, contract, contract.getInterfaces().get(i));
}
// TODO: Add service with port type bindings
@@ -175,6 +178,49 @@
}
/**
+ * 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
+ * @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.Binding ret=null;
+
+ if (intf != null) {
+ javax.wsdl.Definition defn=getDefinition(wsdls, contract, intf.getNamespace());
+
+ if (defn != null) {
+ ret = defn.createBinding();
+ ret.setUndefined(false);
+
+ // TODO: Need to make binding configurable
+
+ if (intf.getName() != null) {
+ ret.setQName(new javax.xml.namespace.QName(intf.getNamespace(),
+ intf.getName()+SOAP_BINDING_SUFFIX));
+ }
+
+ for (int i=0; i < intf.getMessageExchangePatterns().size(); i++) {
+ createBindingOperation(wsdls, contract, ret,
+ intf.getMessageExchangePatterns().get(i));
+ }
+
+ // 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.
*
@@ -244,6 +290,72 @@
}
/**
+ * 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) {
+ javax.wsdl.BindingOperation ret=null;
+
+ javax.wsdl.Definition defn=null;
+
+ if (binding != null) {
+ defn = getDefinition(wsdls, contract, binding.getQName().getNamespaceURI());
+ }
+
+ if (defn != null && mep != null) {
+ ret = defn.createBindingOperation();
+ //ret.setUndefined(false);
+
+ ret.setName(mep.getOperation());
+
+ javax.wsdl.Message mesg=getMessage(wsdls, contract, mep.getTypes());
+
+ if (mesg != null) {
+ javax.wsdl.BindingInput input=defn.createBindingInput();
+ 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());
+ if (om != null) {
+ javax.wsdl.BindingOutput output=defn.createBindingOutput();
+ 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());
+ if (fm != null) {
+ javax.wsdl.BindingFault fault=defn.createBindingFault();
+ fault.setName(fd.getName());
+
+ 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,
Modified:
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java
===================================================================
---
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java 2009-10-12
21:27:38 UTC (rev 42)
+++
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl.tests/src/java/org/jboss/savara/tools/wsdl/tests/WSDLGeneratorTest.java 2009-10-13
20:40:30 UTC (rev 43)
@@ -107,8 +107,45 @@
}
}
- public void testDefnWithPortTypes() {
+ public void testPortTypeBindingNameAndNamespace() {
+ Interface src=new Interface();
+ src.setName(TEST_NAME);
+ src.setNamespace(TEST_NAME_SPACE);
+
+ WSDLGenerator gen=new WSDLGenerator();
+
+ java.util.List<javax.wsdl.Definition> defns=new
java.util.Vector<javax.wsdl.Definition>();
+
+ javax.wsdl.Binding result=gen.createBinding(defns, new Contract(), src);
+
+ if (result == null) {
+ fail("PortType is null");
+ }
+
+ if (result.getQName() == null) {
+ fail("QName not set");
+ }
+
+ if (result.getQName().getNamespaceURI() == null) {
+ fail("QName namespace not set");
+ }
+
+ if (TEST_NAME_SPACE.equals(result.getQName().getNamespaceURI()) == false) {
+ fail("Namespace not correct: "+result.getQName().getNamespaceURI());
+ }
+
+ if (result.getQName().getLocalPart() == null) {
+ fail("QName localpart not set");
+ }
+
+ if
(result.getQName().getLocalPart().equals(TEST_NAME+WSDLGenerator.SOAP_BINDING_SUFFIX) ==
false) {
+ fail("QName localpart not correct: "+result.getQName().getLocalPart());
+ }
+ }
+
+ public void testDefnWithPortTypesAndBindings() {
+
Contract c=new Contract();
c.setNamespace(TEST_NAME_SPACE);
@@ -178,6 +215,12 @@
") does not match number of interfaces ("+
c.getInterfaces().size()+")");
}
+
+ if (defn.getBindings().size() != c.getInterfaces().size()) {
+ fail("Number of port type bindings ("+defn.getBindings().size()+
+ ") does not match number of interfaces ("+
+ c.getInterfaces().size()+")");
+ }
}
public void testOperationOneWay() {
@@ -435,6 +478,11 @@
") does not match number expected (1)");
}
+ if (defn1.getBindings().size() != 1) {
+ fail("1: Number of port type bindings ("+defn1.getBindings().size()+
+ ") does not match number expected (1)");
+ }
+
if (defn1.getMessages().size() != 1) {
fail("1: Number of message ("+defn1.getMessages().size()+
") does not match number expected (1)");
@@ -447,6 +495,11 @@
") does not match number expected (2)");
}
+ if (defn2.getBindings().size() != 2) {
+ fail("2: Number of port type bindings ("+defn2.getBindings().size()+
+ ") does not match number expected (2)");
+ }
+
if (defn2.getMessages().size() != 1) {
fail("2: Number of message ("+defn2.getMessages().size()+
") does not match number expected (1)");
@@ -459,6 +512,11 @@
") does not match number expected (0)");
}
+ if (defn3.getBindings().size() != 0) {
+ fail("3: Number of port type bindings ("+defn3.getBindings().size()+
+ ") does not match number expected (0)");
+ }
+
if (defn3.getMessages().size() != 1) {
fail("3: Number of message ("+defn3.getMessages().size()+
") does not match number expected (1)");