1
# WSDL4R - Creating driver code from WSDL.
2
# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
# redistribute it and/or modify it under the same terms of Ruby's license;
6
# either the dual license version in 2003, or any later version.
10
require 'wsdl/soap/classDefCreatorSupport'
11
require 'soap/rpc/element'
18
class MethodDefCreator
19
include ClassDefCreatorSupport
21
attr_reader :definitions
23
def initialize(definitions)
24
@definitions = definitions
25
@simpletypes = @definitions.collect_simpletypes
26
@complextypes = @definitions.collect_complextypes
27
@elements = @definitions.collect_elements
34
operations = @definitions.porttype(porttype).operations
35
binding = @definitions.porttype_binding(porttype)
36
operations.each do |operation|
37
op_bind = binding.operations[operation.name]
38
next unless op_bind # no binding is defined
39
next unless op_bind.soapoperation # not a SOAP operation binding
40
result << ",\n" unless result.empty?
41
result << dump_method(operation, op_bind).chomp
46
def collect_rpcparameter(operation)
47
result = operation.inputparts.collect { |part|
48
collect_type(part.type)
49
param_set(::SOAP::RPC::SOAPMethod::IN, part.name, rpcdefinedtype(part))
51
outparts = operation.outputparts
54
collect_type(retval.type)
55
result << param_set(::SOAP::RPC::SOAPMethod::RETVAL, retval.name,
56
rpcdefinedtype(retval))
57
cdr(outparts).each { |part|
58
collect_type(part.type)
59
result << param_set(::SOAP::RPC::SOAPMethod::OUT, part.name,
66
def collect_documentparameter(operation)
68
operation.inputparts.each do |input|
69
param << param_set(::SOAP::RPC::SOAPMethod::IN, input.name,
70
documentdefinedtype(input), elementqualified(input))
72
operation.outputparts.each do |output|
73
param << param_set(::SOAP::RPC::SOAPMethod::OUT, output.name,
74
documentdefinedtype(output), elementqualified(output))
81
def dump_method(operation, binding)
82
name = safemethodname(operation.name.name)
83
name_as = operation.name.name
84
style = binding.soapoperation_style
85
inputuse = binding.input.soapbody_use
86
outputuse = binding.output.soapbody_use
87
namespace = binding.input.soapbody.namespace
89
qname = XSD::QName.new(namespace, name_as)
90
paramstr = param2str(collect_rpcparameter(operation))
93
paramstr = param2str(collect_documentparameter(operation))
98
paramstr = "[ " << paramstr.split(/\r?\n/).join("\n ") << " ]"
100
definitions = <<__EOD__
101
#{ndq(binding.soapaction)},
104
{ :request_style => #{sym(style.id2name)}, :request_use => #{sym(inputuse.id2name)},
105
:response_style => #{sym(style.id2name)}, :response_use => #{sym(outputuse.id2name)} }
119
def rpcdefinedtype(part)
120
if mapped = basetype_mapped_class(part.type)
122
elsif definedtype = @simpletypes[part.type]
123
['::' + basetype_mapped_class(definedtype.base).name]
124
elsif definedtype = @elements[part.element]
125
#['::SOAP::SOAPStruct', part.element.namespace, part.element.name]
126
['nil', part.element.namespace, part.element.name]
127
elsif definedtype = @complextypes[part.type]
128
case definedtype.compoundtype
129
when :TYPE_STRUCT, :TYPE_EMPTY # ToDo: empty should be treated as void.
130
type = create_class_name(part.type)
131
[type, part.type.namespace, part.type.name]
133
[Hash.name, part.type.namespace, part.type.name]
135
arytype = definedtype.find_arytype || XSD::AnyTypeName
136
ns = arytype.namespace
137
name = arytype.name.sub(/\[(?:,)*\]$/, '')
138
type = create_class_name(XSD::QName.new(ns, name))
139
[type + '[]', ns, name]
141
raise NotImplementedError.new("must not reach here")
144
raise RuntimeError.new("part: #{part.name} cannot be resolved")
148
def documentdefinedtype(part)
149
if mapped = basetype_mapped_class(part.type)
150
['::' + mapped.name, nil, part.name]
151
elsif definedtype = @simpletypes[part.type]
152
['::' + basetype_mapped_class(definedtype.base).name, nil, part.name]
153
elsif definedtype = @elements[part.element]
154
['::SOAP::SOAPElement', part.element.namespace, part.element.name]
155
elsif definedtype = @complextypes[part.type]
156
['::SOAP::SOAPElement', part.type.namespace, part.type.name]
158
raise RuntimeError.new("part: #{part.name} cannot be resolved")
162
def elementqualified(part)
163
if mapped = basetype_mapped_class(part.type)
165
elsif definedtype = @simpletypes[part.type]
167
elsif definedtype = @elements[part.element]
168
definedtype.elementform == 'qualified'
169
elsif definedtype = @complextypes[part.type]
172
raise RuntimeError.new("part: #{part.name} cannot be resolved")
176
def param_set(io_type, name, type, ele = nil)
177
[io_type, name, type, ele]
180
def collect_type(type)
181
# ignore inline type definition.
183
return if @types.include?(type)
185
return unless @complextypes[type]
186
@complextypes[type].each_element do |element|
187
collect_type(element.type)
191
def param2str(params)
192
params.collect { |param|
193
io, name, type, ele = param
195
"[#{dq(io)}, #{dq(name)}, #{type2str(type)}, #{ele2str(ele)}]"
197
"[#{dq(io)}, #{dq(name)}, #{type2str(type)}]"
206
"[#{dq(type[0])}, #{ndq(type[1])}, #{dq(type[2])}]"