aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/XMPP/XmppSerializer.cs')
-rw-r--r--OpenSim/Framework/Communications/XMPP/XmppSerializer.cs30
1 files changed, 24 insertions, 6 deletions
diff --git a/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs b/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
index f0d2cd5..30a9eac 100644
--- a/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
+++ b/OpenSim/Framework/Communications/XMPP/XmppSerializer.cs
@@ -28,21 +28,27 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection;
31using System.Text; 32using System.Text;
32using System.Xml; 33using System.Xml;
33using System.Xml.Serialization; 34using System.Xml.Serialization;
35using log4net;
34 36
35namespace OpenSim.Framework.Communications.XMPP 37namespace OpenSim.Framework.Communications.XMPP
36{ 38{
37 public class XMPPSerializer 39 public class XmppSerializer
38 { 40 {
41 private static readonly ILog _log =
42 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
39 // need to do it this way, as XmlSerializer(type, extratypes) 44 // need to do it this way, as XmlSerializer(type, extratypes)
40 // does not work on mono (at least). 45 // does not work on mono (at least).
41 private Dictionary<Type, XmlSerializer> _serializers = new Dictionary<Type, XmlSerializer>(); 46 private Dictionary<Type, XmlSerializer> _serializerForType = new Dictionary<Type, XmlSerializer>();
47 private Dictionary<string, XmlSerializer> _serializerForName = new Dictionary<string, XmlSerializer>();
42 private XmlSerializerNamespaces _xmlNs; 48 private XmlSerializerNamespaces _xmlNs;
43 private string _defaultNS; 49 private string _defaultNS;
44 50
45 public XMPPSerializer(bool server) 51 public XmppSerializer(bool server)
46 { 52 {
47 _xmlNs = new XmlSerializerNamespaces(); 53 _xmlNs = new XmlSerializerNamespaces();
48 _xmlNs.Add(String.Empty, String.Empty); 54 _xmlNs.Add(String.Empty, String.Empty);
@@ -51,15 +57,27 @@ namespace OpenSim.Framework.Communications.XMPP
51 else 57 else
52 _defaultNS = "jabber:client"; 58 _defaultNS = "jabber:client";
53 59
54 _serializers[typeof(XmppMessageStanza)] = new XmlSerializer(typeof(XmppMessageStanza), _defaultNS); 60 // TODO: do this via reflection
61 _serializerForType[typeof(XmppMessageStanza)] = _serializerForName["message"] =
62 new XmlSerializer(typeof(XmppMessageStanza), _defaultNS);
55 } 63 }
56 64
57 public void Serialize(XmlWriter xw, object o) 65 public void Serialize(XmlWriter xw, object o)
58 { 66 {
59 if (!_serializers.ContainsKey(o.GetType())) 67 if (!_serializerForType.ContainsKey(o.GetType()))
60 throw new ArgumentException(String.Format("no serializer available for type {0}", o.GetType())); 68 throw new ArgumentException(String.Format("no serializer available for type {0}", o.GetType()));
61 69
62 _serializers[o.GetType()].Serialize(xw, o, _xmlNs); 70 _serializerForType[o.GetType()].Serialize(xw, o, _xmlNs);
71 }
72
73 public object Deserialize(XmlReader xr)
74 {
75 // position on next element
76 xr.Read();
77 if (!_serializerForName.ContainsKey(xr.LocalName))
78 throw new ArgumentException(String.Format("no serializer available for name {0}", xr.LocalName));
79
80 return _serializerForName[xr.LocalName].Deserialize(xr);
63 } 81 }
64 } 82 }
65} 83}