reidiculous-actionwebservice-client 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. data/CHANGELOG +320 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +381 -0
  4. data/Rakefile +180 -0
  5. data/TODO +32 -0
  6. data/lib/action_web_service.rb +71 -0
  7. data/lib/action_web_service/api.rb +297 -0
  8. data/lib/action_web_service/base.rb +38 -0
  9. data/lib/action_web_service/casting.rb +149 -0
  10. data/lib/action_web_service/client.rb +3 -0
  11. data/lib/action_web_service/client/base.rb +28 -0
  12. data/lib/action_web_service/client/soap_client.rb +113 -0
  13. data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
  14. data/lib/action_web_service/container.rb +3 -0
  15. data/lib/action_web_service/container/action_controller_container.rb +93 -0
  16. data/lib/action_web_service/container/delegated_container.rb +86 -0
  17. data/lib/action_web_service/container/direct_container.rb +69 -0
  18. data/lib/action_web_service/dispatcher.rb +2 -0
  19. data/lib/action_web_service/dispatcher/abstract.rb +207 -0
  20. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
  21. data/lib/action_web_service/invocation.rb +202 -0
  22. data/lib/action_web_service/protocol.rb +4 -0
  23. data/lib/action_web_service/protocol/abstract.rb +115 -0
  24. data/lib/action_web_service/protocol/discovery.rb +37 -0
  25. data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
  26. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
  27. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
  28. data/lib/action_web_service/scaffolding.rb +281 -0
  29. data/lib/action_web_service/soap/attachment.rb +107 -0
  30. data/lib/action_web_service/soap/baseData.rb +942 -0
  31. data/lib/action_web_service/soap/element.rb +258 -0
  32. data/lib/action_web_service/soap/encodingstyle/aspDotNetHandler.rb +213 -0
  33. data/lib/action_web_service/soap/encodingstyle/handler.rb +100 -0
  34. data/lib/action_web_service/soap/encodingstyle/literalHandler.rb +226 -0
  35. data/lib/action_web_service/soap/encodingstyle/soapHandler.rb +582 -0
  36. data/lib/action_web_service/soap/generator.rb +268 -0
  37. data/lib/action_web_service/soap/header/handler.rb +57 -0
  38. data/lib/action_web_service/soap/header/handlerset.rb +70 -0
  39. data/lib/action_web_service/soap/header/simplehandler.rb +44 -0
  40. data/lib/action_web_service/soap/httpconfigloader.rb +119 -0
  41. data/lib/action_web_service/soap/mapping.rb +10 -0
  42. data/lib/action_web_service/soap/mapping/factory.rb +355 -0
  43. data/lib/action_web_service/soap/mapping/mapping.rb +381 -0
  44. data/lib/action_web_service/soap/mapping/registry.rb +541 -0
  45. data/lib/action_web_service/soap/mapping/rubytypeFactory.rb +475 -0
  46. data/lib/action_web_service/soap/mapping/typeMap.rb +50 -0
  47. data/lib/action_web_service/soap/mapping/wsdlencodedregistry.rb +280 -0
  48. data/lib/action_web_service/soap/mapping/wsdlliteralregistry.rb +418 -0
  49. data/lib/action_web_service/soap/marshal.rb +59 -0
  50. data/lib/action_web_service/soap/mimemessage.rb +240 -0
  51. data/lib/action_web_service/soap/netHttpClient.rb +190 -0
  52. data/lib/action_web_service/soap/parser.rb +251 -0
  53. data/lib/action_web_service/soap/processor.rb +66 -0
  54. data/lib/action_web_service/soap/property.rb +333 -0
  55. data/lib/action_web_service/soap/rpc/cgistub.rb +206 -0
  56. data/lib/action_web_service/soap/rpc/driver.rb +254 -0
  57. data/lib/action_web_service/soap/rpc/element.rb +325 -0
  58. data/lib/action_web_service/soap/rpc/httpserver.rb +129 -0
  59. data/lib/action_web_service/soap/rpc/proxy.rb +497 -0
  60. data/lib/action_web_service/soap/rpc/router.rb +594 -0
  61. data/lib/action_web_service/soap/rpc/rpc.rb +25 -0
  62. data/lib/action_web_service/soap/rpc/soaplet.rb +162 -0
  63. data/lib/action_web_service/soap/rpc/standaloneServer.rb +43 -0
  64. data/lib/action_web_service/soap/soap.rb +140 -0
  65. data/lib/action_web_service/soap/streamHandler.rb +229 -0
  66. data/lib/action_web_service/soap/wsdlDriver.rb +575 -0
  67. data/lib/action_web_service/struct.rb +64 -0
  68. data/lib/action_web_service/support/class_inheritable_options.rb +28 -0
  69. data/lib/action_web_service/support/signature_types.rb +227 -0
  70. data/lib/action_web_service/test_invoke.rb +110 -0
  71. data/lib/action_web_service/version.rb +9 -0
  72. data/lib/action_web_service/wsdl/binding.rb +65 -0
  73. data/lib/action_web_service/wsdl/data.rb +64 -0
  74. data/lib/action_web_service/wsdl/definitions.rb +250 -0
  75. data/lib/action_web_service/wsdl/documentation.rb +32 -0
  76. data/lib/action_web_service/wsdl/import.rb +80 -0
  77. data/lib/action_web_service/wsdl/importer.rb +38 -0
  78. data/lib/action_web_service/wsdl/info.rb +39 -0
  79. data/lib/action_web_service/wsdl/message.rb +54 -0
  80. data/lib/action_web_service/wsdl/operation.rb +130 -0
  81. data/lib/action_web_service/wsdl/operationBinding.rb +108 -0
  82. data/lib/action_web_service/wsdl/param.rb +85 -0
  83. data/lib/action_web_service/wsdl/parser.rb +163 -0
  84. data/lib/action_web_service/wsdl/part.rb +52 -0
  85. data/lib/action_web_service/wsdl/port.rb +84 -0
  86. data/lib/action_web_service/wsdl/portType.rb +73 -0
  87. data/lib/action_web_service/wsdl/service.rb +61 -0
  88. data/lib/action_web_service/wsdl/soap/address.rb +40 -0
  89. data/lib/action_web_service/wsdl/soap/binding.rb +49 -0
  90. data/lib/action_web_service/wsdl/soap/body.rb +56 -0
  91. data/lib/action_web_service/wsdl/soap/cgiStubCreator.rb +76 -0
  92. data/lib/action_web_service/wsdl/soap/classDefCreator.rb +314 -0
  93. data/lib/action_web_service/wsdl/soap/classDefCreatorSupport.rb +126 -0
  94. data/lib/action_web_service/wsdl/soap/clientSkeltonCreator.rb +78 -0
  95. data/lib/action_web_service/wsdl/soap/complexType.rb +161 -0
  96. data/lib/action_web_service/wsdl/soap/data.rb +42 -0
  97. data/lib/action_web_service/wsdl/soap/definitions.rb +149 -0
  98. data/lib/action_web_service/wsdl/soap/driverCreator.rb +95 -0
  99. data/lib/action_web_service/wsdl/soap/element.rb +28 -0
  100. data/lib/action_web_service/wsdl/soap/fault.rb +56 -0
  101. data/lib/action_web_service/wsdl/soap/header.rb +86 -0
  102. data/lib/action_web_service/wsdl/soap/headerfault.rb +56 -0
  103. data/lib/action_web_service/wsdl/soap/mappingRegistryCreator.rb +92 -0
  104. data/lib/action_web_service/wsdl/soap/methodDefCreator.rb +228 -0
  105. data/lib/action_web_service/wsdl/soap/operation.rb +122 -0
  106. data/lib/action_web_service/wsdl/soap/servantSkeltonCreator.rb +67 -0
  107. data/lib/action_web_service/wsdl/soap/standaloneServerStubCreator.rb +85 -0
  108. data/lib/action_web_service/wsdl/soap/wsdl2ruby.rb +176 -0
  109. data/lib/action_web_service/wsdl/types.rb +43 -0
  110. data/lib/action_web_service/wsdl/wsdl.rb +23 -0
  111. data/lib/action_web_service/wsdl/xmlSchema/all.rb +69 -0
  112. data/lib/action_web_service/wsdl/xmlSchema/annotation.rb +34 -0
  113. data/lib/action_web_service/wsdl/xmlSchema/any.rb +56 -0
  114. data/lib/action_web_service/wsdl/xmlSchema/attribute.rb +127 -0
  115. data/lib/action_web_service/wsdl/xmlSchema/choice.rb +69 -0
  116. data/lib/action_web_service/wsdl/xmlSchema/complexContent.rb +92 -0
  117. data/lib/action_web_service/wsdl/xmlSchema/complexType.rb +139 -0
  118. data/lib/action_web_service/wsdl/xmlSchema/content.rb +96 -0
  119. data/lib/action_web_service/wsdl/xmlSchema/data.rb +80 -0
  120. data/lib/action_web_service/wsdl/xmlSchema/element.rb +154 -0
  121. data/lib/action_web_service/wsdl/xmlSchema/enumeration.rb +36 -0
  122. data/lib/action_web_service/wsdl/xmlSchema/import.rb +65 -0
  123. data/lib/action_web_service/wsdl/xmlSchema/importer.rb +87 -0
  124. data/lib/action_web_service/wsdl/xmlSchema/include.rb +54 -0
  125. data/lib/action_web_service/wsdl/xmlSchema/length.rb +35 -0
  126. data/lib/action_web_service/wsdl/xmlSchema/parser.rb +166 -0
  127. data/lib/action_web_service/wsdl/xmlSchema/pattern.rb +36 -0
  128. data/lib/action_web_service/wsdl/xmlSchema/schema.rb +143 -0
  129. data/lib/action_web_service/wsdl/xmlSchema/sequence.rb +69 -0
  130. data/lib/action_web_service/wsdl/xmlSchema/simpleContent.rb +65 -0
  131. data/lib/action_web_service/wsdl/xmlSchema/simpleExtension.rb +54 -0
  132. data/lib/action_web_service/wsdl/xmlSchema/simpleRestriction.rb +73 -0
  133. data/lib/action_web_service/wsdl/xmlSchema/simpleType.rb +73 -0
  134. data/lib/action_web_service/wsdl/xmlSchema/unique.rb +34 -0
  135. data/lib/action_web_service/wsdl/xmlSchema/xsd2ruby.rb +107 -0
  136. data/lib/action_web_service/xsd/charset.rb +187 -0
  137. data/lib/action_web_service/xsd/codegen.rb +12 -0
  138. data/lib/action_web_service/xsd/codegen/classdef.rb +203 -0
  139. data/lib/action_web_service/xsd/codegen/commentdef.rb +34 -0
  140. data/lib/action_web_service/xsd/codegen/gensupport.rb +166 -0
  141. data/lib/action_web_service/xsd/codegen/methoddef.rb +63 -0
  142. data/lib/action_web_service/xsd/codegen/moduledef.rb +191 -0
  143. data/lib/action_web_service/xsd/datatypes.rb +1269 -0
  144. data/lib/action_web_service/xsd/datatypes1999.rb +20 -0
  145. data/lib/action_web_service/xsd/iconvcharset.rb +33 -0
  146. data/lib/action_web_service/xsd/mapping.rb +42 -0
  147. data/lib/action_web_service/xsd/namedelements.rb +95 -0
  148. data/lib/action_web_service/xsd/ns.rb +140 -0
  149. data/lib/action_web_service/xsd/qname.rb +78 -0
  150. data/lib/action_web_service/xsd/xmlparser.rb +61 -0
  151. data/lib/action_web_service/xsd/xmlparser/parser.rb +96 -0
  152. data/lib/action_web_service/xsd/xmlparser/rexmlparser.rb +54 -0
  153. data/lib/action_web_service/xsd/xmlparser/xmlparser.rb +50 -0
  154. data/lib/action_web_service/xsd/xmlparser/xmlscanner.rb +147 -0
  155. data/lib/actionwebservice.rb +1 -0
  156. data/setup.rb +1379 -0
  157. data/test/abstract_client.rb +183 -0
  158. data/test/abstract_dispatcher.rb +548 -0
  159. data/test/abstract_unit.rb +45 -0
  160. data/test/api_test.rb +103 -0
  161. data/test/apis/auto_load_api.rb +3 -0
  162. data/test/apis/broken_auto_load_api.rb +2 -0
  163. data/test/base_test.rb +42 -0
  164. data/test/casting_test.rb +95 -0
  165. data/test/client_soap_test.rb +156 -0
  166. data/test/client_xmlrpc_test.rb +153 -0
  167. data/test/container_test.rb +73 -0
  168. data/test/dispatcher_action_controller_soap_test.rb +139 -0
  169. data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
  170. data/test/fixtures/db_definitions/mysql.sql +8 -0
  171. data/test/fixtures/db_definitions/sqlite3.sql +8 -0
  172. data/test/fixtures/users.yml +12 -0
  173. data/test/gencov +3 -0
  174. data/test/invocation_test.rb +185 -0
  175. data/test/run +6 -0
  176. data/test/scaffolded_controller_test.rb +146 -0
  177. data/test/struct_test.rb +52 -0
  178. data/test/test_invoke_test.rb +112 -0
  179. metadata +265 -0
