From 312e1457dd576bc61ac2fd2e104813dd86134c4d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 3 Feb 2012 23:47:01 +0000 Subject: Change SceneObjectSerializer to use common ExternalRepresentationUtils.ExecuteReadProcessors() methods. Adds ability to submit a customized exception message to match logging. --- .../External/ExternalRepresentationUtils.cs | 37 ++++++-- .../Scenes/Serialization/SceneObjectSerializer.cs | 103 ++++++--------------- 2 files changed, 57 insertions(+), 83 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs index 39a9f37..a392af6 100644 --- a/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs +++ b/OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs @@ -47,15 +47,36 @@ namespace OpenSim.Framework.Serialization.External /// Populate a node with data read from xml using a dictinoary of processors /// /// - /// - /// A - /// - /// - /// A - /// + /// /param> + /// public static void ExecuteReadProcessors( NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr) { + ExecuteReadProcessors( + nodeToFill, + processors, + xtr, + (o, name, e) + => m_log.ErrorFormat( + "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", + name, e.Message, e.StackTrace)); + } + + /// + /// Populate a node with data read from xml using a dictinoary of processors + /// + /// + /// + /// + /// + /// Action to take if there is a parsing problem. This will usually just be to log the exception + /// + public static void ExecuteReadProcessors( + NodeType nodeToFill, + Dictionary> processors, + XmlTextReader xtr, + Action parseExceptionAction) + { string nodeName = string.Empty; while (xtr.NodeType != XmlNodeType.EndElement) { @@ -74,9 +95,7 @@ namespace OpenSim.Framework.Serialization.External } catch (Exception e) { - m_log.ErrorFormat( - "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}", - nodeName, e.Message, e.StackTrace); + parseExceptionAction(nodeToFill, nodeName, e); if (xtr.NodeType == XmlNodeType.EndElement) xtr.Read(); diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index b54fcb7..ab02f92 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -34,6 +34,7 @@ using System.Xml; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -276,14 +277,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization #region manual serialization - private delegate void SOPXmlProcessor(SceneObjectPart sop, XmlTextReader reader); - private static Dictionary m_SOPXmlProcessors = new Dictionary(); + private static Dictionary> m_SOPXmlProcessors + = new Dictionary>(); - private delegate void TaskInventoryXmlProcessor(TaskInventoryItem item, XmlTextReader reader); - private static Dictionary m_TaskInventoryXmlProcessors = new Dictionary(); + private static Dictionary> m_TaskInventoryXmlProcessors + = new Dictionary>(); - private delegate void ShapeXmlProcessor(PrimitiveBaseShape shape, XmlTextReader reader); - private static Dictionary m_ShapeXmlProcessors = new Dictionary(); + private static Dictionary> m_ShapeXmlProcessors + = new Dictionary>(); static SceneObjectSerializer() { @@ -1464,34 +1465,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization reader.ReadStartElement("SceneObjectPart"); - string nodeName = string.Empty; - while (reader.NodeType != XmlNodeType.EndElement) - { - nodeName = reader.Name; - SOPXmlProcessor p = null; - if (m_SOPXmlProcessors.TryGetValue(reader.Name, out p)) - { - //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); - try - { - p(obj, reader); - } - catch (Exception e) - { - m_log.DebugFormat( - "[SceneObjectSerializer]: exception while parsing {0} in object {1} {2}: {3}{4}", - obj.Name, obj.UUID, nodeName, e.Message, e.StackTrace); - if (reader.NodeType == XmlNodeType.EndElement) - reader.Read(); - } - } - else - { -// m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element {0}", nodeName); - reader.ReadOuterXml(); // ignore - } - - } + ExternalRepresentationUtils.ExecuteReadProcessors( + obj, + m_SOPXmlProcessors, + reader, + (o, nodeName, e) + => m_log.ErrorFormat( + "[SceneObjectSerializer]: Exception while parsing {0} in object {1} {2}: {3}{4}", + ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID, nodeName, e.Message, e.StackTrace)); reader.ReadEndElement(); // SceneObjectPart @@ -1516,17 +1497,12 @@ namespace OpenSim.Region.Framework.Scenes.Serialization reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory TaskInventoryItem item = new TaskInventoryItem(); - while (reader.NodeType != XmlNodeType.EndElement) - { - TaskInventoryXmlProcessor p = null; - if (m_TaskInventoryXmlProcessors.TryGetValue(reader.Name, out p)) - p(item, reader); - else - { -// m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element in TaskInventory {0}, {1}", reader.Name, reader.Value); - reader.ReadOuterXml(); - } - } + + ExternalRepresentationUtils.ExecuteReadProcessors( + item, + m_TaskInventoryXmlProcessors, + reader); + reader.ReadEndElement(); // TaskInventoryItem tinv.Add(item.ItemID, item); @@ -1559,35 +1535,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization reader.ReadStartElement(name, String.Empty); // Shape - string nodeName = string.Empty; - while (reader.NodeType != XmlNodeType.EndElement) - { - nodeName = reader.Name; - //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); - ShapeXmlProcessor p = null; - if (m_ShapeXmlProcessors.TryGetValue(reader.Name, out p)) - { - try - { - p(shape, reader); - } - catch (Exception e) - { - errors = true; - m_log.DebugFormat( - "[SceneObjectSerializer]: exception while parsing Shape property {0}: {1}{2}", - nodeName, e.Message, e.StackTrace); - - if (reader.NodeType == XmlNodeType.EndElement) - reader.Read(); - } - } - else - { - // m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element in Shape {0}", reader.Name); - reader.ReadOuterXml(); - } - } + ExternalRepresentationUtils.ExecuteReadProcessors( + shape, + m_ShapeXmlProcessors, + reader, + (o, nodeName, e) + => m_log.ErrorFormat( + "[SceneObjectSerializer]: Exception while parsing Shape property {0}: {1}{2}", + nodeName, e.Message, e.StackTrace)); reader.ReadEndElement(); // Shape -- cgit v1.1