aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-05-08 15:47:59 +0000
committerJustin Clarke Casey2009-05-08 15:47:59 +0000
commit032e3b49eb4f669ffb74a0209aefafcc86f4f6c7 (patch)
treed275e8445ac33074727e2b0adbc5582b7cbc1aba /OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
parent* Extracted common superclass for GetAssetStreamHandler and CachedGetAssetStr... (diff)
downloadopensim-SC-032e3b49eb4f669ffb74a0209aefafcc86f4f6c7.zip
opensim-SC-032e3b49eb4f669ffb74a0209aefafcc86f4f6c7.tar.gz
opensim-SC-032e3b49eb4f669ffb74a0209aefafcc86f4f6c7.tar.bz2
opensim-SC-032e3b49eb4f669ffb74a0209aefafcc86f4f6c7.tar.xz
* refactor: Break out original xml object serialization into a separate class
* No functional change
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs133
1 files changed, 133 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
new file mode 100644
index 0000000..54e7270
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -0,0 +1,133 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Reflection;
31using System.Xml;
32using log4net;
33using OpenMetaverse;
34using OpenSim.Region.Framework.Scenes;
35
36namespace OpenSim.Region.Framework.Scenes.Serialization
37{
38 /// <summary>
39 /// Serialize and deserialize scene objects.
40 /// </summary>
41 /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
42 /// right now - hopefully this isn't forever.
43 public class SceneObjectSerializer
44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46
47 /// <summary>
48 /// Deserialize a scene object from the original xml format
49 /// </summary>
50 /// <param name="serialization"></param>
51 /// <returns></returns>
52 public static SceneObjectGroup DeserializeOriginalXmlFormat(string serialization)
53 {
54 return DeserializeOriginalXmlFormat(UUID.Zero, serialization);
55 }
56
57 /// <summary>
58 /// Deserialize a scene object from the original xml format
59 /// </summary>
60 /// <param name="serialization"></param>
61 /// <returns></returns>
62 public static SceneObjectGroup DeserializeOriginalXmlFormat(UUID fromUserInventoryItemID, string serialization)
63 {
64 //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
65 //int time = System.Environment.TickCount;
66
67 SceneObjectGroup so = new SceneObjectGroup();
68
69 // libomv.types changes UUID to Guid
70 serialization = serialization.Replace("<UUID>", "<Guid>");
71 serialization = serialization.Replace("</UUID>", "</Guid>");
72
73 // Handle Nested <UUID><UUID> property
74 serialization = serialization.Replace("<Guid><Guid>", "<UUID><Guid>");
75 serialization = serialization.Replace("</Guid></Guid>", "</Guid></UUID>");
76
77 try
78 {
79 StringReader sr;
80 XmlTextReader reader;
81 XmlNodeList parts;
82 XmlDocument doc;
83 int linkNum;
84
85 doc = new XmlDocument();
86 doc.LoadXml(serialization);
87 parts = doc.GetElementsByTagName("RootPart");
88
89 if (parts.Count == 0)
90 {
91 throw new Exception("Invalid Xml format - no root part");
92 }
93 else
94 {
95 sr = new StringReader(parts[0].InnerXml);
96 reader = new XmlTextReader(sr);
97 so.SetRootPart(SceneObjectPart.FromXml(fromUserInventoryItemID, reader));
98 reader.Close();
99 sr.Close();
100 }
101
102 parts = doc.GetElementsByTagName("Part");
103
104 for (int i = 0; i < parts.Count; i++)
105 {
106 sr = new StringReader(parts[i].InnerXml);
107 reader = new XmlTextReader(sr);
108 SceneObjectPart part = SceneObjectPart.FromXml(reader);
109 linkNum = part.LinkNum;
110 so.AddPart(part);
111 part.LinkNum = linkNum;
112 part.TrimPermissions();
113 part.StoreUndoState();
114 reader.Close();
115 sr.Close();
116 }
117
118 // Script state may, or may not, exist. Not having any, is NOT
119 // ever a problem.
120 so.LoadScriptState(doc);
121 }
122 catch (Exception e)
123 {
124 m_log.ErrorFormat(
125 "[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, serialization);
126 }
127
128 //m_log.DebugFormat("[SERIALIZER]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
129
130 return so;
131 }
132 }
133}