Changeset 2005
- Timestamp:
- 10/28/07 17:15:59 (1 year ago)
- Files:
-
- trunk/lib/soap/rpc/element.rb (modified) (6 diffs)
- trunk/lib/soap/rpc/methodDef.rb (added)
- trunk/lib/soap/rpc/proxy.rb (modified) (3 diffs)
- trunk/lib/soap/rpc/router.rb (modified) (4 diffs)
- trunk/lib/soap/wsdlDriver.rb (modified) (2 diffs)
- trunk/lib/wsdl/operation.rb (modified) (2 diffs)
- trunk/lib/wsdl/operationBinding.rb (modified) (4 diffs)
- trunk/lib/wsdl/soap/methodDefCreator.rb (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/soap/rpc/element.rb
r1970 r2005 8 8 9 9 require 'soap/baseData' 10 require 'soap/rpc/methodDef' 10 11 11 12 … … 70 71 71 72 class SOAPMethod < SOAPStruct 72 RETVAL = 'retval'73 IN = 'in'74 OUT = 'out'75 INOUT = 'inout'73 RETVAL = :retval 74 IN = :in 75 OUT = :out 76 INOUT = :inout 76 77 77 78 attr_reader :param_def … … 98 99 @retval_class_name = nil 99 100 100 init_param (@param_def) if @param_def101 init_params(@param_def) if @param_def 101 102 end 102 103 … … 152 153 def SOAPMethod.param_count(param_def, *type) 153 154 count = 0 154 param_def.each do |io_type, name, param_type| 155 if type.include?(io_type) 155 param_def.each do |param| 156 param = MethodDef.to_param(param) 157 if type.include?(param.io_type.to_sym) 156 158 count += 1 157 159 end … … 218 220 end 219 221 220 def init_param(param_def) 221 param_def.each do |io_type, name, param_type| 222 mapped_class, nsdef, namedef = SOAPMethod.parse_param_type(param_type) 223 if nsdef && namedef 224 type_qname = XSD::QName.new(nsdef, namedef) 225 elsif mapped_class 226 type_qname = TypeMap.index(mapped_class) 227 end 228 case io_type 229 when IN 230 @signature.push([IN, name, type_qname]) 231 @inparam_names.push(name) 232 when OUT 233 @signature.push([OUT, name, type_qname]) 234 @outparam_names.push(name) 235 when INOUT 236 @signature.push([INOUT, name, type_qname]) 237 @inoutparam_names.push(name) 238 when RETVAL 239 if @retval_name 240 raise MethodDefinitionError.new('duplicated retval') 241 end 242 @retval_name = name 243 @retval_class_name = mapped_class 244 else 245 raise MethodDefinitionError.new("unknown type: #{io_type}") 246 end 247 end 248 end 249 250 def self.parse_param_type(param_type) 251 mapped_class, nsdef, namedef = param_type 222 def init_params(param_def) 223 param_def.each do |param| 224 param = MethodDef.to_param(param) 225 init_param(param) 226 end 227 end 228 229 def init_param(param) 230 mapped_class = SOAPMethod.parse_mapped_class(param.mapped_class) 231 qname = param.qname 232 if qname.nil? and mapped_class 233 qname = TypeMap.index(mapped_class) 234 end 235 case param.io_type 236 when IN 237 @signature.push([IN, param.name, qname]) 238 @inparam_names.push(param.name) 239 when OUT 240 @signature.push([OUT, param.name, qname]) 241 @outparam_names.push(param.name) 242 when INOUT 243 @signature.push([INOUT, param.name, qname]) 244 @inoutparam_names.push(param.name) 245 when RETVAL 246 if @retval_name 247 raise MethodDefinitionError.new('duplicated retval') 248 end 249 @retval_name = param.name 250 @retval_class_name = mapped_class 251 else 252 raise MethodDefinitionError.new("unknown type: #{param.io_type}") 253 end 254 end 255 256 def self.parse_mapped_class(mapped_class) 252 257 # the first element of typedef in param_def can be a String like 253 258 # "::SOAP::SOAPStruct" or "CustomClass[]". turn this String to a class if … … 261 266 end 262 267 end 263 [mapped_class, nsdef, namedef]268 mapped_class 264 269 end 265 270 end trunk/lib/soap/rpc/proxy.rb
r2000 r2005 378 378 else 379 379 @doc_request_qnames = [] 380 @doc_request_qualified = []381 380 @doc_response_qnames = [] 382 @doc_response_qualified = [] 383 param_def.each do |inout, paramname, typeinfo, eleinfo| 384 klass_not_used, nsdef, namedef = typeinfo 385 qualified = eleinfo 386 if namedef.nil? 387 raise MethodDefinitionError.new("qname must be given") 388 end 389 case inout 381 param_def.each do |param| 382 param = MethodDef.to_param(param) 383 case param.io_type 390 384 when SOAPMethod::IN 391 @doc_request_qnames << XSD::QName.new(nsdef, namedef) 392 @doc_request_qualified << qualified 385 @doc_request_qnames << param.qname 393 386 when SOAPMethod::OUT 394 @doc_response_qnames << XSD::QName.new(nsdef, namedef) 395 @doc_response_qualified << qualified 387 @doc_response_qnames << param.qname 396 388 else 397 389 raise MethodDefinitionError.new( 398 "illegal inout definition for document style: #{ inout}")390 "illegal inout definition for document style: #{param.io_type}") 399 391 end 400 392 end … … 504 496 ele = Mapping.obj2soap(values[idx], mapping_registry, nil, opt) 505 497 ele.elename = @doc_request_qnames[idx] 506 ele.qualified = @doc_request_qualified[idx]507 498 ele 508 499 } … … 514 505 @doc_request_qnames[idx], opt) 515 506 ele.encodingstyle = LiteralNamespace 516 ele.qualified = @doc_request_qualified[idx]517 507 ele 518 508 } trunk/lib/soap/rpc/router.rb
r1974 r2005 218 218 219 219 def first_input_part_qname(param_def) 220 param_def.each do | inout, paramname, typeinfo|221 if inout == SOAPMethod::IN222 klass, nsdef, namedef = typeinfo223 return XSD::QName.new(nsdef, namedef)220 param_def.each do |param| 221 param = MethodDef.to_param(param) 222 if param.io_type == SOAPMethod::IN 223 return param.qname 224 224 end 225 225 end … … 424 424 else 425 425 @doc_request_qnames = [] 426 @doc_request_qualified = []427 426 @doc_response_qnames = [] 428 @doc_response_qualified = [] 429 param_def.each do |inout, paramname, typeinfo, eleinfo| 430 klass, nsdef, namedef = typeinfo 431 qualified = eleinfo 432 case inout 427 param_def.each do |param| 428 param = MethodDef.to_param(param) 429 case param.io_type 433 430 when SOAPMethod::IN 434 @doc_request_qnames << XSD::QName.new(nsdef, namedef) 435 @doc_request_qualified << qualified 431 @doc_request_qnames << param.qname 436 432 when SOAPMethod::OUT 437 @doc_response_qnames << XSD::QName.new(nsdef, namedef) 438 @doc_response_qualified << qualified 433 @doc_response_qnames << param.qname 439 434 else 440 435 raise ArgumentError.new( 441 "illegal inout definition for document style: #{ inout}")436 "illegal inout definition for document style: #{param.io_type}") 442 437 end 443 438 end … … 606 601 ele = Mapping.obj2soap(result[idx], mapping_registry, nil, opt) 607 602 ele.elename = @doc_response_qnames[idx] 608 ele.qualified = @doc_response_qualified[idx]609 603 ele 610 604 } … … 616 610 @doc_response_qnames[idx]) 617 611 ele.encodingstyle = LiteralNamespace 618 ele.qualified = @doc_response_qualified[idx]619 612 ele 620 613 } trunk/lib/soap/wsdlDriver.rb
r2004 r2005 127 127 def add_operation(drv, port) 128 128 port.find_binding.operations.each do |op_bind| 129 op_name = op_bind.soapoperation_name 130 soapaction = op_bind.soapaction || '' 131 orgname = op_name.name 132 name = XSD::CodeGen::GenSupport.safemethodname(orgname) 133 param_def = create_param_def(op_bind) 129 mdef = @methoddefcreator.create_methoddef(op_bind) 134 130 opt = { 135 :request_style => op_bind.soapoperation_style,136 :response_style => op_bind.soapoperation_style,137 :request_use => op_bind.soapbody_use_input,138 :response_use => op_bind.soapbody_use_output131 :request_style => mdef.style, 132 :response_style => mdef.style, 133 :request_use => mdef.inputuse, 134 :response_use => mdef.outputuse 139 135 } 140 if op_bind.soapoperation_style == :rpc 141 drv.add_rpc_operation(op_name, soapaction, name, param_def, opt) 136 qname = mdef.qname 137 soapaction = mdef.soapaction 138 name = mdef.name 139 if mdef.style == :rpc 140 drv.add_rpc_operation(qname, soapaction, name, mdef.parameters, opt) 142 141 else 143 drv.add_document_operation(soapaction, name, param_def, opt)142 drv.add_document_operation(soapaction, name, mdef.parameters, opt) 144 143 end 144 orgname = mdef.qname.name 145 145 if orgname != name and orgname.capitalize == name.capitalize 146 146 ::SOAP::Mapping.define_singleton_method(drv, orgname) do |*arg| … … 154 154 WSDL::Importer.import(location) 155 155 end 156 157 def create_param_def(op_bind)158 op = op_bind.find_operation159 if op_bind.soapoperation_style == :rpc160 param_def = @methoddefcreator.collect_rpcparameter(op)161 else162 param_def = @methoddefcreator.collect_documentparameter(op)163 end164 # the first element of typedef in param_def is a String like165 # "::SOAP::SOAPStruct". turn this String to a class.166 param_def.collect { |io_type, name, param_type|167 [io_type, name, ::SOAP::RPC::SOAPMethod.parse_param_type(param_type)]168 }169 end170 171 def partqname(part)172 if part.type173 part.type174 else175 part.element176 end177 end178 179 def param_def(type, name, klass, partqname)180 [type, name, [klass, partqname.namespace, partqname.name]]181 end182 183 def filter_parts(partsdef, partssource)184 parts = partsdef.split(/\s+/)185 partssource.find_all { |part| parts.include?(part.name) }186 end187 156 end 188 157 trunk/lib/wsdl/operation.rb
r2004 r2005 40 40 41 41 EMPTY = [].freeze 42 # TODO: remove once after OperationInfo created 42 43 def inputparts 43 44 if message = input_message … … 56 57 end 57 58 59 # TODO: remove once after OperationInfo created 58 60 def outputparts 59 61 if message = output_message trunk/lib/wsdl/operationBinding.rb
r2003 r2005 19 19 attr_reader :fault 20 20 attr_reader :soapoperation 21 22 class OperationInfo 23 attr_reader :boundid 24 attr_reader :qname 25 attr_reader :style 26 attr_accessor :inputuse 27 attr_accessor :outputuse 28 attr_reader :parts 29 attr_reader :faults 30 31 def initialize(boundid, qname, style, inputuse, outputuse) 32 @boundid = boundid 33 @qname = qname 34 @style = style 35 @inputuse = inputuse 36 @outputuse = outputuse 37 @parts = [] 38 @faults = {} 39 end 40 end 41 42 class Part 43 attr_reader :io_type 44 attr_reader :name 45 attr_reader :type 46 attr_reader :element 47 48 def initialize(io_type, name, type, element) 49 @io_type = io_type 50 @name = name 51 @type = type 52 @element = element 53 end 54 end 21 55 22 56 class BoundId … … 49 83 @fault = [] 50 84 @soapoperation = nil 85 end 86 87 def operation_info 88 qname = soapoperation_name() 89 style = soapoperation_style() 90 use_input = soapbody_use(@input) 91 use_output = soapbody_use(@output) 92 info = OperationInfo.new(boundid, qname, style, use_input, use_output) 93 op = find_operation() 94 if style == :rpc 95 info.parts.concat(collect_rpcparameter(op)) 96 else 97 info.parts.concat(collect_documentparameter(op)) 98 end 99 @fault.each do |fault| 100 op_fault = {} 101 soapfault = fault.soapfault 102 next if soapfault.nil? 103 op_fault[:ns] = fault.name.namespace 104 op_fault[:name] = fault.name.name 105 op_fault[:namespace] = soapfault.namespace 106 op_fault[:use] = soapfault.use || "literal" 107 op_fault[:encodingstyle] = soapfault.encodingstyle || "document" 108 info.faults[fault.name] = op_fault 109 end 110 info 51 111 end 52 112 … … 95 155 end 96 156 97 def soapbody_use_input98 soapbody_use(@input)99 end100 101 def soapbody_use_output102 soapbody_use(@output)103 end104 105 157 def soapaction 106 158 if @soapoperation … … 151 203 param ? param.soapbody_use : nil 152 204 end 205 206 def collect_rpcparameter(operation) 207 result = operation.inputparts.collect { |part| 208 Part.new(:in, part.name, part.type, part.element) 209 } 210 outparts = operation.outputparts 211 if outparts.size > 0 212 retval = outparts[0] 213 result << Part.new(:retval, retval.name, retval.type, retval.element) 214 cdr(outparts).each { |part| 215 result << Part.new(:out, part.name, part.type, part.element) 216 } 217 end 218 result 219 end 220 221 def collect_documentparameter(operation) 222 param = [] 223 operation.inputparts.each do |input| 224 param << Part.new(:in, input.name, input.type, input.element) 225 end 226 operation.outputparts.each do |output| 227 param << Part.new(:out, output.name, output.type, output.element) 228 end 229 param 230 end 231 232 def cdr(ary) 233 result = ary.dup 234 result.shift 235 result 236 end 153 237 end 154 238 trunk/lib/wsdl/soap/methodDefCreator.rb
r2004 r2005 1 # WSDL4R - Creating driver code from WSDL.1 # WSDL4R - Creating method definition from WSDL 2 2 # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>. 3 3 … … 10 10 require 'wsdl/soap/classDefCreatorSupport' 11 11 require 'soap/rpc/element' 12 require 'soap/rpc/methodDef' 12 13 13 14 … … 62 63 end 63 64 64 def collect_rpcparameter(operation) 65 result = operation.inputparts.collect { |part| 66 collect_type(part.type) 67 param_set(::SOAP::RPC::SOAPMethod::IN, part.name, rpcdefinedtype(part)) 68 } 69 outparts = operation.outputparts 70 if outparts.size > 0 71 retval = outparts[0] 72 collect_type(retval.type) 73 result << param_set(::SOAP::RPC::SOAPMethod::RETVAL, retval.name, 74 rpcdefinedtype(retval)) 75 cdr(outparts).each { |part| 76 collect_type(part.type) 77 result << param_set(::SOAP::RPC::SOAPMethod::OUT, part.name, 78 rpcdefinedtype(part)) 79 } 80 end 81 result 82 end 83 84 def collect_documentparameter(operation) 85 param = [] 86 operation.inputparts.each do |input| 87 param << param_set(::SOAP::RPC::SOAPMethod::IN, input.name, 88 documentdefinedtype(input)) 89 end 90 operation.outputparts.each do |output| 91 param << param_set(::SOAP::RPC::SOAPMethod::OUT, output.name, 92 documentdefinedtype(output)) 93 end 94 param 65 def create_methoddef(op_bind) 66 op_info = op_bind.operation_info 67 name = assign_method_name(op_bind) 68 soapaction = op_info.boundid.soapaction 69 qname = op_bind.soapoperation_name 70 style = op_info.style 71 inputuse = op_info.inputuse 72 outputuse = op_info.outputuse 73 mdef = ::SOAP::RPC::MethodDef.new(name, soapaction, qname) 74 op_info.parts.each do |part| 75 if style == :rpc 76 collect_type(part.type) 77 mapped_class, qname = rpcdefinedtype(part) 78 else 79 mapped_class, qname = documentdefinedtype(part) 80 end 81 mdef.add_parameter(part.io_type, part.name, qname, mapped_class) 82 end 83 op_info.faults.each do |name, faultinfo| 84 faultclass = mapped_class_name(name, @modulepath) 85 mdef.faults[faultclass] = faultinfo 86 end 87 mdef.style = op_info.style 88 mdef.inputuse = op_info.inputuse 89 mdef.outputuse = op_info.outputuse 90 mdef 95 91 end 96 92 … … 98 94 99 95 def dump_method(op_bind) 100 operation = op_bind.find_operation 101 op_faults = {} 102 op_bind.fault.each do |fault| 103 op_fault = {} 104 soapfault = fault.soapfault 105 next if soapfault.nil? 106 faultclass = mapped_class_name(fault.name, @modulepath) 107 op_fault[:ns] = fault.name.namespace 108 op_fault[:name] = fault.name.name 109 op_fault[:namespace] = soapfault.namespace 110 op_fault[:use] = soapfault.use || "literal" 111 op_fault[:encodingstyle] = soapfault.encodingstyle || "document" 112 op_faults[faultclass] = op_fault 113 end 114 op_faults_str = op_faults.inspect 115 name = assign_method_name(op_bind) 116 style = op_bind.soapoperation_style 117 inputuse = op_bind.soapbody_use_input 118 outputuse = op_bind.soapbody_use_output 119 if style == :rpc 120 qname = op_bind.soapoperation_name 121 paramstr = param2str(collect_rpcparameter(operation)) 122 else 123 qname = nil 124 paramstr = param2str(collect_documentparameter(operation)) 125 end 96 mdef = create_methoddef(op_bind) 97 style = mdef.style 98 inputuse = mdef.inputuse 99 outputuse = mdef.outputuse 100 paramstr = param2str(mdef.parameters) 126 101 if paramstr.empty? 127 102 paramstr = '[]' … … 130 105 end 131 106 definitions = <<__EOD__ 132 #{ndq( op_bind.soapaction)},133 #{dq( name)},107 #{ndq(mdef.soapaction)}, 108 #{dq(mdef.name)}, 134 109 #{paramstr}, 135 110 { :request_style => #{nsym(style)}, :request_use => #{nsym(inputuse)}, 136 111 :response_style => #{nsym(style)}, :response_use => #{nsym(outputuse)}, 137 :faults => #{ op_faults_str} }112 :faults => #{mdef.faults.inspect} } 138 113 __EOD__ 139 114 if inputuse == :encoded or outputuse == :encoded … … 144 119 end 145 120 if style == :rpc 146 assign_const( qname.namespace, 'Ns')121 assign_const(mdef.qname.namespace, 'Ns') 147 122 return <<__EOD__ 148 [ #{dqname( qname)},123 [ #{dqname(mdef.qname)}, 149 124 #{definitions}] 150 125 __EOD__ … … 169 144 def rpcdefinedtype(part) 170 145 if mapped = basetype_mapped_class(part.type) 171 ['::' + mapped.name]146 return ['::' + mapped.name, nil] 172 147 elsif definedtype = @simpletypes[part.type] 173 [nil, definedtype.name.namespace, definedtype.name.name]148 return [nil, definedtype.name] 174 149 elsif definedtype = @elements[part.element] 175 [nil, part.element.namespace, part.element.name]150 return [nil, part.element] 176 151 elsif definedtype = @complextypes[part.type] 177 152 case definedtype.compoundtype 178 153 when :TYPE_STRUCT, :TYPE_EMPTY, :TYPE_ARRAY, :TYPE_SIMPLE 179 154 type = mapped_class_name(part.type, @modulepath) 180 [type, part.type.namespace, part.type.name]155 return [type, part.type] 181 156 when :TYPE_MAP 182 [Hash.name, part.type.namespace, part.type.name]157 return [Hash.name, part.type] 183 158 else 184 159 raise NotImplementedError.new("must not reach here: #{definedtype.compoundtype}") 185 160 end 186 161 elsif part.type == XSD::AnyTypeName 187 [nil]162 return [nil, nil] 188 163 else 189 164 raise RuntimeError.new("part: #{part.name} cannot be resolved") … … 193 168 def documentdefinedtype(part) 194 169 if mapped = basetype_mapped_class(part.type) 195 ['::' + mapped.name, nil, part.name]170 return ['::' + mapped.name, XSD::QName.new(nil, part.name)] 196 171 elsif definedtype = @simpletypes[part.type] 197 172 if definedtype.base 198 ['::' + basetype_mapped_class(definedtype.base).name, nil, part.name]173 return ['::' + basetype_mapped_class(definedtype.base).name, XSD::QName.new(nil, part.name)] 199 174 else 200 175 raise RuntimeError.new("unsupported simpleType: #{definedtype}") 201 176 end 202 177 elsif definedtype = @elements[part.element] 203 ['::SOAP::SOAPElement', part.element.namespace, part.element.name]178 return ['::SOAP::SOAPElement', part.element] 204 179 elsif definedtype = @complextypes[part.type] 205 ['::SOAP::SOAPElement', part.type.namespace, part.type.name]180 return ['::SOAP::SOAPElement', part.type] 206 181 else 207 182 raise RuntimeError.new("part: #{part.name} cannot be resolved") 208 183 end 209 end210 211 def param_set(io_type, name, type, ele = nil)212 [io_type, name, type, ele]213 184 end 214 185 … … 239 210 def param2str(params) 240 211 params.collect { |param| 241 io, name, type, ele = param 242 unless ele.nil? 243 "[#{dq(io)}, #{dq(name)}, #{type2str(type)}, #{ele2str(ele)}]" 244 else 245 "[#{dq(io)}, #{dq(name)}, #{type2str(type)}]" 246 end 212 mappingstr = mapping_info2str(param.mapped_class, param.qname) 213 "[:#{param.io_type.id2name}, #{dq(param.name)}, #{mappingstr}]" 247 214 }.join(",\n") 248 215 end 249 216 250 def type2str(type)251 if type.size == 1252 "[#{ndq( type[0])}]"253 else 254 "[#{ndq( type[0])}, #{ndq(type[1])}, #{dq(type[2])}]"217 def mapping_info2str(mapped_class, qname) 218 if qname.nil? 219 "[#{ndq(mapped_class)}]" 220 else 221 "[#{ndq(mapped_class)}, #{ndq(qname.namespace)}, #{dq(qname.name)}]" 255 222 end 256 223 end … … 264 231 end 265 232 end 266 267 def cdr(ary)268 result = ary.dup269 result.shift270 result271 end272 233 end 273 234