Module: SOAP::Mapping

Module | SOAP::Mapping
In: | soap/mapping/wsdlliteralregistry.rb soap/mapping/wsdlencodedregistry.rb soap/mapping/rubytypeFactory.rb soap/mapping/registry.rb soap/mapping/mapping.rb soap/mapping/factory.rb soap/attachment.rb

### Methods

_obj2soap _soap2obj ary2md ary2soap class2element class2qname class_from_name const_from_name create_empty_object create_empty_object define_attr_accessor define_singleton_method elename2name fault2exception get_attribute module_from_name name2elename obj2element obj2soap schema_attribute_definition schema_element_definition schema_ns_definition schema_type_definition set_attributes soap2obj

### Classes and Modules

Module SOAP::Mapping::MappedException
Module SOAP::Mapping::TraverseSupport
Class SOAP::Mapping::ArrayFactory_
Class SOAP::Mapping::AttachmentFactory
Class SOAP::Mapping::Base64Factory_
Class SOAP::Mapping::BasetypeFactory_
Class SOAP::Mapping::DateTimeFactory_
Class SOAP::Mapping::Factory
Class SOAP::Mapping::HashFactory_
Class SOAP::Mapping::MappingError
Class SOAP::Mapping::Object
Class SOAP::Mapping::Registry
Class SOAP::Mapping::RubytypeFactory
Class SOAP::Mapping::SOAPException
Class SOAP::Mapping::StringFactory_
Class SOAP::Mapping::TypedArrayFactory_
Class SOAP::Mapping::TypedStructFactory_
Class SOAP::Mapping::URIFactory_
Class SOAP::Mapping::WSDLEncodedRegistry
Class SOAP::Mapping::WSDLLiteralRegistry

### Constants

