soap4r-ng 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/wsdl2ruby.rb +140 -0
- data/bin/xsd2ruby.rb +92 -0
- data/lib/soap/attachment.rb +109 -0
- data/lib/soap/attrproxy.rb +35 -0
- data/lib/soap/baseData.rb +1095 -0
- data/lib/soap/element.rb +278 -0
- data/lib/soap/encodingstyle/aspDotNetHandler.rb +208 -0
- data/lib/soap/encodingstyle/handler.rb +121 -0
- data/lib/soap/encodingstyle/literalHandler.rb +196 -0
- data/lib/soap/encodingstyle/soapHandler.rb +560 -0
- data/lib/soap/filter.rb +14 -0
- data/lib/soap/filter/filterchain.rb +52 -0
- data/lib/soap/filter/handler.rb +32 -0
- data/lib/soap/filter/streamhandler.rb +30 -0
- data/lib/soap/generator.rb +299 -0
- data/lib/soap/header/handler.rb +62 -0
- data/lib/soap/header/handlerset.rb +71 -0
- data/lib/soap/header/mappinghandler.rb +48 -0
- data/lib/soap/header/simplehandler.rb +45 -0
- data/lib/soap/httpconfigloader.rb +140 -0
- data/lib/soap/mapping.rb +13 -0
- data/lib/soap/mapping/encodedregistry.rb +541 -0
- data/lib/soap/mapping/factory.rb +389 -0
- data/lib/soap/mapping/literalregistry.rb +392 -0
- data/lib/soap/mapping/mapping.rb +577 -0
- data/lib/soap/mapping/registry.rb +296 -0
- data/lib/soap/mapping/rubytypeFactory.rb +446 -0
- data/lib/soap/mapping/schemadefinition.rb +171 -0
- data/lib/soap/mapping/typeMap.rb +107 -0
- data/lib/soap/mapping/wsdlencodedregistry.rb +212 -0
- data/lib/soap/mapping/wsdlliteralregistry.rb +249 -0
- data/lib/soap/marshal.rb +60 -0
- data/lib/soap/mimemessage.rb +243 -0
- data/lib/soap/nestedexception.rb +43 -0
- data/lib/soap/netHttpClient.rb +242 -0
- data/lib/soap/ns.rb +39 -0
- data/lib/soap/parser.rb +253 -0
- data/lib/soap/processor.rb +67 -0
- data/lib/soap/property.rb +330 -0
- data/lib/soap/proxy.rb +15 -0
- data/lib/soap/rpc/cgistub.rb +249 -0
- data/lib/soap/rpc/driver.rb +222 -0
- data/lib/soap/rpc/element.rb +375 -0
- data/lib/soap/rpc/httpserver.rb +144 -0
- data/lib/soap/rpc/methodDef.rb +69 -0
- data/lib/soap/rpc/proxy.rb +573 -0
- data/lib/soap/rpc/router.rb +663 -0
- data/lib/soap/rpc/rpc.rb +26 -0
- data/lib/soap/rpc/soaplet.rb +201 -0
- data/lib/soap/rpc/standaloneServer.rb +44 -0
- data/lib/soap/soap.rb +154 -0
- data/lib/soap/streamHandler.rb +302 -0
- data/lib/soap/version.rb +9 -0
- data/lib/soap/wsdlDriver.rb +165 -0
- data/lib/wsdl/binding.rb +66 -0
- data/lib/wsdl/data.rb +65 -0
- data/lib/wsdl/definitions.rb +237 -0
- data/lib/wsdl/documentation.rb +33 -0
- data/lib/wsdl/import.rb +81 -0
- data/lib/wsdl/importer.rb +39 -0
- data/lib/wsdl/info.rb +51 -0
- data/lib/wsdl/message.rb +55 -0
- data/lib/wsdl/operation.rb +152 -0
- data/lib/wsdl/operationBinding.rb +241 -0
- data/lib/wsdl/param.rb +94 -0
- data/lib/wsdl/parser.rb +180 -0
- data/lib/wsdl/part.rb +53 -0
- data/lib/wsdl/port.rb +67 -0
- data/lib/wsdl/portType.rb +76 -0
- data/lib/wsdl/service.rb +62 -0
- data/lib/wsdl/soap/address.rb +41 -0
- data/lib/wsdl/soap/binding.rb +50 -0
- data/lib/wsdl/soap/body.rb +59 -0
- data/lib/wsdl/soap/cgiStubCreator.rb +93 -0
- data/lib/wsdl/soap/classDefCreator.rb +434 -0
- data/lib/wsdl/soap/classDefCreatorSupport.rb +241 -0
- data/lib/wsdl/soap/classNameCreator.rb +55 -0
- data/lib/wsdl/soap/clientSkeltonCreator.rb +107 -0
- data/lib/wsdl/soap/complexType.rb +174 -0
- data/lib/wsdl/soap/data.rb +43 -0
- data/lib/wsdl/soap/definitions.rb +201 -0
- data/lib/wsdl/soap/driverCreator.rb +121 -0
- data/lib/wsdl/soap/element.rb +34 -0
- data/lib/wsdl/soap/encodedMappingRegistryCreator.rb +74 -0
- data/lib/wsdl/soap/fault.rb +57 -0
- data/lib/wsdl/soap/header.rb +87 -0
- data/lib/wsdl/soap/headerfault.rb +57 -0
- data/lib/wsdl/soap/literalMappingRegistryCreator.rb +116 -0
- data/lib/wsdl/soap/mappingRegistryCreator.rb +59 -0
- data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +377 -0
- data/lib/wsdl/soap/methodDefCreator.rb +200 -0
- data/lib/wsdl/soap/operation.rb +113 -0
- data/lib/wsdl/soap/servantSkeltonCreator.rb +92 -0
- data/lib/wsdl/soap/servletStubCreator.rb +105 -0
- data/lib/wsdl/soap/standaloneServerStubCreator.rb +101 -0
- data/lib/wsdl/soap/wsdl2ruby.rb +227 -0
- data/lib/wsdl/types.rb +45 -0
- data/lib/wsdl/wsdl.rb +25 -0
- data/lib/wsdl/xmlSchema/all.rb +25 -0
- data/lib/wsdl/xmlSchema/annotation.rb +35 -0
- data/lib/wsdl/xmlSchema/any.rb +62 -0
- data/lib/wsdl/xmlSchema/anyAttribute.rb +49 -0
- data/lib/wsdl/xmlSchema/attribute.rb +105 -0
- data/lib/wsdl/xmlSchema/attributeGroup.rb +69 -0
- data/lib/wsdl/xmlSchema/choice.rb +59 -0
- data/lib/wsdl/xmlSchema/complexContent.rb +98 -0
- data/lib/wsdl/xmlSchema/complexExtension.rb +120 -0
- data/lib/wsdl/xmlSchema/complexRestriction.rb +105 -0
- data/lib/wsdl/xmlSchema/complexType.rb +194 -0
- data/lib/wsdl/xmlSchema/content.rb +96 -0
- data/lib/wsdl/xmlSchema/data.rb +117 -0
- data/lib/wsdl/xmlSchema/element.rb +154 -0
- data/lib/wsdl/xmlSchema/enumeration.rb +37 -0
- data/lib/wsdl/xmlSchema/fractiondigits.rb +38 -0
- data/lib/wsdl/xmlSchema/group.rb +101 -0
- data/lib/wsdl/xmlSchema/import.rb +53 -0
- data/lib/wsdl/xmlSchema/importHandler.rb +45 -0
- data/lib/wsdl/xmlSchema/importer.rb +103 -0
- data/lib/wsdl/xmlSchema/include.rb +48 -0
- data/lib/wsdl/xmlSchema/length.rb +38 -0
- data/lib/wsdl/xmlSchema/list.rb +49 -0
- data/lib/wsdl/xmlSchema/maxexclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/maxinclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/maxlength.rb +38 -0
- data/lib/wsdl/xmlSchema/minexclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/mininclusive.rb +38 -0
- data/lib/wsdl/xmlSchema/minlength.rb +38 -0
- data/lib/wsdl/xmlSchema/parser.rb +168 -0
- data/lib/wsdl/xmlSchema/pattern.rb +37 -0
- data/lib/wsdl/xmlSchema/ref.rb +34 -0
- data/lib/wsdl/xmlSchema/schema.rb +179 -0
- data/lib/wsdl/xmlSchema/sequence.rb +55 -0
- data/lib/wsdl/xmlSchema/simpleContent.rb +70 -0
- data/lib/wsdl/xmlSchema/simpleExtension.rb +63 -0
- data/lib/wsdl/xmlSchema/simpleRestriction.rb +133 -0
- data/lib/wsdl/xmlSchema/simpleType.rb +88 -0
- data/lib/wsdl/xmlSchema/totaldigits.rb +38 -0
- data/lib/wsdl/xmlSchema/union.rb +36 -0
- data/lib/wsdl/xmlSchema/unique.rb +35 -0
- data/lib/wsdl/xmlSchema/whitespace.rb +38 -0
- data/lib/wsdl/xmlSchema/xsd2ruby.rb +177 -0
- data/lib/xsd/charset.rb +190 -0
- data/lib/xsd/codegen.rb +13 -0
- data/lib/xsd/codegen/classdef.rb +209 -0
- data/lib/xsd/codegen/commentdef.rb +35 -0
- data/lib/xsd/codegen/gensupport.rb +277 -0
- data/lib/xsd/codegen/methoddef.rb +71 -0
- data/lib/xsd/codegen/moduledef.rb +209 -0
- data/lib/xsd/datatypes.rb +1465 -0
- data/lib/xsd/datatypes1999.rb +21 -0
- data/lib/xsd/iconvcharset.rb +33 -0
- data/lib/xsd/mapping.rb +69 -0
- data/lib/xsd/namedelements.rb +133 -0
- data/lib/xsd/ns.rb +183 -0
- data/lib/xsd/qname.rb +80 -0
- data/lib/xsd/xmlparser.rb +81 -0
- data/lib/xsd/xmlparser/libxmlparser.rb +135 -0
- data/lib/xsd/xmlparser/nokogiriparser.rb +58 -0
- data/lib/xsd/xmlparser/ogaparser.rb +63 -0
- data/lib/xsd/xmlparser/oxparser.rb +101 -0
- data/lib/xsd/xmlparser/parser.rb +101 -0
- data/lib/xsd/xmlparser/rexmlparser.rb +58 -0
- metadata +236 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# SOAP4R - SOAP Header handler set
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'xsd/namedelements'
|
11
|
+
|
12
|
+
|
13
|
+
module SOAP
|
14
|
+
module Header
|
15
|
+
|
16
|
+
|
17
|
+
class HandlerSet
|
18
|
+
def initialize
|
19
|
+
@store = XSD::NamedElements.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def dup
|
23
|
+
obj = HandlerSet.new
|
24
|
+
obj.store = @store.dup
|
25
|
+
obj
|
26
|
+
end
|
27
|
+
|
28
|
+
def add(handler)
|
29
|
+
@store << handler
|
30
|
+
end
|
31
|
+
alias << add
|
32
|
+
|
33
|
+
def delete(handler)
|
34
|
+
@store.delete(handler)
|
35
|
+
end
|
36
|
+
|
37
|
+
def include?(handler)
|
38
|
+
@store.include?(handler)
|
39
|
+
end
|
40
|
+
|
41
|
+
# returns: Array of SOAPHeaderItem
|
42
|
+
def on_outbound(header)
|
43
|
+
@store.collect { |handler|
|
44
|
+
handler.on_outbound_headeritem(header)
|
45
|
+
}.compact
|
46
|
+
end
|
47
|
+
|
48
|
+
# header: SOAPHeaderItem enumerable object
|
49
|
+
def on_inbound(header)
|
50
|
+
header.each do |name, item|
|
51
|
+
handler = @store.find { |handler|
|
52
|
+
handler.elename == item.element.elename
|
53
|
+
}
|
54
|
+
if handler
|
55
|
+
handler.on_inbound_headeritem(header, item)
|
56
|
+
elsif item.mustunderstand
|
57
|
+
raise UnhandledMustUnderstandHeaderError.new(item.element.elename.to_s)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def store=(store)
|
65
|
+
@store = store
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# SOAP4R - SOAP Mapping header item handler
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'soap/header/handler'
|
11
|
+
require 'soap/mapping/mapping'
|
12
|
+
|
13
|
+
|
14
|
+
module SOAP
|
15
|
+
module Header
|
16
|
+
|
17
|
+
|
18
|
+
class MappingHandler < SOAP::Header::Handler
|
19
|
+
attr_accessor :registry
|
20
|
+
|
21
|
+
def initialize(elename, registry = nil)
|
22
|
+
super(elename)
|
23
|
+
@registry = registry
|
24
|
+
end
|
25
|
+
|
26
|
+
# Should return an Object for mapping
|
27
|
+
def on_mapping_outbound
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Given header is a mapped Object
|
32
|
+
def on_mapping_inbound(obj, mustunderstand)
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_outbound
|
36
|
+
obj = on_mapping_outbound
|
37
|
+
obj ? SOAP::Mapping.obj2soap(obj, @registry, @elename) : nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_inbound(header, mustunderstand)
|
41
|
+
obj = SOAP::Mapping.soap2obj(header, @registry)
|
42
|
+
on_mapping_inbound(obj, mustunderstand)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# SOAP4R - SOAP Simple header item handler
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'soap/header/handler'
|
11
|
+
require 'soap/baseData'
|
12
|
+
|
13
|
+
|
14
|
+
module SOAP
|
15
|
+
module Header
|
16
|
+
|
17
|
+
|
18
|
+
class SimpleHandler < SOAP::Header::Handler
|
19
|
+
def initialize(elename)
|
20
|
+
super(elename)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Should return a Hash, String or nil.
|
24
|
+
def on_simple_outbound
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
# Given header is a Hash, String or nil.
|
29
|
+
def on_simple_inbound(header, mustunderstand)
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_outbound
|
33
|
+
h = on_simple_outbound
|
34
|
+
h ? SOAPElement.from_obj(h, elename.namespace) : nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def on_inbound(header, mustunderstand)
|
38
|
+
h = header.respond_to?(:to_obj) ? header.to_obj : header.data
|
39
|
+
on_simple_inbound(h, mustunderstand)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# SOAP4R - HTTP config loader.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'soap/property'
|
11
|
+
|
12
|
+
|
13
|
+
module SOAP
|
14
|
+
|
15
|
+
|
16
|
+
module HTTPConfigLoader
|
17
|
+
module_function
|
18
|
+
|
19
|
+
def set_options(client, options)
|
20
|
+
client.proxy = options["proxy"]
|
21
|
+
options.add_hook("proxy") do |key, value|
|
22
|
+
client.proxy = value
|
23
|
+
end
|
24
|
+
client.no_proxy = options["no_proxy"]
|
25
|
+
options.add_hook("no_proxy") do |key, value|
|
26
|
+
client.no_proxy = value
|
27
|
+
end
|
28
|
+
if client.respond_to?(:protocol_version=)
|
29
|
+
client.protocol_version = options["protocol_version"]
|
30
|
+
options.add_hook("protocol_version") do |key, value|
|
31
|
+
client.protocol_version = value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
ssl_config = options["ssl_config"] ||= ::SOAP::Property.new
|
35
|
+
set_ssl_config(client, ssl_config)
|
36
|
+
ssl_config.add_hook(true) do |key, value|
|
37
|
+
set_ssl_config(client, ssl_config)
|
38
|
+
end
|
39
|
+
basic_auth = options["basic_auth"] ||= ::SOAP::Property.new
|
40
|
+
set_basic_auth(client, basic_auth)
|
41
|
+
basic_auth.add_hook do |key, value|
|
42
|
+
set_basic_auth(client, basic_auth)
|
43
|
+
end
|
44
|
+
auth = options["auth"] ||= ::SOAP::Property.new
|
45
|
+
set_auth(client, auth)
|
46
|
+
auth.add_hook do |key, value|
|
47
|
+
set_auth(client, auth)
|
48
|
+
end
|
49
|
+
options.add_hook("connect_timeout") do |key, value|
|
50
|
+
client.connect_timeout = value
|
51
|
+
end
|
52
|
+
options.add_hook("send_timeout") do |key, value|
|
53
|
+
client.send_timeout = value
|
54
|
+
end
|
55
|
+
options.add_hook("receive_timeout") do |key, value|
|
56
|
+
client.receive_timeout = value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_basic_auth(client, basic_auth)
|
61
|
+
basic_auth.values.each do |ele|
|
62
|
+
client.set_basic_auth(*authele_to_triplets(ele))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_auth(client, auth)
|
67
|
+
auth.values.each do |ele|
|
68
|
+
client.set_auth(*authele_to_triplets(ele))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def authele_to_triplets(ele)
|
73
|
+
if ele.is_a?(::Array)
|
74
|
+
url, userid, passwd = ele
|
75
|
+
else
|
76
|
+
url, userid, passwd = ele[:url], ele[:userid], ele[:password]
|
77
|
+
end
|
78
|
+
return url, userid, passwd
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_ssl_config(client, ssl_config)
|
82
|
+
ssl_config.each do |key, value|
|
83
|
+
cfg = client.ssl_config
|
84
|
+
if cfg.nil?
|
85
|
+
raise NotImplementedError.new("SSL not supported")
|
86
|
+
end
|
87
|
+
case key
|
88
|
+
when 'client_cert'
|
89
|
+
cfg.client_cert = cert_from_file(value)
|
90
|
+
when 'client_key'
|
91
|
+
cfg.client_key = key_from_file(value)
|
92
|
+
when 'client_ca'
|
93
|
+
cfg.client_ca = value
|
94
|
+
when 'ca_path'
|
95
|
+
cfg.set_trust_ca(value)
|
96
|
+
when 'ca_file'
|
97
|
+
cfg.set_trust_ca(value)
|
98
|
+
when 'crl'
|
99
|
+
cfg.set_crl(value)
|
100
|
+
when 'verify_mode'
|
101
|
+
cfg.verify_mode = ssl_config_int(value)
|
102
|
+
when 'verify_depth'
|
103
|
+
cfg.verify_depth = ssl_config_int(value)
|
104
|
+
when 'options'
|
105
|
+
cfg.options = value
|
106
|
+
when 'ciphers'
|
107
|
+
cfg.ciphers = value
|
108
|
+
when 'verify_callback'
|
109
|
+
cfg.verify_callback = value
|
110
|
+
when 'cert_store'
|
111
|
+
cfg.cert_store = value
|
112
|
+
else
|
113
|
+
raise ArgumentError.new("unknown ssl_config property #{key}")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def ssl_config_int(value)
|
119
|
+
if value.nil? or value.to_s.empty?
|
120
|
+
nil
|
121
|
+
else
|
122
|
+
begin
|
123
|
+
Integer(value)
|
124
|
+
rescue ArgumentError
|
125
|
+
::SOAP::Property::Util.const_from_name(value.to_s)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def cert_from_file(filename)
|
131
|
+
OpenSSL::X509::Certificate.new(File.open(filename) { |f| f.read })
|
132
|
+
end
|
133
|
+
|
134
|
+
def key_from_file(filename)
|
135
|
+
OpenSSL::PKey::RSA.new(File.open(filename) { |f| f.read })
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|
data/lib/soap/mapping.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# SOAP4R - Ruby type mapping utility.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'soap/mapping/mapping'
|
11
|
+
require 'soap/mapping/registry'
|
12
|
+
require 'soap/mapping/encodedregistry'
|
13
|
+
require 'soap/mapping/literalregistry'
|
@@ -0,0 +1,541 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# SOAP4R - encoded mapping registry.
|
3
|
+
# Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
4
|
+
|
5
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
6
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
7
|
+
# either the dual license version in 2003, or any later version.
|
8
|
+
|
9
|
+
|
10
|
+
require 'soap/baseData'
|
11
|
+
require 'soap/mapping/mapping'
|
12
|
+
require 'soap/mapping/typeMap'
|
13
|
+
require 'soap/mapping/factory'
|
14
|
+
require 'soap/mapping/rubytypeFactory'
|
15
|
+
module SOAP
|
16
|
+
module Mapping
|
17
|
+
|
18
|
+
|
19
|
+
# Inner class to pass an exception.
|
20
|
+
class SOAPException
|
21
|
+
attr_reader :excn_type_name, :cause
|
22
|
+
|
23
|
+
def initialize(e)
|
24
|
+
@excn_type_name = Mapping.name2elename(e.class.to_s)
|
25
|
+
@cause = e
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_e
|
29
|
+
if @cause.is_a?(::Exception)
|
30
|
+
@cause.extend(::SOAP::Mapping::MappedException)
|
31
|
+
return @cause
|
32
|
+
elsif @cause.respond_to?(:message) and @cause.respond_to?(:backtrace)
|
33
|
+
e = RuntimeError.new(@cause.message)
|
34
|
+
e.set_backtrace(@cause.backtrace)
|
35
|
+
return e
|
36
|
+
end
|
37
|
+
klass = Mapping.class_from_name(Mapping.elename2name(@excn_type_name.to_s))
|
38
|
+
if klass.nil? or not klass <= ::Exception
|
39
|
+
return RuntimeError.new(@cause.inspect)
|
40
|
+
end
|
41
|
+
obj = klass.new(@cause.message)
|
42
|
+
obj.extend(::SOAP::Mapping::MappedException)
|
43
|
+
obj
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
class EncodedRegistry
|
49
|
+
include TraverseSupport
|
50
|
+
include RegistrySupport
|
51
|
+
|
52
|
+
class Map
|
53
|
+
def initialize(registry)
|
54
|
+
@obj2soap = {}
|
55
|
+
@soap2obj = {}
|
56
|
+
@registry = registry
|
57
|
+
end
|
58
|
+
|
59
|
+
def obj2soap(obj)
|
60
|
+
klass = obj.class
|
61
|
+
if map = @obj2soap[klass]
|
62
|
+
map.each do |soap_class, factory, info|
|
63
|
+
ret = factory.obj2soap(soap_class, obj, info, @registry)
|
64
|
+
return ret if ret
|
65
|
+
end
|
66
|
+
end
|
67
|
+
klass.ancestors.each do |baseclass|
|
68
|
+
next if baseclass == klass
|
69
|
+
if map = @obj2soap[baseclass]
|
70
|
+
map.each do |soap_class, factory, info|
|
71
|
+
if info[:derived_class]
|
72
|
+
ret = factory.obj2soap(soap_class, obj, info, @registry)
|
73
|
+
return ret if ret
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def soap2obj(node, klass = nil)
|
82
|
+
if map = @soap2obj[node.class]
|
83
|
+
map.each do |obj_class, factory, info|
|
84
|
+
next if klass and obj_class != klass
|
85
|
+
conv, obj = factory.soap2obj(obj_class, node, info, @registry)
|
86
|
+
return true, obj if conv
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return false, nil
|
90
|
+
end
|
91
|
+
|
92
|
+
# Give priority to former entry.
|
93
|
+
def init(init_map = [])
|
94
|
+
clear
|
95
|
+
init_map.reverse_each do |obj_class, soap_class, factory, info|
|
96
|
+
add(obj_class, soap_class, factory, info)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Give priority to latter entry.
|
101
|
+
def add(obj_class, soap_class, factory, info)
|
102
|
+
info ||= {}
|
103
|
+
(@obj2soap[obj_class] ||= []).unshift([soap_class, factory, info])
|
104
|
+
(@soap2obj[soap_class] ||= []).unshift([obj_class, factory, info])
|
105
|
+
end
|
106
|
+
|
107
|
+
def clear
|
108
|
+
@obj2soap.clear
|
109
|
+
@soap2obj.clear
|
110
|
+
end
|
111
|
+
|
112
|
+
def find_mapped_soap_class(target_obj_class)
|
113
|
+
map = @obj2soap[target_obj_class]
|
114
|
+
map.empty? ? nil : map[0][1]
|
115
|
+
end
|
116
|
+
|
117
|
+
def find_mapped_obj_class(target_soap_class)
|
118
|
+
map = @soap2obj[target_soap_class]
|
119
|
+
map.empty? ? nil : map[0][0]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
StringFactory = StringFactory_.new
|
124
|
+
BasetypeFactory = BasetypeFactory_.new
|
125
|
+
FixnumFactory = FixnumFactory_.new
|
126
|
+
DateTimeFactory = DateTimeFactory_.new
|
127
|
+
ArrayFactory = ArrayFactory_.new
|
128
|
+
Base64Factory = Base64Factory_.new
|
129
|
+
URIFactory = URIFactory_.new
|
130
|
+
TypedArrayFactory = TypedArrayFactory_.new
|
131
|
+
TypedStructFactory = TypedStructFactory_.new
|
132
|
+
|
133
|
+
HashFactory = HashFactory_.new
|
134
|
+
|
135
|
+
SOAPBaseMap = [
|
136
|
+
[::NilClass, ::SOAP::SOAPNil, BasetypeFactory],
|
137
|
+
[::TrueClass, ::SOAP::SOAPBoolean, BasetypeFactory],
|
138
|
+
[::FalseClass, ::SOAP::SOAPBoolean, BasetypeFactory],
|
139
|
+
[::String, ::SOAP::SOAPString, StringFactory,
|
140
|
+
{:derived_class => true}],
|
141
|
+
[::DateTime, ::SOAP::SOAPDateTime, DateTimeFactory],
|
142
|
+
[::Date, ::SOAP::SOAPDate, DateTimeFactory],
|
143
|
+
[::Time, ::SOAP::SOAPDateTime, DateTimeFactory],
|
144
|
+
[::Time, ::SOAP::SOAPTime, DateTimeFactory],
|
145
|
+
[::Float, ::SOAP::SOAPDouble, BasetypeFactory,
|
146
|
+
{:derived_class => true}],
|
147
|
+
[::Float, ::SOAP::SOAPFloat, BasetypeFactory,
|
148
|
+
{:derived_class => true}],
|
149
|
+
[::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
|
150
|
+
[::Integer, ::SOAP::SOAPInt, BasetypeFactory,
|
151
|
+
{:derived_class => true}],
|
152
|
+
[::Integer, ::SOAP::SOAPLong, BasetypeFactory,
|
153
|
+
{:derived_class => true}],
|
154
|
+
[::Integer, ::SOAP::SOAPInteger, BasetypeFactory,
|
155
|
+
{:derived_class => true}],
|
156
|
+
[::Integer, ::SOAP::SOAPShort, BasetypeFactory,
|
157
|
+
{:derived_class => true}],
|
158
|
+
[::Integer, ::SOAP::SOAPByte, BasetypeFactory,
|
159
|
+
{:derived_class => true}],
|
160
|
+
[::Integer, ::SOAP::SOAPNonPositiveInteger, BasetypeFactory,
|
161
|
+
{:derived_class => true}],
|
162
|
+
[::Integer, ::SOAP::SOAPNegativeInteger, BasetypeFactory,
|
163
|
+
{:derived_class => true}],
|
164
|
+
[::Integer, ::SOAP::SOAPNonNegativeInteger, BasetypeFactory,
|
165
|
+
{:derived_class => true}],
|
166
|
+
[::Integer, ::SOAP::SOAPPositiveInteger, BasetypeFactory,
|
167
|
+
{:derived_class => true}],
|
168
|
+
[::Integer, ::SOAP::SOAPUnsignedLong, BasetypeFactory,
|
169
|
+
{:derived_class => true}],
|
170
|
+
[::Integer, ::SOAP::SOAPUnsignedInt, BasetypeFactory,
|
171
|
+
{:derived_class => true}],
|
172
|
+
[::Integer, ::SOAP::SOAPUnsignedShort, BasetypeFactory,
|
173
|
+
{:derived_class => true}],
|
174
|
+
[::Integer, ::SOAP::SOAPUnsignedByte, BasetypeFactory,
|
175
|
+
{:derived_class => true}],
|
176
|
+
[::URI::Generic, ::SOAP::SOAPAnyURI, URIFactory,
|
177
|
+
{:derived_class => true}],
|
178
|
+
[::String, ::SOAP::SOAPBase64, Base64Factory],
|
179
|
+
[::String, ::SOAP::SOAPHexBinary, Base64Factory],
|
180
|
+
[::String, ::SOAP::SOAPDecimal, BasetypeFactory],
|
181
|
+
[::String, ::SOAP::SOAPDuration, BasetypeFactory],
|
182
|
+
[::String, ::SOAP::SOAPGYearMonth, BasetypeFactory],
|
183
|
+
[::String, ::SOAP::SOAPGYear, BasetypeFactory],
|
184
|
+
[::String, ::SOAP::SOAPGMonthDay, BasetypeFactory],
|
185
|
+
[::String, ::SOAP::SOAPGDay, BasetypeFactory],
|
186
|
+
[::String, ::SOAP::SOAPGMonth, BasetypeFactory],
|
187
|
+
[::String, ::SOAP::SOAPQName, BasetypeFactory],
|
188
|
+
|
189
|
+
[::Hash, ::SOAP::SOAPArray, HashFactory,
|
190
|
+
{:derived_class => true}],
|
191
|
+
[::Hash, ::SOAP::SOAPStruct, HashFactory,
|
192
|
+
{:derived_class => true}],
|
193
|
+
|
194
|
+
[::Array, ::SOAP::SOAPArray, ArrayFactory,
|
195
|
+
{:derived_class => true}],
|
196
|
+
|
197
|
+
[::SOAP::Mapping::SOAPException,
|
198
|
+
::SOAP::SOAPStruct, TypedStructFactory,
|
199
|
+
{:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
|
200
|
+
]
|
201
|
+
|
202
|
+
RubyOriginalMap = [
|
203
|
+
[::NilClass, ::SOAP::SOAPNil, BasetypeFactory],
|
204
|
+
[::TrueClass, ::SOAP::SOAPBoolean, BasetypeFactory],
|
205
|
+
[::FalseClass, ::SOAP::SOAPBoolean, BasetypeFactory],
|
206
|
+
[::String, ::SOAP::SOAPString, StringFactory],
|
207
|
+
[::DateTime, ::SOAP::SOAPDateTime, DateTimeFactory],
|
208
|
+
[::Date, ::SOAP::SOAPDate, DateTimeFactory],
|
209
|
+
[::Time, ::SOAP::SOAPDateTime, DateTimeFactory],
|
210
|
+
[::Time, ::SOAP::SOAPTime, DateTimeFactory],
|
211
|
+
[::Float, ::SOAP::SOAPDouble, BasetypeFactory,
|
212
|
+
{:derived_class => true}],
|
213
|
+
[::Float, ::SOAP::SOAPFloat, BasetypeFactory,
|
214
|
+
{:derived_class => true}],
|
215
|
+
[::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
|
216
|
+
[::Integer, ::SOAP::SOAPInt, BasetypeFactory,
|
217
|
+
{:derived_class => true}],
|
218
|
+
[::Integer, ::SOAP::SOAPLong, BasetypeFactory,
|
219
|
+
{:derived_class => true}],
|
220
|
+
[::Integer, ::SOAP::SOAPInteger, BasetypeFactory,
|
221
|
+
{:derived_class => true}],
|
222
|
+
[::Integer, ::SOAP::SOAPShort, BasetypeFactory,
|
223
|
+
{:derived_class => true}],
|
224
|
+
[::Integer, ::SOAP::SOAPByte, BasetypeFactory,
|
225
|
+
{:derived_class => true}],
|
226
|
+
[::Integer, ::SOAP::SOAPNonPositiveInteger, BasetypeFactory,
|
227
|
+
{:derived_class => true}],
|
228
|
+
[::Integer, ::SOAP::SOAPNegativeInteger, BasetypeFactory,
|
229
|
+
{:derived_class => true}],
|
230
|
+
[::Integer, ::SOAP::SOAPNonNegativeInteger, BasetypeFactory,
|
231
|
+
{:derived_class => true}],
|
232
|
+
[::Integer, ::SOAP::SOAPPositiveInteger, BasetypeFactory,
|
233
|
+
{:derived_class => true}],
|
234
|
+
[::Integer, ::SOAP::SOAPUnsignedLong, BasetypeFactory,
|
235
|
+
{:derived_class => true}],
|
236
|
+
[::Integer, ::SOAP::SOAPUnsignedInt, BasetypeFactory,
|
237
|
+
{:derived_class => true}],
|
238
|
+
[::Integer, ::SOAP::SOAPUnsignedShort, BasetypeFactory,
|
239
|
+
{:derived_class => true}],
|
240
|
+
[::Integer, ::SOAP::SOAPUnsignedByte, BasetypeFactory,
|
241
|
+
{:derived_class => true}],
|
242
|
+
[::URI::Generic, ::SOAP::SOAPAnyURI, URIFactory,
|
243
|
+
{:derived_class => true}],
|
244
|
+
[::String, ::SOAP::SOAPBase64, Base64Factory],
|
245
|
+
[::String, ::SOAP::SOAPHexBinary, Base64Factory],
|
246
|
+
[::String, ::SOAP::SOAPDecimal, BasetypeFactory],
|
247
|
+
[::String, ::SOAP::SOAPDuration, BasetypeFactory],
|
248
|
+
[::String, ::SOAP::SOAPGYearMonth, BasetypeFactory],
|
249
|
+
[::String, ::SOAP::SOAPGYear, BasetypeFactory],
|
250
|
+
[::String, ::SOAP::SOAPGMonthDay, BasetypeFactory],
|
251
|
+
[::String, ::SOAP::SOAPGDay, BasetypeFactory],
|
252
|
+
[::String, ::SOAP::SOAPGMonth, BasetypeFactory],
|
253
|
+
[::String, ::SOAP::SOAPQName, BasetypeFactory],
|
254
|
+
|
255
|
+
[::Hash, ::SOAP::SOAPArray, HashFactory],
|
256
|
+
[::Hash, ::SOAP::SOAPStruct, HashFactory],
|
257
|
+
|
258
|
+
# Does not allow Array's subclass here.
|
259
|
+
[::Array, ::SOAP::SOAPArray, ArrayFactory],
|
260
|
+
|
261
|
+
[::SOAP::Mapping::SOAPException,
|
262
|
+
::SOAP::SOAPStruct, TypedStructFactory,
|
263
|
+
{:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
|
264
|
+
]
|
265
|
+
|
266
|
+
attr_accessor :default_factory
|
267
|
+
attr_accessor :excn_handler_obj2soap
|
268
|
+
attr_accessor :excn_handler_soap2obj
|
269
|
+
|
270
|
+
def initialize(config = {})
|
271
|
+
super()
|
272
|
+
@config = config
|
273
|
+
@map = Map.new(self)
|
274
|
+
if @config[:allow_original_mapping]
|
275
|
+
@allow_original_mapping = true
|
276
|
+
@map.init(RubyOriginalMap)
|
277
|
+
else
|
278
|
+
@allow_original_mapping = false
|
279
|
+
@map.init(SOAPBaseMap)
|
280
|
+
end
|
281
|
+
@allow_untyped_struct = @config.key?(:allow_untyped_struct) ?
|
282
|
+
@config[:allow_untyped_struct] : true
|
283
|
+
@rubytype_factory = RubytypeFactory.new(
|
284
|
+
:allow_untyped_struct => @allow_untyped_struct,
|
285
|
+
:allow_original_mapping => @allow_original_mapping
|
286
|
+
)
|
287
|
+
@default_factory = @rubytype_factory
|
288
|
+
@excn_handler_obj2soap = nil
|
289
|
+
@excn_handler_soap2obj = nil
|
290
|
+
end
|
291
|
+
|
292
|
+
# initial mapping interface
|
293
|
+
# new interface Registry#register is defined in RegisterSupport
|
294
|
+
def add(obj_class, soap_class, factory, info = nil)
|
295
|
+
@map.add(obj_class, soap_class, factory, info)
|
296
|
+
end
|
297
|
+
alias set add
|
298
|
+
|
299
|
+
def obj2soap(obj, type_qname = nil)
|
300
|
+
soap = _obj2soap(obj, type_qname)
|
301
|
+
if @allow_original_mapping
|
302
|
+
addextend2soap(soap, obj)
|
303
|
+
end
|
304
|
+
soap
|
305
|
+
end
|
306
|
+
|
307
|
+
def soap2obj(node, klass = nil)
|
308
|
+
obj = _soap2obj(node, klass)
|
309
|
+
if @allow_original_mapping
|
310
|
+
addextend2obj(obj, node.extraattr[RubyExtendName])
|
311
|
+
addiv2obj(obj, node.extraattr[RubyIVarName])
|
312
|
+
end
|
313
|
+
obj
|
314
|
+
end
|
315
|
+
|
316
|
+
def find_mapped_soap_class(obj_class)
|
317
|
+
@map.find_mapped_soap_class(obj_class)
|
318
|
+
end
|
319
|
+
|
320
|
+
def find_mapped_obj_class(soap_class)
|
321
|
+
@map.find_mapped_obj_class(soap_class)
|
322
|
+
end
|
323
|
+
|
324
|
+
private
|
325
|
+
|
326
|
+
def _obj2soap(obj, type_qname = nil)
|
327
|
+
ret = nil
|
328
|
+
if obj.is_a?(SOAPCompoundtype)
|
329
|
+
obj.replace do |ele|
|
330
|
+
Mapping._obj2soap(ele, self)
|
331
|
+
end
|
332
|
+
return obj
|
333
|
+
elsif obj.is_a?(SOAPBasetype)
|
334
|
+
return obj
|
335
|
+
elsif type_qname && type = TypeMap[type_qname]
|
336
|
+
return base2soap(obj, type)
|
337
|
+
end
|
338
|
+
cause = nil
|
339
|
+
begin
|
340
|
+
if definition = schema_definition_from_class(obj.class)
|
341
|
+
return stubobj2soap(obj, definition)
|
342
|
+
end
|
343
|
+
ret = @map.obj2soap(obj) ||
|
344
|
+
@default_factory.obj2soap(nil, obj, nil, self)
|
345
|
+
return ret if ret
|
346
|
+
rescue MappingError
|
347
|
+
cause = $!
|
348
|
+
end
|
349
|
+
if @excn_handler_obj2soap
|
350
|
+
ret = @excn_handler_obj2soap.call(obj) { |yield_obj|
|
351
|
+
Mapping._obj2soap(yield_obj, self)
|
352
|
+
}
|
353
|
+
return ret if ret
|
354
|
+
end
|
355
|
+
raise MappingError.new("Cannot map #{ obj.class.name } to SOAP/OM.", cause)
|
356
|
+
end
|
357
|
+
|
358
|
+
# Might return nil as a mapping result.
|
359
|
+
def _soap2obj(node, klass = nil)
|
360
|
+
definition = find_node_definition(node)
|
361
|
+
if klass
|
362
|
+
klass_definition = schema_definition_from_class(klass)
|
363
|
+
if definition and (definition.class_for < klass)
|
364
|
+
klass = definition.class_for
|
365
|
+
else
|
366
|
+
definition = klass_definition
|
367
|
+
end
|
368
|
+
else
|
369
|
+
klass = definition.class_for if definition
|
370
|
+
end
|
371
|
+
if definition and node.is_a?(::SOAP::SOAPNameAccessible)
|
372
|
+
return elesoap2stubobj(node, klass, definition)
|
373
|
+
end
|
374
|
+
if node.extraattr.key?(RubyTypeName)
|
375
|
+
conv, obj = @rubytype_factory.soap2obj(nil, node, nil, self)
|
376
|
+
return obj if conv
|
377
|
+
end
|
378
|
+
conv, obj = @map.soap2obj(node)
|
379
|
+
return obj if conv
|
380
|
+
conv, obj = @default_factory.soap2obj(nil, node, nil, self)
|
381
|
+
return obj if conv
|
382
|
+
cause = nil
|
383
|
+
if @excn_handler_soap2obj
|
384
|
+
begin
|
385
|
+
return @excn_handler_soap2obj.call(node) { |yield_node|
|
386
|
+
Mapping._soap2obj(yield_node, self)
|
387
|
+
}
|
388
|
+
rescue Exception
|
389
|
+
cause = $!
|
390
|
+
end
|
391
|
+
end
|
392
|
+
raise MappingError.new("Cannot map #{ node.type } to Ruby object.", cause)
|
393
|
+
end
|
394
|
+
|
395
|
+
def addiv2obj(obj, attr)
|
396
|
+
return unless attr
|
397
|
+
vars = {}
|
398
|
+
attr.__getobj__.each do |name, value|
|
399
|
+
vars[name] = Mapping._soap2obj(value, self)
|
400
|
+
end
|
401
|
+
Mapping.set_attributes(obj, vars)
|
402
|
+
end
|
403
|
+
|
404
|
+
def addextend2obj(obj, attr)
|
405
|
+
return unless attr
|
406
|
+
attr.split(/ /).reverse_each do |mstr|
|
407
|
+
ext_module = Mapping.module_from_name(mstr)
|
408
|
+
return if ext_module.is_a?(Class) # RubyJedi: Apparently needed for Ruby 2.1 and above?
|
409
|
+
obj.extend(ext_module)
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
def addextend2soap(node, obj)
|
414
|
+
return if [Symbol, Fixnum, Bignum, Float].any?{ |c| obj.is_a?(c) }
|
415
|
+
list = (class << obj; self; end).ancestors - obj.class.ancestors
|
416
|
+
list = list.reject{|c| c.class == Class } ## As of Ruby 2.1 Singleton Classes are now included in the ancestry. Need to filter those out here.
|
417
|
+
|
418
|
+
return if list.empty?
|
419
|
+
extra_attrs = list.collect { |c|
|
420
|
+
name = c.name
|
421
|
+
if name.nil? or name.empty?
|
422
|
+
raise TypeError.new("singleton can't be dumped #{ obj }")
|
423
|
+
end
|
424
|
+
name
|
425
|
+
}.join(" ")
|
426
|
+
node.extraattr[RubyExtendName] = extra_attrs
|
427
|
+
end
|
428
|
+
|
429
|
+
def stubobj2soap(obj, definition)
|
430
|
+
case obj
|
431
|
+
when ::Array
|
432
|
+
array2soap(obj, definition)
|
433
|
+
else
|
434
|
+
unknownstubobj2soap(obj, definition)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
def array2soap(obj, definition)
|
439
|
+
return SOAPNil.new if obj.nil? # ToDo: check nillable.
|
440
|
+
eledef = definition.elements[0]
|
441
|
+
soap_obj = SOAPArray.new(ValueArrayName, 1, eledef.elename)
|
442
|
+
mark_marshalled_obj(obj, soap_obj)
|
443
|
+
obj.each do |item|
|
444
|
+
soap_obj.add(typedobj2soap(item, eledef.mapped_class))
|
445
|
+
end
|
446
|
+
soap_obj
|
447
|
+
end
|
448
|
+
|
449
|
+
def unknownstubobj2soap(obj, definition)
|
450
|
+
return SOAPNil.new if obj.nil?
|
451
|
+
if definition.elements.size == 0
|
452
|
+
ele = Mapping.obj2soap(obj)
|
453
|
+
ele.elename = definition.elename if definition.elename
|
454
|
+
ele.extraattr[XSD::AttrTypeName] = definition.type if definition.type
|
455
|
+
return ele
|
456
|
+
else
|
457
|
+
ele = SOAPStruct.new(definition.type)
|
458
|
+
mark_marshalled_obj(obj, ele)
|
459
|
+
end
|
460
|
+
definition.elements.each do |eledef|
|
461
|
+
name = eledef.elename.name
|
462
|
+
if obj.respond_to?(:each) and eledef.as_array?
|
463
|
+
obj.each do |item|
|
464
|
+
ele.add(name, typedobj2soap(item, eledef.mapped_class))
|
465
|
+
end
|
466
|
+
else
|
467
|
+
child = Mapping.get_attribute(obj, eledef.varname)
|
468
|
+
if child.respond_to?(:each) and eledef.as_array?
|
469
|
+
child = child.lines if child.respond_to?(:lines) # RubyJedi: compatible with Ruby 1.8.6 and above
|
470
|
+
child.each do |item|
|
471
|
+
ele.add(name, typedobj2soap(item, eledef.mapped_class))
|
472
|
+
end
|
473
|
+
else
|
474
|
+
ele.add(name, typedobj2soap(child, eledef.mapped_class))
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
ele
|
479
|
+
end
|
480
|
+
|
481
|
+
def typedobj2soap(value, klass)
|
482
|
+
if klass and klass.include?(::SOAP::SOAPBasetype)
|
483
|
+
base2soap(value, klass)
|
484
|
+
else
|
485
|
+
Mapping._obj2soap(value, self)
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
def elesoap2stubobj(node, obj_class, definition)
|
490
|
+
obj = Mapping.create_empty_object(obj_class)
|
491
|
+
add_elesoap2stubobj(node, obj, definition)
|
492
|
+
obj
|
493
|
+
end
|
494
|
+
|
495
|
+
# XXX consider to merge with the method in LiteralRegistry
|
496
|
+
def add_elesoap2stubobj(node, obj, definition)
|
497
|
+
vars = {}
|
498
|
+
node.each do |name, value|
|
499
|
+
item = definition.elements.find_element(value.elename)
|
500
|
+
if item
|
501
|
+
child = soap2typedobj(value, item.mapped_class)
|
502
|
+
else
|
503
|
+
# unknown element is treated as anyType.
|
504
|
+
child = Mapping._soap2obj(value, self)
|
505
|
+
end
|
506
|
+
if item and item.as_array?
|
507
|
+
(vars[name] ||= []) << child
|
508
|
+
elsif vars.key?(name)
|
509
|
+
vars[name] = [vars[name], child].flatten
|
510
|
+
else
|
511
|
+
vars[name] = child
|
512
|
+
end
|
513
|
+
end
|
514
|
+
if obj.is_a?(::Array) and is_stubobj_elements_for_array(vars)
|
515
|
+
Array.instance_method(:replace).bind(obj).call(vars.values[0])
|
516
|
+
else
|
517
|
+
Mapping.set_attributes(obj, vars)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
def soap2typedobj(value, klass)
|
522
|
+
unless klass
|
523
|
+
raise MappingError.new("unknown class: #{klass}")
|
524
|
+
end
|
525
|
+
if klass.include?(::SOAP::SOAPBasetype)
|
526
|
+
obj = base2obj(value, klass)
|
527
|
+
else
|
528
|
+
obj = Mapping._soap2obj(value, self, klass)
|
529
|
+
end
|
530
|
+
obj
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
|
535
|
+
Registry = EncodedRegistry
|
536
|
+
DefaultRegistry = EncodedRegistry.new
|
537
|
+
RubyOriginalRegistry = EncodedRegistry.new(:allow_original_mapping => true)
|
538
|
+
|
539
|
+
|
540
|
+
end
|
541
|
+
end
|