soybean 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +38 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +44 -0
  8. data/VERSION +1 -0
  9. data/bin/soybean +22 -0
  10. data/bin/xsd2ruby +90 -0
  11. data/lib/soybean.rb +11 -0
  12. data/lib/soybean/actions/generate_classes.rb +33 -0
  13. data/soybean.gemspec +236 -0
  14. data/spec/soybean_spec.rb +5 -0
  15. data/spec/spec_helper.rb +12 -0
  16. data/vendor/soap4r/soap/attachment.rb +109 -0
  17. data/vendor/soap4r/soap/attrproxy.rb +35 -0
  18. data/vendor/soap4r/soap/base_data.rb +1095 -0
  19. data/vendor/soap4r/soap/element.rb +278 -0
  20. data/vendor/soap4r/soap/encodingstyle/asp_dot_net_handler.rb +208 -0
  21. data/vendor/soap4r/soap/encodingstyle/handler.rb +121 -0
  22. data/vendor/soap4r/soap/encodingstyle/literal_handler.rb +196 -0
  23. data/vendor/soap4r/soap/encodingstyle/soap_handler.rb +560 -0
  24. data/vendor/soap4r/soap/filter.rb +14 -0
  25. data/vendor/soap4r/soap/filter/filterchain.rb +52 -0
  26. data/vendor/soap4r/soap/filter/handler.rb +32 -0
  27. data/vendor/soap4r/soap/filter/streamhandler.rb +30 -0
  28. data/vendor/soap4r/soap/generator.rb +299 -0
  29. data/vendor/soap4r/soap/header/handler.rb +62 -0
  30. data/vendor/soap4r/soap/header/handlerset.rb +71 -0
  31. data/vendor/soap4r/soap/header/mappinghandler.rb +48 -0
  32. data/vendor/soap4r/soap/header/simplehandler.rb +45 -0
  33. data/vendor/soap4r/soap/httpconfigloader.rb +140 -0
  34. data/vendor/soap4r/soap/mapping.rb +13 -0
  35. data/vendor/soap4r/soap/mapping/encodedregistry.rb +539 -0
  36. data/vendor/soap4r/soap/mapping/factory.rb +389 -0
  37. data/vendor/soap4r/soap/mapping/literalregistry.rb +392 -0
  38. data/vendor/soap4r/soap/mapping/mapping.rb +577 -0
  39. data/vendor/soap4r/soap/mapping/registry.rb +296 -0
  40. data/vendor/soap4r/soap/mapping/rubytype_factory.rb +446 -0
  41. data/vendor/soap4r/soap/mapping/schemadefinition.rb +171 -0
  42. data/vendor/soap4r/soap/mapping/type_map.rb +107 -0
  43. data/vendor/soap4r/soap/mapping/wsdlencodedregistry.rb +212 -0
  44. data/vendor/soap4r/soap/mapping/wsdlliteralregistry.rb +249 -0
  45. data/vendor/soap4r/soap/marshal.rb +60 -0
  46. data/vendor/soap4r/soap/mimemessage.rb +243 -0
  47. data/vendor/soap4r/soap/nestedexception.rb +43 -0
  48. data/vendor/soap4r/soap/net_http_client.rb +242 -0
  49. data/vendor/soap4r/soap/ns.rb +39 -0
  50. data/vendor/soap4r/soap/parser.rb +253 -0
  51. data/vendor/soap4r/soap/processor.rb +67 -0
  52. data/vendor/soap4r/soap/property.rb +340 -0
  53. data/vendor/soap4r/soap/proxy.rb +15 -0
  54. data/vendor/soap4r/soap/rpc/cgistub.rb +248 -0
  55. data/vendor/soap4r/soap/rpc/driver.rb +222 -0
  56. data/vendor/soap4r/soap/rpc/element.rb +375 -0
  57. data/vendor/soap4r/soap/rpc/httpserver.rb +143 -0
  58. data/vendor/soap4r/soap/rpc/method_def.rb +69 -0
  59. data/vendor/soap4r/soap/rpc/proxy.rb +573 -0
  60. data/vendor/soap4r/soap/rpc/router.rb +663 -0
  61. data/vendor/soap4r/soap/rpc/rpc.rb +26 -0
  62. data/vendor/soap4r/soap/rpc/soaplet.rb +201 -0
  63. data/vendor/soap4r/soap/rpc/standalone_server.rb +44 -0
  64. data/vendor/soap4r/soap/soap.rb +154 -0
  65. data/vendor/soap4r/soap/stream_handler.rb +302 -0
  66. data/vendor/soap4r/soap/version.rb +9 -0
  67. data/vendor/soap4r/soap/wsdl_driver.rb +165 -0
  68. data/vendor/soap4r/wsdl/binding.rb +66 -0
  69. data/vendor/soap4r/wsdl/data.rb +65 -0
  70. data/vendor/soap4r/wsdl/definitions.rb +237 -0
  71. data/vendor/soap4r/wsdl/documentation.rb +33 -0
  72. data/vendor/soap4r/wsdl/import.rb +81 -0
  73. data/vendor/soap4r/wsdl/importer.rb +39 -0
  74. data/vendor/soap4r/wsdl/info.rb +51 -0
  75. data/vendor/soap4r/wsdl/message.rb +55 -0
  76. data/vendor/soap4r/wsdl/operation.rb +152 -0
  77. data/vendor/soap4r/wsdl/operation_binding.rb +241 -0
  78. data/vendor/soap4r/wsdl/param.rb +94 -0
  79. data/vendor/soap4r/wsdl/parser.rb +165 -0
  80. data/vendor/soap4r/wsdl/part.rb +53 -0
  81. data/vendor/soap4r/wsdl/port.rb +67 -0
  82. data/vendor/soap4r/wsdl/port_type.rb +76 -0
  83. data/vendor/soap4r/wsdl/service.rb +62 -0
  84. data/vendor/soap4r/wsdl/soap/address.rb +41 -0
  85. data/vendor/soap4r/wsdl/soap/binding.rb +50 -0
  86. data/vendor/soap4r/wsdl/soap/body.rb +59 -0
  87. data/vendor/soap4r/wsdl/soap/cgi_stub_creator.rb +93 -0
  88. data/vendor/soap4r/wsdl/soap/class_def_creator.rb +437 -0
  89. data/vendor/soap4r/wsdl/soap/class_def_creator_support.rb +241 -0
  90. data/vendor/soap4r/wsdl/soap/class_name_creator.rb +55 -0
  91. data/vendor/soap4r/wsdl/soap/client_skelton_creator.rb +107 -0
  92. data/vendor/soap4r/wsdl/soap/complex_type.rb +174 -0
  93. data/vendor/soap4r/wsdl/soap/data.rb +43 -0
  94. data/vendor/soap4r/wsdl/soap/definitions.rb +201 -0
  95. data/vendor/soap4r/wsdl/soap/driver_creator.rb +121 -0
  96. data/vendor/soap4r/wsdl/soap/element.rb +34 -0
  97. data/vendor/soap4r/wsdl/soap/encoded_mapping_registry_creator.rb +74 -0
  98. data/vendor/soap4r/wsdl/soap/fault.rb +57 -0
  99. data/vendor/soap4r/wsdl/soap/header.rb +87 -0
  100. data/vendor/soap4r/wsdl/soap/headerfault.rb +57 -0
  101. data/vendor/soap4r/wsdl/soap/literal_mapping_registry_creator.rb +116 -0
  102. data/vendor/soap4r/wsdl/soap/mapping_registry_creator.rb +59 -0
  103. data/vendor/soap4r/wsdl/soap/mapping_registry_creator_support.rb +377 -0
  104. data/vendor/soap4r/wsdl/soap/method_def_creator.rb +200 -0
  105. data/vendor/soap4r/wsdl/soap/operation.rb +113 -0
  106. data/vendor/soap4r/wsdl/soap/servant_skelton_creator.rb +92 -0
  107. data/vendor/soap4r/wsdl/soap/servlet_stub_creator.rb +105 -0
  108. data/vendor/soap4r/wsdl/soap/standalone_server_stub_creator.rb +101 -0
  109. data/vendor/soap4r/wsdl/soap/wsdl2ruby.rb +226 -0
  110. data/vendor/soap4r/wsdl/types.rb +45 -0
  111. data/vendor/soap4r/wsdl/wsdl.rb +25 -0
  112. data/vendor/soap4r/wsdl/xml_schema/all.rb +25 -0
  113. data/vendor/soap4r/wsdl/xml_schema/annotation.rb +35 -0
  114. data/vendor/soap4r/wsdl/xml_schema/any.rb +62 -0
  115. data/vendor/soap4r/wsdl/xml_schema/any_attribute.rb +49 -0
  116. data/vendor/soap4r/wsdl/xml_schema/attribute.rb +105 -0
  117. data/vendor/soap4r/wsdl/xml_schema/attribute_group.rb +69 -0
  118. data/vendor/soap4r/wsdl/xml_schema/choice.rb +59 -0
  119. data/vendor/soap4r/wsdl/xml_schema/complex_content.rb +98 -0
  120. data/vendor/soap4r/wsdl/xml_schema/complex_extension.rb +120 -0
  121. data/vendor/soap4r/wsdl/xml_schema/complex_restriction.rb +105 -0
  122. data/vendor/soap4r/wsdl/xml_schema/complex_type.rb +194 -0
  123. data/vendor/soap4r/wsdl/xml_schema/content.rb +96 -0
  124. data/vendor/soap4r/wsdl/xml_schema/data.rb +117 -0
  125. data/vendor/soap4r/wsdl/xml_schema/element.rb +154 -0
  126. data/vendor/soap4r/wsdl/xml_schema/enumeration.rb +37 -0
  127. data/vendor/soap4r/wsdl/xml_schema/fractiondigits.rb +38 -0
  128. data/vendor/soap4r/wsdl/xml_schema/group.rb +101 -0
  129. data/vendor/soap4r/wsdl/xml_schema/import.rb +54 -0
  130. data/vendor/soap4r/wsdl/xml_schema/import_handler.rb +46 -0
  131. data/vendor/soap4r/wsdl/xml_schema/importer.rb +103 -0
  132. data/vendor/soap4r/wsdl/xml_schema/include.rb +49 -0
  133. data/vendor/soap4r/wsdl/xml_schema/length.rb +38 -0
  134. data/vendor/soap4r/wsdl/xml_schema/list.rb +49 -0
  135. data/vendor/soap4r/wsdl/xml_schema/maxexclusive.rb +38 -0
  136. data/vendor/soap4r/wsdl/xml_schema/maxinclusive.rb +38 -0
  137. data/vendor/soap4r/wsdl/xml_schema/maxlength.rb +38 -0
  138. data/vendor/soap4r/wsdl/xml_schema/minexclusive.rb +38 -0
  139. data/vendor/soap4r/wsdl/xml_schema/mininclusive.rb +38 -0
  140. data/vendor/soap4r/wsdl/xml_schema/minlength.rb +38 -0
  141. data/vendor/soap4r/wsdl/xml_schema/parser.rb +168 -0
  142. data/vendor/soap4r/wsdl/xml_schema/pattern.rb +37 -0
  143. data/vendor/soap4r/wsdl/xml_schema/ref.rb +34 -0
  144. data/vendor/soap4r/wsdl/xml_schema/schema.rb +179 -0
  145. data/vendor/soap4r/wsdl/xml_schema/sequence.rb +55 -0
  146. data/vendor/soap4r/wsdl/xml_schema/simple_content.rb +70 -0
  147. data/vendor/soap4r/wsdl/xml_schema/simple_extension.rb +63 -0
  148. data/vendor/soap4r/wsdl/xml_schema/simple_restriction.rb +133 -0
  149. data/vendor/soap4r/wsdl/xml_schema/simple_type.rb +88 -0
  150. data/vendor/soap4r/wsdl/xml_schema/totaldigits.rb +38 -0
  151. data/vendor/soap4r/wsdl/xml_schema/union.rb +36 -0
  152. data/vendor/soap4r/wsdl/xml_schema/unique.rb +35 -0
  153. data/vendor/soap4r/wsdl/xml_schema/whitespace.rb +38 -0
  154. data/vendor/soap4r/wsdl/xml_schema/xsd2ruby.rb +176 -0
  155. data/vendor/soap4r/xsd/charset.rb +190 -0
  156. data/vendor/soap4r/xsd/codegen.rb +13 -0
  157. data/vendor/soap4r/xsd/codegen/classdef.rb +209 -0
  158. data/vendor/soap4r/xsd/codegen/commentdef.rb +35 -0
  159. data/vendor/soap4r/xsd/codegen/gensupport.rb +277 -0
  160. data/vendor/soap4r/xsd/codegen/methoddef.rb +71 -0
  161. data/vendor/soap4r/xsd/codegen/moduledef.rb +209 -0
  162. data/vendor/soap4r/xsd/datatypes.rb +1466 -0
  163. data/vendor/soap4r/xsd/datatypes1999.rb +21 -0
  164. data/vendor/soap4r/xsd/iconvcharset.rb +34 -0
  165. data/vendor/soap4r/xsd/mapping.rb +69 -0
  166. data/vendor/soap4r/xsd/namedelements.rb +133 -0
  167. data/vendor/soap4r/xsd/ns.rb +183 -0
  168. data/vendor/soap4r/xsd/qname.rb +80 -0
  169. data/vendor/soap4r/xsd/xmlparser.rb +77 -0
  170. data/vendor/soap4r/xsd/xmlparser/libxmlparser.rb +116 -0
  171. data/vendor/soap4r/xsd/xmlparser/parser.rb +101 -0
  172. data/vendor/soap4r/xsd/xmlparser/rexmlparser.rb +59 -0
  173. data/vendor/soap4r/xsd/xmlparser/xmlparser.rb +51 -0
  174. data/vendor/soap4r/xsd/xmlparser/xmlscanner.rb +150 -0
  175. metadata +316 -0
