Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Changeset 2005

Show
Ignore:
Timestamp:
10/28/07 17:15:59 (1 year ago)
Author:
nahi
Message:
  • introduce SOAP::RPC::MethodDef? and use it instead of complex Array structure.
  • param type 'in', 'out', 'retval' -> :in, :out, :retval
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/soap/rpc/element.rb

    r1970 r2005  
    88 
    99require 'soap/baseData' 
     10require 'soap/rpc/methodDef' 
    1011 
    1112 
     
    7071 
    7172class 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 
    7677 
    7778  attr_reader :param_def 
     
    9899    @retval_class_name = nil 
    99100 
    100     init_param(@param_def) if @param_def 
     101    init_params(@param_def) if @param_def 
    101102  end 
    102103 
     
    152153  def SOAPMethod.param_count(param_def, *type) 
    153154    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) 
    156158        count += 1 
    157159      end 
     
    218220  end 
    219221 
    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) 
    252257    # the first element of typedef in param_def can be a String like 
    253258    # "::SOAP::SOAPStruct" or "CustomClass[]".  turn this String to a class if 
     
    261266      end 
    262267    end 
    263     [mapped_class, nsdef, namedef] 
     268    mapped_class 
    264269  end 
    265270end 
  • trunk/lib/soap/rpc/proxy.rb

    r2000 r2005  
    378378      else 
    379379        @doc_request_qnames = [] 
    380         @doc_request_qualified = [] 
    381380        @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 
    390384          when SOAPMethod::IN 
    391             @doc_request_qnames << XSD::QName.new(nsdef, namedef) 
    392             @doc_request_qualified << qualified 
     385            @doc_request_qnames << param.qname 
    393386          when SOAPMethod::OUT 
    394             @doc_response_qnames << XSD::QName.new(nsdef, namedef) 
    395             @doc_response_qualified << qualified 
     387            @doc_response_qnames << param.qname 
    396388          else 
    397389            raise MethodDefinitionError.new( 
    398               "illegal inout definition for document style: #{inout}") 
     390              "illegal inout definition for document style: #{param.io_type}") 
    399391          end 
    400392        end 
     
    504496        ele = Mapping.obj2soap(values[idx], mapping_registry, nil, opt) 
    505497        ele.elename = @doc_request_qnames[idx] 
    506         ele.qualified = @doc_request_qualified[idx] 
    507498        ele 
    508499      } 
     
    514505          @doc_request_qnames[idx], opt) 
    515506        ele.encodingstyle = LiteralNamespace 
    516         ele.qualified = @doc_request_qualified[idx] 
    517507        ele 
    518508      } 
  • trunk/lib/soap/rpc/router.rb

    r1974 r2005  
    218218 
    219219  def first_input_part_qname(param_def) 
    220     param_def.each do |inout, paramname, typeinfo
    221       if inout == SOAPMethod::IN 
    222         klass, nsdef, namedef = typeinfo 
    223         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 
    224224      end 
    225225    end 
     
    424424      else 
    425425        @doc_request_qnames = [] 
    426         @doc_request_qualified = [] 
    427426        @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 
    433430          when SOAPMethod::IN 
    434             @doc_request_qnames << XSD::QName.new(nsdef, namedef) 
    435             @doc_request_qualified << qualified 
     431            @doc_request_qnames << param.qname 
    436432          when SOAPMethod::OUT 
    437             @doc_response_qnames << XSD::QName.new(nsdef, namedef) 
    438             @doc_response_qualified << qualified 
     433            @doc_response_qnames << param.qname 
    439434          else 
    440435            raise ArgumentError.new( 
    441               "illegal inout definition for document style: #{inout}") 
     436              "illegal inout definition for document style: #{param.io_type}") 
    442437          end 
    443438        end 
     
    606601        ele = Mapping.obj2soap(result[idx], mapping_registry, nil, opt) 
    607602        ele.elename = @doc_response_qnames[idx] 
    608         ele.qualified = @doc_response_qualified[idx] 
    609603        ele 
    610604      } 
     
    616610          @doc_response_qnames[idx]) 
    617611        ele.encodingstyle = LiteralNamespace 
    618         ele.qualified = @doc_response_qualified[idx] 
    619612        ele 
    620613      } 
  • trunk/lib/soap/wsdlDriver.rb

    r2004 r2005  
    127127  def add_operation(drv, port) 
    128128    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) 
    134130      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_output 
     131        :request_style => mdef.style, 
     132        :response_style => mdef.style, 
     133        :request_use => mdef.inputuse
     134        :response_use => mdef.outputuse 
    139135      } 
    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) 
    142141      else 
    143         drv.add_document_operation(soapaction, name, param_def, opt) 
     142        drv.add_document_operation(soapaction, name, mdef.parameters, opt) 
    144143      end 
     144      orgname = mdef.qname.name 
    145145      if orgname != name and orgname.capitalize == name.capitalize 
    146146        ::SOAP::Mapping.define_singleton_method(drv, orgname) do |*arg| 
     
    154154    WSDL::Importer.import(location) 
    155155  end 
    156  
    157   def create_param_def(op_bind) 
    158     op = op_bind.find_operation 
    159     if op_bind.soapoperation_style == :rpc 
    160       param_def = @methoddefcreator.collect_rpcparameter(op) 
    161     else 
    162       param_def = @methoddefcreator.collect_documentparameter(op) 
    163     end 
    164     # the first element of typedef in param_def is a String like 
    165     # "::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   end 
    170  
    171   def partqname(part) 
    172     if part.type 
    173       part.type 
    174     else 
    175       part.element 
    176     end 
    177   end 
    178  
    179   def param_def(type, name, klass, partqname) 
    180     [type, name, [klass, partqname.namespace, partqname.name]] 
    181   end 
    182  
    183   def filter_parts(partsdef, partssource) 
    184     parts = partsdef.split(/\s+/) 
    185     partssource.find_all { |part| parts.include?(part.name) } 
    186   end 
    187156end 
    188157 
  • trunk/lib/wsdl/operation.rb

    r2004 r2005  
    4040 
    4141  EMPTY = [].freeze 
     42  # TODO: remove once after OperationInfo created 
    4243  def inputparts 
    4344    if message = input_message 
     
    5657  end 
    5758 
     59  # TODO: remove once after OperationInfo created 
    5860  def outputparts 
    5961    if message = output_message 
  • trunk/lib/wsdl/operationBinding.rb

    r2003 r2005  
    1919  attr_reader :fault 
    2020  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 
    2155 
    2256  class BoundId 
     
    4983    @fault = [] 
    5084    @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 
    51111  end 
    52112 
     
    95155  end 
    96156 
    97   def soapbody_use_input 
    98     soapbody_use(@input) 
    99   end 
    100  
    101   def soapbody_use_output 
    102     soapbody_use(@output) 
    103   end 
    104  
    105157  def soapaction 
    106158    if @soapoperation 
     
    151203    param ? param.soapbody_use : nil 
    152204  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 
    153237end 
    154238 
  • trunk/lib/wsdl/soap/methodDefCreator.rb

    r2004 r2005  
    1 # WSDL4R - Creating driver code from WSDL. 
     1# WSDL4R - Creating method definition from WSDL 
    22# Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>. 
    33 
     
    1010require 'wsdl/soap/classDefCreatorSupport' 
    1111require 'soap/rpc/element' 
     12require 'soap/rpc/methodDef' 
    1213 
    1314 
     
    6263  end 
    6364 
    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 
    9591  end 
    9692 
     
    9894 
    9995  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) 
    126101    if paramstr.empty? 
    127102      paramstr = '[]' 
     
    130105    end 
    131106    definitions = <<__EOD__ 
    132 #{ndq(op_bind.soapaction)}, 
    133   #{dq(name)}, 
     107#{ndq(mdef.soapaction)}, 
     108  #{dq(mdef.name)}, 
    134109  #{paramstr}, 
    135110  { :request_style =>  #{nsym(style)}, :request_use =>  #{nsym(inputuse)}, 
    136111    :response_style => #{nsym(style)}, :response_use => #{nsym(outputuse)}, 
    137     :faults => #{op_faults_str} } 
     112    :faults => #{mdef.faults.inspect} } 
    138113__EOD__ 
    139114    if inputuse == :encoded or outputuse == :encoded 
     
    144119    end 
    145120    if style == :rpc 
    146       assign_const(qname.namespace, 'Ns') 
     121      assign_const(mdef.qname.namespace, 'Ns') 
    147122      return <<__EOD__ 
    148 [ #{dqname(qname)}, 
     123[ #{dqname(mdef.qname)}, 
    149124  #{definitions}] 
    150125__EOD__ 
     
    169144  def rpcdefinedtype(part) 
    170145    if mapped = basetype_mapped_class(part.type) 
    171       ['::' + mapped.name
     146      return ['::' + mapped.name, nil
    172147    elsif definedtype = @simpletypes[part.type] 
    173       [nil, definedtype.name.namespace, definedtype.name.name] 
     148      return [nil, definedtype.name] 
    174149    elsif definedtype = @elements[part.element] 
    175       [nil, part.element.namespace, part.element.name
     150      return [nil, part.element
    176151    elsif definedtype = @complextypes[part.type] 
    177152      case definedtype.compoundtype 
    178153      when :TYPE_STRUCT, :TYPE_EMPTY, :TYPE_ARRAY, :TYPE_SIMPLE 
    179154        type = mapped_class_name(part.type, @modulepath) 
    180         [type, part.type.namespace, part.type.name] 
     155        return [type, part.type] 
    181156      when :TYPE_MAP 
    182         [Hash.name, part.type.namespace, part.type.name] 
     157        return [Hash.name, part.type] 
    183158      else 
    184159        raise NotImplementedError.new("must not reach here: #{definedtype.compoundtype}") 
    185160      end 
    186161    elsif part.type == XSD::AnyTypeName 
    187       [nil] 
     162      return [nil, nil] 
    188163    else 
    189164      raise RuntimeError.new("part: #{part.name} cannot be resolved") 
     
    193168  def documentdefinedtype(part) 
    194169    if mapped = basetype_mapped_class(part.type) 
    195       ['::' + mapped.name, nil, part.name
     170      return ['::' + mapped.name, XSD::QName.new(nil, part.name)
    196171    elsif definedtype = @simpletypes[part.type] 
    197172      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)
    199174      else 
    200175        raise RuntimeError.new("unsupported simpleType: #{definedtype}") 
    201176      end 
    202177    elsif definedtype = @elements[part.element] 
    203       ['::SOAP::SOAPElement', part.element.namespace, part.element.name
     178      return ['::SOAP::SOAPElement', part.element
    204179    elsif definedtype = @complextypes[part.type] 
    205       ['::SOAP::SOAPElement', part.type.namespace, part.type.name] 
     180      return ['::SOAP::SOAPElement', part.type] 
    206181    else 
    207182      raise RuntimeError.new("part: #{part.name} cannot be resolved") 
    208183    end 
    209   end 
    210  
    211   def param_set(io_type, name, type, ele = nil) 
    212     [io_type, name, type, ele] 
    213184  end 
    214185 
     
    239210  def param2str(params) 
    240211    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}]" 
    247214    }.join(",\n") 
    248215  end 
    249216 
    250   def type2str(type) 
    251     if type.size == 1 
    252       "[#{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)}]"  
    255222    end 
    256223  end 
     
    264231    end 
    265232  end 
    266  
    267   def cdr(ary) 
    268     result = ary.dup 
    269     result.shift 
    270     result 
    271   end 
    272233end 
    273234