transform wsdl into html using xslt to obtain readable API signatures
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 29 Mar 2011 13:37:26 +0000 (15:37 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 29 Mar 2011 13:37:26 +0000 (15:37 +0200)
wsdl/Makefile
wsdl/sfa2wsdl.py
wsdl/wsdl2html.xsl [new file with mode: 0644]

index 1abba02..7f6bd2c 100644 (file)
@@ -1,8 +1,11 @@
 # attempt to update at build-time
 
-WSDLS = sfa.wsdl registry.wsdl slice-manager.wsdl aggregate.wsdl 
+INTERFACES=sfa registry slice-manager aggregate
 
-all: $(WSDLS)
+WSDLS = $(foreach interface,$(INTERFACES),$(interface).wsdl)
+HTMLS = $(foreach interface,$(INTERFACES),$(interface).html)
+
+all: $(WSDLS) $(HTMLS)
 
 # temporary: turn off wsdl generation as it is failing
 #TEMPORARY_OFF = yes
@@ -39,7 +42,7 @@ $(DESTDIR)$(INSTALL_PATH)/%: $(DESTDIR)$(INSTALL_PATH) %
        install -c -m 0755 $(wsdl) $@
 
 #################### clean
-clean:
+clean::
        rm -f *wsdl
 
 install-clean:
@@ -47,3 +50,10 @@ install-clean:
 
 .PHONY: all clean install install-clean
 
+#################### generate html document
+%.html: %.wsdl wsdl2html.xsl
+       xsltproc $(XSLTFLAGS) wsdl2html.xsl $*.wsdl > $@ || rm $@
+
+clean::
+       rm -f *.html
+
index f3a6b93..ddcb85d 100755 (executable)
@@ -41,6 +41,13 @@ class WSDLGen:
     def __init__(self, interface_options):
         self.interface_options = interface_options
 
+    def interface_name (self):
+         if self.interface_options.aggregate: return "aggregate"
+         elif self.interface_options.slicemgr: return "slicemgr"
+         elif self.interface_options.registry: return "registry"
+         elif self.interface_options.component: return "component"
+         else: return "unknown"
+
     def filter_argname(self,argname):
         if (not self.interface_options.lite or (argname!="cred")):
             if (argname.find('(') != -1):
@@ -172,7 +179,7 @@ class WSDLGen:
             #print
 
             
-            in_el = self.wsdl.firstChild.appendChild(self.wsdl.createElement("message"))
+            in_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("message"))
             in_el.setAttribute("name", method + "_in")
 
             for service_name in function.interfaces:
@@ -194,7 +201,7 @@ class WSDLGen:
                     
             # Return type            
             return_type = function.returns
-            out_el = self.wsdl.firstChild.appendChild(self.wsdl.createElement("message"))
+            out_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("message"))
             out_el.setAttribute("name", method + "_out")
             ret_part = out_el.appendChild(self.wsdl.createElement("part"))
             ret_part.setAttribute("name", "Result")
@@ -202,7 +209,7 @@ class WSDLGen:
 
             # Port connecting arguments with return type
 
-            port_el = self.wsdl.firstChild.appendChild(self.wsdl.createElement("portType"))
+            port_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("portType"))
             port_el.setAttribute("name", method + "_port")
             
             op_el = port_el.appendChild(self.wsdl.createElement("operation"))
@@ -218,7 +225,7 @@ class WSDLGen:
 
             # Bindings
 
-            bind_el = self.wsdl.firstChild.appendChild(self.wsdl.createElement("binding"))
+            bind_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("binding"))
             bind_el.setAttribute("name", method + "_binding")
             bind_el.setAttribute("type", "tns:" + method + "_port")
             
@@ -250,7 +257,7 @@ class WSDLGen:
     def add_wsdl_services(self):
         for service in self.services.keys():
             if (getattr(self.interface_options,service)):
-                service_el = self.wsdl.firstChild.appendChild(self.wsdl.createElement("service"))
+                service_el = self.wsdl.lastChild.appendChild(self.wsdl.createElement("service"))
                 service_el.setAttribute("name", service)
 
                 for method in self.services[service]:
