PageRenderTime 128ms CodeModel.GetById 114ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/Ruby/lib/ruby/1.8/soap/marshal.rb

http://github.com/agross/netopenspace
Ruby | 59 lines | 38 code | 15 blank | 6 comment | 1 complexity | a9b9addc0cb4e27fbb52b139dfdb9c0a MD5 | raw file
 1# SOAP4R - Marshalling/Unmarshalling Ruby's object using SOAP Encoding.
 2# Copyright (C) 2001, 2003  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
 9require "soap/mapping"
10require "soap/processor"
11
12
13module SOAP
14
15
16module Marshal
17  # Trying xsd:dateTime data to be recovered as aTime.
18  MarshalMappingRegistry = Mapping::Registry.new(
19    :allow_original_mapping => true)
20  MarshalMappingRegistry.add(
21    Time,
22    ::SOAP::SOAPDateTime,
23    ::SOAP::Mapping::Registry::DateTimeFactory
24  )
25
26  class << self
27  public
28    def dump(obj, io = nil)
29      marshal(obj, MarshalMappingRegistry, io)
30    end
31
32    def load(stream)
33      unmarshal(stream, MarshalMappingRegistry)
34    end
35
36    def marshal(obj, mapping_registry = MarshalMappingRegistry, io = nil)
37      elename = Mapping.name2elename(obj.class.to_s)
38      soap_obj = Mapping.obj2soap(obj, mapping_registry)
39      body = SOAPBody.new
40      body.add(elename, soap_obj)
41      env = SOAPEnvelope.new(nil, body)
42      SOAP::Processor.marshal(env, {}, io)
43    end
44
45    def unmarshal(stream, mapping_registry = MarshalMappingRegistry)
46      env = SOAP::Processor.unmarshal(stream)
47      if env.nil?
48	raise ArgumentError.new("Illegal SOAP marshal format.")
49      end
50      Mapping.soap2obj(env.body.root_node, mapping_registry)
51    end
52  end
53end
54
55
56end
57
58
59SOAPMarshal = SOAP::Marshal