Sha256: bbeab2c10445050d74c818625f8e138f1c42362aea62aeb830164e556332f132

Contents?: true

Size: 1.82 KB

Versions: 30

Compression:

Stored size: 1.82 KB

Contents

# 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

30 entries across 30 versions & 12 rubygems

Version Path
mumboe-soap4r-1.6.0.pre.beta lib/xsd/mapping.rb
DefV-soap4r-1.5.8.2 lib/xsd/mapping.rb
mumboe-soap4r-1.5.8.7 lib/xsd/mapping.rb
soap2r-1.5.8 lib/xsd/mapping.rb
teo-soap4r-1.5.9b lib/xsd/mapping.rb
mumboe-soap4r-1.5.8.6 lib/xsd/mapping.rb
soap4r-spox-1.6.0 lib/xsd/mapping.rb
soap4r-r19-1.5.9 lib/xsd/mapping.rb
mumboe-soap4r-1.5.8.5 lib/xsd/mapping.rb
soap4r-ruby1.9-2.0.5 lib/xsd/mapping.rb
soap4r-sgonyea-1.6.0 lib/xsd/mapping.rb
soap4r-straightjacket-1.5.9 lib/xsd/mapping.rb
soap4r-straightjacket-1.5.8 lib/xsd/mapping.rb
soap4r-ruby1.9-2.0.3 lib/xsd/mapping.rb
soap4r-ruby1.9-2.0.2 lib/xsd/mapping.rb
soap4r-ruby1.9-2.0.1 lib/xsd/mapping.rb
mumboe-soap4r-1.5.8.4 lib/xsd/mapping.rb
soap4r-ruby1.9-2.0.0 lib/xsd/mapping.rb
hands-soap4r-1.5.8.4 lib/xsd/mapping.rb
soap4r-ruby1.9-1.0.0 lib/xsd/mapping.rb