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

Changeset 1650

Show
Ignore:
Timestamp:
10/19/05 22:35:12 (3 years ago)
Author:
nahi
Message:

<any/> support for WSDL2Ruby generated class and stubs. closes #148.

Files:

Legend:

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

    r1649 r1650  
    621621      else 
    622622        k, v = value 
    623         ele = from_obj(value
    624         ele.name = XSD::QName.new(nil, k) 
     623        ele = from_obj(v
     624        ele.elename = XSD::QName.new(nil, k) 
    625625        ele 
    626626      end 
  • trunk/lib/soap/mapping/mapping.rb

    r1649 r1650  
    345345 
    346346  def self.schema_element_definition(klass) 
    347     schema_element = class_schema_variable(:schema_element, klass) or return nil 
     347    schema_element = class_schema_variable(:schema_element, klass) 
     348    return nil unless schema_element 
    348349    schema_ns = schema_ns_definition(klass) 
    349350    elements = [] 
    350351    as_array = [] 
     352    have_any = false 
    351353    schema_element.each do |varname, definition| 
    352354      class_name, name = definition 
     
    355357        as_array << (name ? name.name : varname) 
    356358      end 
    357       elements << [name || XSD::QName.new(schema_ns, varname), class_name] 
    358     end 
    359     [elements, as_array] 
     359      if name == XSD::AnyTypeName 
     360        have_any = true 
     361      end 
     362      elements << 
     363        [name || XSD::QName.new(schema_ns, varname), class_name] 
     364    end 
     365    [elements, as_array, have_any] 
    360366  end 
    361367 
  • trunk/lib/soap/mapping/wsdlliteralregistry.rb

    r1649 r1650  
    165165    else 
    166166      any = Mapping.get_attributes(obj) 
    167       elements.each do |child_ele| 
    168         child = Mapping.get_attribute(obj, child_ele.name.name) 
    169         if k = any.key(child) 
    170           any.delete(k) 
     167      if elements 
     168        elements.each do |child_ele| 
     169          child = Mapping.get_attribute(obj, child_ele.name.name) 
     170          if k = any.key(child) 
     171            any.delete(k) 
     172          end 
    171173        end 
    172174      end 
     
    247249 
    248250  def add_elements2soap(obj, ele) 
    249     elements, as_array = schema_element_definition(obj.class) 
     251    elements, as_array, have_any = schema_element_definition(obj.class) 
     252    any = nil 
     253    if have_any 
     254      any = scan_any(obj, elements) 
     255    end 
    250256    if elements 
    251257      elements.each do |elename, type| 
    252         if child = Mapping.get_attribute(obj, elename.name) 
     258        if elename == XSD::AnyTypeName 
     259          if any 
     260            SOAPElement.from_objs(any).each do |child| 
     261              ele.add(child) 
     262            end 
     263          end 
     264        elsif child = Mapping.get_attribute(obj, elename.name) 
    253265          if as_array.include?(elename.name) 
    254266            child.each do |item| 
     
    455467  # changed while a lifetime of a WSDLLiteralRegistry. 
    456468  def schema_element_definition(klass) 
    457     @schema_element_cache[klass] ||= Mapping.schema_element_definition(klass) 
     469    @schema_element_cache[klass] ||= 
     470      Mapping.schema_element_definition(klass) 
    458471  end 
    459472 
    460473  def schema_attribute_definition(klass) 
    461     @schema_attribute_cache[klass] ||= Mapping.schema_attribute_definition(klass) 
     474    @schema_attribute_cache[klass] ||= 
     475      Mapping.schema_attribute_definition(klass) 
    462476  end 
    463477end 
  • trunk/lib/wsdl/soap/classDefCreator.rb

    r1649 r1650  
    148148        end 
    149149        init_lines << "@__xmlele_any = nil\n" 
     150        varname = 'any' # not used 
     151        eleqname = XSD::AnyTypeName 
     152        type = nil 
     153        schema_element << [varname, eleqname, type] 
    150154        next 
    151155      end 
  • trunk/sample/wsdl/salesforce/client.rb

    r1609 r1650  
    11#!/usr/bin/env ruby 
     2 
    23require 'defaultDriver.rb' 
    34require 'soap/header/simplehandler' 
     5include XSD 
     6include SOAP 
    47 
    58class SessionHeaderHandler < SOAP::Header::SimpleHandler 
     
    5053obj.wiredump_dev = STDOUT 
    5154 
     55if false 
     56require 'soap/wsdlDriver' 
     57obj = SOAP::WSDLDriverFactory.new("partner.wsdl").create_rpc_driver 
     58end 
     59 
     60ns = "urn:sobject.partner.soap.sforce.com" 
     61 
     62if false 
     63require 'orderedhash' 
     64sobj = OrderedHash.new 
     65sobj[QName.new(ns, "type")] = "Contact" 
     66sobj[QName.new(ns, "Id")] = "012345678901234567" 
     67#sobj["type"] = "Contact" 
     68#sobj["Id"] = "012345678901234567" 
     69sobj[:FirstName] = "Joe" 
     70sobj[:lastname] = "Blow" 
     71sobj[:Salutation] = "Mr." 
     72sobj[:Phone] = "999.999.9999" 
     73sobj[:Title] = "Purchasing Director" 
     74obj.test_loopback_response << '' 
     75obj.create(:sObjects => [sobj, sobj]) 
     76end 
     77 
     78if false 
     79ns1 = 'urn:partner.soap.sforce.com' 
     80ns2 = "urn:sobject.partner.soap.sforce.com" 
     81ele = SOAPElement.new(QName.new(ns1, 'create')) 
     82sobj = SOAPElement.new(QName.new(ns1, 'sObjects')) 
     83sobj.add(SOAPElement.new(QName.new(ns2, "type"), "Contact")) 
     84sobj.add(SOAPElement.new(QName.new(ns2, 'Id'), "012345678901234567")) 
     85sobj.add(SOAPElement.new(QName.new(nil, 'FirstName'), 'Joe')) 
     86sobj.add(SOAPElement.new(QName.new(nil, 'lastname'), 'Blow')) 
     87sobj.add(SOAPElement.new(QName.new(nil, 'Salutation'), 'Mr.')) 
     88sobj.add(SOAPElement.new(QName.new(nil, 'Phone'), '999.999.9999')) 
     89sobj.add(SOAPElement.new(QName.new(nil, 'Title'), 'Purchasing Director')) 
     90ele.add(sobj) 
     91ele.add(sobj) 
     92obj.test_loopback_response << '' 
     93obj.create(:sObjects => [sobj, sobj]) rescue nil 
     94end 
     95 
     96sobj = [ 
     97  [QName.new(ns, "type"), "Contact"], 
     98  [QName.new(ns, "Id"), "012345678901234567"], 
     99  [:FirstName, "Joe"], 
     100  [:lastname, "Blow"], 
     101  [:Salutation, "Mr."], 
     102  [:Phone, "999.999.9999"], 
     103  [:Title, "Purchasing Director"] 
     104] 
     105obj.test_loopback_response << '' 
     106obj.create(:sObjects => [sobj, sobj]) rescue nil 
     107 
     108 
     109mycontact = SObject.new 
     110mycontact.type = "Contact" 
     111mycontact.Id = "012345678901234567" 
     112mycontact.set_any([ 
     113  [:FirstName, "Joe"], 
     114  [:lastname, "Blow"], 
     115  [:Salutation, "Mr."], 
     116  [:Phone, "999.999.9999"], 
     117  [:Title, "Purchasing Director"] 
     118]) 
     119 
     120obj.test_loopback_response << '' 
     121obj.create(Create.new([mycontact, mycontact])) rescue nil 
     122exit 
     123 
     124 
     125 
     126ns = "urn:sobject.partner.soap.sforce.com" 
     127ele = SOAP::SOAPElement.new(XSD::QName.new(nil, "type")) 
     128ele.text = "Contact" 
     129ele.extraattr["xmlns"] = ns 
     130 
     131sobj = SObject.new("Contact") 
     132sobj.instance_eval do 
     133  @Id = "id" 
     134  @FirstName = "Joe" 
     135  @lastname = "Blow" 
     136  @Salutation = "Mr." 
     137  @Phone = "999.999.9999" 
     138  @Title = "Purchasing Director" 
     139end 
     140 
     141obj.create(Create.new([sobj])) 
     142#obj.create(Create.new([SObject.new(ele, ["fields", "To", "Null"], "id", {"LastName" => "Spaceley"}) ])) 
     143 
     144exit 
     145 
    52146calloptions_handler.client = 'client' 
    53147 
  • trunk/sample/wsdl/salesforce/default.rb

    r1630 r1650  
    590590  @@schema_type = "sObject" 
    591591  @@schema_ns = "urn:sobject.partner.soap.sforce.com" 
    592   @@schema_element = [["type", "SOAP::SOAPString"], ["fieldsToNull", "SOAP::SOAPString[]"], ["id", ["SOAP::SOAPString", XSD::QName.new("urn:sobject.partner.soap.sforce.com", "Id")]], ["any", [nil, XSD::QName.new(nil, "any")]]] 
     592  @@schema_element = [["type", "SOAP::SOAPString"], ["fieldsToNull", "SOAP::SOAPString[]"], ["id", ["SOAP::SOAPString", XSD::QName.new("urn:sobject.partner.soap.sforce.com", "Id")]], ["any", [nil, XSD::QName.new("http://www.w3.org/2001/XMLSchema", "anyType")]]] 
    593593 
    594594  attr_accessor :type 
    595595  attr_accessor :fieldsToNull 
    596   attr_accessor :any 
     596  attr_reader :__xmlele_any 
    597597 
    598598  def Id 
     
    604604  end 
    605605 
    606   def initialize(type = nil, fieldsToNull = [], id = nil, any = nil) 
     606  def set_any(elements) 
     607    @__xmlele_any = elements 
     608  end 
     609 
     610  def initialize(type = nil, fieldsToNull = [], id = nil) 
    607611    @type = type 
    608612    @fieldsToNull = fieldsToNull 
    609613    @id = id 
    610     @any = any 
     614    @__xmlele_any = nil 
    611615  end 
    612616end 
     
    11921196  @@schema_type = "LoginFault" 
    11931197  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1194   @@schema_element = [] 
    1195  
    1196   def initialize 
     1198  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1199 
     1200  attr_accessor :exceptionCode 
     1201  attr_accessor :exceptionMessage 
     1202 
     1203  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1204    @exceptionCode = exceptionCode 
     1205    @exceptionMessage = exceptionMessage 
    11971206  end 
    11981207end 
     
    12021211  @@schema_type = "InvalidSObjectFault" 
    12031212  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1204   @@schema_element = [] 
    1205  
    1206   def initialize 
     1213  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1214 
     1215  attr_accessor :exceptionCode 
     1216  attr_accessor :exceptionMessage 
     1217 
     1218  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1219    @exceptionCode = exceptionCode 
     1220    @exceptionMessage = exceptionMessage 
    12071221  end 
    12081222end 
     
    12121226  @@schema_type = "InvalidFieldFault" 
    12131227  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1214   @@schema_element = [] 
    1215  
    1216   def initialize 
     1228  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1229 
     1230  attr_accessor :exceptionCode 
     1231  attr_accessor :exceptionMessage 
     1232 
     1233  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1234    @exceptionCode = exceptionCode 
     1235    @exceptionMessage = exceptionMessage 
    12171236  end 
    12181237end 
     
    12221241  @@schema_type = "MalformedQueryFault" 
    12231242  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1224   @@schema_element = [] 
    1225  
    1226   def initialize 
     1243  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1244 
     1245  attr_accessor :exceptionCode 
     1246  attr_accessor :exceptionMessage 
     1247 
     1248  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1249    @exceptionCode = exceptionCode 
     1250    @exceptionMessage = exceptionMessage 
    12271251  end 
    12281252end 
     
    12321256  @@schema_type = "InvalidQueryLocatorFault" 
    12331257  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1234   @@schema_element = [] 
    1235  
    1236   def initialize 
     1258  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1259 
     1260  attr_accessor :exceptionCode 
     1261  attr_accessor :exceptionMessage 
     1262 
     1263  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1264    @exceptionCode = exceptionCode 
     1265    @exceptionMessage = exceptionMessage 
    12371266  end 
    12381267end 
     
    12421271  @@schema_type = "MalformedSearchFault" 
    12431272  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1244   @@schema_element = [] 
    1245  
    1246   def initialize 
     1273  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1274 
     1275  attr_accessor :exceptionCode 
     1276  attr_accessor :exceptionMessage 
     1277 
     1278  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1279    @exceptionCode = exceptionCode 
     1280    @exceptionMessage = exceptionMessage 
    12471281  end 
    12481282end 
     
    12521286  @@schema_type = "InvalidNewPasswordFault" 
    12531287  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1254   @@schema_element = [] 
    1255  
    1256   def initialize 
     1288  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1289 
     1290  attr_accessor :exceptionCode 
     1291  attr_accessor :exceptionMessage 
     1292 
     1293  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1294    @exceptionCode = exceptionCode 
     1295    @exceptionMessage = exceptionMessage 
    12571296  end 
    12581297end 
     
    12621301  @@schema_type = "InvalidIdFault" 
    12631302  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1264   @@schema_element = [] 
    1265  
    1266   def initialize 
     1303  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1304 
     1305  attr_accessor :exceptionCode 
     1306  attr_accessor :exceptionMessage 
     1307 
     1308  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1309    @exceptionCode = exceptionCode 
     1310    @exceptionMessage = exceptionMessage 
    12671311  end 
    12681312end 
     
    12721316  @@schema_type = "UnexpectedErrorFault" 
    12731317  @@schema_ns = "urn:fault.partner.soap.sforce.com" 
    1274   @@schema_element = [] 
    1275  
    1276   def initialize 
     1318  @@schema_element = [["exceptionCode", "SOAP::SOAPString"], ["exceptionMessage", "SOAP::SOAPString"]] 
     1319 
     1320  attr_accessor :exceptionCode 
     1321  attr_accessor :exceptionMessage 
     1322 
     1323  def initialize(exceptionCode = nil, exceptionMessage = nil) 
     1324    @exceptionCode = exceptionCode 
     1325    @exceptionMessage = exceptionMessage 
    12771326  end 
    12781327end 
  • trunk/test/wsdl/any/expectedEcho.rb

    r1649 r1650  
    55  @@schema_type = "foo.bar" 
    66  @@schema_ns = "urn:example.com:echo-type" 
    7   @@schema_element = [
     7  @@schema_element = [["before", ["SOAP::SOAPString", XSD::QName.new(nil, "before")]], ["any", [nil, XSD::QName.new("http://www.w3.org/2001/XMLSchema", "anyType")]], ["after", ["SOAP::SOAPString", XSD::QName.new(nil, "after")]]
    88 
     9  attr_accessor :before 
    910  attr_reader :__xmlele_any 
     11  attr_accessor :after 
    1012 
    1113  def set_any(elements) 
     
    1315  end 
    1416 
    15   def initialize 
     17  def initialize(before = nil, after = nil) 
     18    @before = before 
    1619    @__xmlele_any = nil 
     20    @after = after 
    1721  end 
    1822end 
  • trunk/test/wsdl/any/test_any.rb

    r1649 r1650  
    154154      ] 
    155155    ) 
    156     p @client.echo(arg) 
     156    res = @client.echo(arg) 
     157    assert_equal(arg.before, res.before) 
     158    assert_equal("bar", res.foo) 
     159    assert_equal("qux", res.baz) 
     160    assert_equal(arg.after, res.after) 
    157161  end 
    158162end