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 /// Populate a node with data read from xml using a dictinoary of processors
/// </summary> /// </summary>
/// <param name="nodeToFill"></param> /// <param name="nodeToFill"></param>
/// <param name="processors"> /// <param name="processors">/param>
/// A <see cref="Dictionary<System.String, Action<NodeType, XmlTextReader>>"/> /// <param name="xtr"></param>
/// </param>
/// <param name="xtr">
/// A <see cref="XmlTextReader"/>
/// </param>
public static void ExecuteReadProcessors<NodeType>( public static void ExecuteReadProcessors<NodeType>(
NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlTextReader>> processors, XmlTextReader xtr) 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; string nodeName = string.Empty;
while (xtr.NodeType != XmlNodeType.EndElement) while (xtr.NodeType != XmlNodeType.EndElement)
@ -74,9 +95,7 @@ namespace OpenSim.Framework.Serialization.External
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat( parseExceptionAction(nodeToFill, nodeName, e);
"[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}",
nodeName, e.Message, e.StackTrace);
if (xtr.NodeType == XmlNodeType.EndElement) if (xtr.NodeType == XmlNodeType.EndElement)
xtr.Read(); xtr.Read();

View File

@ -34,6 +34,7 @@ using System.Xml;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Serialization.External;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
@ -276,14 +277,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
#region manual serialization #region manual serialization
private delegate void SOPXmlProcessor(SceneObjectPart sop, XmlTextReader reader); private static Dictionary<string, Action<SceneObjectPart, XmlTextReader>> m_SOPXmlProcessors
private static Dictionary<string, SOPXmlProcessor> m_SOPXmlProcessors = new Dictionary<string, SOPXmlProcessor>(); = new Dictionary<string, Action<SceneObjectPart, XmlTextReader>>();
private delegate void TaskInventoryXmlProcessor(TaskInventoryItem item, XmlTextReader reader); private static Dictionary<string, Action<TaskInventoryItem, XmlTextReader>> m_TaskInventoryXmlProcessors
private static Dictionary<string, TaskInventoryXmlProcessor> m_TaskInventoryXmlProcessors = new Dictionary<string, TaskInventoryXmlProcessor>(); = new Dictionary<string, Action<TaskInventoryItem, XmlTextReader>>();
private delegate void ShapeXmlProcessor(PrimitiveBaseShape shape, XmlTextReader reader); private static Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>> m_ShapeXmlProcessors
private static Dictionary<string, ShapeXmlProcessor> m_ShapeXmlProcessors = new Dictionary<string, ShapeXmlProcessor>(); = new Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>>();
static SceneObjectSerializer() static SceneObjectSerializer()
{ {
@ -1464,34 +1465,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
reader.ReadStartElement("SceneObjectPart"); reader.ReadStartElement("SceneObjectPart");
string nodeName = string.Empty; ExternalRepresentationUtils.ExecuteReadProcessors(
while (reader.NodeType != XmlNodeType.EndElement) obj,
{ m_SOPXmlProcessors,
nodeName = reader.Name; reader,
SOPXmlProcessor p = null; (o, nodeName, e)
if (m_SOPXmlProcessors.TryGetValue(reader.Name, out p)) => m_log.ErrorFormat(
{ "[SceneObjectSerializer]: Exception while parsing {0} in object {1} {2}: {3}{4}",
//m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID, nodeName, e.Message, e.StackTrace));
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
}
}
reader.ReadEndElement(); // SceneObjectPart reader.ReadEndElement(); // SceneObjectPart
@ -1516,17 +1497,12 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
TaskInventoryItem item = new TaskInventoryItem(); TaskInventoryItem item = new TaskInventoryItem();
while (reader.NodeType != XmlNodeType.EndElement)
{ ExternalRepresentationUtils.ExecuteReadProcessors(
TaskInventoryXmlProcessor p = null; item,
if (m_TaskInventoryXmlProcessors.TryGetValue(reader.Name, out p)) m_TaskInventoryXmlProcessors,
p(item, reader); reader);
else
{
// m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element in TaskInventory {0}, {1}", reader.Name, reader.Value);
reader.ReadOuterXml();
}
}
reader.ReadEndElement(); // TaskInventoryItem reader.ReadEndElement(); // TaskInventoryItem
tinv.Add(item.ItemID, item); tinv.Add(item.ItemID, item);
@ -1559,35 +1535,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
reader.ReadStartElement(name, String.Empty); // Shape reader.ReadStartElement(name, String.Empty); // Shape
string nodeName = string.Empty; ExternalRepresentationUtils.ExecuteReadProcessors(
while (reader.NodeType != XmlNodeType.EndElement) shape,
{ m_ShapeXmlProcessors,
nodeName = reader.Name; reader,
//m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); (o, nodeName, e)
ShapeXmlProcessor p = null; => m_log.ErrorFormat(
if (m_ShapeXmlProcessors.TryGetValue(reader.Name, out p)) "[SceneObjectSerializer]: Exception while parsing Shape property {0}: {1}{2}",
{ nodeName, e.Message, e.StackTrace));
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();
}
}
reader.ReadEndElement(); // Shape reader.ReadEndElement(); // Shape

View File

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