aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/XmlRpcCS/XmlRpcSerializer.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Common/XmlRpcCS/XmlRpcSerializer.cs143
1 files changed, 0 insertions, 143 deletions
diff --git a/Common/XmlRpcCS/XmlRpcSerializer.cs b/Common/XmlRpcCS/XmlRpcSerializer.cs
deleted file mode 100644
index b3b9af3..0000000
--- a/Common/XmlRpcCS/XmlRpcSerializer.cs
+++ /dev/null
@@ -1,143 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28namespace Nwc.XmlRpc
29{
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Xml;
34 using System.Text;
35
36 /// <summary>Base class of classes serializing data to XML-RPC's XML format.</summary>
37 /// <remarks>This class handles the basic type conversions like Integer to &lt;i4&gt;. </remarks>
38 /// <seealso cref="XmlRpcXmlTokens"/>
39 public class XmlRpcSerializer : XmlRpcXmlTokens
40 {
41
42 /// <summary>Serialize the <c>XmlRpcRequest</c> to the output stream.</summary>
43 /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
44 /// <param name="obj">An <c>Object</c> to serialize.</param>
45 /// <seealso cref="XmlRpcRequest"/>
46 virtual public void Serialize(XmlTextWriter output, Object obj)
47 {
48 }
49
50 /// <summary>Serialize the <c>XmlRpcRequest</c> to a String.</summary>
51 /// <remarks>Note this may represent a real memory hog for a large request.</remarks>
52 /// <param name="obj">An <c>Object</c> to serialize.</param>
53 /// <returns><c>String</c> containing XML-RPC representation of the request.</returns>
54 /// <seealso cref="XmlRpcRequest"/>
55 public String Serialize(Object obj)
56 {
57 using (MemoryStream memStream = new MemoryStream(4096))
58 {
59 XmlTextWriter xml = new XmlTextWriter( memStream, null );
60 xml.Formatting = Formatting.Indented;
61 xml.Indentation = 4;
62 Serialize(xml, obj);
63 xml.Flush();
64
65 byte[] resultBytes = memStream.ToArray();
66
67 UTF8Encoding encoder = new UTF8Encoding();
68 String returns = encoder.GetString( resultBytes, 0, resultBytes.Length );
69 xml.Close();
70 return returns;
71 }
72 }
73
74 /// <remarks>Serialize the object to the output stream.</remarks>
75 /// <param name="output">An <c>XmlTextWriter</c> stream to write data to.</param>
76 /// <param name="obj">An <c>Object</c> to serialize.</param>
77 public void SerializeObject(XmlTextWriter output, Object obj)
78 {
79 if (obj == null)
80 return;
81
82 if (obj is byte[])
83 {
84 byte[] ba = (byte[])obj;
85 output.WriteStartElement(BASE64);
86 output.WriteBase64(ba, 0, ba.Length);
87 output.WriteEndElement();
88 }
89 else if (obj is String)
90 {
91 output.WriteElementString(STRING, obj.ToString());
92 }
93 else if (obj is Int32)
94 {
95 output.WriteElementString(INT, obj.ToString());
96 }
97 else if (obj is DateTime)
98 {
99 output.WriteElementString(DATETIME, ((DateTime)obj).ToString(ISO_DATETIME));
100 }
101 else if (obj is Double)
102 {
103 output.WriteElementString(DOUBLE, obj.ToString());
104 }
105 else if (obj is Boolean)
106 {
107 output.WriteElementString(BOOLEAN, ((((Boolean)obj) == true) ? "1" : "0"));
108 }
109 else if (obj is IList)
110 {
111 output.WriteStartElement(ARRAY);
112 output.WriteStartElement(DATA);
113 if (((ArrayList)obj).Count > 0)
114 {
115 foreach (Object member in ((IList)obj))
116 {
117 output.WriteStartElement(VALUE);
118 SerializeObject(output, member);
119 output.WriteEndElement();
120 }
121 }
122 output.WriteEndElement();
123 output.WriteEndElement();
124 }
125 else if (obj is IDictionary)
126 {
127 IDictionary h = (IDictionary)obj;
128 output.WriteStartElement(STRUCT);
129 foreach (String key in h.Keys)
130 {
131 output.WriteStartElement(MEMBER);
132 output.WriteElementString(NAME, key);
133 output.WriteStartElement(VALUE);
134 SerializeObject(output, h[key]);
135 output.WriteEndElement();
136 output.WriteEndElement();
137 }
138 output.WriteEndElement();
139 }
140
141 }
142 }
143}