Changeset 1650
- Timestamp:
- 10/19/05 22:35:12 (3 years ago)
- Files:
-
- trunk/lib/soap/baseData.rb (modified) (1 diff)
- trunk/lib/soap/mapping/mapping.rb (modified) (2 diffs)
- trunk/lib/soap/mapping/wsdlliteralregistry.rb (modified) (3 diffs)
- trunk/lib/wsdl/soap/classDefCreator.rb (modified) (1 diff)
- trunk/sample/wsdl/salesforce/client.rb (modified) (2 diffs)
- trunk/sample/wsdl/salesforce/default.rb (modified) (11 diffs)
- trunk/test/wsdl/any/expectedEcho.rb (modified) (2 diffs)
- trunk/test/wsdl/any/test_any.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/soap/baseData.rb
r1649 r1650 621 621 else 622 622 k, v = value 623 ele = from_obj(v alue)624 ele. name = XSD::QName.new(nil, k)623 ele = from_obj(v) 624 ele.elename = XSD::QName.new(nil, k) 625 625 ele 626 626 end trunk/lib/soap/mapping/mapping.rb
r1649 r1650 345 345 346 346 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 348 349 schema_ns = schema_ns_definition(klass) 349 350 elements = [] 350 351 as_array = [] 352 have_any = false 351 353 schema_element.each do |varname, definition| 352 354 class_name, name = definition … … 355 357 as_array << (name ? name.name : varname) 356 358 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] 360 366 end 361 367 trunk/lib/soap/mapping/wsdlliteralregistry.rb
r1649 r1650 165 165 else 166 166 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 171 173 end 172 174 end … … 247 249 248 250 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 250 256 if elements 251 257 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) 253 265 if as_array.include?(elename.name) 254 266 child.each do |item| … … 455 467 # changed while a lifetime of a WSDLLiteralRegistry. 456 468 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) 458 471 end 459 472 460 473 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) 462 476 end 463 477 end trunk/lib/wsdl/soap/classDefCreator.rb
r1649 r1650 148 148 end 149 149 init_lines << "@__xmlele_any = nil\n" 150 varname = 'any' # not used 151 eleqname = XSD::AnyTypeName 152 type = nil 153 schema_element << [varname, eleqname, type] 150 154 next 151 155 end trunk/sample/wsdl/salesforce/client.rb
r1609 r1650 1 1 #!/usr/bin/env ruby 2 2 3 require 'defaultDriver.rb' 3 4 require 'soap/header/simplehandler' 5 include XSD 6 include SOAP 4 7 5 8 class SessionHeaderHandler < SOAP::Header::SimpleHandler … … 50 53 obj.wiredump_dev = STDOUT 51 54 55 if false 56 require 'soap/wsdlDriver' 57 obj = SOAP::WSDLDriverFactory.new("partner.wsdl").create_rpc_driver 58 end 59 60 ns = "urn:sobject.partner.soap.sforce.com" 61 62 if false 63 require 'orderedhash' 64 sobj = OrderedHash.new 65 sobj[QName.new(ns, "type")] = "Contact" 66 sobj[QName.new(ns, "Id")] = "012345678901234567" 67 #sobj["type"] = "Contact" 68 #sobj["Id"] = "012345678901234567" 69 sobj[:FirstName] = "Joe" 70 sobj[:lastname] = "Blow" 71 sobj[:Salutation] = "Mr." 72 sobj[:Phone] = "999.999.9999" 73 sobj[:Title] = "Purchasing Director" 74 obj.test_loopback_response << '' 75 obj.create(:sObjects => [sobj, sobj]) 76 end 77 78 if false 79 ns1 = 'urn:partner.soap.sforce.com' 80 ns2 = "urn:sobject.partner.soap.sforce.com" 81 ele = SOAPElement.new(QName.new(ns1, 'create')) 82 sobj = SOAPElement.new(QName.new(ns1, 'sObjects')) 83 sobj.add(SOAPElement.new(QName.new(ns2, "type"), "Contact")) 84 sobj.add(SOAPElement.new(QName.new(ns2, 'Id'), "012345678901234567")) 85 sobj.add(SOAPElement.new(QName.new(nil, 'FirstName'), 'Joe')) 86 sobj.add(SOAPElement.new(QName.new(nil, 'lastname'), 'Blow')) 87 sobj.add(SOAPElement.new(QName.new(nil, 'Salutation'), 'Mr.')) 88 sobj.add(SOAPElement.new(QName.new(nil, 'Phone'), '999.999.9999')) 89 sobj.add(SOAPElement.new(QName.new(nil, 'Title'), 'Purchasing Director')) 90 ele.add(sobj) 91 ele.add(sobj) 92 obj.test_loopback_response << '' 93 obj.create(:sObjects => [sobj, sobj]) rescue nil 94 end 95 96 sobj = [ 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 ] 105 obj.test_loopback_response << '' 106 obj.create(:sObjects => [sobj, sobj]) rescue nil 107 108 109 mycontact = SObject.new 110 mycontact.type = "Contact" 111 mycontact.Id = "012345678901234567" 112 mycontact.set_any([ 113 [:FirstName, "Joe"], 114 [:lastname, "Blow"], 115 [:Salutation, "Mr."], 116 [:Phone, "999.999.9999"], 117 [:Title, "Purchasing Director"] 118 ]) 119 120 obj.test_loopback_response << '' 121 obj.create(Create.new([mycontact, mycontact])) rescue nil 122 exit 123 124 125 126 ns = "urn:sobject.partner.soap.sforce.com" 127 ele = SOAP::SOAPElement.new(XSD::QName.new(nil, "type")) 128 ele.text = "Contact" 129 ele.extraattr["xmlns"] = ns 130 131 sobj = SObject.new("Contact") 132 sobj.instance_eval do 133 @Id = "id" 134 @FirstName = "Joe" 135 @lastname = "Blow" 136 @Salutation = "Mr." 137 @Phone = "999.999.9999" 138 @Title = "Purchasing Director" 139 end 140 141 obj.create(Create.new([sobj])) 142 #obj.create(Create.new([SObject.new(ele, ["fields", "To", "Null"], "id", {"LastName" => "Spaceley"}) ])) 143 144 exit 145 52 146 calloptions_handler.client = 'client' 53 147 trunk/sample/wsdl/salesforce/default.rb
r1630 r1650 590 590 @@schema_type = "sObject" 591 591 @@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")]]] 593 593 594 594 attr_accessor :type 595 595 attr_accessor :fieldsToNull 596 attr_ accessor :any596 attr_reader :__xmlele_any 597 597 598 598 def Id … … 604 604 end 605 605 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) 607 611 @type = type 608 612 @fieldsToNull = fieldsToNull 609 613 @id = id 610 @ any = any614 @__xmlele_any = nil 611 615 end 612 616 end … … 1192 1196 @@schema_type = "LoginFault" 1193 1197 @@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 1197 1206 end 1198 1207 end … … 1202 1211 @@schema_type = "InvalidSObjectFault" 1203 1212 @@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 1207 1221 end 1208 1222 end … … 1212 1226 @@schema_type = "InvalidFieldFault" 1213 1227 @@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 1217 1236 end 1218 1237 end … … 1222 1241 @@schema_type = "MalformedQueryFault" 1223 1242 @@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 1227 1251 end 1228 1252 end … … 1232 1256 @@schema_type = "InvalidQueryLocatorFault" 1233 1257 @@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 1237 1266 end 1238 1267 end … … 1242 1271 @@schema_type = "MalformedSearchFault" 1243 1272 @@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 1247 1281 end 1248 1282 end … … 1252 1286 @@schema_type = "InvalidNewPasswordFault" 1253 1287 @@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 1257 1296 end 1258 1297 end … … 1262 1301 @@schema_type = "InvalidIdFault" 1263 1302 @@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 1267 1311 end 1268 1312 end … … 1272 1316 @@schema_type = "UnexpectedErrorFault" 1273 1317 @@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 1277 1326 end 1278 1327 end trunk/test/wsdl/any/expectedEcho.rb
r1649 r1650 5 5 @@schema_type = "foo.bar" 6 6 @@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")]]] 8 8 9 attr_accessor :before 9 10 attr_reader :__xmlele_any 11 attr_accessor :after 10 12 11 13 def set_any(elements) … … 13 15 end 14 16 15 def initialize 17 def initialize(before = nil, after = nil) 18 @before = before 16 19 @__xmlele_any = nil 20 @after = after 17 21 end 18 22 end trunk/test/wsdl/any/test_any.rb
r1649 r1650 154 154 ] 155 155 ) 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) 157 161 end 158 162 end