Class: VimSdk::Soap::SoapDeserializer
Instance Attribute Summary collapse
Instance Method Summary
collapse
#end_element_namespace, #namespace_and_wsdl_name, #start_element_namespace
Constructor Details
#initialize(stub = nil, version = nil) ⇒ SoapDeserializer
Returns a new instance of SoapDeserializer.
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/ruby_vim_sdk/soap/deserializer.rb', line 66
def initialize(stub = nil, version = nil)
super(nil)
@stub = stub
if version
@version = version
elsif @stub
@version = @stub.version
else
@version = nil
end
@result = nil
end
|
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
64
65
66
|
# File 'lib/ruby_vim_sdk/soap/deserializer.rb', line 64
def result
@result
end
|
Instance Method Details
#characters(string) ⇒ Object
245
246
247
|
# File 'lib/ruby_vim_sdk/soap/deserializer.rb', line 245
def characters(string)
@data += string
end
|
#deserialize(delegated_document, result_type = Object, is_fault = false, namespace_map = nil) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/ruby_vim_sdk/soap/deserializer.rb', line 79
def deserialize(delegated_document, result_type = Object, is_fault = false, namespace_map = nil)
@is_fault = is_fault
@delegated_document = delegated_document
@original_document = @delegated_document.__getobj__
@delegated_document.__setobj__(self)
@result_type = result_type
@stack = []
@data = ""
if @result_type.ancestors.include?(Array)
@result = []
else
@result = nil
end
@namespace_map = namespace_map || {}
end
|
#end_namespaced_element(name) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/ruby_vim_sdk/soap/deserializer.rb', line 167
def end_namespaced_element(name)
if @stack.empty?
@delegated_document.__setobj__(@original_document)
@original_document.end_namespaced_element(name)
return
end
object = @stack.pop
if object.kind_of?(Class) || object == Vmodl::TypeName
if object == Vmodl::TypeName
if @data.empty?
object = nil
else
object_name = namespace_and_wsdl_name(@data)
object = VmomiSupport.guess_wsdl_type(object_name[1])
end
elsif object == Vmodl::MethodName
object_name = namespace_and_wsdl_name(@data)
object = VmomiSupport.guess_wsdl_type(object_name[1])
elsif object == SoapBoolean
if @data == "0" || @data.downcase == "false"
object = false
elsif @data == "1" || @data.downcase == "true"
object = true
else
raise "Invalid boolean value: #{@data}"
end
elsif object == SoapBinary
object = Base64.decode64(@data)
elsif object == String
object = @data
elsif object == Time
object = Time.iso8601(@data)
else
ancestor_set = Set.new(object.ancestors)
if ancestor_set.include?(Vmodl::ManagedObject)
object = object.new(@data, @stub)
elsif object.ancestors.include?(SoapEnum)
object = object.const_get(VmodlHelper.underscore(@data).upcase)
elsif object == SoapFloat || object == SoapDouble
object = Float(@data)
elsif object == SoapInteger || object == SoapByte || object == SoapShort || object == SoapLong
object = Integer(@data)
else
object = object.new(@data)
end
end
elsif object.kind_of?(Vmodl::LocalizedMethodFault)
object.fault.msg = object.localized_message
object = object.fault
end
if !@stack.empty?
parent_object = @stack.last
if parent_object.kind_of?(Array)
parent_object << object
elsif parent_object.kind_of?(Vmodl::DataObject)
property_info = parent_object.class.property(:wsdl_name => name[1])
raise "Can't find #{name[1]} for #{parent_object.class.name}" if property_info.nil?
if !object.kind_of?(Array) && property_info.type.ancestors.include?(Array)
parent_object.send(property_info.name) << object
else
parent_object.send("#{property_info.name}=".to_sym, object)
end
else
parent_object.send("#{name[1]}=", object)
end
else
if !object.kind_of?(Array) && @result_type.ancestors.include?(Array)
@result << object
else
@result = object
@delegated_document.__setobj__(@original_document)
end
end
end
|
#lookup_wsdl_type(namespace, name, allow_managed_object_reference = false) ⇒ Object
#start_namespaced_element(name, attrs = {}) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/ruby_vim_sdk/soap/deserializer.rb', line 116
def start_namespaced_element(name, attrs = {})
@data = ""
deserialize_as_localized_method_fault = true
if @stack.empty?
if @is_fault
object_type = lookup_wsdl_type(name[0], name[1][0..-("Fault".length + 1)])
deserialize_as_localized_method_fault = false
else
object_type = @result_type
end
else
parent_object = @stack.last
if parent_object.kind_of?(Array)
object_type = parent_object.class.item
elsif parent_object.kind_of?(Vmodl::DataObject)
object_type = parent_object.class.property(:wsdl_name => name[1]).type
if name[1] == "fault" and parent_object.kind_of?(Vmodl::LocalizedMethodFault)
deserialize_as_localized_method_fault = false
end
else
raise "Invalid type for tag #{name.pretty_inspect}"
end
end
xsi_type = attrs[[XMLNS_XSI, "type"]]
if xsi_type
unless DYNAMIC_TYPES.include?(object_type)
name = namespace_and_wsdl_name(xsi_type)
dynamic_type = lookup_wsdl_type(name[0], name[1], true)
object_type = dynamic_type unless dynamic_type.kind_of?(Array) || object_type.kind_of?(Array)
end
else
object_type = object_type.item if object_type.ancestors.include?(Array)
end
object_type = VmomiSupport.compatible_type(object_type, @version) if @version
ancestor_set = Set.new(object_type.ancestors)
if ancestor_set.include?(Vmodl::ManagedObject)
type_attr = attrs[[name[0], "type"]]
type_name = namespace_and_wsdl_name(type_attr)
@stack << VmomiSupport.guess_wsdl_type(type_name[1])
elsif ancestor_set.include?(Vmodl::DataObject) || ancestor_set.include?(Array)
if deserialize_as_localized_method_fault and object_type.ancestors.include?(Vmodl::MethodFault)
object_type = Vmodl::LocalizedMethodFault
end
@stack << object_type.new
else
@stack << object_type
end
end
|