Change SceneObjectSerializer to use common ExternalRepresentationUtils.ExecuteReadProcessors() methods.

Adds ability to submit a customized exception message to match logging.
iar_mods
Justin Clark-Casey (justincc) 2012-02-03 23:47:01 +00:00
parent ce34b359ad
commit 312e1457dd
3 changed files with 58 additions and 83 deletions

View File

@ -47,14 +47,35 @@ namespace OpenSim.Framework.Serialization.External
/// Populate a node with data read from xml using a dictinoary of processors
/// </summary>
/// <param name="nodeToFill"></param>
/// <param name="processors">
/// A <see cref="Dictionary<System.String, Action<NodeType, XmlTextReader>>"/>
/// </param>
/// <param name="xtr">
/// A <see cref="XmlTextReader"/>
/// </param>
/// <param name="processors">/param>
/// <param name="xtr"></param>
public static void ExecuteReadProcessors<NodeType>(
NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlTextReader>> 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));
}
/// <summary>
/// Populate a node with data read from xml using a dictinoary of processors
/// </summary>
/// <param name="nodeToFill"></param>
/// <param name="processors"></param>
/// <param name="xtr"></param>
/// <param name="parseExceptionAction">
/// Action to take if there is a parsing problem. This will usually just be to log the exception
/// </param>
public static void ExecuteReadProcessors<NodeType>(
NodeType nodeToFill,
Dictionary<string, Action<NodeType, XmlTextReader>> processors,
XmlTextReader xtr,
Action<NodeType, string, Exception> 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();

View File

@ -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<string, SOPXmlProcessor> m_SOPXmlProcessors = new Dictionary<string, SOPXmlProcessor>();
private static Dictionary<string, Action<SceneObjectPart, XmlTextReader>> m_SOPXmlProcessors
= new Dictionary<string, Action<SceneObjectPart, XmlTextReader>>();
private delegate void TaskInventoryXmlProcessor(TaskInventoryItem item, XmlTextReader reader);
private static Dictionary<string, TaskInventoryXmlProcessor> m_TaskInventoryXmlProcessors = new Dictionary<string, TaskInventoryXmlProcessor>();
private static Dictionary<string, Action<TaskInventoryItem, XmlTextReader>> m_TaskInventoryXmlProcessors
= new Dictionary<string, Action<TaskInventoryItem, XmlTextReader>>();
private delegate void ShapeXmlProcessor(PrimitiveBaseShape shape, XmlTextReader reader);
private static Dictionary<string, ShapeXmlProcessor> m_ShapeXmlProcessors = new Dictionary<string, ShapeXmlProcessor>();
private static Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>> m_ShapeXmlProcessors
= new Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>>();
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

View File

@ -768,6 +768,7 @@
<Reference name="OpenSim.Framework.Communications"/>
<Reference name="OpenSim.Data"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Framework.Serialization"/>
<Reference name="OpenSim.Framework.Servers"/>
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
<Reference name="OpenSim.Framework.Statistics"/>