# File lib/soap/mapping/mapping.rb, line 122
  def self._obj2soap(obj, registry, type = nil)
    if obj.respond_to?(:to_xmlpart)
      SOAPRawData.new(obj)
    elsif defined?(::REXML) and obj.is_a?(::REXML::Element)
      SOAPRawData.new(SOAPREXMLElementWrap.new(obj))
    elsif referent = Thread.current[:SOAPMapping][:MarshalKey][obj.__id__] and
        !Thread.current[:SOAPMapping][:NoReference]
      SOAPReference.new(referent)
    elsif registry
      registry.obj2soap(obj, type)
    else
      raise MappingError.new("no mapping registry given")
    end
  end