diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-22 13:20:28 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-22 13:20:28 +0000 |
commit | 991d0c409cc6b1d916330a32a9624aef808176a4 (patch) | |
tree | 5e2cc150dc84ab3f6f64685ec7f54e6b2077eae7 /lib/wsdl/soap/methodDefCreator.rb | |
parent | 15b7d439885f4aa97e0f508ef485cadab4b23577 (diff) |
* lib/{soap,wsdl,xsd}, test/{soap,wsdl,xsd}: imported soap4r/1.5.4.
== SOAP client and server ==
=== for both client side and server side ===
* improved document/literal service support.
style(rpc,document)/use(encoding, literal) combination are all
supported. for the detail about combination, see
test/soap/test_style.rb.
* let WSDLEncodedRegistry#soap2obj map SOAP/OM to Ruby according to
WSDL as well as obj2soap. closes #70.
* let SOAP::Mapping::Object handle XML attribute for doc/lit service.
you can set/get XML attribute via accessor methods which as a name
'xmlattr_' prefixed (<foo name="bar"/> -> Foo#xmlattr_name).
=== client side ===
* WSDLDriver capitalized name operation bug fixed. from
1.5.3-ruby1.8.2, operation which has capitalized name (such as
KeywordSearchRequest in AWS) is defined as a method having
uncapitalized name. (converted with GenSupport.safemethodname
to handle operation name 'foo-bar'). it introduced serious
incompatibility; in the past, it was defined as a capitalized.
define capitalized method as well under that circumstance.
* added new factory interface 'WSDLDriverFactory#create_rpc_driver'
to create RPC::Driver, not WSDLDriver (RPC::Driver and WSDLDriver
are merged). 'WSDLDriverFactory#create_driver' still creates
WSDLDriver for compatibility but it warns that the method is
deprecated. please use create_rpc_driver instead of create_driver.
* allow to use an URI object as an endpoint_url even with net/http,
not http-access2.
=== server side ===
* added mod_ruby support to SOAP::CGIStub. rename a CGI script
server.cgi to server.rb and let mod_ruby's RubyHandler handles the
script. CGIStub detects if it's running under mod_ruby environment
or not.
* added fcgi support to SOAP::CGIStub. see the sample at
sample/soap/calc/server.fcgi. (almost same as server.cgi but has
fcgi handler at the bottom.)
* allow to return a SOAPFault object to respond customized SOAP fault.
* added the interface 'generate_explicit_type' for server side
(CGIStub, HTTPServer). call 'self.generate_explicit_type = true'
if you want to return simplified XML even if it's rpc/encoded
service.
== WSDL ==
=== WSDL definition ===
* improved XML Schema support such as extension, restriction,
simpleType, complexType + simpleContent, ref, length, import,
include.
* reduced "unknown element/attribute" warnings (warn only 1 time for
each QName).
* importing XSD file at schemaLocation with xsd:import.
=== code generation from WSDL ===
* generator crashed when there's '-' in defined element/attribute
name.
* added ApacheMap WSDL definition.
* sample/{soap,wsdl}: removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/wsdl/soap/methodDefCreator.rb')
-rw-r--r-- | lib/wsdl/soap/methodDefCreator.rb | 116 |
1 files changed, 65 insertions, 51 deletions
diff --git a/lib/wsdl/soap/methodDefCreator.rb b/lib/wsdl/soap/methodDefCreator.rb index 59b8ee4253..f256b42451 100644 --- a/lib/wsdl/soap/methodDefCreator.rb +++ b/lib/wsdl/soap/methodDefCreator.rb @@ -1,5 +1,5 @@ # WSDL4R - Creating driver code from WSDL. -# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. +# Copyright (C) 2002, 2003, 2005 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; @@ -8,6 +8,7 @@ require 'wsdl/info' require 'wsdl/soap/classDefCreatorSupport' +require 'soap/rpc/element' module WSDL @@ -24,75 +25,80 @@ class MethodDefCreator @simpletypes = @definitions.collect_simpletypes @complextypes = @definitions.collect_complextypes @elements = @definitions.collect_elements - @types = nil + @types = [] end def dump(porttype) - @types = [] + @types.clear result = "" operations = @definitions.porttype(porttype).operations binding = @definitions.porttype_binding(porttype) operations.each do |operation| op_bind = binding.operations[operation.name] + next unless op_bind # no binding is defined + next unless op_bind.soapoperation # not a SOAP operation binding 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 - stylestr = binding.soapoperation.operation_style.id2name - if binding.soapoperation.operation_style == :rpc - soapaction = binding.soapoperation.soapaction - namespace = binding.input.soapbody.namespace - params = collect_rpcparameter(operation) - else - soapaction = namespace = nil - params = collect_documentparameter(operation) - end - paramstr = param2str(params) - if paramstr.empty? - paramstr = '[]' - else - paramstr = "[\n" << paramstr.gsub(/^/, ' ') << "\n ]" - end - return <<__EOD__ -[#{ dq(name_as) }, #{ dq(name) }, - #{ paramstr }, - #{ ndq(soapaction) }, #{ ndq(namespace) }, #{ sym(stylestr) } -] -__EOD__ - end - def collect_rpcparameter(operation) result = operation.inputparts.collect { |part| collect_type(part.type) - param_set('in', rpcdefinedtype(part), part.name) + param_set(::SOAP::RPC::SOAPMethod::IN, rpcdefinedtype(part), part.name) } outparts = operation.outputparts if outparts.size > 0 retval = outparts[0] collect_type(retval.type) - result << param_set('retval', rpcdefinedtype(retval), retval.name) + result << param_set(::SOAP::RPC::SOAPMethod::RETVAL, + rpcdefinedtype(retval), retval.name) cdr(outparts).each { |part| collect_type(part.type) - result << param_set('out', rpcdefinedtype(part), part.name) + result << param_set(::SOAP::RPC::SOAPMethod::OUT, rpcdefinedtype(part), + part.name) } end result end def collect_documentparameter(operation) - input = operation.inputparts[0] - output = operation.outputparts[0] - [ - param_set('input', documentdefinedtype(input), input.name), - param_set('output', documentdefinedtype(output), output.name) - ] + param = [] + operation.inputparts.each do |input| + param << param_set(::SOAP::RPC::SOAPMethod::IN, + documentdefinedtype(input), input.name) + end + operation.outputparts.each do |output| + param << param_set(::SOAP::RPC::SOAPMethod::OUT, + documentdefinedtype(output), output.name) + end + param + end + +private + + def dump_method(operation, binding) + name = safemethodname(operation.name.name) + name_as = operation.name.name + style = binding.soapoperation_style + namespace = binding.input.soapbody.namespace + if style == :rpc + paramstr = param2str(collect_rpcparameter(operation)) + else + paramstr = param2str(collect_documentparameter(operation)) + end + if paramstr.empty? + paramstr = '[]' + else + paramstr = "[\n" << paramstr.gsub(/^/, ' ') << "\n ]" + end + return <<__EOD__ +[#{dq(name_as)}, #{dq(name)}, + #{paramstr}, + #{ndq(binding.soapaction)}, #{ndq(namespace)}, #{sym(style.id2name)} +] +__EOD__ end def rpcdefinedtype(part) @@ -101,33 +107,40 @@ __EOD__ elsif definedtype = @simpletypes[part.type] ['::' + basetype_mapped_class(definedtype.base).name] elsif definedtype = @elements[part.element] - ['::SOAP::SOAPStruct', part.element.namespace, part.element.name] + #['::SOAP::SOAPStruct', part.element.namespace, part.element.name] + ['nil', part.element.namespace, part.element.name] elsif definedtype = @complextypes[part.type] case definedtype.compoundtype - when :TYPE_STRUCT - ['::SOAP::SOAPStruct', part.type.namespace, part.type.name] + when :TYPE_STRUCT, :TYPE_EMPTY # ToDo: empty should be treated as void. + type = create_class_name(part.type) + [type, part.type.namespace, part.type.name] + when :TYPE_MAP + [Hash.name, 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] + type = create_class_name(XSD::QName.new(ns, name)) + [type + '[]', ns, name] else - raise NotImplementedError.new("Must not reach here.") + raise NotImplementedError.new("must not reach here") end else - raise RuntimeError.new("Part: #{part.name} cannot be resolved.") + raise RuntimeError.new("part: #{part.name} cannot be resolved") end end def documentdefinedtype(part) - if definedtype = @simpletypes[part.type] + if mapped = basetype_mapped_class(part.type) + ['::' + mapped.name, nil, part.name] + elsif definedtype = @simpletypes[part.type] ['::' + basetype_mapped_class(definedtype.base).name, nil, part.name] elsif definedtype = @elements[part.element] ['::SOAP::SOAPElement', part.element.namespace, part.element.name] elsif definedtype = @complextypes[part.type] ['::SOAP::SOAPElement', part.type.namespace, part.type.name] else - raise RuntimeError.new("Part: #{part.name} cannot be resolved.") + raise RuntimeError.new("part: #{part.name} cannot be resolved") end end @@ -138,6 +151,7 @@ __EOD__ def collect_type(type) # ignore inline type definition. return if type.nil? + return if @types.include?(type) @types << type return unless @complextypes[type] @complextypes[type].each_element do |element| @@ -147,15 +161,15 @@ __EOD__ def param2str(params) params.collect { |param| - "[#{ dq(param[0]) }, #{ dq(param[2]) }, #{ type2str(param[1]) }]" + "[#{dq(param[0])}, #{dq(param[2])}, #{type2str(param[1])}]" }.join(",\n") end def type2str(type) if type.size == 1 - "[#{ type[0] }]" + "[#{dq(type[0])}]" else - "[#{ type[0] }, #{ ndq(type[1]) }, #{ dq(type[2]) }]" + "[#{dq(type[0])}, #{ndq(type[1])}, #{dq(type[2])}]" end end |