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

Changeset 1663

Show
Ignore:
Timestamp:
11/06/05 22:54:11 (3 years ago)
Author:
nahi
Message:

suppor simpleContent + attribute extension. closes #176.

Files:

Legend:

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

    r1655 r1663  
    411411        if /\[\]$/ =~ class_name 
    412412          class_name = class_name.sub(/\[\]$/, '') 
     413          if class_name.empty? 
     414            class_name = nil 
     415          end 
    413416          as_array = true 
    414417        end 
  • trunk/lib/soap/mapping/wsdlencodedregistry.rb

    r1660 r1663  
    242242    node.each do |name, value| 
    243243      item = definition.elements.find { |k, v| k.elename.name == name } 
    244       if item 
     244      if item and item.type 
    245245        if klass = Mapping.class_from_name(item.type) 
    246246          # klass must be a SOAPBasetype or a class 
  • trunk/lib/soap/mapping/wsdlliteralregistry.rb

    r1660 r1663  
    3636  def obj2soap(obj, qname) 
    3737    soap_obj = nil 
    38     if ele = @definedelements[qname] 
    39       soap_obj = obj2elesoap(obj, ele) 
     38    if obj.is_a?(SOAPElement) 
     39      soap_obj = obj 
     40    elsif eledef = @definedelements[qname] 
     41      soap_obj = obj2elesoap(obj, eledef) 
    4042    elsif type = @definedtypes[qname] 
    4143      soap_obj = obj2typesoap(obj, type, true) 
     
    7981  MAPPING_OPT = { :no_reference => true } 
    8082 
    81   def obj2elesoap(obj, ele) 
    82     o = nil 
    83     qualified = (ele.elementform == 'qualified') 
    84     if ele.type 
    85       if type = @definedtypes[ele.type] 
    86         o = obj2typesoap(obj, type, qualified) 
    87       elsif type = TypeMap[ele.type] 
    88         o = base2soap(obj, type) 
    89       else 
    90         raise MappingError.new("cannot find type #{ele.type}") 
    91       end 
    92     elsif ele.local_complextype 
    93       o = obj2typesoap(obj, ele.local_complextype, qualified) 
    94       add_attributes2soap(obj, o) 
    95     elsif ele.local_simpletype 
    96       o = obj2typesoap(obj, ele.local_simpletype, qualified) 
     83  def obj2elesoap(obj, eledef) 
     84    ele = nil 
     85    qualified = (eledef.elementform == 'qualified') 
     86    if eledef.type 
     87      if type = @definedtypes[eledef.type] 
     88        ele = obj2typesoap(obj, type, qualified) 
     89      elsif type = TypeMap[eledef.type] 
     90        ele = base2soap(obj, type) 
     91      else 
     92        raise MappingError.new("cannot find type #{eledef.type}") 
     93      end 
     94    elsif eledef.local_complextype 
     95      ele = obj2typesoap(obj, eledef.local_complextype, qualified) 
     96    elsif eledef.local_simpletype 
     97      ele = obj2typesoap(obj, eledef.local_simpletype, qualified) 
    9798    else 
    9899      raise MappingError.new('illegal schema?') 
    99100    end 
    100     o.elename = ele.name 
    101     o 
     101    ele.elename = eledef.name 
     102    ele 
    102103  end 
    103104 
    104105  def obj2typesoap(obj, type, qualified) 
     106    ele = nil 
    105107    if type.is_a?(::WSDL::XMLSchema::SimpleType) 
    106       simpleobj2soap(obj, type) 
    107     else 
    108       complexobj2soap(obj, type, qualified) 
    109     end 
     108      ele = simpleobj2soap(obj, type) 
     109    elsif type.simplecontent 
     110      ele = simpleobj2soap(obj, type.simplecontent) 
     111    else 
     112      ele = complexobj2soap(obj, type, qualified) 
     113    end 
     114    add_attributes2soap(obj, ele) 
     115    ele 
    110116  end 
    111117 
     
    114120    return SOAPNil.new if obj.nil?      # TODO: check nillable. 
    115121    if type.base 
    116       base2soap(obj, TypeMap[type.base]) 
     122      ele = base2soap(obj, TypeMap[type.base]) 
    117123    elsif type.list 
    118       base2soap(obj.join(" "), SOAP::SOAPString) 
     124      ele = base2soap(obj.join(" "), SOAP::SOAPString) 
    119125    else 
    120126      raise MappingError.new("unsupported simpleType: #{type}") 
    121127    end 
     128    ele 
    122129  end 
    123130 
     
    174181  def complexobj2soapchildren(obj, ele, child_ele, allow_nil_value = false) 
    175182    if child_ele.map_as_array? 
    176       child = Mapping.get_attribute(obj, child_ele.name.name) 
    177       if child.nil? and obj.is_a?(::Array) 
    178         child = obj 
    179       end 
    180       if child.nil? 
    181         return false if allow_nil_value 
    182         if child_soap = nil2soap(child_ele) 
    183           ele.add(child_soap) 
    184         else 
    185           return false 
    186         end 
    187       else 
    188         child.each do |item| 
    189           child_soap = obj2elesoap(item, child_ele) 
    190           ele.add(child_soap) 
    191         end 
    192       end 
    193     else 
    194       child = Mapping.get_attribute(obj, child_ele.name.name) 
    195       if child.nil? 
    196         return false if allow_nil_value 
    197         if child_soap = nil2soap(child_ele) 
    198           ele.add(child_soap) 
    199         else 
    200           return false 
    201         end 
    202       else 
    203         child_soap = obj2elesoap(child, child_ele) 
     183      complexobj2soapchildren_array(obj, ele, child_ele, allow_nil_value) 
     184    else 
     185      complexobj2soapchildren_single(obj, ele, child_ele, allow_nil_value) 
     186    end 
     187  end 
     188 
     189  def complexobj2soapchildren_array(obj, ele, child_ele, allow_nil_value) 
     190    child = Mapping.get_attribute(obj, child_ele.name.name) 
     191    if child.nil? and obj.respond_to?(:each) 
     192      child = obj 
     193    end 
     194    if child.nil? 
     195      return false if allow_nil_value 
     196      if child_soap = nil2soap(child_ele) 
    204197        ele.add(child_soap) 
     198        return true 
     199      else 
     200        return false 
     201      end 
     202    end 
     203    unless child.respond_to?(:each) 
     204      return false 
     205    end 
     206    child.each do |item| 
     207      if item.is_a?(SOAPElement) 
     208        ele.add(item) 
     209      else 
     210        child_soap = obj2elesoap(item, child_ele) 
     211        ele.add(child_soap) 
    205212      end 
    206213    end 
    207214    true 
     215  end 
     216 
     217  def complexobj2soapchildren_single(obj, ele, child_ele, allow_nil_value) 
     218    child = Mapping.get_attribute(obj, child_ele.name.name) 
     219    case child 
     220    when NilClass 
     221      return false if allow_nil_value 
     222      if child_soap = nil2soap(child_ele) 
     223        ele.add(child_soap) 
     224        true 
     225      else 
     226        false 
     227      end 
     228    when SOAPElement 
     229      ele.add(child) 
     230      true 
     231    else 
     232      child_soap = obj2elesoap(child, child_ele) 
     233      ele.add(child_soap) 
     234      true 
     235    end 
    208236  end 
    209237 
     
    236264 
    237265  def any2soap(obj, qname) 
    238     if obj.is_a?(SOAPElement) 
    239       obj 
    240     elsif obj.class.class_variables.include?('@@schema_element') 
    241       stubobj2soap(obj, qname) 
     266    ele = nil 
     267    if obj.class.class_variables.include?('@@schema_element') 
     268      ele = stubobj2soap(obj, qname) 
    242269    elsif obj.is_a?(SOAP::Mapping::Object) 
    243       mappingobj2soap(obj, qname) 
     270      ele = mappingobj2soap(obj, qname) 
    244271    elsif obj.is_a?(Hash) 
    245272      ele = SOAPElement.from_obj(obj) 
    246273      ele.elename = qname 
    247       ele 
    248274    elsif obj.is_a?(Array) 
    249275      # treat as a list of simpletype 
    250276      ele = SOAPElement.new(qname, obj.join(" ")) 
    251       ele 
    252277    elsif obj.is_a?(XSD::QName) 
    253278      ele = SOAPElement.new(qname) 
    254279      ele.text = obj 
    255       ele 
    256280    else 
    257281      # expected to be a basetype or an anyType. 
     
    260284        ele = Mapping.obj2soap(obj, nil, nil, MAPPING_OPT) 
    261285        ele.elename = qname 
    262         ele 
    263286      rescue MappingError 
    264287        ele = SOAPElement.new(qname, obj.to_s) 
    265288      end 
    266       if obj.respond_to?(:__xmlattr) 
    267         obj.__xmlattr.each do |key, value| 
    268           ele.extraattr[key] = value 
    269         end 
    270       end 
    271       ele 
    272     end 
     289    end 
     290    add_attributes2soap(obj, ele) 
     291    ele 
    273292  end 
    274293 
     
    279298      obj.class.class_eval('@@schema_qualified')) 
    280299    add_elements2soap(obj, ele) 
    281     add_attributes2soap(obj, ele) 
    282300    ele 
    283301  end 
     
    294312      end 
    295313    end 
    296     obj.__xmlattr.each do |key, value| 
    297       ele.extraattr[key] = value 
    298     end 
    299314    ele 
    300315  end 
     
    321336          ele.add(obj2soap(child, eledef.elename)) 
    322337        end 
    323       elsif obj.is_a?(::Array) and eledef.as_array? 
     338      elsif obj.respond_to?(:each) and eledef.as_array? 
    324339        obj.each do |item| 
    325340          ele.add(obj2soap(item, eledef.elename)) 
     
    333348    if attributes 
    334349      attributes.each do |qname, param| 
    335         attr = obj.__send__('xmlattr_' + 
    336           XSD::CodeGen::GenSupport.safevarname(qname.name)) 
     350        attr = obj.__send__( 
     351          XSD::CodeGen::GenSupport.safemethodname('xmlattr_' + qname.name)) 
    337352        ele.extraattr[qname] = attr 
     353      end 
     354    elsif obj.respond_to?(:__xmlattr) 
     355      obj.__xmlattr.each do |key, value| 
     356        ele.extraattr[key] = value 
    338357      end 
    339358    end 
     
    397416    node.each do |name, value| 
    398417      item = definition.elements.find { |k, v| k.elename.name == name } 
    399       if item 
     418      if item and item.type 
    400419        if klass = Mapping.class_from_name(item.type) 
    401420          # klass must be a SOAPBasetype or a class 
     
    472491  if RUBY_VERSION > "1.7.0" 
    473492    def define_xmlattr_accessor(obj, qname) 
    474       name = XSD::CodeGen::GenSupport.safemethodname(qname.name) 
    475       Mapping.define_attr_accessor(obj, 'xmlattr_' + name, 
     493      name = XSD::CodeGen::GenSupport.safemethodname('xmlattr_' + qname.name) 
     494      Mapping.define_attr_accessor(obj, name, 
    476495        proc { @__xmlattr[qname] }, 
    477496        proc { |value| @__xmlattr[qname] = value }) 
     
    479498  else 
    480499    def define_xmlattr_accessor(obj, qname) 
    481       name = XSD::CodeGen::GenSupport.safemethodname(qname.name) 
     500      name = XSD::CodeGen::GenSupport.safemethodname('xmlattr_' + qname.name) 
    482501      obj.instance_eval <<-EOS 
    483502        def #{name} 
  • trunk/lib/wsdl/operation.rb

    r1608 r1663  
    4747 
    4848  def input_info 
    49     typename = input.find_message.name 
     49    if message = input_message 
     50      typename = message.name 
     51    else 
     52      typename = nil 
     53    end 
    5054    NameInfo.new(@name, typename, inputparts) 
    5155  end 
    5256 
    5357  def output_info 
    54     typename = output.find_message.name 
     58    if message = output_message 
     59      typename = message.name 
     60    else 
     61      typename = nil 
     62    end 
    5563    NameInfo.new(@name, typename, outputparts) 
    5664  end 
    5765 
     66  EMPTY = [].freeze 
     67 
    5868  def inputparts 
    59     sort_parts(input.find_message.parts) 
     69    if message = input_message 
     70      sort_parts(message.parts) 
     71    else 
     72      EMPTY 
     73    end 
    6074  end 
    6175 
    6276  def inputname 
    63     XSD::QName.new(targetnamespace, input.name ? input.name.name : @name.name) 
     77    if input 
     78      XSD::QName.new(targetnamespace, input.name ? input.name.name : @name.name) 
     79    else 
     80      nil 
     81    end 
    6482  end 
    6583 
    6684  def outputparts 
    67     sort_parts(output.find_message.parts) 
     85    if message = output_message 
     86      sort_parts(message.parts) 
     87    else 
     88      EMPTY 
     89    end 
    6890  end 
    6991 
    7092  def outputname 
    71     XSD::QName.new(targetnamespace, 
    72       output.name ? output.name.name : @name.name + 'Response') 
     93    if output 
     94      XSD::QName.new(targetnamespace, 
     95        output.name ? output.name.name : @name.name + 'Response') 
     96    else 
     97      nil 
     98    end 
    7399  end 
    74100 
     
    110136private 
    111137 
     138  def input_message 
     139    if input and message = input.find_message 
     140      message 
     141    else 
     142      nil 
     143    end 
     144  end 
     145 
     146  def output_message 
     147    if output and message = output.find_message 
     148      message 
     149    else 
     150      nil 
     151    end 
     152  end 
     153 
    112154  def sort_parts(parts) 
    113155    return parts.dup unless parameter_order 
  • trunk/lib/wsdl/soap/classDefCreator.rb

    r1660 r1663  
    1818class ClassDefCreator 
    1919  include ClassDefCreatorSupport 
     20  include XSD::CodeGen 
    2021 
    2122  def initialize(definitions) 
    2223    @elements = definitions.collect_elements 
    2324    @elements.uniq! 
     25    @attributes = definitions.collect_attributes 
     26    @attributes.uniq! 
    2427    @simpletypes = definitions.collect_simpletypes 
    2528    @simpletypes.uniq! 
     
    4245        result << str 
    4346      end 
     47      str = dump_attribute 
     48      unless str.empty? 
     49        result << "\n" unless result.empty? 
     50        result << str 
     51      end 
    4452      str = dump_complextype 
    4553      unless str.empty? 
     
    6169    @elements.collect { |ele| 
    6270      if ele.local_complextype 
    63         dump_classdef(ele.name, ele.local_complextype, 
    64           ele.elementform == 'qualified'
     71        qualified = ele.elementform == 'qualified' 
     72        dump_complextypedef(ele.name, ele.local_complextype, qualified
    6573      elsif ele.local_simpletype 
    6674        dump_simpletypedef(ele.name, ele.local_simpletype) 
     
    7179  end 
    7280 
     81  def dump_attribute 
     82    @attributes.collect { |attr| 
     83      if attr.local_simpletype 
     84        dump_simpletypedef(attr.name, attr.local_simpletype) 
     85      end 
     86    }.compact.join("\n") 
     87  end 
     88 
    7389  def dump_simpletype 
    7490    @simpletypes.collect { |type| 
     
    7995  def dump_complextype 
    8096    @complextypes.collect { |type| 
    81       case type.compoundtype 
    82       when :TYPE_STRUCT, :TYPE_EMPTY 
    83         dump_classdef(type.name, type) 
    84       when :TYPE_ARRAY 
    85         dump_arraydef(type) 
    86       when :TYPE_SIMPLE 
    87         dump_simpleclassdef(type) 
    88       when :TYPE_MAP 
    89         # mapped as a general Hash 
    90         nil 
    91       else 
    92         raise RuntimeError.new( 
    93           "unknown kind of complexContent: #{type.compoundtype}") 
    94       end 
     97      dump_complextypedef(type.name, type) 
    9598    }.compact.join("\n") 
    9699  end 
     
    111114      return nil 
    112115    end 
    113     c = XSD::CodeGen::ModuleDef.new(create_class_name(qname)) 
     116    c = ModuleDef.new(create_class_name(qname)) 
    114117    c.comment = "#{qname}" 
    115118    define_enum_restriction(c, restriction.enumeration) 
     
    118121 
    119122  def dump_simpletypedef_list(qname, list) 
    120     c = XSD::CodeGen::ClassDef.new(create_class_name(qname), '::Array') 
     123    c = ClassDef.new(create_class_name(qname), '::Array') 
    121124    c.comment = "#{qname}" 
    122125    if simpletype = list.local_simpletype 
     
    147150  end 
    148151 
    149   def dump_simpleclassdef(type_or_element) 
    150     qname = type_or_element.name 
     152  def dump_simpleclassdef(qname, type_or_element) 
    151153    base = create_class_name(type_or_element.simplecontent.base) 
    152     c = XSD::CodeGen::ClassDef.new(create_class_name(qname), base) 
     154    c = ClassDef.new(create_class_name(qname), base) 
    153155    c.comment = "#{qname}" 
     156    unless type_or_element.attributes.empty? 
     157      define_attribute(c, type_or_element.attributes) 
     158      c.def_method('initialize', '*arg') do 
     159        "super\n" + "@__xmlattr = {}" 
     160      end 
     161    end 
    154162    c.dump 
     163  end 
     164 
     165  def dump_complextypedef(qname, type, qualified = false) 
     166    case type.compoundtype 
     167    when :TYPE_STRUCT, :TYPE_EMPTY 
     168      dump_classdef(qname, type, qualified) 
     169    when :TYPE_ARRAY 
     170      dump_arraydef(qname, type) 
     171    when :TYPE_SIMPLE 
     172      dump_simpleclassdef(qname, type) 
     173    when :TYPE_MAP 
     174      # mapped as a general Hash 
     175      nil 
     176    else 
     177      raise RuntimeError.new( 
     178        "unknown kind of complexContent: #{type.compoundtype}") 
     179    end 
    155180  end 
    156181 
    157182  def dump_classdef(qname, typedef, qualified = false) 
    158183    if @faulttypes and @faulttypes.index(qname) 
    159       c = XSD::CodeGen::ClassDef.new(create_class_name(qname), 
    160         '::StandardError') 
    161     else 
    162       c = XSD::CodeGen::ClassDef.new(create_class_name(qname)) 
     184      c = ClassDef.new(create_class_name(qname), '::StandardError') 
     185    else 
     186      c = ClassDef.new(create_class_name(qname)) 
    163187    end 
    164188    c.comment = "#{qname}" 
     
    255279        end 
    256280        name = name_element(element).name 
    257         attrname = safemethodname?(name) ? name : safemethodname(name) 
     281        #attrname = safemethodname?(name) ? name : safemethodname(name) 
     282        attrname = safemethodname(name) 
    258283        varname = safevarname(name) 
    259284        c.def_attr(attrname, true, varname) 
     
    261286        if element.map_as_array? 
    262287          init_params << "#{varname} = []" 
    263           type << '[]' if type 
     288          if type 
     289            type << '[]' 
     290          else 
     291            type = '[]' 
     292          end 
    264293        else 
    265294          init_params << "#{varname} = nil" 
     
    363392  DEFAULT_ITEM_NAME = XSD::QName.new(nil, 'item') 
    364393 
    365   def dump_arraydef(complextype) 
    366     qname = complextype.name 
    367     c = XSD::CodeGen::ClassDef.new(create_class_name(qname), '::Array') 
     394  def dump_arraydef(qname, complextype) 
     395    c = ClassDef.new(create_class_name(qname), '::Array') 
    368396    c.comment = "#{qname}" 
    369397    child_type = complextype.child_type 
  • trunk/lib/wsdl/xmlSchema/complexType.rb

    r1653 r1663  
    7272    if @complexcontent 
    7373      @complexcontent.attributes 
     74    elsif @simplecontent 
     75      @simplecontent.attributes 
    7476    else 
    7577      @attributes 
  • trunk/lib/wsdl/xmlSchema/simpleContent.rb

    r1445 r1663  
    3333  end 
    3434 
     35  def attributes 
     36    content.attributes 
     37  end 
     38 
    3539  def targetnamespace 
    3640    parent.targetnamespace 
  • trunk/sample/wsdl/salesforce/client.rb

    r1650 r1663  
    5252obj.headerhandler << calloptions_handler 
    5353obj.wiredump_dev = STDOUT 
     54 
     55p obj.delete(Delete.new([1, 2, 3])) 
     56p obj.describeSObject(:sObjectType => "hello world") 
     57p obj.describeSObject(DescribeSObject.new("hello world")) 
    5458 
    5559if false 
  • trunk/test/wsdl/complexcontent/test_echo.rb

    r1643 r1663  
    8484    @client.wiredump_dev = STDOUT if $DEBUG 
    8585    d = Derived.new 
    86     d.Name = "NaHi" 
     86    d.name = "NaHi" 
    8787    assert_instance_of(Echo, @client.echo(Echo.new(d))) 
    8888  end 
  • trunk/test/wsdl/ref/expectedProduct.rb

    r1655 r1663  
    11require 'xsd/qname' 
    22 
    3 # {urn:product}Rating 
     3# {urn:ref}Rating 
    44module Rating 
    55  C_0 = "0" 
     
    88end 
    99 
    10 # {urn:product}Product-Bag 
     10# {urn:ref}Product-Bag 
    1111class ProductBag 
    1212  @@schema_type = "Product-Bag" 
    13   @@schema_ns = "urn:product
    14   @@schema_attribute = {XSD::QName.new("urn:product", "version") => "SOAP::SOAPString", XSD::QName.new("urn:product", "yesno") => "SOAP::SOAPString"} 
     13  @@schema_ns = "urn:ref
     14  @@schema_attribute = {XSD::QName.new("urn:ref", "version") => "SOAP::SOAPString", XSD::QName.new("urn:ref", "yesno") => "SOAP::SOAPString"} 
    1515  @@schema_element = [ 
    1616    ["bag", ["Product[]", XSD::QName.new(nil, "bag")]], 
    17     ["rating", ["SOAP::SOAPString[]", XSD::QName.new("urn:product", "Rating")]], 
    18     ["product_Bag", ["ProductBag", XSD::QName.new("urn:product", "Product-Bag")]], 
    19     ["comment_1", [nil, XSD::QName.new(nil, "comment_1")]], 
     17    ["rating", ["SOAP::SOAPString[]", XSD::QName.new("urn:ref", "Rating")]], 
     18    ["comment_1", ["[]", XSD::QName.new(nil, "comment_1")]], 
    2019    ["comment_2", ["Comment[]", XSD::QName.new(nil, "comment-2")]]] 
    2120 
    2221  attr_accessor :bag 
    23   attr_accessor :product_Ba
     22  attr_accessor :ratin
    2423  attr_accessor :comment_1 
    2524  attr_accessor :comment_2 
    2625 
    27   def Rating 
    28     @rating 
    29   end 
    30  
    31   def Rating=(value) 
    32     @rating = value 
    33   end 
    34  
    3526  def xmlattr_version 
    36     (@__xmlattr ||= {})[XSD::QName.new("urn:product", "version")] 
     27    (@__xmlattr ||= {})[XSD::QName.new("urn:ref", "version")] 
    3728  end 
    3829 
    3930  def xmlattr_version=(value) 
    40     (@__xmlattr ||= {})[XSD::QName.new("urn:product", "version")] = value 
     31    (@__xmlattr ||= {})[XSD::QName.new("urn:ref", "version")] = value 
    4132  end 
    4233 
    4334  def xmlattr_yesno 
    44     (@__xmlattr ||= {})[XSD::QName.new("urn:product", "yesno")] 
     35    (@__xmlattr ||= {})[XSD::QName.new("urn:ref", "yesno")] 
    4536  end 
    4637 
    4738  def xmlattr_yesno=(value) 
    48     (@__xmlattr ||= {})[XSD::QName.new("urn:product", "yesno")] = value 
     39    (@__xmlattr ||= {})[XSD::QName.new("urn:ref", "yesno")] = value 
    4940  end 
    5041 
    51   def initialize(bag = [], rating = [], product_Bag = nil, comment_1 = [], comment_2 = []) 
     42  def initialize(bag = [], rating = [], comment_1 = [], comment_2 = []) 
    5243    @bag = bag 
    5344    @rating = rating 
    54     @product_Bag = product_Bag 
    5545    @comment_1 = comment_1 
    5646    @comment_2 = comment_2 
     
    5949end 
    6050 
    61 # {urn:product}Creator 
    62 class Creator 
    63   @@schema_type = "Creator" 
    64   @@schema_ns = "urn:product" 
    65   @@schema_element = [] 
     51# {urn:ref}Creator 
     52class Creator < String 
     53  @@schema_attribute = {XSD::QName.new(nil, "Role") => nil} 
    6654 
    67   def initialize 
     55  def xmlattr_Role 
     56    (@__xmlattr ||= {})[XSD::QName.new(nil, "Role")] 
     57  end 
     58 
     59  def xmlattr_Role=(value) 
     60    (@__xmlattr ||= {})[XSD::QName.new(nil, "Role")] = value 
     61  end 
     62 
     63  def initialize(*arg) 
     64    super 
     65    @__xmlattr = {} 
    6866  end 
    6967end 
    7068 
    71 # {urn:product}Product 
     69# {urn:ref}yesno 
     70module Yesno 
     71  N = "N" 
     72  Y = "Y" 
     73end 
     74 
     75# {urn:ref}Product 
    7276class Product 
    7377  @@schema_type = "Product" 
    74   @@schema_ns = "urn:product
     78  @@schema_ns = "urn:ref
    7579  @@schema_element = [ 
    7680    ["name", ["SOAP::SOAPString", XSD::QName.new(nil, "name")]], 
    77     ["rating", ["SOAP::SOAPString", XSD::QName.new("urn:product", "Rating")]]] 
     81    ["rating", ["SOAP::SOAPString", XSD::QName.new("urn:ref", "Rating")]]] 
    7882 
    7983  attr_accessor :name 
    80  
    81   def Rating 
    82     @rating 
    83   end 
    84  
    85   def Rating=(value) 
    86     @rating = value 
    87   end 
     84  attr_accessor :rating 
    8885 
    8986  def initialize(name = nil, rating = nil) 
     
    9390end 
    9491 
    95 # {urn:product}Comment 
     92# {urn:ref}Comment 
    9693class Comment < String 
     94  @@schema_attribute = {XSD::QName.new(nil, "msgid") => "SOAP::SOAPString"} 
     95 
     96  def xmlattr_msgid 
     97    (@__xmlattr ||= {})[XSD::QName.new(nil, "msgid")] 
     98  end 
     99 
     100  def xmlattr_msgid=(value) 
     101    (@__xmlattr ||= {})[XSD::QName.new(nil, "msgid")] = value 
     102  end 
     103 
     104  def initialize(*arg) 
     105    super 
     106    @__xmlattr = {} 
     107  end 
    97108end 
  • trunk/test/wsdl/ref/product.wsdl

    r1444 r1663  
    11<?xml version="1.0"?> 
    22<definitions name="product" 
    3     targetNamespace="urn:product
    4     xmlns:tns="urn:product
     3    targetNamespace="urn:ref
     4    xmlns:tns="urn:ref
    55    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    66    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
     
    88  <types> 
    99    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" 
    10         targetNamespace="urn:product"> 
     10        targetNamespace="urn:ref"> 
    1111      <simpleType name="non-empty-string"> 
    1212        <restriction base="xsd:string"> 
     
    5656            <element name="bag" type="tns:Product" minOccurs="0" maxOccurs="unbounded"/> 
    5757            <element ref="tns:Rating" minOccurs="0" maxOccurs="unbounded"/> 
    58             <element ref="tns:Product-Bag"/> 
    5958            <element name="comment_1" minOccurs="0" maxOccurs="unbounded"> 
    6059              <complexType> 
     
    7372      </element> 
    7473 
    75       <element name="Creator" minOccurs="0" maxOccurs="unbounded"
     74      <element name="Creator"
    7675        <complexType> 
    7776          <simpleContent> 
     
    8483    </xsd:schema> 
    8584  </types> 
     85 
     86  <message name="echo_in"> 
     87    <part name="parameters" element="tns:Product-Bag" /> 
     88  </message> 
     89  <message name="echo_out"> 
     90    <part name="parameters" element="tns:Creator" /> 
     91  </message> 
     92 
     93  <portType name="ref_porttype"> 
     94    <operation name="echo"> 
     95      <input message="tns:echo_in" /> 
     96      <output message="tns:echo_out" /> 
     97    </operation> 
     98  </portType> 
     99 
     100  <binding name="ref_binding" type="tns:ref_porttype"> 
     101    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
     102    <operation name="echo"> 
     103      <soap:operation soapAction="urn:ref:echo" style="document" /> 
     104      <input> 
     105        <soap:body use="literal" /> 
     106      </input> 
     107      <output> 
     108        <soap:body use="literal" /> 
     109      </output> 
     110    </operation> 
     111  </binding> 
     112 
     113  <service name="ref_service"> 
     114    <port name="ref_service_port" binding="tns:ref_binding"> 
     115      <soap:address location="http://localhost:17171/" /> 
     116    </port> 
     117  </service> 
    86118</definitions> 
  • trunk/test/wsdl/ref/test_ref.rb

    r1653 r1663  
    1010 
    1111class TestRef < Test::Unit::TestCase 
     12  Namespace = 'urn:ref' 
     13 
     14  class Server < ::SOAP::RPC::StandaloneServer 
     15    Namespace = TestRef::Namespace 
     16 
     17    def on_init 
     18      add_document_method( 
     19        self, 
     20        Namespace + ':echo', 
     21        'echo', 
     22        XSD::QName.new(Namespace, 'Product-Bag'), 
     23        XSD::QName.new(Namespace, 'Creator') 
     24      ) 
     25    end 
     26   
     27    def echo(arg) 
     28      content = [ 
     29        arg.bag[0].name, 
     30        arg.bag[0].rating, 
     31        arg.bag[1].name, 
     32        arg.bag[1].rating, 
     33        arg.rating[0], 
     34        arg.rating[1], 
     35        arg.rating[2], 
     36        arg.comment_1[0], 
     37        arg.comment_1[0].xmlattr_msgid, 
     38        arg.comment_1[1], 
     39        arg.comment_1[1].xmlattr_msgid, 
     40        arg.comment_2[0], 
     41        arg.comment_2[0].xmlattr_msgid, 
     42        arg.comment_2[1], 
     43        arg.comment_2[1].xmlattr_msgid 
     44      ] 
     45      rv = Creator.new(content.join(" ")) 
     46      rv.xmlattr_Role = "role" 
     47      rv 
     48    end 
     49  end 
     50 
    1251  DIR = File.dirname(File.expand_path(__FILE__)) 
     52 
    1353  Port = 17171 
     54 
     55  def setup 
     56    setup_server 
     57    setup_classdef 
     58    @client = nil 
     59  end 
     60 
     61  def teardown 
     62    teardown_server 
     63    File.unlink(pathname('product.rb')) unless $DEBUG 
     64    File.unlink(pathname('productDriver.rb')) unless $DEBUG 
     65    @client.reset_stream if @client 
     66  end 
     67 
     68  def setup_server 
     69    @server = Server.new('Test', Namespace, '0.0.0.0', Port) 
     70    @server.level = Logger::Severity::ERROR 
     71    @server_thread = start_server_thread(@server) 
     72  end 
     73 
     74  def setup_classdef 
     75    gen = WSDL::SOAP::WSDL2Ruby.new 
     76    gen.location = pathname("product.wsdl") 
     77    gen.basedir = DIR 
     78    gen.logger.level = Logger::FATAL 
     79    gen.opt['classdef'] = nil 
     80    gen.opt['driver'] = nil 
     81    gen.opt['force'] = true 
     82    gen.run 
     83    begin 
     84      back = $:.dup 
     85      $:.unshift(pathname(".")) 
     86      require pathname('product') 
     87      require pathname('productDriver') 
     88    ensure 
     89      $:.replace(back) if back 
     90    end 
     91  end 
     92 
     93  def teardown_server 
     94    @server.shutdown 
     95    @server_thread.kill 
     96    @server_thread.join 
     97  end 
     98 
     99  def start_server_thread(server) 
     100    t = Thread.new { 
     101      Thread.current.abort_on_exception = true 
     102      server.start 
     103    } 
     104    t 
     105  end 
     106 
     107  def pathname(filename) 
     108    File.join(DIR, filename) 
     109  end 
     110 
     111  def compare(expected, actual) 
     112    assert_equal(loadfile(expected), loadfile(actual), actual) 
     113  end 
     114 
     115  def loadfile(file) 
     116    File.open(pathname(file)) { |f| f.read } 
     117  end 
     118 
     119  def suppress_warning 
     120    back = $VERBOSE 
     121    $VERBOSE = nil 
     122    begin 
     123      yield 
     124    ensure 
     125      $VERBOSE = back 
     126    end 
     127  end 
    14128 
    15129  def test_classdef 
     
    24138    end 
    25139    compare("expectedProduct.rb", "product.rb") 
    26     File.unlink(pathname('product.rb')) unless $DEBUG 
    27   end 
    28  
    29   def compare(expected, actual) 
    30     assert_equal(loadfile(expected), loadfile(actual), actual) 
    31   end 
    32  
    33   def loadfile(file) 
    34     File.open(pathname(file)) { |f| f.read } 
    35   end 
    36  
    37   def pathname(filename) 
    38     File.join(DIR, filename) 
    39   end 
    40  
    41   def suppress_warning 
    42     back = $VERBOSE 
    43     $VERBOSE = nil 
    44     begin 
    45       yield 
    46     ensure 
    47       $VERBOSE = back 
    48     end 
     140  end 
     141 
     142  def test_wsdl 
     143    wsdl = File.join(DIR, 'product.wsdl') 
     144    @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver 
     145    @client.endpoint_url = "http://localhost:#{Port}/" 
     146    @client.wiredump_dev = STDOUT if $DEBUG 
     147    p1 = e("bag") 
     148      p1.add(e("name", "foo")) 
     149      p1.add(e(q(Namespace, "Rating"), "0")) 
     150    p2 = e("bag") 
     151      p2.add(e("name", "bar")) 
     152      p2.add(e(q(Namespace, "Rating"), "+1")) 
     153    r1 = e(q(Namespace, "Rating"), "0") 
     154    r2 = e(q(Namespace, "Rating"), "+1") 
     155    r3 = e(q(Namespace, "Rating"), "-1") 
     156    c11 = e("comment_1", "comment11") 
     157    c11.extraattr["msgid"] = "msgid11" 
     158    c12 = e("comment_1", "comment12") 
     159    c12.extraattr["msgid"] = "msgid12" 
     160    c21 = e("comment-2", "comment21") 
     161    c21.extraattr["msgid"] = "msgid21" 
     162    c22 = e("comment-2", "comment22") 
     163    c22.extraattr["msgid"] = "msgid22" 
     164    bag = e(q(Namespace, "Product-Bag")) 
     165      bag.add(p1) 
     166      bag.add(p2) 
     167      bag.add(r1) 
     168      bag.add(r2) 
     169      bag.add(r3) 
     170      bag.add(c11) 
     171      bag.add(c12) 
     172      bag.add(c21) 
     173      bag.add(c22) 
     174    bag.extraattr["version"] = "version" 
     175    bag.extraattr["yesno"] = "Y" 
     176    ret = @client.echo(bag) 
     177    assert_equal( 
     178      [ 
     179        p1["name"].text, p1["Rating"].text, 
     180        p2["name"].text, p2["Rating"].text, 
     181        r1.text, r2.text, r3.text, 
     182        c11.text, c11.extraattr["msgid"], 
     183        c12.text, c12.extraattr["msgid"], 
     184        c21.text, c21.extraattr["msgid"], 
     185        c22.text, c22.extraattr["msgid"] 
     186      ].join(" "), 
     187      ret 
     188    ) 
     189    assert_equal("role", ret.xmlattr_Role) 
     190  end 
     191 
     192  def test_wsdl_with_classdef 
     193    wsdl = File.join(DIR, 'product.wsdl') 
     194    @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver 
     195    @client.endpoint_url = "http://localhost:#{Port}/" 
     196    @client.wiredump_dev = STDOUT if $DEBUG 
     197    p1 = Product.new("foo", Rating::C_0) 
     198    p2 = Product.new("bar", Rating::C_1) 
     199    r1 = Rating::C_0 
     200    r2 = Rating::C_1 
     201    r3 = Rating::C_1_2 
     202    c11 = ::SOAP::SOAPElement.new("comment_1", "comment11") 
     203    c11.extraattr["msgid"] = "msgid11" 
     204    c12 = ::SOAP::SOAPElement.new("comment_1", "comment12") 
     205    c12.extraattr["msgid"] = "msgid12" 
     206    c21 = Comment.new("comment21") 
     207    c21.xmlattr_msgid = "msgid21" 
     208    c22 = Comment.new("comment22") 
     209    c22.xmlattr_msgid = "msgid22" 
     210    bag = ProductBag.new([p1, p2], [r1, r2, r3], [c11, c12], [c21, c22]) 
     211    bag.xmlattr_version = "version" 
     212    bag.xmlattr_yesno = Yesno::Y 
     213    ret = @client.echo(bag) 
     214    assert_equal( 
     215      [ 
     216        p1.name, p1.rating, 
     217        p2.name, p2.rating, 
     218        r1, r2, r3, 
     219        c11.text, c11.extraattr["msgid"], 
     220        c12.text, c12.extraattr["msgid"], 
     221        c21, c21.xmlattr_msgid, 
     222        c22, c22.xmlattr_msgid 
     223      ].join(" "), 
     224      ret 
     225    ) 
     226    assert_equal("role", ret.xmlattr_Role) 
     227  end 
     228 
     229  def test_naive&nbs