aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-02-03 23:47:01 +0000
committerJustin Clark-Casey (justincc)2012-02-03 23:47:01 +0000
commit312e1457dd576bc61ac2fd2e104813dd86134c4d (patch)
treea67d8bbdf782d5d276a2da4f6ea9d1d191ca0762 /OpenSim
parentExtend m_avatars lock in NpcModule.CreateNPC over both creation of NPC scene ... (diff)
downloadopensim-SC_OLD-312e1457dd576bc61ac2fd2e104813dd86134c4d.zip
opensim-SC_OLD-312e1457dd576bc61ac2fd2e104813dd86134c4d.tar.gz
opensim-SC_OLD-312e1457dd576bc61ac2fd2e104813dd86134c4d.tar.bz2
opensim-SC_OLD-312e1457dd576bc61ac2fd2e104813dd86134c4d.tar.xz
Change SceneObjectSerializer to use common ExternalRepresentationUtils.ExecuteReadProcessors() methods.
Adds ability to submit a customized exception message to match logging.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs37
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs103
2 files changed, 57 insertions, 83 deletions
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
47 /// Populate a node with data read from xml using a dictinoary of processors 47 /// Populate a node with data read from xml using a dictinoary of processors
48 /// </summary> 48 /// </summary>
49 /// <param name="nodeToFill"></param> 49 /// <param name="nodeToFill"></param>
50 /// <param name="processors"> 50 /// <param name="processors">/param>
51 /// A <see cref="Dictionary<System.String, Action<NodeType, XmlTextReader>>"/> 51 /// <param name="xtr"></param>
52 /// </param>
53 /// <param name="xtr">
54 /// A <see cref="XmlTextReader"/>
55 /// </param>
56 public static void ExecuteReadProcessors<NodeType>( 52 public static void ExecuteReadProcessors<NodeType>(
57 NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlTextReader>> processors, XmlTextReader xtr) 53 NodeType nodeToFill, Dictionary<string, Action<NodeType, XmlTextReader>> processors, XmlTextReader xtr)
58 { 54 {
55 ExecuteReadProcessors(
56 nodeToFill,
57 processors,
58 xtr,
59 (o, name, e)
60 => m_log.ErrorFormat(
61 "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}",
62 name, e.Message, e.StackTrace));
63 }
64
65 /// <summary>
66 /// Populate a node with data read from xml using a dictinoary of processors
67 /// </summary>
68 /// <param name="nodeToFill"></param>
69 /// <param name="processors"></param>
70 /// <param name="xtr"></param>
71 /// <param name="parseExceptionAction">
72 /// Action to take if there is a parsing problem. This will usually just be to log the exception
73 /// </param>
74 public static void ExecuteReadProcessors<NodeType>(
75 NodeType nodeToFill,
76 Dictionary<string, Action<NodeType, XmlTextReader>> processors,
77 XmlTextReader xtr,
78 Action<NodeType, string, Exception> parseExceptionAction)
79 {
59 string nodeName = string.Empty; 80 string nodeName = string.Empty;
60 while (xtr.NodeType != XmlNodeType.EndElement) 81 while (xtr.NodeType != XmlNodeType.EndElement)
61 { 82 {
@@ -74,9 +95,7 @@ namespace OpenSim.Framework.Serialization.External
74 } 95 }
75 catch (Exception e) 96 catch (Exception e)
76 { 97 {
77 m_log.ErrorFormat( 98 parseExceptionAction(nodeToFill, nodeName, e);
78 "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}",
79 nodeName, e.Message, e.StackTrace);
80 99
81 if (xtr.NodeType == XmlNodeType.EndElement) 100 if (xtr.NodeType == XmlNodeType.EndElement)
82 xtr.Read(); 101 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;
34using log4net; 34using log4net;
35using OpenMetaverse; 35using OpenMetaverse;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Framework.Serialization.External;
37using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 39using OpenSim.Region.Framework.Scenes;
39 40
@@ -276,14 +277,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
276 277
277 #region manual serialization 278 #region manual serialization
278 279
279 private delegate void SOPXmlProcessor(SceneObjectPart sop, XmlTextReader reader); 280 private static Dictionary<string, Action<SceneObjectPart, XmlTextReader>> m_SOPXmlProcessors
280 private static Dictionary<string, SOPXmlProcessor> m_SOPXmlProcessors = new Dictionary<string, SOPXmlProcessor>(); 281 = new Dictionary<string, Action<SceneObjectPart, XmlTextReader>>();
281 282
282 private delegate void TaskInventoryXmlProcessor(TaskInventoryItem item, XmlTextReader reader); 283 private static Dictionary<string, Action<TaskInventoryItem, XmlTextReader>> m_TaskInventoryXmlProcessors
283 private static Dictionary<string, TaskInventoryXmlProcessor> m_TaskInventoryXmlProcessors = new Dictionary<string, TaskInventoryXmlProcessor>(); 284 = new Dictionary<string, Action<TaskInventoryItem, XmlTextReader>>();
284 285
285 private delegate void ShapeXmlProcessor(PrimitiveBaseShape shape, XmlTextReader reader); 286 private static Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>> m_ShapeXmlProcessors
286 private static Dictionary<string, ShapeXmlProcessor> m_ShapeXmlProcessors = new Dictionary<string, ShapeXmlProcessor>(); 287 = new Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>>();
287 288
288 static SceneObjectSerializer() 289 static SceneObjectSerializer()
289 { 290 {
@@ -1464,34 +1465,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1464 1465
1465 reader.ReadStartElement("SceneObjectPart"); 1466 reader.ReadStartElement("SceneObjectPart");
1466 1467
1467 string nodeName = string.Empty; 1468 ExternalRepresentationUtils.ExecuteReadProcessors(
1468 while (reader.NodeType != XmlNodeType.EndElement) 1469 obj,
1469 { 1470 m_SOPXmlProcessors,
1470 nodeName = reader.Name; 1471 reader,
1471 SOPXmlProcessor p = null; 1472 (o, nodeName, e)
1472 if (m_SOPXmlProcessors.TryGetValue(reader.Name, out p)) 1473 => m_log.ErrorFormat(
1473 { 1474 "[SceneObjectSerializer]: Exception while parsing {0} in object {1} {2}: {3}{4}",
1474 //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); 1475 ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID, nodeName, e.Message, e.StackTrace));
1475 try
1476 {
1477 p(obj, reader);
1478 }
1479 catch (Exception e)
1480 {
1481 m_log.DebugFormat(
1482 "[SceneObjectSerializer]: exception while parsing {0} in object {1} {2}: {3}{4}",
1483 obj.Name, obj.UUID, nodeName, e.Message, e.StackTrace);
1484 if (reader.NodeType == XmlNodeType.EndElement)
1485 reader.Read();
1486 }
1487 }
1488 else
1489 {
1490// m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element {0}", nodeName);
1491 reader.ReadOuterXml(); // ignore
1492 }
1493
1494 }
1495 1476
1496 reader.ReadEndElement(); // SceneObjectPart 1477 reader.ReadEndElement(); // SceneObjectPart
1497 1478
@@ -1516,17 +1497,12 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1516 reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory 1497 reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
1517 1498
1518 TaskInventoryItem item = new TaskInventoryItem(); 1499 TaskInventoryItem item = new TaskInventoryItem();
1519 while (reader.NodeType != XmlNodeType.EndElement) 1500
1520 { 1501 ExternalRepresentationUtils.ExecuteReadProcessors(
1521 TaskInventoryXmlProcessor p = null; 1502 item,
1522 if (m_TaskInventoryXmlProcessors.TryGetValue(reader.Name, out p)) 1503 m_TaskInventoryXmlProcessors,
1523 p(item, reader); 1504 reader);
1524 else 1505
1525 {
1526// m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element in TaskInventory {0}, {1}", reader.Name, reader.Value);
1527 reader.ReadOuterXml();
1528 }
1529 }
1530 reader.ReadEndElement(); // TaskInventoryItem 1506 reader.ReadEndElement(); // TaskInventoryItem
1531 tinv.Add(item.ItemID, item); 1507 tinv.Add(item.ItemID, item);
1532 1508
@@ -1559,35 +1535,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
1559 1535
1560 reader.ReadStartElement(name, String.Empty); // Shape 1536 reader.ReadStartElement(name, String.Empty); // Shape
1561 1537
1562 string nodeName = string.Empty; 1538 ExternalRepresentationUtils.ExecuteReadProcessors(
1563 while (reader.NodeType != XmlNodeType.EndElement) 1539 shape,
1564 { 1540 m_ShapeXmlProcessors,
1565 nodeName = reader.Name; 1541 reader,
1566 //m_log.DebugFormat("[XXX] Processing: {0}", reader.Name); 1542 (o, nodeName, e)
1567 ShapeXmlProcessor p = null; 1543 => m_log.ErrorFormat(
1568 if (m_ShapeXmlProcessors.TryGetValue(reader.Name, out p)) 1544 "[SceneObjectSerializer]: Exception while parsing Shape property {0}: {1}{2}",
1569 { 1545 nodeName, e.Message, e.StackTrace));
1570 try
1571 {
1572 p(shape, reader);
1573 }
1574 catch (Exception e)
1575 {
1576 errors = true;
1577 m_log.DebugFormat(
1578 "[SceneObjectSerializer]: exception while parsing Shape property {0}: {1}{2}",
1579 nodeName, e.Message, e.StackTrace);
1580
1581 if (reader.NodeType == XmlNodeType.EndElement)
1582 reader.Read();
1583 }
1584 }
1585 else
1586 {
1587 // m_log.DebugFormat("[SceneObjectSerializer]: caught unknown element in Shape {0}", reader.Name);
1588 reader.ReadOuterXml();
1589 }
1590 }
1591 1546
1592 reader.ReadEndElement(); // Shape 1547 reader.ReadEndElement(); // Shape
1593 1548