aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs53
-rw-r--r--OpenSim/Framework/Serialization/External/LandDataSerializer.cs74
-rw-r--r--OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs33
-rw-r--r--prebuild.xml1
4 files changed, 63 insertions, 98 deletions
diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
index 7447ac2..39a9f37 100644
--- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
+++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs
@@ -24,11 +24,13 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27
27using System; 28using System;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.IO; 30using System.IO;
31using System.Reflection;
30using System.Xml; 32using System.Xml;
31 33using log4net;
32using OpenMetaverse; 34using OpenMetaverse;
33using OpenSim.Services.Interfaces; 35using OpenSim.Services.Interfaces;
34 36
@@ -39,6 +41,55 @@ namespace OpenSim.Framework.Serialization.External
39 /// </summary> 41 /// </summary>
40 public class ExternalRepresentationUtils 42 public class ExternalRepresentationUtils
41 { 43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 /// <summary>
47 /// Populate a node with data read from xml using a dictinoary of processors
48 /// </summary>
49 /// <param name="nodeToFill"></param>
50 /// <param name="processors">
51 /// A <see cref="Dictionary<System.String, Action<NodeType, XmlTextReader>>"/>
52 /// </param>
53 /// <param name="xtr">
54 /// A <see cref="XmlTextReader"/>
55 /// </param>
56 public static void ExecuteReadProcessors<NodeType>(
57 NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlTextReader>> processors, XmlTextReader xtr)
58 {
59 string nodeName = string.Empty;
60 while (xtr.NodeType != XmlNodeType.EndElement)
61 {
62 nodeName = xtr.Name;
63
64// m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName);
65
66 Action<NodeType, XmlTextReader> p = null;
67 if (processors.TryGetValue(xtr.Name, out p))
68 {
69// m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName);
70
71 try
72 {
73 p(nodeToFill, xtr);
74 }
75 catch (Exception e)
76 {
77 m_log.ErrorFormat(
78 "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}",
79 nodeName, e.Message, e.StackTrace);
80
81 if (xtr.NodeType == XmlNodeType.EndElement)
82 xtr.Read();
83 }
84 }
85 else
86 {
87 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
88 xtr.ReadOuterXml(); // ignore
89 }
90 }
91 }
92
42 /// <summary> 93 /// <summary>
43 /// Takes a XML representation of a SceneObjectPart and returns another XML representation 94 /// Takes a XML representation of a SceneObjectPart and returns another XML representation
44 /// with creator data added to it. 95 /// with creator data added to it.
diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
index bf6c4e5..a12877a 100644
--- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs
@@ -46,13 +46,11 @@ namespace OpenSim.Framework.Serialization.External
46 46
47 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding(); 47 protected static UTF8Encoding m_utf8Encoding = new UTF8Encoding();
48 48
49 private delegate void LandDataProcessor(LandData landData, XmlTextReader reader); 49 private static Dictionary<string, Action<LandData, XmlTextReader>> m_ldProcessors
50 private static Dictionary<string, LandDataProcessor> m_ldProcessors 50 = new Dictionary<string, Action<LandData, XmlTextReader>>();
51 = new Dictionary<string, LandDataProcessor>();
52 51
53 private delegate void LandAccessEntryProcessor(LandAccessEntry lae, XmlTextReader reader); 52 private static Dictionary<string, Action<LandAccessEntry, XmlTextReader>> m_laeProcessors
54 private static Dictionary<string, LandAccessEntryProcessor> m_laeProcessors 53 = new Dictionary<string, Action<LandAccessEntry, XmlTextReader>>();
55 = new Dictionary<string, LandAccessEntryProcessor>();
56 54
57 static LandDataSerializer() 55 static LandDataSerializer()
58 { 56 {
@@ -146,38 +144,7 @@ namespace OpenSim.Framework.Serialization.External
146 144
147 xtr.ReadStartElement("ParcelAccessEntry"); 145 xtr.ReadStartElement("ParcelAccessEntry");
148 146
149 string nodeName = string.Empty; 147 ExternalRepresentationUtils.ExecuteReadProcessors<LandAccessEntry>(lae, m_laeProcessors, xtr);
150 while (xtr.NodeType != XmlNodeType.EndElement)
151 {
152 nodeName = xtr.Name;
153
154// m_log.DebugFormat("[LandDataSerializer]: Processing: {0} in ParcelAccessEntry", nodeName);
155
156 LandAccessEntryProcessor p = null;
157 if (m_laeProcessors.TryGetValue(xtr.Name, out p))
158 {
159// m_log.DebugFormat("[LandDataSerializer]: Found {0} processor in ParcelAccessEntry", nodeName);
160
161 try
162 {
163 p(lae, xtr);
164 }
165 catch (Exception e)
166 {
167 m_log.ErrorFormat(
168 "[LandDataSerializer]: Exception while parsing element {0} in ParcelAccessEntry, continuing. Exception {1}{2}",
169 nodeName, e.Message, e.StackTrace);
170
171 if (xtr.NodeType == XmlNodeType.EndElement)
172 xtr.Read();
173 }
174 }
175 else
176 {
177 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
178 xtr.ReadOuterXml(); // ignore
179 }
180 }
181 148
182 xtr.ReadEndElement(); 149 xtr.ReadEndElement();
183 150
@@ -213,36 +180,7 @@ namespace OpenSim.Framework.Serialization.External
213 { 180 {
214 reader.ReadStartElement("LandData"); 181 reader.ReadStartElement("LandData");
215 182
216 string nodeName = string.Empty; 183 ExternalRepresentationUtils.ExecuteReadProcessors<LandData>(landData, m_ldProcessors, reader);
217 while (reader.NodeType != XmlNodeType.EndElement)
218 {
219 nodeName = reader.Name;
220
221// m_log.DebugFormat("[LandDataSerializer]: Processing: {0}", nodeName);
222
223 LandDataProcessor p = null;
224 if (m_ldProcessors.TryGetValue(reader.Name, out p))
225 {
226 try
227 {
228 p(landData, reader);
229 }
230 catch (Exception e)
231 {
232 m_log.ErrorFormat(
233 "[LandDataSerializer]: exception while parsing element {0}, continuing. Exception {1}{2}",
234 nodeName, e.Message, e.StackTrace);
235
236 if (reader.NodeType == XmlNodeType.EndElement)
237 reader.Read();
238 }
239 }
240 else
241 {
242 // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
243 reader.ReadOuterXml(); // ignore
244 }
245 }
246 184
247 reader.ReadEndElement(); 185 reader.ReadEndElement();
248 } 186 }
diff --git a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
index 5d986d5..f6fdc4b 100644
--- a/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
+++ b/OpenSim/Framework/Serialization/External/UserInventoryItemSerializer.cs
@@ -46,8 +46,8 @@ namespace OpenSim.Framework.Serialization.External
46 { 46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader); 49 private static Dictionary<string, Action<InventoryItemBase, XmlTextReader>> m_InventoryItemXmlProcessors
50 private static Dictionary<string, InventoryItemXmlProcessor> m_InventoryItemXmlProcessors = new Dictionary<string, InventoryItemXmlProcessor>(); 50 = new Dictionary<string, Action<InventoryItemBase, XmlTextReader>>();
51 51
52 #region InventoryItemBase Processor initialization 52 #region InventoryItemBase Processor initialization
53 static UserInventoryItemSerializer() 53 static UserInventoryItemSerializer()
@@ -204,39 +204,14 @@ namespace OpenSim.Framework.Serialization.External
204 { 204 {
205 reader.ReadStartElement("InventoryItem"); 205 reader.ReadStartElement("InventoryItem");
206 206
207 string nodeName = string.Empty; 207 ExternalRepresentationUtils.ExecuteReadProcessors<InventoryItemBase>(
208 while (reader.NodeType != XmlNodeType.EndElement) 208 item, m_InventoryItemXmlProcessors, reader);
209 {
210 nodeName = reader.Name;
211 InventoryItemXmlProcessor p = null;
212 if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p))
213 {
214 //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name);
215 try
216 {
217 p(item, reader);
218 }
219 catch (Exception e)
220 {
221 m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e);
222 if (reader.NodeType == XmlNodeType.EndElement)
223 reader.Read();
224 }
225 }
226 else
227 {
228 // m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName);
229 reader.ReadOuterXml(); // ignore
230 }
231
232 }
233 209
234 reader.ReadEndElement(); // InventoryItem 210 reader.ReadEndElement(); // InventoryItem
235 } 211 }
236 212
237 //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID); 213 //m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID);
238 return item; 214 return item;
239
240 } 215 }
241 216
242 public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService) 217 public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService)
diff --git a/prebuild.xml b/prebuild.xml
index 65383ee..c402cf5 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -218,6 +218,7 @@
218 218
219 <ReferencePath>../../../bin/</ReferencePath> 219 <ReferencePath>../../../bin/</ReferencePath>
220 <Reference name="System"/> 220 <Reference name="System"/>
221 <Reference name="System.Core"/>
221 <Reference name="System.Xml"/> 222 <Reference name="System.Xml"/>
222 <Reference name="log4net" path="../../../bin/"/> 223 <Reference name="log4net" path="../../../bin/"/>
223 <Reference name="OpenMetaverse" path="../../../bin/"/> 224 <Reference name="OpenMetaverse" path="../../../bin/"/>