~ubuntu-branches/ubuntu/intrepid/ruby1.8/intrepid-updates

« back to all changes in this revision

Viewing changes to lib/xsd/mapping.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# XSD4R - XML Mapping for Ruby
 
2
# Copyright (C) 2005  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
 
3
 
 
4
# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
 
5
# redistribute it and/or modify it under the same terms of Ruby's license;
 
6
# either the dual license version in 2003, or any later version.
 
7
 
 
8
 
 
9
require "soap/parser"
 
10
require 'soap/encodingstyle/literalHandler'
 
11
require "soap/generator"
 
12
require "soap/mapping"
 
13
require "soap/mapping/wsdlliteralregistry"
 
14
 
 
15
 
 
16
module XSD
 
17
 
 
18
 
 
19
module Mapping
 
20
  MappingRegistry = SOAP::Mapping::WSDLLiteralRegistry.new
 
21
  MappingOpt = {:default_encodingstyle => SOAP::LiteralNamespace}
 
22
 
 
23
  def self.obj2xml(obj, elename = nil, io = nil)
 
24
    if !elename.nil? and !elename.is_a?(XSD::QName)
 
25
      elename = XSD::QName.new(nil, elename)
 
26
    end
 
27
    elename ||= XSD::QName.new(nil, SOAP::Mapping.name2elename(obj.class.to_s))
 
28
    soap = SOAP::Mapping.obj2soap(obj, MappingRegistry)
 
29
    soap.elename = elename
 
30
    generator = SOAP::SOAPGenerator.new(MappingOpt)
 
31
    generator.generate(soap, io)
 
32
  end
 
33
 
 
34
  def self.xml2obj(stream)
 
35
    parser = SOAP::Parser.new(MappingOpt)
 
36
    soap = parser.parse(stream)
 
37
    SOAP::Mapping.soap2obj(soap, MappingRegistry)
 
38
  end
 
39
end
 
40
 
 
41
 
 
42
end