@@ -265,43 +272,45 @@ class WSDLGen:
 
     def compute_wsdl_definitions(self):
         wsdl_text_header = """
+            <?xml-stylesheet type="text/xsl" href="wsdl2html.xsl"?>
             <wsdl:definitions
-            name="sfa_autogenerated"
-            targetNamespace="%s/2009/07/sfa.wsdl"
+            name="myplc-sfa-%s"
+            targetNamespace="%s/sfa.wsdl"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-            xmlns:xsdl="%s/2009/07/schema"
-            xmlns:tns="%s/2009/07/sfa.wsdl"
+            xmlns:xsdl="%s/schema"
+            xmlns:tns="%s/sfa.wsdl"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
-            """ % (globals.plc_ns,globals.plc_ns,globals.plc_ns)
+            """ % (self.interface_name(),globals.plc_ns,globals.plc_ns,globals.plc_ns)
             
         self.wsdl = xml.dom.minidom.parseString(wsdl_text_header)
         
 
     def compute_wsdl_definitions_and_types(self):
         wsdl_text_header = """
+        <?xml-stylesheet type="text/xsl" href="wsdl2html.xsl"?>
         <wsdl:definitions
-            name="sfa_autogenerated"
-            targetNamespace="%s/2009/07/sfa.wsdl"
+            name="myplc-sfa-%s"
+            targetNamespace="%s/sfa.wsdl"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-            xmlns:xsdl="%s/2009/07/schema"
-            xmlns:tns="%s/2009/07/sfa.wsdl"
+            xmlns:xsdl="%s/schema"
+            xmlns:tns="%s/sfa.wsdl"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
             <types>
-                <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="%s/2009/07/schema"/>
+                <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="%s/schema"/>
             </types>
-        </wsdl:definitions> """ % (globals.plc_ns, globals.plc_ns, globals.plc_ns, globals.plc_ns)
+        </wsdl:definitions> """ % (self.interface_name(),globals.plc_ns, globals.plc_ns, globals.plc_ns, globals.plc_ns)
         self.types = xml.dom.minidom.parseString(wsdl_text_header)
         
 
     def add_wsdl_types(self):
         wsdl_types = self.wsdl.importNode(self.types.getElementsByTagName("types")[0], True)
-        self.wsdl.firstChild.appendChild(wsdl_types)
+        self.wsdl.lastChild.appendChild(wsdl_types)
 
     def generate_wsdl(self):
         self.compute_wsdl_definitions_and_types()
diff --git a/wsdl/wsdl2html.xsl b/wsdl/wsdl2html.xsl
new file mode 100644 (file)
index 0000000..3ad341a
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet 
+version="1.0"  
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+xmlns:fn="http://www.w3.org/2005/02/xpath-functions" 
+>
+<xsl:output method="html" />
+
+<!-- to locate the out message -->
+<xsl:key name="messages" match="wsdl:message" use="@name"/>
+
+<xsl:template match="wsdl:definitions">
+<html>
+<head> <title> <xsl:value-of select="./@name" /> </title> </head>
+<body>
+<table border='1'><tr><th>method</th><th>in</th><th>out</th></tr>
+<xsl:apply-templates mode="messages" />
+</table>
+</body>
+</html>
+</xsl:template>
+
+<xsl:template match="wsdl:message" mode="messages">
+<xsl:variable name="methodname" select="substring-before(@name,'_in')" />
+<xsl:variable name="outmessage" select="concat($methodname,'_out')" />
+<xsl:if test="contains(@name,'_in')">
+<tr>
+<td>
+<xsl:value-of select="$methodname" />
+</td>
+<td>
+<xsl:for-each select="wsdl:part">
+<xsl:value-of select="@name" />
+(<xsl:value-of select="@type" />)
+<xsl:text> </xsl:text>
+</xsl:for-each>
+</td>
+<td> 
+<xsl:value-of select="key('messages',$outmessage)/wsdl:part/@type" />
+
+</td>
+</tr>
+</xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
+