From 4cf5c3470b72e58615a9dd1b288c78670a8f5e6f Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Mon, 15 Jun 2009 20:14:39 +0000 Subject: [PATCH] Generate WSDL types --- wsdl/gw2wsdl.py | 69 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/wsdl/gw2wsdl.py b/wsdl/gw2wsdl.py index a5dd69d9..4e69edc4 100755 --- a/wsdl/gw2wsdl.py +++ b/wsdl/gw2wsdl.py @@ -14,30 +14,71 @@ import xml.dom.minidom import xml.dom.ext import globals import apistub +from types import * from geni.util.auth import Auth -from geni.util.parameter import Parameter,Mixed,python_type,xmlrpc_type +from geni.util.parameter import Parameter,Mixed +complex_types = {} +services = {} + +num_types = 0 +class SoapError(Exception): + def __init__(self, value): + self.value = value + def __str__(self): + return repr(self.value) try: set except NameError: from sets import Set set = Set -# Class functions -def param_type(param): - -# if isinstance(param, Mixed) and len(param): -# subtypes = [param_type(subparam) for subparam in param] -# return " or ".join(subtypes) -# elif isinstance(param, (list, tuple, set)) and len(param): -# return "array of " + " or ".join([param_type(subparam) for subparam in param]) -# else: -# return xmlrpc_type(python_type(param)) - return "some type - todo" +def name_vector_type(acc,arg): + name = name_complex_type(elt) + complex_types[arg]=name + acc.append(name) + return acc +def name_complex_type(arg): + if (instanceof(arg, Mixed)): + inner_types = reduce(name_vector_type, arg) + + num_types=num_types+1 + type_name = "Type%d"%num_types + complex_type = types.firstChild.appendChild(types.createElement("wsdl:complexType")) + complex_type.setAttribute("name", type_name) + + choice = complex_type.appendChild(complex_type.createElement("xsd:choice")) + choice.appendChild(choice.createElement("element")) + for i in types: + choice.setAttribute("name", "Foobar") + choice.setAttribute("minOccurs","1") + choice.setAttribute("maxOccurs","1") + choice.setAttribute("type", "tns:$i") + + return type_name + else: + return (name_simple_type(arg)) + +def name_simple_type(arg): + arg_type=arg.type + if arg_type == IntType or arg_type == LongType: + return "int" + elif arg_type == bool: + return "boolean" + elif arg_type == FloatType: + return "double" + elif arg_type in StringTypes: + return "string" + else: + pdb.set_trace() + raise SoapError, "Cannot handle %s objects" % arg_type + +def param_type(arg): + return (name_complex_type(arg)) def add_wsdl_ports_and_bindings (wsdl): for method in apistub.methods: @@ -145,12 +186,12 @@ def get_wsdl_definitions(): xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>""" % (globals.plc_ns,globals.plc_ns) wsdl = xml.dom.minidom.parseString(wsdl_text_header) - + return wsdl -services = {} +types = get_wsdl_definitions() wsdl = get_wsdl_definitions() add_wsdl_ports_and_bindings(wsdl) add_wsdl_service(wsdl) -- 2.47.0