source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/soap/marshal.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 1.5 KB
Line 
1# SOAP4R - Marshalling/Unmarshalling Ruby's object using SOAP Encoding.
2# Copyright (C) 2001, 2003 NAKAMURA, Hiroshi <[email protected]>.
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
Note: See TracBrowser for help on using the repository browser.