summaryrefslogtreecommitdiff
path: root/lib/wsdl/soap/methodDefCreator.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-03 13:33:20 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-03 13:33:20 +0000
commitdf731e37a1953755edfedd1462995fa824ca22bf (patch)
tree38a98e1b29b3784843ad079fa003790c8f352f58 /lib/wsdl/soap/methodDefCreator.rb
parent0d6fa996d9e842fe435308cef68df06bc3596a76 (diff)
* added files:
* lib/soap/header/* * lib/soap/rpc/httpserver.rb * lib/wsdl/soap/cgiStubCreator.rb * lib/wsdl/soap/classDefCreator.rb * lib/wsdl/soap/classDefCreatorSupport.rb * lib/wsdl/soap/clientSkeltonCreator.rb * lib/wsdl/soap/driverCreator.rb * lib/wsdl/soap/mappingRegistryCreator.rb * lib/wsdl/soap/methodDefCreator.rb * lib/wsdl/soap/servantSkeltonCreator.rb * lib/wsdl/soap/standaloneServerStubCreator.rb * lib/wsdl/xmlSchema/enumeration.rb * lib/wsdl/xmlSchema/simpleRestriction.rb * lib/wsdl/xmlSchema/simpleType.rb * lib/xsd/codegen/* * lib/xsd/codegen.rb * sample/soap/authheader/* * sample/soap/raa2.4/* * sample/soap/ssl/* * sample/soap/swa/* * sample/soap/whois.rb * sample/wsdl/raa2.4/* * test/soap/header/* * test/soap/ssl/* * test/soap/struct/* * test/soap/swa/* * test/soap/wsdlDriver/* * test/wsdl/multiplefault.wsdl * test/wsdl/simpletype/* * test/wsdl/test_multiplefault.rb * modified files: * lib/soap/baseData.rb * lib/soap/element.rb * lib/soap/generator.rb * lib/soap/netHttpClient.rb * lib/soap/parser.rb * lib/soap/property.rb * lib/soap/soap.rb * lib/soap/streamHandler.rb * lib/soap/wsdlDriver.rb * lib/soap/wsdlDriver.rb * lib/soap/encodingstyle/handler.rb * lib/soap/encodingstyle/literalHandler.rb * lib/soap/encodingstyle/soapHandler.rb * lib/soap/mapping/factory.rb * lib/soap/mapping/mapping.rb * lib/soap/mapping/registry.rb * lib/soap/mapping/rubytypeFactory.rb * lib/soap/mapping/wsdlRegistry.rb * lib/soap/rpc/cgistub.rb * lib/soap/rpc/driver.rb * lib/soap/rpc/proxy.rb * lib/soap/rpc/router.rb * lib/soap/rpc/soaplet.rb * lib/soap/rpc/standaloneServer.rb * lib/wsdl/data.rb * lib/wsdl/definitions.rb * lib/wsdl/operation.rb * lib/wsdl/parser.rb * lib/wsdl/soap/definitions.rb * lib/wsdl/xmlSchema/complexContent.rb * lib/wsdl/xmlSchema/complexType.rb * lib/wsdl/xmlSchema/data.rb * lib/wsdl/xmlSchema/parser.rb * lib/wsdl/xmlSchema/schema.rb * lib/xsd/datatypes.rb * lib/xsd/qname.rb * sample/soap/sampleStruct/server.rb * sample/wsdl/amazon/AmazonSearch.rb * sample/wsdl/amazon/AmazonSearchDriver.rb * test/soap/test_property.rb * test/soap/calc/test_calc_cgi.rb * test/wsdl/test_emptycomplextype.rb * summary * add SOAP Header mustUnderstand support. * add HTTP client SSL configuration and Cookies support (works completely with http-access2). * add header handler for handling sending/receiving SOAP Header. * map Ruby's anonymous Struct to common SOAP Struct in SOAP Object Model. it caused error. * add WSDL simpleType support to restrict lexical value space. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/wsdl/soap/methodDefCreator.rb')
-rw-r--r--lib/wsdl/soap/methodDefCreator.rb148
1 files changed, 148 insertions, 0 deletions
diff --git a/lib/wsdl/soap/methodDefCreator.rb b/lib/wsdl/soap/methodDefCreator.rb
new file mode 100644
index 0000000000..eded972cdc
--- /dev/null
+++ b/lib/wsdl/soap/methodDefCreator.rb
@@ -0,0 +1,148 @@
+# WSDL4R - Creating driver code from WSDL.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/classDefCreatorSupport'
+
+
+module WSDL
+module SOAP
+
+
+class MethodDefCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ @simpletypes = @definitions.collect_simpletypes
+ @complextypes = @definitions.collect_complextypes
+ @elements = @definitions.collect_elements
+ @types = nil
+ end
+
+ def dump(porttype)
+ @types = []
+ result = ""
+ operations = @definitions.porttype(porttype).operations
+ binding = @definitions.porttype_binding(porttype)
+ operations.each do |operation|
+ op_bind = binding.operations[operation.name]
+ result << ",\n" unless result.empty?
+ result << dump_method(operation, op_bind).chomp
+ end
+ return result, @types
+ end
+
+private
+
+ def dump_method(operation, binding)
+ name = safemethodname(operation.name.name)
+ name_as = operation.name.name
+ params = collect_parameter(operation)
+ soapaction = binding.soapoperation.soapaction
+ namespace = binding.input.soapbody.namespace
+ paramstr = param2str(params)
+ if paramstr.empty?
+ paramstr = '[]'
+ else
+ paramstr = "[\n" << paramstr.gsub(/^/, ' ') << "\n ]"
+ end
+ return <<__EOD__
+[#{ dq(name_as) }, #{ dq(name) },
+ #{ paramstr },
+ #{ soapaction ? dq(soapaction) : "nil" }, #{ dq(namespace) }
+]
+__EOD__
+ end
+
+ def collect_parameter(operation)
+ result = operation.inputparts.collect { |part|
+ collect_type(part.type)
+ param_set('in', definedtype(part), part.name)
+ }
+ outparts = operation.outputparts
+ if outparts.size > 0
+ retval = outparts[0]
+ collect_type(retval.type)
+ result << param_set('retval', definedtype(retval), retval.name)
+ cdr(outparts).each { |part|
+ collect_type(part.type)
+ result << param_set('out', definedtype(part), part.name)
+ }
+ end
+ result
+ end
+
+ def definedtype(part)
+ if mapped = basetype_mapped_class(part.type)
+ ['::' + mapped.name]
+ elsif definedelement = @elements[part.element]
+ raise RuntimeError.new("Part: #{part.name} should be typed for RPC service for now.")
+ elsif definedtype = @simpletypes[part.type]
+ ['::' + basetype_mapped_class(definedtype.base).name]
+ elsif definedtype = @complextypes[part.type]
+ case definedtype.compoundtype
+ when :TYPE_STRUCT
+ ['::SOAP::SOAPStruct', part.type.namespace, part.type.name]
+ when :TYPE_ARRAY
+ arytype = definedtype.find_arytype || XSD::AnyTypeName
+ ns = arytype.namespace
+ name = arytype.name.sub(/\[(?:,)*\]$/, '')
+ ['::SOAP::SOAPArray', ns, name]
+ else
+ raise NotImplementedError.new("Must not reach here.")
+ end
+ else
+ raise RuntimeError.new("Part: #{part.name} cannot be resolved.")
+ end
+ end
+
+ def param_set(io_type, type, name)
+ [io_type, type, name]
+ end
+
+ def collect_type(type)
+ # ignore inline type definition.
+ return if type.nil?
+ @types << type
+ return unless @complextypes[type]
+ @complextypes[type].each_element do |element|
+ collect_type(element.type)
+ end
+ end
+
+ def param2str(params)
+ params.collect { |param|
+ "[#{ dq(param[0]) }, #{ dq(param[2]) }, #{ type2str(param[1]) }]"
+ }.join(",\n")
+ end
+
+ def type2str(type)
+ if type.size == 1
+ "[#{ type[0] }]"
+ else
+ "[#{ type[0] }, #{ dq(type[1]) }, #{ dq(type[2]) }]"
+ end
+ end
+
+ def dq(ele)
+ "\"" << ele << "\""
+ end
+
+ def cdr(ary)
+ result = ary.dup
+ result.shift
+ result
+ end
+end
+
+
+end
+end