Class ActionWebService::Protocol::Soap::SoapMarshaler
In: actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb
Parent: Object

Methods

Attributes

namespace  [R] 
registry  [R] 

Public Class methods

[Source]

# File actionwebservice/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

Public Instance methods

[Source]

# File actionwebservice/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
lookup_type(type)

Alias for register_type

[Source]

# File actionwebservice/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

[Source]

# File actionwebservice/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

[Source]

# File actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb, line 30
        def soap_to_ruby(obj)
          SOAP::Mapping.soap2obj(obj, @registry)
        end

Private Instance methods

[Source]

# File actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb, line 103
          def mark_typed_array(array, qname)
            (class << array; self; end).class_eval do 
              define_method(:arytype) do
                qname
              end
            end
          end

[Source]

# File actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb, line 120
          def register_static_factories
            @registry.add(ActionWebService::Base64, SOAP::SOAPBase64, SoapBase64Factory.new, nil)
            mapping = @registry.find_mapped_soap_class(ActionWebService::Base64)
            @type2binding[ActionWebService::Base64] =
              SoapBinding.new(self, SOAP::SOAPBase64::Type, ActionWebService::Base64, mapping)
            @registry.add(Array, SOAP::SOAPArray, SoapTypedArrayFactory.new, nil)
            @registry.add(::BigDecimal, SOAP::SOAPDouble, SOAP::Mapping::Registry::BasetypeFactory, {:derived_class => true})
          end

[Source]

# File actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb, line 111
          def soap_base_type_name(type)
            xsd_type = type.ancestors.find{ |c| c.const_defined? 'Type' }
            xsd_type ? xsd_type.const_get('Type') : XSD::XSDAnySimpleType::Type
          end

[Source]

# File actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb, line 116
          def soap_type_name(type_name)
            type_name.gsub(/::/, '..')
          end

[Source]

# File actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb, line 92
          def typed_struct_factory(type_class)
            if Object.const_defined?('ActiveRecord')
              if type_class.ancestors.include?(ActiveRecord::Base)
                qname =  XSD::QName.new(@namespace, soap_type_name(type_class.name))
                type_class.instance_variable_set('@qname', qname)
                return SoapActiveRecordStructFactory.new
              end
            end
            SOAP::Mapping::Registry::TypedStructFactory
          end

[Validate]