Class: ActionWebService::Protocol::Soap::SoapMarshaler
- Inherits:
-
Object
- Object
- ActionWebService::Protocol::Soap::SoapMarshaler
- Defined in:
- lib/action_web_service/protocol/soap_protocol/marshaler.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
- #annotate_arrays(binding, value) ⇒ Object
-
#initialize(namespace = nil) ⇒ SoapMarshaler
constructor
A new instance of SoapMarshaler.
- #register_type(type) ⇒ Object (also: #lookup_type)
- #ruby_to_soap(obj) ⇒ Object
- #soap_to_ruby(obj) ⇒ Object
Constructor Details
#initialize(namespace = nil) ⇒ SoapMarshaler
Returns a new instance of SoapMarshaler.
23 24 25 26 27 28 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 23 def initialize(namespace=nil) @namespace = namespace || 'urn:ActionWebService' @registry = Registry.new @type2binding = {} register_static_factories end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
20 21 22 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 20 def namespace @namespace end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
21 22 23 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 21 def registry @registry end |
Instance Method Details
#annotate_arrays(binding, value) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 72 def annotate_arrays(binding, value) if value.nil? return elsif binding.type.array? mark_typed_array(value, binding.element_binding.qname) if binding.element_binding.type.custom? value.each do |element| annotate_arrays(binding.element_binding, element) end end elsif binding.type.structured? binding.type.each_member do |name, type| member_binding = register_type(type) member_value = value.respond_to?('[]') ? value[name] : value.send(name) annotate_arrays(member_binding, member_value) if type.custom? end end end |
#register_type(type) ⇒ Object Also known as: lookup_type
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 40 def register_type(type) return @type2binding[type] if @type2binding.has_key?(type) if type.array? array_mapping = @registry.find_mapped_soap_class(Array) qname = XSD::QName.new(@namespace, soap_type_name(type.element_type.type_class.name) + 'Array') element_type_binding = register_type(type.element_type) @type2binding[type] = SoapBinding.new(self, qname, type, array_mapping, element_type_binding) elsif (mapping = @registry.find_mapped_soap_class(type.type_class) rescue nil) qname = mapping[2] ? mapping[2][:type] : nil qname ||= soap_base_type_name(mapping[0]) @type2binding[type] = SoapBinding.new(self, qname, type, mapping) else qname = XSD::QName.new(@namespace, soap_type_name(type.type_class.name)) @registry.add(type.type_class, SOAP::SOAPStruct, typed_struct_factory(type.type_class), { :type => qname }) mapping = @registry.find_mapped_soap_class(type.type_class) @type2binding[type] = SoapBinding.new(self, qname, type, mapping) end if type.structured? type.each_member do |m_name, m_type| register_type(m_type) end end @type2binding[type] end |
#ruby_to_soap(obj) ⇒ Object
34 35 36 37 38 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 34 def ruby_to_soap(obj) soap = SOAP::Mapping.obj2soap(obj, @registry) soap.elename = XSD::QName.new if SOAP::Version >= "1.5.5" && soap.elename == XSD::QName::EMPTY soap end |
#soap_to_ruby(obj) ⇒ Object
30 31 32 |
# File 'lib/action_web_service/protocol/soap_protocol/marshaler.rb', line 30 def soap_to_ruby(obj) SOAP::Mapping.soap2obj(obj, @registry) end |