@@ -0,0 +1,50 @@
1
+ # SOAP4R - Base type mapping definition
2
+ # Copyright (C) 2000, 2001, 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
+
4
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
+ # redistribute it and/or modify it under the same terms of Ruby's license;
6
+ # either the dual license version in 2003, or any later version.
7
+
8
+
9
+ module SOAP
10
+
11
+
12
+ TypeMap = {
13
+ XSD::XSDAnySimpleType::Type => SOAPAnySimpleType,
14
+ XSD::XSDString::Type => SOAPString,
15
+ XSD::XSDBoolean::Type => SOAPBoolean,
16
+ XSD::XSDDecimal::Type => SOAPDecimal,
17
+ XSD::XSDFloat::Type => SOAPFloat,
18
+ XSD::XSDDouble::Type => SOAPDouble,
19
+ XSD::XSDDuration::Type => SOAPDuration,
20
+ XSD::XSDDateTime::Type => SOAPDateTime,
21
+ XSD::XSDTime::Type => SOAPTime,
22
+ XSD::XSDDate::Type => SOAPDate,
23
+ XSD::XSDGYearMonth::Type => SOAPGYearMonth,
24
+ XSD::XSDGYear::Type => SOAPGYear,
25
+ XSD::XSDGMonthDay::Type => SOAPGMonthDay,
26
+ XSD::XSDGDay::Type => SOAPGDay,
27
+ XSD::XSDGMonth::Type => SOAPGMonth,
28
+ XSD::XSDHexBinary::Type => SOAPHexBinary,
29
+ XSD::XSDBase64Binary::Type => SOAPBase64,
30
+ XSD::XSDAnyURI::Type => SOAPAnyURI,
31
+ XSD::XSDQName::Type => SOAPQName,
32
+ XSD::XSDInteger::Type => SOAPInteger,
33
+ XSD::XSDNonPositiveInteger::Type => SOAPNonPositiveInteger,
34
+ XSD::XSDNegativeInteger::Type => SOAPNegativeInteger,
35
+ XSD::XSDLong::Type => SOAPLong,
36
+ XSD::XSDInt::Type => SOAPInt,
37
+ XSD::XSDShort::Type => SOAPShort,
38
+ XSD::XSDByte::Type => SOAPByte,
39
+ XSD::XSDNonNegativeInteger::Type => SOAPNonNegativeInteger,
40
+ XSD::XSDUnsignedLong::Type => SOAPUnsignedLong,
41
+ XSD::XSDUnsignedInt::Type => SOAPUnsignedInt,
42
+ XSD::XSDUnsignedShort::Type => SOAPUnsignedShort,
43
+ XSD::XSDUnsignedByte::Type => SOAPUnsignedByte,
44
+ XSD::XSDPositiveInteger::Type => SOAPPositiveInteger,
45
+
46
+ SOAP::SOAPBase64::Type => SOAPBase64,
47
+ }
48
+
49
+
50
+ end
@@ -0,0 +1,280 @@
1
+ # SOAP4R - WSDL encoded mapping registry.
2
+ # Copyright (C) 2000-2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
+
4
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
+ # redistribute it and/or modify it under the same terms of Ruby's license;
6
+ # either the dual license version in 2003, or any later version.
7
+
8
+
9
+ require 'action_web_service/xsd/qname'
10
+ require 'action_web_service/xsd/namedelements'
11
+ require 'action_web_service/soap/baseData'
12
+ require 'action_web_service/soap/mapping/mapping'
13
+ require 'action_web_service/soap/mapping/typeMap'
14
+
15
+
16
+ module SOAP
17
+ module Mapping
18
+
19
+
20
+ class WSDLEncodedRegistry < Registry
21
+ include TraverseSupport
22
+
23
+ attr_reader :definedelements
24
+ attr_reader :definedtypes
25
+ attr_accessor :excn_handler_obj2soap
26
+ attr_accessor :excn_handler_soap2obj
27
+
28
+ def initialize(definedtypes = XSD::NamedElements::Empty)
29
+ @definedtypes = definedtypes
30
+ # @definedelements = definedelements needed?
31
+ @excn_handler_obj2soap = nil
32
+ @excn_handler_soap2obj = nil
33
+ # For mapping AnyType element.
34
+ @rubytype_factory = RubytypeFactory.new(
35
+ :allow_untyped_struct => true,
36
+ :allow_original_mapping => true
37
+ )
38
+ @schema_element_cache = {}
39
+ end
40
+
41
+ def obj2soap(obj, qname = nil)
42
+ soap_obj = nil
43
+ if type = @definedtypes[qname]
44
+ soap_obj = obj2typesoap(obj, type)
45
+ else
46
+ soap_obj = any2soap(obj, qname)
47
+ end
48
+ return soap_obj if soap_obj
49
+ if @excn_handler_obj2soap
50
+ soap_obj = @excn_handler_obj2soap.call(obj) { |yield_obj|
51
+ Mapping._obj2soap(yield_obj, self)
52
+ }
53
+ return soap_obj if soap_obj
54
+ end
55
+ if qname
56
+ raise MappingError.new("cannot map #{obj.class.name} as #{qname}")
57
+ else
58
+ raise MappingError.new("cannot map #{obj.class.name} to SOAP/OM")
59
+ end
60
+ end
61
+
62
+ # map anything for now: must refer WSDL while mapping. [ToDo]
63
+ def soap2obj(node, obj_class = nil)
64
+ begin
65
+ return any2obj(node, obj_class)
66
+ rescue MappingError
67
+ end
68
+ if @excn_handler_soap2obj
69
+ begin
70
+ return @excn_handler_soap2obj.call(node) { |yield_node|
71
+ Mapping._soap2obj(yield_node, self)
72
+ }
73
+ rescue Exception
74
+ end
75
+ end
76
+ raise MappingError.new("cannot map #{node.type.name} to Ruby object")
77
+ end
78
+
79
+ private
80
+
81
+ def any2soap(obj, qname)
82
+ if obj.nil?
83
+ SOAPNil.new
84
+ elsif qname.nil? or qname == XSD::AnyTypeName
85
+ @rubytype_factory.obj2soap(nil, obj, nil, self)
86
+ elsif obj.is_a?(XSD::NSDBase)
87
+ soap2soap(obj, qname)
88
+ elsif (type = TypeMap[qname])
89
+ base2soap(obj, type)
90
+ else
91
+ nil
92
+ end
93
+ end
94
+
95
+ def soap2soap(obj, type_qname)
96
+ if obj.is_a?(SOAPBasetype)
97
+ obj
98
+ elsif obj.is_a?(SOAPStruct) && (type = @definedtypes[type_qname])
99
+ soap_obj = obj
100
+ mark_marshalled_obj(obj, soap_obj)
101
+ elements2soap(obj, soap_obj, type.content.elements)
102
+ soap_obj
103
+ elsif obj.is_a?(SOAPArray) && (type = @definedtypes[type_qname])
104
+ soap_obj = obj
105
+ contenttype = type.child_type
106
+ mark_marshalled_obj(obj, soap_obj)
107
+ obj.replace do |ele|
108
+ Mapping._obj2soap(ele, self, contenttype)
109
+ end
110
+ soap_obj
111
+ else
112
+ nil
113
+ end
114
+ end
115
+
116
+ def obj2typesoap(obj, type)
117
+ if type.is_a?(::WSDL::XMLSchema::SimpleType)
118
+ simpleobj2soap(obj, type)
119
+ else
120
+ complexobj2soap(obj, type)
121
+ end
122
+ end
123
+
124
+ def simpleobj2soap(obj, type)
125
+ type.check_lexical_format(obj)
126
+ return SOAPNil.new if obj.nil? # ToDo: check nillable.
127
+ o = base2soap(obj, TypeMap[type.base])
128
+ o
129
+ end
130
+
131
+ def complexobj2soap(obj, type)
132
+ case type.compoundtype
133
+ when :TYPE_STRUCT
134
+ struct2soap(obj, type.name, type)
135
+ when :TYPE_ARRAY
136
+ array2soap(obj, type.name, type)
137
+ when :TYPE_MAP
138
+ map2soap(obj, type.name, type)
139
+ when :TYPE_SIMPLE
140
+ simpleobj2soap(obj, type.simplecontent)
141
+ when :TYPE_EMPTY
142
+ raise MappingError.new("should be empty") unless obj.nil?
143
+ SOAPNil.new
144
+ else
145
+ raise MappingError.new("unknown compound type: #{type.compoundtype}")
146
+ end
147
+ end
148
+
149
+ def base2soap(obj, type)
150
+ soap_obj = nil
151
+ if type <= XSD::XSDString
152
+ str = XSD::Charset.encoding_conv(obj.to_s,
153
+ Thread.current[:SOAPExternalCES], XSD::Charset.encoding)
154
+ soap_obj = type.new(str)
155
+ mark_marshalled_obj(obj, soap_obj)
156
+ else
157
+ soap_obj = type.new(obj)
158
+ end
159
+ soap_obj
160
+ end
161
+
162
+ def struct2soap(obj, type_qname, type)
163
+ return SOAPNil.new if obj.nil? # ToDo: check nillable.
164
+ soap_obj = SOAPStruct.new(type_qname)
165
+ unless obj.nil?
166
+ mark_marshalled_obj(obj, soap_obj)
167
+ elements2soap(obj, soap_obj, type.content.elements)
168
+ end
169
+ soap_obj
170
+ end
171
+
172
+ def array2soap(obj, type_qname, type)
173
+ return SOAPNil.new if obj.nil? # ToDo: check nillable.
174
+ arytype = type.child_type
175
+ soap_obj = SOAPArray.new(ValueArrayName, 1, arytype)
176
+ unless obj.nil?
177
+ mark_marshalled_obj(obj, soap_obj)
178
+ obj.each do |item|
179
+ soap_obj.add(Mapping._obj2soap(item, self, arytype))
180
+ end
181
+ end
182
+ soap_obj
183
+ end
184
+
185
+ MapKeyName = XSD::QName.new(nil, "key")
186
+ MapValueName = XSD::QName.new(nil, "value")
187
+ def map2soap(obj, type_qname, type)
188
+ return SOAPNil.new if obj.nil? # ToDo: check nillable.
189
+ keytype = type.child_type(MapKeyName) || XSD::AnyTypeName
190
+ valuetype = type.child_type(MapValueName) || XSD::AnyTypeName
191
+ soap_obj = SOAPStruct.new(MapQName)
192
+ unless obj.nil?
193
+ mark_marshalled_obj(obj, soap_obj)
194
+ obj.each do |key, value|
195
+ elem = SOAPStruct.new
196
+ elem.add("key", Mapping._obj2soap(key, self, keytype))
197
+ elem.add("value", Mapping._obj2soap(value, self, valuetype))
198
+ # ApacheAxis allows only 'item' here.
199
+ soap_obj.add("item", elem)
200
+ end
201
+ end
202
+ soap_obj
203
+ end
204
+
205
+ def elements2soap(obj, soap_obj, elements)
206
+ elements.each do |element|
207
+ name = element.name.name
208
+ child_obj = Mapping.get_attribute(obj, name)
209
+ soap_obj.add(name,
210
+ Mapping._obj2soap(child_obj, self, element.type || element.name))
211
+ end
212
+ end
213
+
214
+ def any2obj(node, obj_class)
215
+ unless obj_class
216
+ typestr = XSD::CodeGen::GenSupport.safeconstname(node.elename.name)
217
+ obj_class = Mapping.class_from_name(typestr)
218
+ end
219
+ if obj_class and obj_class.class_variables.include?('@@schema_element')
220
+ soap2stubobj(node, obj_class)
221
+ else
222
+ Mapping._soap2obj(node, Mapping::DefaultRegistry, obj_class)
223
+ end
224
+ end
225
+
226
+ def soap2stubobj(node, obj_class)
227
+ obj = Mapping.create_empty_object(obj_class)
228
+ unless node.is_a?(SOAPNil)
229
+ add_elements2stubobj(node, obj)
230
+ end
231
+ obj
232
+ end
233
+
234
+ def add_elements2stubobj(node, obj)
235
+ elements, as_array = schema_element_definition(obj.class)
236
+ vars = {}
237
+ node.each do |name, value|
238
+ item = elements.find { |k, v| k.name == name }
239
+ if item
240
+ elename, class_name = item
241
+ if klass = Mapping.class_from_name(class_name)
242
+ # klass must be a SOAPBasetype or a class
243
+ if klass.ancestors.include?(::SOAP::SOAPBasetype)
244
+ if value.respond_to?(:data)
245
+ child = klass.new(value.data).data
246
+ else
247
+ child = klass.new(nil).data
248
+ end
249
+ else
250
+ child = Mapping._soap2obj(value, self, klass)
251
+ end
252
+ elsif klass = Mapping.module_from_name(class_name)
253
+ # simpletype
254
+ if value.respond_to?(:data)
255
+ child = value.data
256
+ else
257
+ raise MappingError.new(
258
+ "cannot map to a module value: #{class_name}")
259
+ end
260
+ else
261
+ raise MappingError.new("unknown class: #{class_name}")
262
+ end
263
+ else # untyped element is treated as anyType.
264
+ child = Mapping._soap2obj(value, self)
265
+ end
266
+ vars[name] = child
267
+ end
268
+ Mapping.set_attributes(obj, vars)
269
+ end
270
+
271
+ # it caches @@schema_element. this means that @@schema_element must not be
272
+ # changed while a lifetime of a WSDLLiteralRegistry.
273
+ def schema_element_definition(klass)
274
+ @schema_element_cache[klass] ||= Mapping.schema_element_definition(klass)
275
+ end
276
+ end
277
+
278
+
279
+ end
280
+ end
@@ -0,0 +1,418 @@
1
+ # SOAP4R - WSDL literal mapping registry.
2
+ # Copyright (C) 2004, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
+
4
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
+ # redistribute it and/or modify it under the same terms of Ruby's license;
6
+ # either the dual license version in 2003, or any later version.
7
+
8
+
9
+ require 'action_web_service/soap/baseData'
10
+ require 'action_web_service/soap/mapping/mapping'
11
+ require 'action_web_service/soap/mapping/typeMap'
12
+ require 'action_web_service/xsd/codegen/gensupport'
13
+ require 'action_web_service/xsd/namedelements'
14
+
15
+
16
+ module SOAP
17
+ module Mapping
18
+
19
+
20
+ class WSDLLiteralRegistry < Registry
21
+ attr_reader :definedelements
22
+ attr_reader :definedtypes
23
+ attr_accessor :excn_handler_obj2soap
24
+ attr_accessor :excn_handler_soap2obj
25
+
26
+ def initialize(definedtypes = XSD::NamedElements::Empty,
27
+ definedelements = XSD::NamedElements::Empty)
28
+ @definedtypes = definedtypes
29
+ @definedelements = definedelements
30
+ @excn_handler_obj2soap = nil
31
+ @excn_handler_soap2obj = nil
32
+ @schema_element_cache = {}
33
+ @schema_attribute_cache = {}
34
+ end
35
+
36
+ def obj2soap(obj, qname)
37
+ soap_obj = nil
38
+ if ele = @definedelements[qname]
39
+ soap_obj = obj2elesoap(obj, ele)
40
+ elsif type = @definedtypes[qname]
41
+ soap_obj = obj2typesoap(obj, type, true)
42
+ else
43
+ soap_obj = any2soap(obj, qname)
44
+ end
45
+ return soap_obj if soap_obj
46
+ if @excn_handler_obj2soap
47
+ soap_obj = @excn_handler_obj2soap.call(obj) { |yield_obj|
48
+ Mapping.obj2soap(yield_obj, nil, nil, MAPPING_OPT)
49
+ }
50
+ return soap_obj if soap_obj
51
+ end
52
+ raise MappingError.new("cannot map #{obj.class.name} as #{qname}")
53
+ end
54
+
55
+ # node should be a SOAPElement
56
+ def soap2obj(node, obj_class = nil)
57
+ # obj_class is given when rpc/literal service. but ignored for now.
58
+ begin
59
+ return any2obj(node)
60
+ rescue MappingError
61
+ end
62
+ if @excn_handler_soap2obj
63
+ begin
64
+ return @excn_handler_soap2obj.call(node) { |yield_node|
65
+ Mapping.soap2obj(yield_node, nil, nil, MAPPING_OPT)
66
+ }
67
+ rescue Exception
68
+ end
69
+ end
70
+ if node.respond_to?(:type)
71
+ raise MappingError.new("cannot map #{node.type.name} to Ruby object")
72
+ else
73
+ raise MappingError.new("cannot map #{node.elename.name} to Ruby object")
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ MAPPING_OPT = { :no_reference => true }
80
+
81
+ def obj2elesoap(obj, ele)
82
+ o = nil
83
+ qualified = (ele.elementform == 'qualified')
84
+ if ele.type
85
+ if type = @definedtypes[ele.type]
86
+ o = obj2typesoap(obj, type, qualified)
87
+ elsif type = TypeMap[ele.type]
88
+ o = base2soap(obj, type)
89
+ else
90
+ raise MappingError.new("cannot find type #{ele.type}")
91
+ end
92
+ elsif ele.local_complextype
93
+ o = obj2typesoap(obj, ele.local_complextype, qualified)
94
+ add_attributes2soap(obj, o)
95
+ elsif ele.local_simpletype
96
+ o = obj2typesoap(obj, ele.local_simpletype, qualified)
97
+ else
98
+ raise MappingError.new('illegal schema?')
99
+ end
100
+ o.elename = ele.name
101
+ o
102
+ end
103
+
104
+ def obj2typesoap(obj, type, qualified)
105
+ if type.is_a?(::WSDL::XMLSchema::SimpleType)
106
+ simpleobj2soap(obj, type)
107
+ else
108
+ complexobj2soap(obj, type, qualified)
109
+ end
110
+ end
111
+
112
+ def simpleobj2soap(obj, type)
113
+ type.check_lexical_format(obj)
114
+ return SOAPNil.new if obj.nil? # ToDo: check nillable.
115
+ o = base2soap(obj, TypeMap[type.base])
116
+ o
117
+ end
118
+
119
+ def complexobj2soap(obj, type, qualified)
120
+ o = SOAPElement.new(type.name)
121
+ o.qualified = qualified
122
+ type.each_element do |child_ele|
123
+ child = Mapping.get_attribute(obj, child_ele.name.name)
124
+ if child.nil?
125
+ if child_ele.nillable
126
+ # ToDo: test
127
+ # add empty element
128
+ child_soap = obj2elesoap(nil, child_ele)
129
+ o.add(child_soap)
130
+ elsif Integer(child_ele.minoccurs) == 0
131
+ # nothing to do
132
+ else
133
+ raise MappingError.new("nil not allowed: #{child_ele.name.name}")
134
+ end
135
+ elsif child_ele.map_as_array?
136
+ child.each do |item|
137
+ child_soap = obj2elesoap(item, child_ele)
138
+ o.add(child_soap)
139
+ end
140
+ else
141
+ child_soap = obj2elesoap(child, child_ele)
142
+ o.add(child_soap)
143
+ end
144
+ end
145
+ o
146
+ end
147
+
148
+ def any2soap(obj, qname)
149
+ if obj.is_a?(SOAPElement)
150
+ obj
151
+ elsif obj.class.class_variables.include?('@@schema_element')
152
+ stubobj2soap(obj, qname)
153
+ elsif obj.is_a?(SOAP::Mapping::Object)
154
+ mappingobj2soap(obj, qname)
155
+ elsif obj.is_a?(Hash)
156
+ ele = SOAPElement.from_obj(obj)
157
+ ele.elename = qname
158
+ ele
159
+ else
160
+ # expected to be a basetype or an anyType.
161
+ # SOAPStruct, etc. is used instead of SOAPElement.
162
+ begin
163
+ ele = Mapping.obj2soap(obj, nil, nil, MAPPING_OPT)
164
+ ele.elename = qname
165
+ ele
166
+ rescue MappingError
167
+ ele = SOAPElement.new(qname, obj.to_s)
168
+ end
169
+ if obj.respond_to?(:__xmlattr)
170
+ obj.__xmlattr.each do |key, value|
171
+ ele.extraattr[key] = value
172
+ end
173
+ end
174
+ ele
175
+ end
176
+ end
177
+
178
+ def stubobj2soap(obj, qname)
179
+ ele = SOAPElement.new(qname)
180
+ ele.qualified =
181
+ (obj.class.class_variables.include?('@@schema_qualified') and
182
+ obj.class.class_eval('@@schema_qualified'))
183
+ add_elements2soap(obj, ele)
184
+ add_attributes2soap(obj, ele)
185
+ ele
186
+ end
187
+
188
+ def mappingobj2soap(obj, qname)
189
+ ele = SOAPElement.new(qname)
190
+ obj.__xmlele.each do |key, value|
191
+ if value.is_a?(::Array)
192
+ value.each do |item|
193
+ ele.add(obj2soap(item, key))
194
+ end
195
+ else
196
+ ele.add(obj2soap(value, key))
197
+ end
198
+ end
199
+ obj.__xmlattr.each do |key, value|
200
+ ele.extraattr[key] = value
201
+ end
202
+ ele
203
+ end
204
+
205
+ def add_elements2soap(obj, ele)
206
+ elements, as_array = schema_element_definition(obj.class)
207
+ if elements
208
+ elements.each do |elename, type|
209
+ if child = Mapping.get_attribute(obj, elename.name)
210
+ if as_array.include?(elename.name)
211
+ child.each do |item|
212
+ ele.add(obj2soap(item, elename))
213
+ end
214
+ else
215
+ ele.add(obj2soap(child, elename))
216
+ end
217
+ elsif obj.is_a?(::Array) and as_array.include?(elename.name)
218
+ obj.each do |item|
219
+ ele.add(obj2soap(item, elename))
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ def add_attributes2soap(obj, ele)
227
+ attributes = schema_attribute_definition(obj.class)
228
+ if attributes
229
+ attributes.each do |qname, param|
230
+ attr = obj.__send__('xmlattr_' +
231
+ XSD::CodeGen::GenSupport.safevarname(qname.name))
232
+ ele.extraattr[qname] = attr
233
+ end
234
+ end
235
+ end
236
+
237
+ def base2soap(obj, type)
238
+ soap_obj = nil
239
+ if type <= XSD::XSDString
240
+ str = XSD::Charset.encoding_conv(obj.to_s,
241
+ Thread.current[:SOAPExternalCES], XSD::Charset.encoding)
242
+ soap_obj = type.new(str)
243
+ else
244
+ soap_obj = type.new(obj)
245
+ end
246
+ soap_obj
247
+ end
248
+
249
+ def anytype2obj(node)
250
+ if node.is_a?(::SOAP::SOAPBasetype)
251
+ return node.data
252
+ end
253
+ klass = ::SOAP::Mapping::Object
254
+ obj = klass.new
255
+ obj
256
+ end
257
+
258
+ def any2obj(node, obj_class = nil)
259
+ unless obj_class
260
+ typestr = XSD::CodeGen::GenSupport.safeconstname(node.elename.name)
261
+ obj_class = Mapping.class_from_name(typestr)
262
+ end
263
+ if obj_class and obj_class.class_variables.include?('@@schema_element')
264
+ soapele2stubobj(node, obj_class)
265
+ elsif node.is_a?(SOAPElement) or node.is_a?(SOAPStruct)
266
+ # SOAPArray for literal?
267
+ soapele2plainobj(node)
268
+ else
269
+ obj = Mapping.soap2obj(node, nil, obj_class, MAPPING_OPT)
270
+ add_attributes2plainobj(node, obj)
271
+ obj
272
+ end
273
+ end
274
+
275
+ def soapele2stubobj(node, obj_class)
276
+ obj = Mapping.create_empty_object(obj_class)
277
+ add_elements2stubobj(node, obj)
278
+ add_attributes2stubobj(node, obj)
279
+ obj
280
+ end
281
+
282
+ def soapele2plainobj(node)
283
+ obj = anytype2obj(node)
284
+ add_elements2plainobj(node, obj)
285
+ add_attributes2plainobj(node, obj)
286
+ obj
287
+ end
288
+
289
+ def add_elements2stubobj(node, obj)
290
+ elements, as_array = schema_element_definition(obj.class)
291
+ vars = {}
292
+ node.each do |name, value|
293
+ item = elements.find { |k, v| k.name == name }
294
+ if item
295
+ elename, class_name = item
296
+ if klass = Mapping.class_from_name(class_name)
297
+ # klass must be a SOAPBasetype or a class
298
+ if klass.ancestors.include?(::SOAP::SOAPBasetype)
299
+ if value.respond_to?(:data)
300
+ child = klass.new(value.data).data
301
+ else
302
+ child = klass.new(nil).data
303
+ end
304
+ else
305
+ child = any2obj(value, klass)
306
+ end
307
+ elsif klass = Mapping.module_from_name(class_name)
308
+ # simpletype
309
+ if value.respond_to?(:data)
310
+ child = value.data
311
+ else
312
+ raise MappingError.new(
313
+ "cannot map to a module value: #{class_name}")
314
+ end
315
+ else
316
+ raise MappingError.new("unknown class/module: #{class_name}")
317
+ end
318
+ else # untyped element is treated as anyType.
319
+ child = any2obj(value)
320
+ end
321
+ if as_array.include?(elename.name)
322
+ (vars[name] ||= []) << child
323
+ else
324
+ vars[name] = child
325
+ end
326
+ end
327
+ Mapping.set_attributes(obj, vars)
328
+ end
329
+
330
+ def add_attributes2stubobj(node, obj)
331
+ if attributes = schema_attribute_definition(obj.class)
332
+ define_xmlattr(obj)
333
+ attributes.each do |qname, class_name|
334
+ attr = node.extraattr[qname]
335
+ next if attr.nil? or attr.empty?
336
+ klass = Mapping.class_from_name(class_name)
337
+ if klass.ancestors.include?(::SOAP::SOAPBasetype)
338
+ child = klass.new(attr).data
339
+ else
340
+ child = attr
341
+ end
342
+ obj.__xmlattr[qname] = child
343
+ define_xmlattr_accessor(obj, qname)
344
+ end
345
+ end
346
+ end
347
+
348
+ def add_elements2plainobj(node, obj)
349
+ node.each do |name, value|
350
+ obj.__add_xmlele_value(value.elename, any2obj(value))
351
+ end
352
+ end
353
+
354
+ def add_attributes2plainobj(node, obj)
355
+ return if node.extraattr.empty?
356
+ define_xmlattr(obj)
357
+ node.extraattr.each do |qname, value|
358
+ obj.__xmlattr[qname] = value
359
+ define_xmlattr_accessor(obj, qname)
360
+ end
361
+ end
362
+
363
+ if RUBY_VERSION > "1.7.0"
364
+ def define_xmlattr_accessor(obj, qname)
365
+ name = XSD::CodeGen::GenSupport.safemethodname(qname.name)
366
+ Mapping.define_attr_accessor(obj, 'xmlattr_' + name,
367
+ proc { @__xmlattr[qname] },
368
+ proc { |value| @__xmlattr[qname] = value })
369
+ end
370
+ else
371
+ def define_xmlattr_accessor(obj, qname)
372
+ name = XSD::CodeGen::GenSupport.safemethodname(qname.name)
373
+ obj.instance_eval <<-EOS
374
+ def #{name}
375
+ @__xmlattr[#{qname.dump}]
376
+ end
377
+
378
+ def #{name}=(value)
379
+ @__xmlattr[#{qname.dump}] = value
380
+ end
381
+ EOS
382
+ end
383
+ end
384
+
385
+ if RUBY_VERSION > "1.7.0"
386
+ def define_xmlattr(obj)
387
+ obj.instance_variable_set('@__xmlattr', {})
388
+ unless obj.respond_to?(:__xmlattr)
389
+ Mapping.define_attr_accessor(obj, :__xmlattr, proc { @__xmlattr })
390
+ end
391
+ end
392
+ else
393
+ def define_xmlattr(obj)
394
+ obj.instance_variable_set('@__xmlattr', {})
395
+ unless obj.respond_to?(:__xmlattr)
396
+ obj.instance_eval <<-EOS
397
+ def __xmlattr
398
+ @__xmlattr
399
+ end
400
+ EOS
401
+ end
402
+ end
403
+ end
404
+
405
+ # it caches @@schema_element. this means that @@schema_element must not be
406
+ # changed while a lifetime of a WSDLLiteralRegistry.
407
+ def schema_element_definition(klass)
408
+ @schema_element_cache[klass] ||= Mapping.schema_element_definition(klass)
409
+ end
410
+
411
+ def schema_attribute_definition(klass)
412
+ @schema_attribute_cache[klass] ||= Mapping.schema_attribute_definition(klass)
413
+ end
414
+ end
415
+
416
+
417
+ end
418
+ end