Sha256: d88e5cebea67d53fb88921e822ecf8f4a66bec5119355216e794d1578d1038a9

Contents?: true

Size: 1.85 KB

Versions: 38

Compression:

Stored size: 1.85 KB

Contents

# encoding: ASCII-8BIT
# XSD4R - XML Mapping for Ruby
# Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.

# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.


require "soap/parser"
require 'soap/encodingstyle/literalHandler'
require "soap/generator"
require "soap/mapping"
require "soap/mapping/wsdlliteralregistry"


module XSD


module Mapping
  MappingRegistry = SOAP::Mapping::LiteralRegistry.new

  def self.obj2xml(obj, elename = nil, io = nil)
    Mapper.new(MappingRegistry).obj2xml(obj, elename, io)
  end

  def self.xml2obj(stream, klass = nil)
    Mapper.new(MappingRegistry).xml2obj(stream, klass)
  end

  class Mapper
    MAPPING_OPT = {
      :default_encodingstyle => SOAP::LiteralNamespace,
      :generate_explicit_type => false,
      :root_type_hint => true
    }.freeze

    def initialize(registry)
      @registry = registry
    end

    def obj2xml(obj, elename = nil, io = nil)
      opt = MAPPING_OPT.dup
      unless elename
        if definition = @registry.elename_schema_definition_from_class(obj.class)
          elename = definition.elename
          opt[:root_type_hint] = false
        end
      end
      elename = SOAP::Mapping.to_qname(elename) if elename
      soap = SOAP::Mapping.obj2soap(obj, @registry, elename, opt)
      if soap.elename.nil? or soap.elename == XSD::QName::EMPTY
        soap.elename =
          XSD::QName.new(nil, SOAP::Mapping.name2elename(obj.class.to_s))
      end
      generator = SOAP::Generator.new(opt)
      generator.generate(soap, io)
    end

    def xml2obj(stream, klass = nil)
      parser = SOAP::Parser.new(MAPPING_OPT)
      soap = parser.parse(stream)
      SOAP::Mapping.soap2obj(soap, @registry, klass)
    end
  end
end


end

Version data entries

38 entries across 38 versions & 10 rubygems

Version Path
soybean-2.5.5 vendor/soap4r/xsd/mapping.rb
malagant-soap4r-1.5.8.20141127181857 lib/xsd/mapping.rb
rtiss_soap4r-1.6.1 lib/xsd/mapping.rb
rtiss_soap4r-1.6.0 lib/xsd/mapping.rb
eSpace_soap4r-1.5.8 lib/xsd/mapping.rb
soap4r-ruby19-1.5.9 lib/xsd/mapping.rb
tomdz-soap4r-1.5.8.20120202093209 lib/xsd/mapping.rb
soap5r-2.0.3 lib/xsd/mapping.rb
soap5r-2.0.2 lib/xsd/mapping.rb
soap5r-2.0.1 lib/xsd/mapping.rb
soap5r-2.0.0 lib/xsd/mapping.rb
soap5r-2.0.0.20120130130121 lib/xsd/mapping.rb
soap4r-sgonyea-1.5.9 lib/xsd/mapping.rb
sunteya-soap4r-1.5.8.0 lib/xsd/mapping.rb
soybean-2.5.4 vendor/soap4r/xsd/mapping.rb
tomdz-soap4r-1.5.8.20111103171510 lib/xsd/mapping.rb
soybean-2.5.3 vendor/soap4r/xsd/mapping.rb
soybean-2.5.2 vendor/soap4r/xsd/mapping.rb
soybean-2.5.1 vendor/soap4r/xsd/mapping.rb
soybean-2.5.0 vendor/soap4r/xsd/mapping.rb