1 |
|
/* |
2 |
|
* DotGNU XmlRpc implementation |
3 |
|
* |
4 |
|
* Copyright (C) 2003 Free Software Foundation, Inc. |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
8 |
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* This program is distributed in the hope that it will be useful, |
12 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
* |
20 |
|
* $Revision$ $Date$ |
21 |
|
* |
22 |
|
* -------------------------------------------------------------------------- |
23 |
|
*/ |
24 |
|
using System.Runtime.Serialization; |
25 |
|
using System.IO; |
26 |
|
using DotGNU.XmlRpc; |
27 |
|
using System.Xml; |
28 |
|
|
29 |
|
namespace DotGNU.XmlRpc.Serialization.Formatters |
30 |
|
{ |
31 |
|
public sealed class MethodCallFormatter : IFormatter |
32 |
|
{ |
33 |
|
private SerializationBinder binder; |
34 |
|
private StreamingContext context; |
35 |
|
private ISurrogateSelector surrogateSelector; |
36 |
|
|
37 |
|
public MethodCallFormatter() |
38 |
|
{ |
39 |
|
context = new StreamingContext( StreamingContextStates.All ); |
40 |
|
} |
41 |
|
|
42 |
|
// Returns a XmlRpcMethod object from the incoming stream |
43 |
|
public object Deserialize( Stream stream ) |
44 |
|
{ |
45 |
|
XmlTextReader tr = new XmlTextReader( stream ); |
46 |
|
XmlRpcMethod method = new XmlRpcMethod(); |
47 |
|
method.Read( tr ); |
48 |
|
|
49 |
|
return method; |
50 |
|
} |
51 |
|
|
52 |
|
// Writes a XmlRpc MethodCall from the XmlRpcMethod object |
53 |
|
public void Serialize( Stream stream, object o ) |
54 |
|
{ |
55 |
|
if( o is XmlRpcMethod ) { |
56 |
|
StringWriter s = new StringWriter(); |
57 |
|
XmlRpcWriter w = new XmlRpcWriter( s ); |
58 |
|
w.Write( (XmlRpcMethod)o ); |
59 |
|
|
60 |
|
StreamWriter sw = new StreamWriter( stream ); |
61 |
|
sw.Write( s.ToString() ); |
62 |
|
sw.Flush(); |
63 |
|
} |
64 |
|
else { |
65 |
|
Console.Out.WriteLine |
66 |
|
( "BUMMER: wrong type given: {0}, expected and object of type {1}", |
67 |
|
o.GetType(), "DotGNU.XmlRpc.XmlRpcMethod" ); |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
|
public SerializationBinder Binder |
72 |
|
{ |
73 |
|
get{ |
74 |
|
return this.binder; |
75 |
|
} |
76 |
|
set{ |
77 |
|
this.binder = value; |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
public StreamingContext Context |
82 |
|
{ |
83 |
|
get{ |
84 |
|
return new StreamingContext(); |
85 |
|
} |
86 |
|
set { |
87 |
|
} |
88 |
|
} |
89 |
|
|
90 |
|
public ISurrogateSelector SurrogateSelector |
91 |
|
{ |
92 |
|
get { |
93 |
|
return this.surrogateSelector; |
94 |
|
} |
95 |
|
set { |
96 |
|
this.surrogateSelector = value; |
97 |
|
} |
98 |
|
} |
99 |
|
} |
100 |
|
} |
101 |
|
|
102 |
|
|