RubyTypeName | = | XSD::QName.new(RubyTypeInstanceNamespace, 'rubyType')
RubyExtendName | = | XSD::QName.new(RubyTypeInstanceNamespace, 'extends')
RubyIVarName | = | XSD::QName.new(RubyTypeInstanceNamespace, 'ivars')
DefaultRegistry | = | Registry.new
RubyOriginalRegistry | = | Registry.new(:allow_original_mapping => true)
RubyTypeNamespace | = | 'http://www.ruby-lang.org/xmlns/ruby/type/1.6'
RubyTypeInstanceNamespace | = | 'http://www.ruby-lang.org/xmlns/ruby/type-instance'
RubyCustomTypeNamespace | = | 'http://www.ruby-lang.org/xmlns/ruby/type/custom'
ApacheSOAPTypeNamespace | = | 'http://xml.apache.org/xml-soap'
EMPTY_OPT | = | {}
MARSHAL_TAG | = | { String => ['"', 1], Regexp => ['/', 2], Array => ['[', 1], Hash => ['{', 1]
MapQName | = | XSD::QName.new(ApacheSOAPTypeNamespace, 'Map')

### Public Class methods

_obj2soap(obj, registry, type = nil)

[Source]

    # File soap/mapping/mapping.rb, line 122
      def self._obj2soap(obj, registry, type = nil)
        if referent = Thread.current[:SOAPMarshalDataKey][obj.__id__] and
            !Thread.current[:SOAPMarshalNoReference]
          SOAPReference.new(referent)
        elsif registry
          registry.obj2soap(obj, type)
        else
          raise MappingError.new("no mapping registry given")
        end
      end

_soap2obj(node, registry, klass = nil)

[Source]

    # File soap/mapping/mapping.rb, line 133
      def self._soap2obj(node, registry, klass = nil)
        if node.nil?
          return nil
        elsif node.is_a?(SOAPReference)
          target = node.__getobj__
          # target.id is not Object#id but SOAPReference#id
          if referent = Thread.current[:SOAPMarshalDataKey][target.id] and
              !Thread.current[:SOAPMarshalNoReference]
            return referent
          else
            return _soap2obj(target, registry, klass)
          end
        end
        return registry.soap2obj(node, klass)
      end

ary2md(ary, rank, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil, opt = EMPTY_OPT)

[Source]

    # File soap/mapping/mapping.rb, line 79
      def self.ary2md(ary, rank, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil, opt = EMPTY_OPT)
        registry ||= Mapping::DefaultRegistry
        type = XSD::QName.new(type_ns, typename)
        md_ary = SOAPArray.new(ValueArrayName, rank, type)
        protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do
          Thread.current[:SOAPMarshalDataKey] = {}
          Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE
          Thread.current[:SOAPMarshalNoReference] = opt[:no_reference]
          add_md_ary(md_ary, ary, [], registry)
        end
        md_ary
      end

ary2soap(ary, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil, opt = EMPTY_OPT)

[Source]

    # File soap/mapping/mapping.rb, line 64
      def self.ary2soap(ary, type_ns = XSD::Namespace, typename = XSD::AnyTypeLiteral, registry = nil, opt = EMPTY_OPT)
        registry ||= Mapping::DefaultRegistry
        type = XSD::QName.new(type_ns, typename)
        soap_ary = SOAPArray.new(ValueArrayName, 1, type)
        protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do
          Thread.current[:SOAPMarshalDataKey] = {}
          Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE
          Thread.current[:SOAPMarshalNoReference] = opt[:no_reference]
          ary.each do |ele|
            soap_ary.add(_obj2soap(ele, registry, type))
          end
        end
        soap_ary
      end

class2element(klass)

[Source]

    # File soap/mapping/mapping.rb, line 244
      def self.class2element(klass)
        type = Mapping.class2qname(klass)
        type.name ||= Mapping.name2elename(klass.name)
        type.namespace ||= RubyCustomTypeNamespace
        type
      end

class2qname(klass)

[Source]

    # File soap/mapping/mapping.rb, line 238
      def self.class2qname(klass)
        name = schema_type_definition(klass)
        namespace = schema_ns_definition(klass)
        XSD::QName.new(namespace, name)
      end

class_from_name(name, lenient = false)

[Source]

    # File soap/mapping/mapping.rb, line 220
      def self.class_from_name(name, lenient = false)
        const = const_from_name(name, lenient)
        if const.is_a?(::Class)
          const
        else
          nil
        end
      end

const_from_name(name, lenient = false)

[Source]

    # File soap/mapping/mapping.rb, line 200
      def self.const_from_name(name, lenient = false)
        const = ::Object
        name.sub(/\A::/, '').split('::').each do |const_str|
          if XSD::CodeGen::GenSupport.safeconstname?(const_str)
            if const.const_defined?(const_str)
              const = const.const_get(const_str)
              next
            end
          elsif lenient
            const_str = XSD::CodeGen::GenSupport.safeconstname(const_str)
            if const.const_defined?(const_str)
              const = const.const_get(const_str)
              next
            end
          end
          return nil
        end
        const
      end

create_empty_object(klass)

ruby/1.7 or later.

[Source]

    # File soap/mapping/mapping.rb, line 151
        def self.create_empty_object(klass)
          klass.allocate
        end

create_empty_object(klass)

[Source]

    # File soap/mapping/mapping.rb, line 161
        def self.create_empty_object(klass)
          if klass <= Struct
            name = klass.name
            return ::Marshal.load(sprintf("\004\006S:%c%s\000", name.length + 5, name))
          end
          if MARSHAL_TAG.has_key?(klass)
            tag, terminate = MARSHAL_TAG[klass]
            return ::Marshal.load(sprintf("\004\006%s%s", tag, "\000" * terminate))
          end
          MARSHAL_TAG.each do |k, v|
            if klass < k
              name = klass.name
              tag, terminate = v
              return ::Marshal.load(sprintf("\004\006C:%c%s%s%s", name.length + 5, name, tag, "\000" * terminate))
            end
          end
          name = klass.name
          ::Marshal.load(sprintf("\004\006o:%c%s\000", name.length + 5, name))
        end

define_attr_accessor(obj, name, getterproc, setterproc = nil)

[Source]

    # File soap/mapping/mapping.rb, line 313
      def self.define_attr_accessor(obj, name, getterproc, setterproc = nil)
        define_singleton_method(obj, name, &getterproc)
        define_singleton_method(obj, name + '=', &setterproc) if setterproc
      end

define_singleton_method(obj, name, &block)

[Source]

    # File soap/mapping/mapping.rb, line 267
      def self.define_singleton_method(obj, name, &block)
        sclass = (class << obj; self; end)
        sclass.class_eval {
          define_method(name, &block)
        }
      end

elename2name(name)

[Source]

    # File soap/mapping/mapping.rb, line 194
      def self.elename2name(name)
        name.gsub(/\.\./n, '::').gsub(/((?:\.[0-9a-fA-F]{2})+)/n) {
          [$1.delete('.')].pack('H*')
        }
      end

fault2exception(fault, registry = nil)

[Source]

    # File soap/mapping/mapping.rb, line 92
      def self.fault2exception(fault, registry = nil)
        registry ||= Mapping::DefaultRegistry
        detail = if fault.detail
            soap2obj(fault.detail, registry) || ""
          else
            ""
          end
        if detail.is_a?(Mapping::SOAPException)
          begin
            e = detail.to_e
            remote_backtrace = e.backtrace
            e.set_backtrace(nil)
            raise e # ruby sets current caller as local backtrace of e => e2.
          rescue Exception => e
            e.set_backtrace(remote_backtrace + e.backtrace[1..-1])
            raise
          end
        else
          fault.detail = detail
          fault.set_backtrace(
            if detail.is_a?(Array)
              detail
            else
              [detail.to_s]
            end
          )
          raise
        end
      end

get_attribute(obj, attr_name)

[Source]

    # File soap/mapping/mapping.rb, line 274
      def self.get_attribute(obj, attr_name)
        if obj.is_a?(::Hash)
          obj[attr_name] || obj[attr_name.intern]
        else
          name = XSD::CodeGen::GenSupport.safevarname(attr_name)
          if obj.instance_variables.include?('@' + name)
            obj.instance_variable_get('@' + name)
          elsif ((obj.is_a?(::Struct) or obj.is_a?(Marshallable)) and
              obj.respond_to?(name))
            obj.__send__(name)
          end
        end
      end

module_from_name(name, lenient = false)

[Source]

    # File soap/mapping/mapping.rb, line 229
      def self.module_from_name(name, lenient = false)
        const = const_from_name(name, lenient)
        if const.is_a?(::Module)
          const
        else
          nil
        end
      end

name2elename(name)

Allow only (Letter | ‘_’) (Letter | Digit | ’-’ | ‘_’)* here. Caution: ’.’ is not allowed here. To follow XML spec., it should be NCName.

      (denied chars) => .[0-F][0-F]
      ex. a.b => a.2eb

[Source]

    # File soap/mapping/mapping.rb, line 188
      def self.name2elename(name)
        name.gsub(/([^a-zA-Z0-9:_\-]+)/n) {
          '.' << $1.unpack('H2' * $1.size).join('.')
        }.gsub(/::/n, '..')
      end

obj2element(obj)

[Source]

    # File soap/mapping/mapping.rb, line 251
      def self.obj2element(obj)
        name = namespace = nil
        ivars = obj.instance_variables
        if ivars.include?('@schema_type')
          name = obj.instance_variable_get('@schema_type')
        end
        if ivars.include?('@schema_ns')
          namespace = obj.instance_variable_get('@schema_ns')
        end
        if !name or !namespace
          class2qname(obj.class)
        else
          XSD::QName.new(namespace, name)
        end
      end

obj2soap(obj, registry = nil, type = nil, opt = EMPTY_OPT)

[Source]

    # File soap/mapping/mapping.rb, line 40
      def self.obj2soap(obj, registry = nil, type = nil, opt = EMPTY_OPT)
        registry ||= Mapping::DefaultRegistry
        soap_obj = nil
        protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do
          Thread.current[:SOAPMarshalDataKey] = {}
          Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE
          Thread.current[:SOAPMarshalNoReference] = opt[:no_reference]
          soap_obj = _obj2soap(obj, registry, type)
        end
        soap_obj
      end

schema_attribute_definition(klass)

[Source]

    # File soap/mapping/mapping.rb, line 342
      def self.schema_attribute_definition(klass)
        class_schema_variable(:schema_attribute, klass)
      end

schema_element_definition(klass)

[Source]

    # File soap/mapping/mapping.rb, line 326
      def self.schema_element_definition(klass)
        schema_element = class_schema_variable(:schema_element, klass) or return nil
        schema_ns = schema_ns_definition(klass)
        elements = []
        as_array = []
        schema_element.each do |varname, definition|
          class_name, name = definition
          if /\[\]$/ =~ class_name
            class_name = class_name.sub(/\[\]$/, '')
            as_array << (name ? name.name : varname)
          end
          elements << [name || XSD::QName.new(schema_ns, varname), class_name]
        end
        [elements, as_array]
      end

schema_ns_definition(klass)

[Source]

    # File soap/mapping/mapping.rb, line 322
      def self.schema_ns_definition(klass)
        class_schema_variable(:schema_ns, klass)
      end

schema_type_definition(klass)

[Source]

    # File soap/mapping/mapping.rb, line 318
      def self.schema_type_definition(klass)
        class_schema_variable(:schema_type, klass)
      end

set_attributes(obj, values)

[Source]

    # File soap/mapping/mapping.rb, line 288
      def self.set_attributes(obj, values)
        if obj.is_a?(::SOAP::Mapping::Object)
          values.each do |attr_name, value|
            obj.__add_xmlele_value(attr_name, value)
          end
        else
          values.each do |attr_name, value|
            name = XSD::CodeGen::GenSupport.safevarname(attr_name)
            setter = name + "="
            if obj.respond_to?(setter)
              obj.__send__(setter, value)
            else
              obj.instance_variable_set('@' + name, value)
              begin
                define_attr_accessor(obj, name,
                  proc { instance_variable_get('@' + name) },
                  proc { |value| instance_variable_set('@' + name, value) })
              rescue TypeError
                # singleton class may not exist (e.g. Float)
              end
            end
          end
        end
      end

soap2obj(node, registry = nil, klass = nil, opt = EMPTY_OPT)

[Source]

    # File soap/mapping/mapping.rb, line 52
      def self.soap2obj(node, registry = nil, klass = nil, opt = EMPTY_OPT)
        registry ||= Mapping::DefaultRegistry
        obj = nil
        protect_threadvars(:SOAPMarshalDataKey, :SOAPExternalCES, :SOAPMarshalNoReference) do
          Thread.current[:SOAPMarshalDataKey] = {}
          Thread.current[:SOAPExternalCES] = opt[:external_ces] || $KCODE
          Thread.current[:SOAPMarshalNoReference] = opt[:no_reference]
          obj = _soap2obj(node, registry, klass)
        end
        obj
      end

[Validate]