Permalink
Browse files

* introduce SOAP::RPC::MethodDef and use it instead of complex Array…

… structure.

 * param type 'in', 'out', 'retval' -> :in, :out, :retval


git-svn-id: http://dev.ctor.org/svn/soap4r/trunk@2005 23c4dcf6-64ea-0310-84d7-d424c7495ec0
  • Loading branch information...
1 parent 1355672 commit c8e296654b7a691b5fad178b6fc9d7f080eaafe2 @nahi nahi committed Oct 28, 2007
View
@@ -7,6 +7,7 @@
require 'soap/baseData'
+require 'soap/rpc/methodDef'
module SOAP
@@ -69,10 +70,10 @@ class MethodDefinitionError < RPCError; end
class ParameterError < RPCError; end
class SOAPMethod < SOAPStruct
- RETVAL = 'retval'
- IN = 'in'
- OUT = 'out'
- INOUT = 'inout'
+ RETVAL = :retval
+ IN = :in
+ OUT = :out
+ INOUT = :inout
attr_reader :param_def
attr_reader :inparam
@@ -97,7 +98,7 @@ def initialize(qname, param_def = nil)
@retval_name = nil
@retval_class_name = nil
- init_param(@param_def) if @param_def
+ init_params(@param_def) if @param_def
end
def have_member
@@ -151,8 +152,9 @@ def get_paramtypes(names)
def SOAPMethod.param_count(param_def, *type)
count = 0
- param_def.each do |io_type, name, param_type|
- if type.include?(io_type)
+ param_def.each do |param|
+ param = MethodDef.to_param(param)
+ if type.include?(param.io_type.to_sym)
count += 1
end
end
@@ -217,38 +219,41 @@ def collect_params(*type)
names
end
- def init_param(param_def)
- param_def.each do |io_type, name, param_type|
- mapped_class, nsdef, namedef = SOAPMethod.parse_param_type(param_type)
- if nsdef && namedef
- type_qname = XSD::QName.new(nsdef, namedef)
- elsif mapped_class
- type_qname = TypeMap.index(mapped_class)
- end
- case io_type
- when IN
- @signature.push([IN, name, type_qname])
- @inparam_names.push(name)
- when OUT
- @signature.push([OUT, name, type_qname])
- @outparam_names.push(name)
- when INOUT
- @signature.push([INOUT, name, type_qname])
- @inoutparam_names.push(name)
- when RETVAL
- if @retval_name
- raise MethodDefinitionError.new('duplicated retval')
- end
- @retval_name = name
- @retval_class_name = mapped_class
- else
- raise MethodDefinitionError.new("unknown type: #{io_type}")
+ def init_params(param_def)
+ param_def.each do |param|
+ param = MethodDef.to_param(param)
+ init_param(param)
+ end
+ end
+
+ def init_param(param)
+ mapped_class = SOAPMethod.parse_mapped_class(param.mapped_class)
+ qname = param.qname
+ if qname.nil? and mapped_class
+ qname = TypeMap.index(mapped_class)
+ end
+ case param.io_type
+ when IN
+ @signature.push([IN, param.name, qname])
+ @inparam_names.push(param.name)
+ when OUT
+ @signature.push([OUT, param.name, qname])
+ @outparam_names.push(param.name)
+ when INOUT
+ @signature.push([INOUT, param.name, qname])
+ @inoutparam_names.push(param.name)
+ when RETVAL
+ if @retval_name
+ raise MethodDefinitionError.new('duplicated retval')
end
+ @retval_name = param.name
+ @retval_class_name = mapped_class
+ else
+ raise MethodDefinitionError.new("unknown type: #{param.io_type}")
end
end
- def self.parse_param_type(param_type)
- mapped_class, nsdef, namedef = param_type
+ def self.parse_mapped_class(mapped_class)
# the first element of typedef in param_def can be a String like
# "::SOAP::SOAPStruct" or "CustomClass[]". turn this String to a class if
# we can.
@@ -260,7 +265,7 @@ def self.parse_param_type(param_type)
mapped_class = Mapping.class_from_name(mapped_class)
end
end
- [mapped_class, nsdef, namedef]
+ mapped_class
end
end
View
@@ -0,0 +1,68 @@
+# SOAP4R - A method definition
+# Copyright (C) 2000-2007 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.
+
+
+module SOAP
+module RPC
+
+
+class MethodDef
+ attr_reader :name
+ attr_reader :soapaction
+ attr_reader :qname
+ attr_accessor :style
+ attr_accessor :inputuse
+ attr_accessor :outputuse
+ attr_reader :parameters
+ attr_reader :faults
+
+ def initialize(name, soapaction, qname)
+ @name = name
+ @soapaction = soapaction
+ @qname = qname
+ @style = @inputuse = @outputuse = nil
+ @parameters = []
+ @faults = {}
+ end
+
+ def add_parameter(io_type, name, qname, mapped_class)
+ @parameters << Parameter.new(io_type, name, qname, mapped_class)
+ end
+
+ def self.to_param(param)
+ if param.respond_to?(:io_type)
+ param
+ else
+ io_type, name, param_type = param
+ mapped_class_str, nsdef, namedef = param_type
+ if nsdef && namedef
+ qname = XSD::QName.new(nsdef, namedef)
+ else
+ qname = nil
+ end
+ MethodDef::Parameter.new(io_type.to_sym, name, qname, mapped_class_str)
+ end
+ end
+
+ class Parameter
+ attr_reader :io_type
+ attr_reader :name
+ attr_reader :qname
+ attr_reader :mapped_class
+
+ def initialize(io_type, name, qname, mapped_class)
+ @io_type = io_type
+ @name = name
+ @qname = qname
+ @mapped_class = mapped_class
+ end
+ end
+end
+
+
+end
+end
View
@@ -377,25 +377,17 @@ def initialize(soapaction, param_def, opt)
RPC::SOAPMethodRequest.new(@rpc_request_qname, param_def, @soapaction)
else
@doc_request_qnames = []
- @doc_request_qualified = []
@doc_response_qnames = []
- @doc_response_qualified = []
- param_def.each do |inout, paramname, typeinfo, eleinfo|
- klass_not_used, nsdef, namedef = typeinfo
- qualified = eleinfo
- if namedef.nil?
- raise MethodDefinitionError.new("qname must be given")
- end
- case inout
+ param_def.each do |param|
+ param = MethodDef.to_param(param)
+ case param.io_type
when SOAPMethod::IN
- @doc_request_qnames << XSD::QName.new(nsdef, namedef)
- @doc_request_qualified << qualified
+ @doc_request_qnames << param.qname
when SOAPMethod::OUT
- @doc_response_qnames << XSD::QName.new(nsdef, namedef)
- @doc_response_qualified << qualified
+ @doc_response_qnames << param.qname
else
raise MethodDefinitionError.new(
- "illegal inout definition for document style: #{inout}")
+ "illegal inout definition for document style: #{param.io_type}")
end
end
end
@@ -503,7 +495,6 @@ def request_doc_enc(values, mapping_registry, opt)
(0...values.size).collect { |idx|
ele = Mapping.obj2soap(values[idx], mapping_registry, nil, opt)
ele.elename = @doc_request_qnames[idx]
- ele.qualified = @doc_request_qualified[idx]
ele
}
end
@@ -513,7 +504,6 @@ def request_doc_lit(values, mapping_registry, opt)
ele = Mapping.obj2soap(values[idx], mapping_registry,
@doc_request_qnames[idx], opt)
ele.encodingstyle = LiteralNamespace
- ele.qualified = @doc_request_qualified[idx]
ele
}
end
View
@@ -217,10 +217,10 @@ def create_fault_response(e)
private
def first_input_part_qname(param_def)
- param_def.each do |inout, paramname, typeinfo|
- if inout == SOAPMethod::IN
- klass, nsdef, namedef = typeinfo
- return XSD::QName.new(nsdef, namedef)
+ param_def.each do |param|
+ param = MethodDef.to_param(param)
+ if param.io_type == SOAPMethod::IN
+ return param.qname
end
end
nil
@@ -423,22 +423,17 @@ def initialize(soapaction, name, param_def, opt)
@rpc_response_qname = opt[:response_qname]
else
@doc_request_qnames = []
- @doc_request_qualified = []
@doc_response_qnames = []
- @doc_response_qualified = []
- param_def.each do |inout, paramname, typeinfo, eleinfo|
- klass, nsdef, namedef = typeinfo
- qualified = eleinfo
- case inout
+ param_def.each do |param|
+ param = MethodDef.to_param(param)
+ case param.io_type
when SOAPMethod::IN
- @doc_request_qnames << XSD::QName.new(nsdef, namedef)
- @doc_request_qualified << qualified
+ @doc_request_qnames << param.qname
when SOAPMethod::OUT
- @doc_response_qnames << XSD::QName.new(nsdef, namedef)
- @doc_response_qualified << qualified
+ @doc_response_qnames << param.qname
else
raise ArgumentError.new(
- "illegal inout definition for document style: #{inout}")
+ "illegal inout definition for document style: #{param.io_type}")
end
end
end
@@ -605,7 +600,6 @@ def response_doc_enc(result, mapping_registry, opt)
(0...result.size).collect { |idx|
ele = Mapping.obj2soap(result[idx], mapping_registry, nil, opt)
ele.elename = @doc_response_qnames[idx]
- ele.qualified = @doc_response_qualified[idx]
ele
}
end
@@ -615,7 +609,6 @@ def response_doc_lit(result, mapping_registry, opt)
ele = Mapping.obj2soap(result[idx], mapping_registry,
@doc_response_qnames[idx])
ele.encodingstyle = LiteralNamespace
- ele.qualified = @doc_response_qualified[idx]
ele
}
end
View
@@ -126,22 +126,22 @@ def init_driver(drv, port)
def add_operation(drv, port)
port.find_binding.operations.each do |op_bind|
- op_name = op_bind.soapoperation_name
- soapaction = op_bind.soapaction || ''
- orgname = op_name.name
- name = XSD::CodeGen::GenSupport.safemethodname(orgname)
- param_def = create_param_def(op_bind)
+ mdef = @methoddefcreator.create_methoddef(op_bind)
opt = {
- :request_style => op_bind.soapoperation_style,
- :response_style => op_bind.soapoperation_style,
- :request_use => op_bind.soapbody_use_input,
- :response_use => op_bind.soapbody_use_output
+ :request_style => mdef.style,
+ :response_style => mdef.style,
+ :request_use => mdef.inputuse,
+ :response_use => mdef.outputuse
}
- if op_bind.soapoperation_style == :rpc
- drv.add_rpc_operation(op_name, soapaction, name, param_def, opt)
+ qname = mdef.qname
+ soapaction = mdef.soapaction
+ name = mdef.name
+ if mdef.style == :rpc
+ drv.add_rpc_operation(qname, soapaction, name, mdef.parameters, opt)
else
- drv.add_document_operation(soapaction, name, param_def, opt)
+ drv.add_document_operation(soapaction, name, mdef.parameters, opt)
end
+ orgname = mdef.qname.name
if orgname != name and orgname.capitalize == name.capitalize
::SOAP::Mapping.define_singleton_method(drv, orgname) do |*arg|
__send__(name, *arg)
@@ -153,37 +153,6 @@ def add_operation(drv, port)
def import(location)
WSDL::Importer.import(location)
end
-
- def create_param_def(op_bind)
- op = op_bind.find_operation
- if op_bind.soapoperation_style == :rpc
- param_def = @methoddefcreator.collect_rpcparameter(op)
- else
- param_def = @methoddefcreator.collect_documentparameter(op)
- end
- # the first element of typedef in param_def is a String like
- # "::SOAP::SOAPStruct". turn this String to a class.
- param_def.collect { |io_type, name, param_type|
- [io_type, name, ::SOAP::RPC::SOAPMethod.parse_param_type(param_type)]
- }
- end
-
- def partqname(part)
- if part.type
- part.type
- else
- part.element
- end
- end
-
- def param_def(type, name, klass, partqname)
- [type, name, [klass, partqname.namespace, partqname.name]]
- end
-
- def filter_parts(partsdef, partssource)
- parts = partsdef.split(/\s+/)
- partssource.find_all { |part| parts.include?(part.name) }
- end
end
View
@@ -39,6 +39,7 @@ def operationname
end
EMPTY = [].freeze
+ # TODO: remove once after OperationInfo created
def inputparts
if message = input_message
sort_parts(message.parts)
@@ -55,6 +56,7 @@ def inputname
end
end
+ # TODO: remove once after OperationInfo created
def outputparts
if message = output_message
sort_parts(message.parts)
Oops, something went wrong.

0 comments on commit c8e2966

Please sign in to comment.