| Class | WSDL::SOAP::MethodDefCreator |
| In: |
lib/wsdl/soap/methodDefCreator.rb
|
| Parent: | Object |
| definitions | [R] |
# File lib/wsdl/soap/methodDefCreator.rb, line 23
23: def initialize(definitions)
24: @definitions = definitions
25: @simpletypes = @definitions.collect_simpletypes
26: @complextypes = @definitions.collect_complextypes
27: @elements = @definitions.collect_elements
28: @types = []
29: end
# File lib/wsdl/soap/methodDefCreator.rb, line 66
66: def collect_documentparameter(operation)
67: param = []
68: operation.inputparts.each do |input|
69: param << param_set(::SOAP::RPC::SOAPMethod::IN, input.name,
70: documentdefinedtype(input), elementqualified(input))
71: end
72: operation.outputparts.each do |output|
73: param << param_set(::SOAP::RPC::SOAPMethod::OUT, output.name,
74: documentdefinedtype(output), elementqualified(output))
75: end
76: param
77: end
# File lib/wsdl/soap/methodDefCreator.rb, line 46
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))
50: }
51: outparts = operation.outputparts
52: if outparts.size > 0
53: retval = outparts[0]
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,
60: rpcdefinedtype(part))
61: }
62: end
63: result
64: end
# File lib/wsdl/soap/methodDefCreator.rb, line 31
31: def dump(porttype)
32: @types.clear
33: result = ""
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
42: end
43: return result, @types
44: end
# File lib/wsdl/soap/methodDefCreator.rb, line 222
222: def cdr(ary)
223: result = ary.dup
224: result.shift
225: result
226: end
# File lib/wsdl/soap/methodDefCreator.rb, line 183
183: def collect_type(type)
184: # ignore inline type definition.
185: return if type.nil?
186: return if @types.include?(type)
187: @types << type
188: return unless @complextypes[type]
189: @complextypes[type].each_element do |element|
190: collect_type(element.type)
191: end
192: end
# File lib/wsdl/soap/methodDefCreator.rb, line 151
151: def documentdefinedtype(part)
152: if mapped = basetype_mapped_class(part.type)
153: ['::' + mapped.name, nil, part.name]
154: elsif definedtype = @simpletypes[part.type]
155: ['::' + basetype_mapped_class(definedtype.base).name, nil, part.name]
156: elsif definedtype = @elements[part.element]
157: ['::SOAP::SOAPElement', part.element.namespace, part.element.name]
158: elsif definedtype = @complextypes[part.type]
159: ['::SOAP::SOAPElement', part.type.namespace, part.type.name]
160: else
161: raise RuntimeError.new("part: #{part.name} cannot be resolved")
162: end
163: end
# File lib/wsdl/soap/methodDefCreator.rb, line 81
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
88: if style == :rpc
89: qname = XSD::QName.new(namespace, name_as)
90: paramstr = param2str(collect_rpcparameter(operation))
91: else
92: qname = nil
93: paramstr = param2str(collect_documentparameter(operation))
94: end
95: if paramstr.empty?
96: paramstr = '[]'
97: else
98: paramstr = "[ " << paramstr.split(/\r?\n/).join("\n ") << " ]"
99: end
100: definitions = "\#{ndq(binding.soapaction)},\n \#{dq(name)},\n \#{paramstr},\n { :request_style => \#{sym(style.id2name)}, :request_use => \#{sym(inputuse.id2name)},\n :response_style => \#{sym(style.id2name)}, :response_use => \#{sym(outputuse.id2name)} }\n"
101: if style == :rpc
102: return "[ \#{qname.dump},\n \#{definitions}]\n"
103: else
104: return "[ \#{definitions}]\n"
105: end
106: end
# File lib/wsdl/soap/methodDefCreator.rb, line 213
213: def ele2str(ele)
214: qualified = ele
215: if qualified
216: "true"
217: else
218: "false"
219: end
220: end
# File lib/wsdl/soap/methodDefCreator.rb, line 165
165: def elementqualified(part)
166: if mapped = basetype_mapped_class(part.type)
167: false
168: elsif definedtype = @simpletypes[part.type]
169: false
170: elsif definedtype = @elements[part.element]
171: definedtype.elementform == 'qualified'
172: elsif definedtype = @complextypes[part.type]
173: false
174: else
175: raise RuntimeError.new("part: #{part.name} cannot be resolved")
176: end
177: end
# File lib/wsdl/soap/methodDefCreator.rb, line 194
194: def param2str(params)
195: params.collect { |param|
196: io, name, type, ele = param
197: unless ele.nil?
198: "[#{dq(io)}, #{dq(name)}, #{type2str(type)}, #{ele2str(ele)}]"
199: else
200: "[#{dq(io)}, #{dq(name)}, #{type2str(type)}]"
201: end
202: }.join(",\n")
203: end
# File lib/wsdl/soap/methodDefCreator.rb, line 179
179: def param_set(io_type, name, type, ele = nil)
180: [io_type, name, type, ele]
181: end
# File lib/wsdl/soap/methodDefCreator.rb, line 122
122: def rpcdefinedtype(part)
123: if mapped = basetype_mapped_class(part.type)
124: ['::' + mapped.name]
125: elsif definedtype = @simpletypes[part.type]
126: ['::' + basetype_mapped_class(definedtype.base).name]
127: elsif definedtype = @elements[part.element]
128: #['::SOAP::SOAPStruct', part.element.namespace, part.element.name]
129: ['nil', part.element.namespace, part.element.name]
130: elsif definedtype = @complextypes[part.type]
131: case definedtype.compoundtype
132: when :TYPE_STRUCT, :TYPE_EMPTY # ToDo: empty should be treated as void.
133: type = create_class_name(part.type)
134: [type, part.type.namespace, part.type.name]
135: when :TYPE_MAP
136: [Hash.name, part.type.namespace, part.type.name]
137: when :TYPE_ARRAY
138: arytype = definedtype.find_arytype || XSD::AnyTypeName
139: ns = arytype.namespace
140: name = arytype.name.sub(/\[(?:,)*\]$/, '')
141: type = create_class_name(XSD::QName.new(ns, name))
142: [type + '[]', ns, name]
143: else
144: raise NotImplementedError.new("must not reach here")
145: end
146: else
147: raise RuntimeError.new("part: #{part.name} cannot be resolved")
148: end
149: end