Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/lib/soap/marshal.rb

Revision 1824, 1.5 kB (checked in by nahi, 1 year ago)
  • Copyright notice updated. add '2000-2007' uniformly.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # SOAP4R - Marshalling/Unmarshalling Ruby's object using SOAP Encoding.
2 # Copyright (C) 2000-2007  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/mapping"
10 require "soap/processor"
11
12
13 module SOAP
14
15
16 module Marshal
17   # Trying xsd:dateTime data to be recovered as aTime.
18   MarshalMappingRegistry = Mapping::EncodedRegistry.new(
19     :allow_original_mapping => true)
20   MarshalMappingRegistry.add(
21     Time,
22     ::SOAP::SOAPDateTime,
23     ::SOAP::Mapping::EncodedRegistry::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
53 end
54
55
56 end
57
58
59 SOAPMarshal = SOAP::Marshal
Note: See TracBrowser for help on using the browser.