@@ -0,0 +1,71 @@
1
+ # encoding: ASCII-8BIT
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: ASCII-8BIT
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: ASCII-8BIT
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/base_data'
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: ASCII-8BIT
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
@@ -0,0 +1,13 @@
1
+ # encoding: ASCII-8BIT
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,539 @@
1
+ # encoding: ASCII-8BIT
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/base_data'
11
+ require 'soap/mapping/mapping'
12
+ require 'soap/mapping/type_map'
13
+ require 'soap/mapping/factory'
14
+ require 'soap/mapping/rubytype_factory'
15
+
16
+
17
+ module SOAP
18
+ module Mapping
19
+
20
+
21
+ # Inner class to pass an exception.
22
+ class SOAPException
23
+ attr_reader :excn_type_name, :cause
24
+
25
+ def initialize(e)
26
+ @excn_type_name = Mapping.name2elename(e.class.to_s)
27
+ @cause = e
28
+ end
29
+
30
+ def to_e
31
+ if @cause.is_a?(::Exception)
32
+ @cause.extend(::SOAP::Mapping::MappedException)
33
+ return @cause
34
+ elsif @cause.respond_to?(:message) and @cause.respond_to?(:backtrace)
35
+ e = RuntimeError.new(@cause.message)
36
+ e.set_backtrace(@cause.backtrace)
37
+ return e
38
+ end
39
+ klass = Mapping.class_from_name(Mapping.elename2name(@excn_type_name.to_s))
40
+ if klass.nil? or not klass <= ::Exception
41
+ return RuntimeError.new(@cause.inspect)
42
+ end
43
+ obj = klass.new(@cause.message)
44
+ obj.extend(::SOAP::Mapping::MappedException)
45
+ obj
46
+ end
47
+ end
48
+
49
+
50
+ class EncodedRegistry
51
+ include TraverseSupport
52
+ include RegistrySupport
53
+
54
+ class Map
55
+ def initialize(registry)
56
+ @obj2soap = {}
57
+ @soap2obj = {}
58
+ @registry = registry
59
+ end
60
+
61
+ def obj2soap(obj)
62
+ klass = obj.class
63
+ if map = @obj2soap[klass]
64
+ map.each do |soap_class, factory, info|
65
+ ret = factory.obj2soap(soap_class, obj, info, @registry)
66
+ return ret if ret
67
+ end
68
+ end
69
+ klass.ancestors.each do |baseclass|
70
+ next if baseclass == klass
71
+ if map = @obj2soap[baseclass]
72
+ map.each do |soap_class, factory, info|
73
+ if info[:derived_class]
74
+ ret = factory.obj2soap(soap_class, obj, info, @registry)
75
+ return ret if ret
76
+ end
77
+ end
78
+ end
79
+ end
80
+ nil
81
+ end
82
+
83
+ def soap2obj(node, klass = nil)
84
+ if map = @soap2obj[node.class]
85
+ map.each do |obj_class, factory, info|
86
+ next if klass and obj_class != klass
87
+ conv, obj = factory.soap2obj(obj_class, node, info, @registry)
88
+ return true, obj if conv
89
+ end
90
+ end
91
+ return false, nil
92
+ end
93
+
94
+ # Give priority to former entry.
95
+ def init(init_map = [])
96
+ clear
97
+ init_map.reverse_each do |obj_class, soap_class, factory, info|
98
+ add(obj_class, soap_class, factory, info)
99
+ end
100
+ end
101
+
102
+ # Give priority to latter entry.
103
+ def add(obj_class, soap_class, factory, info)
104
+ info ||= {}
105
+ (@obj2soap[obj_class] ||= []).unshift([soap_class, factory, info])
106
+ (@soap2obj[soap_class] ||= []).unshift([obj_class, factory, info])
107
+ end
108
+
109
+ def clear
110
+ @obj2soap.clear
111
+ @soap2obj.clear
112
+ end
113
+
114
+ def find_mapped_soap_class(target_obj_class)
115
+ map = @obj2soap[target_obj_class]
116
+ map.empty? ? nil : map[0][1]
117
+ end
118
+
119
+ def find_mapped_obj_class(target_soap_class)
120
+ map = @soap2obj[target_soap_class]
121
+ map.empty? ? nil : map[0][0]
122
+ end
123
+ end
124
+
125
+ StringFactory = StringFactory_.new
126
+ BasetypeFactory = BasetypeFactory_.new
127
+ FixnumFactory = FixnumFactory_.new
128
+ DateTimeFactory = DateTimeFactory_.new
129
+ ArrayFactory = ArrayFactory_.new
130
+ Base64Factory = Base64Factory_.new
131
+ URIFactory = URIFactory_.new
132
+ TypedArrayFactory = TypedArrayFactory_.new
133
+ TypedStructFactory = TypedStructFactory_.new
134
+
135
+ HashFactory = HashFactory_.new
136
+
137
+ SOAPBaseMap = [
138
+ [::NilClass, ::SOAP::SOAPNil, BasetypeFactory],
139
+ [::TrueClass, ::SOAP::SOAPBoolean, BasetypeFactory],
140
+ [::FalseClass, ::SOAP::SOAPBoolean, BasetypeFactory],
141
+ [::String, ::SOAP::SOAPString, StringFactory,
142
+ {:derived_class => true}],
143
+ [::DateTime, ::SOAP::SOAPDateTime, DateTimeFactory],
144
+ [::Date, ::SOAP::SOAPDate, DateTimeFactory],
145
+ [::Time, ::SOAP::SOAPDateTime, DateTimeFactory],
146
+ [::Time, ::SOAP::SOAPTime, DateTimeFactory],
147
+ [::Float, ::SOAP::SOAPDouble, BasetypeFactory,
148
+ {:derived_class => true}],
149
+ [::Float, ::SOAP::SOAPFloat, BasetypeFactory,
150
+ {:derived_class => true}],
151
+ [::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
152
+ [::Integer, ::SOAP::SOAPInt, BasetypeFactory,
153
+ {:derived_class => true}],
154
+ [::Integer, ::SOAP::SOAPLong, BasetypeFactory,
155
+ {:derived_class => true}],
156
+ [::Integer, ::SOAP::SOAPInteger, BasetypeFactory,
157
+ {:derived_class => true}],
158
+ [::Integer, ::SOAP::SOAPShort, BasetypeFactory,
159
+ {:derived_class => true}],
160
+ [::Integer, ::SOAP::SOAPByte, BasetypeFactory,
161
+ {:derived_class => true}],
162
+ [::Integer, ::SOAP::SOAPNonPositiveInteger, BasetypeFactory,
163
+ {:derived_class => true}],
164
+ [::Integer, ::SOAP::SOAPNegativeInteger, BasetypeFactory,
165
+ {:derived_class => true}],
166
+ [::Integer, ::SOAP::SOAPNonNegativeInteger, BasetypeFactory,
167
+ {:derived_class => true}],
168
+ [::Integer, ::SOAP::SOAPPositiveInteger, BasetypeFactory,
169
+ {:derived_class => true}],
170
+ [::Integer, ::SOAP::SOAPUnsignedLong, BasetypeFactory,
171
+ {:derived_class => true}],
172
+ [::Integer, ::SOAP::SOAPUnsignedInt, BasetypeFactory,
173
+ {:derived_class => true}],
174
+ [::Integer, ::SOAP::SOAPUnsignedShort, BasetypeFactory,
175
+ {:derived_class => true}],
176
+ [::Integer, ::SOAP::SOAPUnsignedByte, BasetypeFactory,
177
+ {:derived_class => true}],
178
+ [::URI::Generic, ::SOAP::SOAPAnyURI, URIFactory,
179
+ {:derived_class => true}],
180
+ [::String, ::SOAP::SOAPBase64, Base64Factory],
181
+ [::String, ::SOAP::SOAPHexBinary, Base64Factory],
182
+ [::String, ::SOAP::SOAPDecimal, BasetypeFactory],
183
+ [::String, ::SOAP::SOAPDuration, BasetypeFactory],
184
+ [::String, ::SOAP::SOAPGYearMonth, BasetypeFactory],
185
+ [::String, ::SOAP::SOAPGYear, BasetypeFactory],
186
+ [::String, ::SOAP::SOAPGMonthDay, BasetypeFactory],
187
+ [::String, ::SOAP::SOAPGDay, BasetypeFactory],
188
+ [::String, ::SOAP::SOAPGMonth, BasetypeFactory],
189
+ [::String, ::SOAP::SOAPQName, BasetypeFactory],
190
+
191
+ [::Hash, ::SOAP::SOAPArray, HashFactory,
192
+ {:derived_class => true}],
193
+ [::Hash, ::SOAP::SOAPStruct, HashFactory,
194
+ {:derived_class => true}],
195
+
196
+ [::Array, ::SOAP::SOAPArray, ArrayFactory,
197
+ {:derived_class => true}],
198
+
199
+ [::SOAP::Mapping::SOAPException,
200
+ ::SOAP::SOAPStruct, TypedStructFactory,
201
+ {:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
202
+ ]
203
+
204
+ RubyOriginalMap = [
205
+ [::NilClass, ::SOAP::SOAPNil, BasetypeFactory],
206
+ [::TrueClass, ::SOAP::SOAPBoolean, BasetypeFactory],
207
+ [::FalseClass, ::SOAP::SOAPBoolean, BasetypeFactory],
208
+ [::String, ::SOAP::SOAPString, StringFactory],
209
+ [::DateTime, ::SOAP::SOAPDateTime, DateTimeFactory],
210
+ [::Date, ::SOAP::SOAPDate, DateTimeFactory],
211
+ [::Time, ::SOAP::SOAPDateTime, DateTimeFactory],
212
+ [::Time, ::SOAP::SOAPTime, DateTimeFactory],
213
+ [::Float, ::SOAP::SOAPDouble, BasetypeFactory,
214
+ {:derived_class => true}],
215
+ [::Float, ::SOAP::SOAPFloat, BasetypeFactory,
216
+ {:derived_class => true}],
217
+ [::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
218
+ [::Integer, ::SOAP::SOAPInt, BasetypeFactory,
219
+ {:derived_class => true}],
220
+ [::Integer, ::SOAP::SOAPLong, BasetypeFactory,
221
+ {:derived_class => true}],
222
+ [::Integer, ::SOAP::SOAPInteger, BasetypeFactory,
223
+ {:derived_class => true}],
224
+ [::Integer, ::SOAP::SOAPShort, BasetypeFactory,
225
+ {:derived_class => true}],
226
+ [::Integer, ::SOAP::SOAPByte, BasetypeFactory,
227
+ {:derived_class => true}],
228
+ [::Integer, ::SOAP::SOAPNonPositiveInteger, BasetypeFactory,
229
+ {:derived_class => true}],
230
+ [::Integer, ::SOAP::SOAPNegativeInteger, BasetypeFactory,
231
+ {:derived_class => true}],
232
+ [::Integer, ::SOAP::SOAPNonNegativeInteger, BasetypeFactory,
233
+ {:derived_class => true}],
234
+ [::Integer, ::SOAP::SOAPPositiveInteger, BasetypeFactory,
235
+ {:derived_class => true}],
236
+ [::Integer, ::SOAP::SOAPUnsignedLong, BasetypeFactory,
237
+ {:derived_class => true}],
238
+ [::Integer, ::SOAP::SOAPUnsignedInt, BasetypeFactory,
239
+ {:derived_class => true}],
240
+ [::Integer, ::SOAP::SOAPUnsignedShort, BasetypeFactory,
241
+ {:derived_class => true}],
242
+ [::Integer, ::SOAP::SOAPUnsignedByte, BasetypeFactory,
243
+ {:derived_class => true}],
244
+ [::URI::Generic, ::SOAP::SOAPAnyURI, URIFactory,
245
+ {:derived_class => true}],
246
+ [::String, ::SOAP::SOAPBase64, Base64Factory],
247
+ [::String, ::SOAP::SOAPHexBinary, Base64Factory],
248
+ [::String, ::SOAP::SOAPDecimal, BasetypeFactory],
249
+ [::String, ::SOAP::SOAPDuration, BasetypeFactory],
250
+ [::String, ::SOAP::SOAPGYearMonth, BasetypeFactory],
251
+ [::String, ::SOAP::SOAPGYear, BasetypeFactory],
252
+ [::String, ::SOAP::SOAPGMonthDay, BasetypeFactory],
253
+ [::String, ::SOAP::SOAPGDay, BasetypeFactory],
254
+ [::String, ::SOAP::SOAPGMonth, BasetypeFactory],
255
+ [::String, ::SOAP::SOAPQName, BasetypeFactory],
256
+
257
+ [::Hash, ::SOAP::SOAPArray, HashFactory],
258
+ [::Hash, ::SOAP::SOAPStruct, HashFactory],
259
+
260
+ # Does not allow Array's subclass here.
261
+ [::Array, ::SOAP::SOAPArray, ArrayFactory],
262
+
263
+ [::SOAP::Mapping::SOAPException,
264
+ ::SOAP::SOAPStruct, TypedStructFactory,
265
+ {:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
266
+ ]
267
+
268
+ attr_accessor :default_factory
269
+ attr_accessor :excn_handler_obj2soap
270
+ attr_accessor :excn_handler_soap2obj
271
+
272
+ def initialize(config = {})
273
+ super()
274
+ @config = config
275
+ @map = Map.new(self)
276
+ if @config[:allow_original_mapping]
277
+ @allow_original_mapping = true
278
+ @map.init(RubyOriginalMap)
279
+ else
280
+ @allow_original_mapping = false
281
+ @map.init(SOAPBaseMap)
282
+ end
283
+ @allow_untyped_struct = @config.key?(:allow_untyped_struct) ?
284
+ @config[:allow_untyped_struct] : true
285
+ @rubytype_factory = RubytypeFactory.new(
286
+ :allow_untyped_struct => @allow_untyped_struct,
287
+ :allow_original_mapping => @allow_original_mapping
288
+ )
289
+ @default_factory = @rubytype_factory
290
+ @excn_handler_obj2soap = nil
291
+ @excn_handler_soap2obj = nil
292
+ end
293
+
294
+ # initial mapping interface
295
+ # new interface Registry#register is defined in RegisterSupport
296
+ def add(obj_class, soap_class, factory, info = nil)
297
+ @map.add(obj_class, soap_class, factory, info)
298
+ end
299
+ alias set add
300
+
301
+ def obj2soap(obj, type_qname = nil)
302
+ soap = _obj2soap(obj, type_qname)
303
+ if @allow_original_mapping
304
+ addextend2soap(soap, obj)
305
+ end
306
+ soap
307
+ end
308
+
309
+ def soap2obj(node, klass = nil)
310
+ obj = _soap2obj(node, klass)
311
+ if @allow_original_mapping
312
+ addextend2obj(obj, node.extraattr[RubyExtendName])
313
+ addiv2obj(obj, node.extraattr[RubyIVarName])
314
+ end
315
+ obj
316
+ end
317
+
318
+ def find_mapped_soap_class(obj_class)
319
+ @map.find_mapped_soap_class(obj_class)
320
+ end
321
+
322
+ def find_mapped_obj_class(soap_class)
323
+ @map.find_mapped_obj_class(soap_class)
324
+ end
325
+
326
+ private
327
+
328
+ def _obj2soap(obj, type_qname = nil)
329
+ ret = nil
330
+ if obj.is_a?(SOAPCompoundtype)
331
+ obj.replace do |ele|
332
+ Mapping._obj2soap(ele, self)
333
+ end
334
+ return obj
335
+ elsif obj.is_a?(SOAPBasetype)
336
+ return obj
337
+ elsif type_qname && type = TypeMap[type_qname]
338
+ return base2soap(obj, type)
339
+ end
340
+ cause = nil
341
+ begin
342
+ if definition = schema_definition_from_class(obj.class)
343
+ return stubobj2soap(obj, definition)
344
+ end
345
+ ret = @map.obj2soap(obj) ||
346
+ @default_factory.obj2soap(nil, obj, nil, self)
347
+ return ret if ret
348
+ rescue MappingError
349
+ cause = $!
350
+ end
351
+ if @excn_handler_obj2soap
352
+ ret = @excn_handler_obj2soap.call(obj) { |yield_obj|
353
+ Mapping._obj2soap(yield_obj, self)
354
+ }
355
+ return ret if ret
356
+ end
357
+ raise MappingError.new("Cannot map #{ obj.class.name } to SOAP/OM.", cause)
358
+ end
359
+
360
+ # Might return nil as a mapping result.
361
+ def _soap2obj(node, klass = nil)
362
+ definition = find_node_definition(node)
363
+ if klass
364
+ klass_definition = schema_definition_from_class(klass)
365
+ if definition and (definition.class_for < klass)
366
+ klass = definition.class_for
367
+ else
368
+ definition = klass_definition
369
+ end
370
+ else
371
+ klass = definition.class_for if definition
372
+ end
373
+ if definition and node.is_a?(::SOAP::SOAPNameAccessible)
374
+ return elesoap2stubobj(node, klass, definition)
375
+ end
376
+ if node.extraattr.key?(RubyTypeName)
377
+ conv, obj = @rubytype_factory.soap2obj(nil, node, nil, self)
378
+ return obj if conv
379
+ end
380
+ conv, obj = @map.soap2obj(node)
381
+ return obj if conv
382
+ conv, obj = @default_factory.soap2obj(nil, node, nil, self)
383
+ return obj if conv
384
+ cause = nil
385
+ if @excn_handler_soap2obj
386
+ begin
387
+ return @excn_handler_soap2obj.call(node) { |yield_node|
388
+ Mapping._soap2obj(yield_node, self)
389
+ }
390
+ rescue Exception
391
+ cause = $!
392
+ end
393
+ end
394
+ raise MappingError.new("Cannot map #{ node.type } to Ruby object.", cause)
395
+ end
396
+
397
+ def addiv2obj(obj, attr)
398
+ return unless attr
399
+ vars = {}
400
+ attr.__getobj__.each do |name, value|
401
+ vars[name] = Mapping._soap2obj(value, self)
402
+ end
403
+ Mapping.set_attributes(obj, vars)
404
+ end
405
+
406
+ def addextend2obj(obj, attr)
407
+ return unless attr
408
+ attr.split(/ /).reverse_each do |mstr|
409
+ obj.extend(Mapping.module_from_name(mstr))
410
+ end
411
+ end
412
+
413
+ def addextend2soap(node, obj)
414
+ return if obj.is_a?(Symbol) or obj.is_a?(Fixnum)
415
+ list = (class << obj; self; end).ancestors - obj.class.ancestors
416
+ unless list.empty?
417
+ node.extraattr[RubyExtendName] = list.collect { |c|
418
+ name = c.name
419
+ if name.nil? or name.empty?
420
+ raise TypeError.new("singleton can't be dumped #{ obj }")
421
+ end
422
+ name
423
+ }.join(" ")
424
+ end
425
+ end
426
+
427
+ def stubobj2soap(obj, definition)
428
+ case obj
429
+ when ::Array
430
+ array2soap(obj, definition)
431
+ else
432
+ unknownstubobj2soap(obj, definition)
433
+ end
434
+ end
435
+
436
+ def array2soap(obj, definition)
437
+ return SOAPNil.new if obj.nil? # ToDo: check nillable.
438
+ eledef = definition.elements[0]
439
+ soap_obj = SOAPArray.new(ValueArrayName, 1, eledef.elename)
440
+ mark_marshalled_obj(obj, soap_obj)
441
+ obj.each do |item|
442
+ soap_obj.add(typedobj2soap(item, eledef.mapped_class))
443
+ end
444
+ soap_obj
445
+ end
446
+
447
+ def unknownstubobj2soap(obj, definition)
448
+ return SOAPNil.new if obj.nil?
449
+ if definition.elements.size == 0
450
+ ele = Mapping.obj2soap(obj)
451
+ ele.elename = definition.elename if definition.elename
452
+ ele.extraattr[XSD::AttrTypeName] = definition.type if definition.type
453
+ return ele
454
+ else
455
+ ele = SOAPStruct.new(definition.type)
456
+ mark_marshalled_obj(obj, ele)
457
+ end
458
+ definition.elements.each do |eledef|
459
+ name = eledef.elename.name
460
+ if obj.respond_to?(:each) and eledef.as_array?
461
+ obj.each do |item|
462
+ ele.add(name, typedobj2soap(item, eledef.mapped_class))
463
+ end
464
+ else
465
+ child = Mapping.get_attribute(obj, eledef.varname)
466
+ if child.respond_to?(:each) and eledef.as_array?
467
+ child = child.lines if child.respond_to?(:lines) # RubyJedi: compatible with Ruby 1.8.6 and above
468
+ child.each do |item|
469
+ ele.add(name, typedobj2soap(item, eledef.mapped_class))
470
+ end
471
+ else
472
+ ele.add(name, typedobj2soap(child, eledef.mapped_class))
473
+ end
474
+ end
475
+ end
476
+ ele
477
+ end
478
+
479
+ def typedobj2soap(value, klass)
480
+ if klass and klass.include?(::SOAP::SOAPBasetype)
481
+ base2soap(value, klass)
482
+ else
483
+ Mapping._obj2soap(value, self)
484
+ end
485
+ end
486
+
487
+ def elesoap2stubobj(node, obj_class, definition)
488
+ obj = Mapping.create_empty_object(obj_class)
489
+ add_elesoap2stubobj(node, obj, definition)
490
+ obj
491
+ end
492
+
493
+ # XXX consider to merge with the method in LiteralRegistry
494
+ def add_elesoap2stubobj(node, obj, definition)
495
+ vars = {}
496
+ node.each do |name, value|
497
+ item = definition.elements.find_element(value.elename)
498
+ if item
499
+ child = soap2typedobj(value, item.mapped_class)
500
+ else
501
+ # unknown element is treated as anyType.
502
+ child = Mapping._soap2obj(value, self)
503
+ end
504
+ if item and item.as_array?
505
+ (vars[name] ||= []) << child
506
+ elsif vars.key?(name)
507
+ vars[name] = [vars[name], child].flatten
508
+ else
509
+ vars[name] = child
510
+ end
511
+ end
512
+ if obj.is_a?(::Array) and is_stubobj_elements_for_array(vars)
513
+ Array.instance_method(:replace).bind(obj).call(vars.values[0])
514
+ else
515
+ Mapping.set_attributes(obj, vars)
516
+ end
517
+ end
518
+
519
+ def soap2typedobj(value, klass)
520
+ unless klass
521
+ raise MappingError.new("unknown class: #{klass}")
522
+ end
523
+ if klass.include?(::SOAP::SOAPBasetype)
524
+ obj = base2obj(value, klass)
525
+ else
526
+ obj = Mapping._soap2obj(value, self, klass)
527
+ end
528
+ obj
529
+ end
530
+ end
531
+
532
+
533
+ Registry = EncodedRegistry
534
+ DefaultRegistry = EncodedRegistry.new
535
+ RubyOriginalRegistry = EncodedRegistry.new(:allow_original_mapping => true)
536
+
537
+
538
+ end
539
+ end