[savara-commits] savara SVN: r35 - in trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl: src/java/org/jboss/savara/tools/wsdl and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sat Oct 3 16:51:58 EDT 2009
Author: objectiser
Date: 2009-10-03 16:51:57 -0400 (Sat, 03 Oct 2009)
New Revision: 35
Modified:
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF
trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java
Log:
Added more generation functionality.
Modified: trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF
===================================================================
--- trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF 2009-10-02 21:25:19 UTC (rev 34)
+++ trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/META-INF/MANIFEST.MF 2009-10-03 20:51:57 UTC (rev 35)
@@ -7,6 +7,8 @@
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: www.jboss.org
-Require-Bundle: javax.wsdl;bundle-version="1.5.1",
+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.apache.commons.logging;bundle-version="1.0.4",
+ org.scribble.core;bundle-version="0.1.0"
+Export-Package: org.jboss.savara.tools.wsdl
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-02 21:25:19 UTC (rev 34)
+++ trunk/tools/eclipse/plugins/org.jboss.savara.tools.wsdl/src/java/org/jboss/savara/tools/wsdl/WSDLGenerator.java 2009-10-03 20:51:57 UTC (rev 35)
@@ -19,6 +19,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.scribble.contract.model.FaultDetails;
+import org.scribble.contract.model.RequestResponseMEP;
+import org.scribble.model.TypeReference;
/**
* This class generates a WSDL definition from a Contract model.
@@ -31,7 +34,13 @@
public WSDLGenerator() {
}
- public javax.wsdl.Definition generate(org.scribble.contract.model.Contract contract) {
+ /**
+ * This method generates a WSDL definition from a Scribble contract model.
+ *
+ * @param contract The contract model
+ * @return The WSDL definition
+ */
+ public javax.wsdl.Definition generateDefinition(org.scribble.contract.model.Contract contract) {
javax.wsdl.Definition ret=null;
try {
@@ -40,10 +49,143 @@
ret = fact.newDefinition();
+ // Set details on the definition
+ if (contract.getName() != null) {
+ ret.setQName(new javax.xml.namespace.QName(contract.getName()));
+ }
+ ret.setTargetNamespace(contract.getNamespace());
+
+ // Define a port type per interface
+ for (int i=0; i < contract.getInterfaces().size(); i++) {
+ javax.wsdl.PortType ptype=generatePortType(ret, contract.getInterfaces().get(i));
+
+ if (ptype != null) {
+ ret.addPortType(ptype);
+ }
+ }
+
} catch(Exception e) {
logger.error("Failed to generate WSDL", e);
}
return(ret);
}
+
+ /**
+ * This method generates a port type, using the supplied WSDL definition,
+ * based on the information in the supplied interface definition. Note that
+ * the port type is not automatically added to the definition.
+ *
+ * @param defn The WSDL definition used to create the port type
+ * @param intf The interface model
+ * @return The WSDL port type
+ */
+ public javax.wsdl.PortType generatePortType(javax.wsdl.Definition defn,
+ org.scribble.contract.model.Interface intf) {
+ javax.wsdl.PortType ret=null;
+
+ if (defn != null && intf != null) {
+ ret = defn.createPortType();
+
+ if (intf.getName() != null) {
+ ret.setQName(new javax.xml.namespace.QName(intf.getNamespace(), intf.getName()));
+ }
+
+ for (int i=0; i < intf.getMessageExchangePatterns().size(); i++) {
+ javax.wsdl.Operation op=generateOperation(defn,
+ intf.getMessageExchangePatterns().get(i));
+ if (op != null) {
+ ret.addOperation(op);
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method generates an operation, using the supplied WSDL definition,
+ * based on the information in the supplied message exchange pattern.
+ *
+ * @param defn The WSDL definition
+ * @param mep The message exchange pattern
+ * @return The WSDL operation
+ */
+ public javax.wsdl.Operation generateOperation(javax.wsdl.Definition defn,
+ org.scribble.contract.model.MessageExchangePattern mep) {
+ javax.wsdl.Operation ret=null;
+
+ if (defn != null && mep != null) {
+ ret = defn.createOperation();
+
+ ret.setName(mep.getOperation());
+
+ javax.wsdl.Message mesg=generateMessage(defn, mep.getTypes());
+
+ 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=generateMessage(defn, rr.getResponseTypes());
+ 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=generateMessage(defn, fd.getTypes());
+ if (fm != null) {
+ javax.wsdl.Fault fault=defn.createFault();
+ fault.setName(fd.getName());
+ fault.setMessage(fm);
+
+ ret.addFault(fault);
+ }
+ }
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method generates 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.
+ *
+ * @param defn The WSDL definition
+ * @param types The list of type references
+ * @return The WSDL message
+ */
+ public javax.wsdl.Message generateMessage(javax.wsdl.Definition defn,
+ java.util.List<TypeReference> types) {
+ javax.wsdl.Message ret=null;
+
+ if (defn != null && types != null && types.size() > 0) {
+ ret = defn.createMessage();
+
+ if (types.size() == 1) {
+ TypeReference ref=types.get(0);
+ ret.setQName(new javax.xml.namespace.QName(ref.getNamespace(),ref.getLocalpart()));
+ } else {
+ throw new UnsupportedOperationException("Currently only supports single type reference");
+ }
+ }
+
+ return(ret);
+ }
}
More information about the savara-commits
mailing list