soap4r_es 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/bin/wsdl2ruby.rb +140 -0
  3. data/bin/wsdl2ruby_rails.rb +140 -0
  4. data/bin/xsd2ruby.rb +92 -0
  5. data/lib/soap/attachment.rb +109 -0
  6. data/lib/soap/attrproxy.rb +35 -0
  7. data/lib/soap/baseData.rb +1095 -0
  8. data/lib/soap/element.rb +278 -0
  9. data/lib/soap/encodingstyle/aspDotNetHandler.rb +208 -0
  10. data/lib/soap/encodingstyle/handler.rb +121 -0
  11. data/lib/soap/encodingstyle/literalHandler.rb +196 -0
  12. data/lib/soap/encodingstyle/soapHandler.rb +560 -0
  13. data/lib/soap/filter/filterchain.rb +52 -0
  14. data/lib/soap/filter/handler.rb +32 -0
  15. data/lib/soap/filter/streamhandler.rb +30 -0
  16. data/lib/soap/filter.rb +14 -0
  17. data/lib/soap/generator.rb +299 -0
  18. data/lib/soap/header/handler.rb +64 -0
  19. data/lib/soap/header/handlerset.rb +78 -0
  20. data/lib/soap/header/mappinghandler.rb +48 -0
  21. data/lib/soap/header/simplehandler.rb +45 -0
  22. data/lib/soap/httpconfigloader.rb +140 -0
  23. data/lib/soap/mapping/encodedregistry.rb +541 -0
  24. data/lib/soap/mapping/factory.rb +389 -0
  25. data/lib/soap/mapping/literalregistry.rb +392 -0
  26. data/lib/soap/mapping/mapping.rb +577 -0
  27. data/lib/soap/mapping/registry.rb +297 -0
  28. data/lib/soap/mapping/rubytypeFactory.rb +446 -0
  29. data/lib/soap/mapping/schemadefinition.rb +171 -0
  30. data/lib/soap/mapping/typeMap.rb +107 -0
  31. data/lib/soap/mapping/wsdlencodedregistry.rb +212 -0
  32. data/lib/soap/mapping/wsdlliteralregistry.rb +249 -0
  33. data/lib/soap/mapping.rb +13 -0
  34. data/lib/soap/marshal.rb +60 -0
  35. data/lib/soap/mimemessage.rb +243 -0
  36. data/lib/soap/nestedexception.rb +43 -0
  37. data/lib/soap/netHttpClient.rb +242 -0
  38. data/lib/soap/ns.rb +39 -0
  39. data/lib/soap/parser.rb +253 -0
  40. data/lib/soap/processor.rb +67 -0
  41. data/lib/soap/property.rb +330 -0
  42. data/lib/soap/proxy.rb +15 -0
  43. data/lib/soap/rpc/cgistub.rb +249 -0
  44. data/lib/soap/rpc/driver.rb +222 -0
  45. data/lib/soap/rpc/element.rb +375 -0
  46. data/lib/soap/rpc/httpserver.rb +144 -0
  47. data/lib/soap/rpc/methodDef.rb +69 -0
  48. data/lib/soap/rpc/proxy.rb +573 -0
  49. data/lib/soap/rpc/router.rb +672 -0
  50. data/lib/soap/rpc/rpc.rb +26 -0
  51. data/lib/soap/rpc/soaplet.rb +201 -0
  52. data/lib/soap/rpc/standaloneServer.rb +44 -0
  53. data/lib/soap/soap.rb +163 -0
  54. data/lib/soap/streamHandler.rb +302 -0
  55. data/lib/soap/version.rb +12 -0
  56. data/lib/soap/wsdlDriver.rb +165 -0
  57. data/lib/wsdl/binding.rb +66 -0
  58. data/lib/wsdl/data.rb +65 -0
  59. data/lib/wsdl/definitions.rb +237 -0
  60. data/lib/wsdl/documentation.rb +33 -0
  61. data/lib/wsdl/import.rb +81 -0
  62. data/lib/wsdl/importer.rb +39 -0
  63. data/lib/wsdl/info.rb +51 -0
  64. data/lib/wsdl/message.rb +55 -0
  65. data/lib/wsdl/operation.rb +152 -0
  66. data/lib/wsdl/operationBinding.rb +241 -0
  67. data/lib/wsdl/param.rb +94 -0
  68. data/lib/wsdl/parser.rb +180 -0
  69. data/lib/wsdl/part.rb +53 -0
  70. data/lib/wsdl/port.rb +67 -0
  71. data/lib/wsdl/portType.rb +76 -0
  72. data/lib/wsdl/service.rb +62 -0
  73. data/lib/wsdl/soap/address.rb +41 -0
  74. data/lib/wsdl/soap/binding.rb +50 -0
  75. data/lib/wsdl/soap/body.rb +59 -0
  76. data/lib/wsdl/soap/cgiStubCreator.rb +93 -0
  77. data/lib/wsdl/soap/classDefCreator.rb +529 -0
  78. data/lib/wsdl/soap/classDefCreatorSupport.rb +242 -0
  79. data/lib/wsdl/soap/classNameCreator.rb +57 -0
  80. data/lib/wsdl/soap/clientSkeltonCreator.rb +107 -0
  81. data/lib/wsdl/soap/complexType.rb +174 -0
  82. data/lib/wsdl/soap/data.rb +43 -0
  83. data/lib/wsdl/soap/definitions.rb +201 -0
  84. data/lib/wsdl/soap/driverCreator.rb +121 -0
  85. data/lib/wsdl/soap/element.rb +34 -0
  86. data/lib/wsdl/soap/encodedMappingRegistryCreator.rb +74 -0
  87. data/lib/wsdl/soap/fault.rb +57 -0
  88. data/lib/wsdl/soap/header.rb +87 -0
  89. data/lib/wsdl/soap/headerfault.rb +57 -0
  90. data/lib/wsdl/soap/literalMappingRegistryCreator.rb +116 -0
  91. data/lib/wsdl/soap/mappingRegistryCreator.rb +59 -0
  92. data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +380 -0
  93. data/lib/wsdl/soap/methodDefCreator.rb +200 -0
  94. data/lib/wsdl/soap/operation.rb +113 -0
  95. data/lib/wsdl/soap/servantSkeltonCreator.rb +92 -0
  96. data/lib/wsdl/soap/servletStubCreator.rb +105 -0
  97. data/lib/wsdl/soap/standaloneServerStubCreator.rb +101 -0
  98. data/lib/wsdl/soap/wsdl2ruby.rb +249 -0
  99. data/lib/wsdl/types.rb +45 -0
  100. data/lib/wsdl/wsdl.rb +25 -0
  101. data/lib/wsdl/xmlSchema/all.rb +25 -0
  102. data/lib/wsdl/xmlSchema/annotation.rb +35 -0
  103. data/lib/wsdl/xmlSchema/any.rb +62 -0
  104. data/lib/wsdl/xmlSchema/anyAttribute.rb +49 -0
  105. data/lib/wsdl/xmlSchema/attribute.rb +105 -0
  106. data/lib/wsdl/xmlSchema/attributeGroup.rb +69 -0
  107. data/lib/wsdl/xmlSchema/choice.rb +59 -0
  108. data/lib/wsdl/xmlSchema/complexContent.rb +98 -0
  109. data/lib/wsdl/xmlSchema/complexExtension.rb +120 -0
  110. data/lib/wsdl/xmlSchema/complexRestriction.rb +105 -0
  111. data/lib/wsdl/xmlSchema/complexType.rb +194 -0
  112. data/lib/wsdl/xmlSchema/content.rb +96 -0
  113. data/lib/wsdl/xmlSchema/data.rb +117 -0
  114. data/lib/wsdl/xmlSchema/element.rb +154 -0
  115. data/lib/wsdl/xmlSchema/enumeration.rb +37 -0
  116. data/lib/wsdl/xmlSchema/fractiondigits.rb +38 -0
  117. data/lib/wsdl/xmlSchema/group.rb +101 -0
  118. data/lib/wsdl/xmlSchema/import.rb +53 -0
  119. data/lib/wsdl/xmlSchema/importHandler.rb +45 -0
  120. data/lib/wsdl/xmlSchema/importer.rb +103 -0
  121. data/lib/wsdl/xmlSchema/include.rb +48 -0
  122. data/lib/wsdl/xmlSchema/length.rb +38 -0
  123. data/lib/wsdl/xmlSchema/list.rb +49 -0
  124. data/lib/wsdl/xmlSchema/maxexclusive.rb +38 -0
  125. data/lib/wsdl/xmlSchema/maxinclusive.rb +38 -0
  126. data/lib/wsdl/xmlSchema/maxlength.rb +38 -0
  127. data/lib/wsdl/xmlSchema/minexclusive.rb +38 -0
  128. data/lib/wsdl/xmlSchema/mininclusive.rb +38 -0
  129. data/lib/wsdl/xmlSchema/minlength.rb +38 -0
  130. data/lib/wsdl/xmlSchema/parser.rb +168 -0
  131. data/lib/wsdl/xmlSchema/pattern.rb +37 -0
  132. data/lib/wsdl/xmlSchema/ref.rb +34 -0
  133. data/lib/wsdl/xmlSchema/schema.rb +179 -0
  134. data/lib/wsdl/xmlSchema/sequence.rb +55 -0
  135. data/lib/wsdl/xmlSchema/simpleContent.rb +70 -0
  136. data/lib/wsdl/xmlSchema/simpleExtension.rb +63 -0
  137. data/lib/wsdl/xmlSchema/simpleRestriction.rb +133 -0
  138. data/lib/wsdl/xmlSchema/simpleType.rb +88 -0
  139. data/lib/wsdl/xmlSchema/totaldigits.rb +38 -0
  140. data/lib/wsdl/xmlSchema/union.rb +36 -0
  141. data/lib/wsdl/xmlSchema/unique.rb +35 -0
  142. data/lib/wsdl/xmlSchema/whitespace.rb +38 -0
  143. data/lib/wsdl/xmlSchema/xsd2ruby.rb +177 -0
  144. data/lib/xsd/charset.rb +190 -0
  145. data/lib/xsd/codegen/classdef.rb +230 -0
  146. data/lib/xsd/codegen/commentdef.rb +35 -0
  147. data/lib/xsd/codegen/gensupport.rb +277 -0
  148. data/lib/xsd/codegen/methoddef.rb +71 -0
  149. data/lib/xsd/codegen/moduledef.rb +209 -0
  150. data/lib/xsd/codegen.rb +13 -0
  151. data/lib/xsd/datatypes.rb +1465 -0
  152. data/lib/xsd/datatypes1999.rb +21 -0
  153. data/lib/xsd/iconvcharset.rb +33 -0
  154. data/lib/xsd/mapping.rb +69 -0
  155. data/lib/xsd/namedelements.rb +133 -0
  156. data/lib/xsd/ns.rb +183 -0
  157. data/lib/xsd/qname.rb +80 -0
  158. data/lib/xsd/xmlparser/libxmlparser.rb +136 -0
  159. data/lib/xsd/xmlparser/nokogiriparser.rb +63 -0
  160. data/lib/xsd/xmlparser/ogaparser.rb +53 -0
  161. data/lib/xsd/xmlparser/oxparser.rb +97 -0
  162. data/lib/xsd/xmlparser/parser.rb +101 -0
  163. data/lib/xsd/xmlparser/rexmlparser.rb +54 -0
  164. data/lib/xsd/xmlparser.rb +81 -0
  165. metadata +240 -0
@@ -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