From 623426421132fdc41d9de006fb55aedc660d5362 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 3 Feb 2012 22:45:50 +0000
Subject: Refactor common deserialization processor code to generic method
ExternalRepresentationUtils.ExecuteReadProcessors()
---
.../External/ExternalRepresentationUtils.cs | 53 +++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Serialization/External/ExternalRepresentationUtils.cs')
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 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
using System;
using System.Collections.Generic;
using System.IO;
+using System.Reflection;
using System.Xml;
-
+using log4net;
using OpenMetaverse;
using OpenSim.Services.Interfaces;
@@ -39,6 +41,55 @@ namespace OpenSim.Framework.Serialization.External
///
public class ExternalRepresentationUtils
{
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+
+ ///
+ /// Populate a node with data read from xml using a dictinoary of processors
+ ///
+ ///
+ ///
+ /// A
+ ///
+ ///
+ /// A
+ ///
+ public static void ExecuteReadProcessors(
+ NodeType nodeToFill, Dictionary> processors, XmlTextReader xtr)
+ {
+ string nodeName = string.Empty;
+ while (xtr.NodeType != XmlNodeType.EndElement)
+ {
+ nodeName = xtr.Name;
+
+// m_log.DebugFormat("[ExternalRepresentationUtils]: Processing: {0}", nodeName);
+
+ Action p = null;
+ if (processors.TryGetValue(xtr.Name, out p))
+ {
+// m_log.DebugFormat("[ExternalRepresentationUtils]: Found {0} processor, nodeName);
+
+ try
+ {
+ p(nodeToFill, xtr);
+ }
+ catch (Exception e)
+ {
+ m_log.ErrorFormat(
+ "[ExternalRepresentationUtils]: Exception while parsing element {0}, continuing. Exception {1}{2}",
+ nodeName, e.Message, e.StackTrace);
+
+ if (xtr.NodeType == XmlNodeType.EndElement)
+ xtr.Read();
+ }
+ }
+ else
+ {
+ // m_log.DebugFormat("[LandDataSerializer]: caught unknown element {0}", nodeName);
+ xtr.ReadOuterXml(); // ignore
+ }
+ }
+ }
+
///
/// Takes a XML representation of a SceneObjectPart and returns another XML representation
/// with creator data added to it.
--
cgit v1.1