* refactor: Break out original xml object serialization into a separate class

* No functional change
0.6.5-rc1
Justin Clarke Casey 2009-05-08 15:47:59 +00:00
parent 54b5346f16
commit 032e3b49eb
6 changed files with 144 additions and 98 deletions

View File

@ -34,6 +34,7 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Communications.Clients;
using OpenSim.Region.Framework.Scenes.Serialization;
//using HyperGrid.Framework;
//using OpenSim.Region.Communications.Hypergrid;
@ -254,13 +255,12 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid
if ((asset != null) && ((AssetType)asset.Type == AssetType.Object))
{
string ass_str = Utils.BytesToString(asset.Data);
SceneObjectGroup sog = new SceneObjectGroup(ass_str, true);
SceneObjectGroup sog = SceneObjectSerializer.DeserializeOriginalXmlFormat(ass_str);
SniffTextureUUIDs(uuids, sog);
// We need to sniff further...
SniffTaskInventoryUUIDs(uuids, sog);
}
return uuids;

View File

@ -37,6 +37,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache;
using OpenSim.Region.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes.Serialization;
namespace OpenSim.Region.Framework.Scenes
{
@ -2263,7 +2264,8 @@ namespace OpenSim.Region.Framework.Scenes
}
string xmlData = Utils.BytesToString(rezAsset.Data);
SceneObjectGroup group = new SceneObjectGroup(itemId, xmlData, true);
SceneObjectGroup group
= SceneObjectSerializer.DeserializeOriginalXmlFormat(itemId, xmlData);
if (!Permissions.CanRezObject(
group.Children.Count, remoteClient.AgentId, pos)
@ -2419,7 +2421,7 @@ namespace OpenSim.Region.Framework.Scenes
if (rezAsset != null)
{
string xmlData = Utils.BytesToString(rezAsset.Data);
SceneObjectGroup group = new SceneObjectGroup(xmlData, true);
SceneObjectGroup group = SceneObjectSerializer.DeserializeOriginalXmlFormat(xmlData);
if (!Permissions.CanRezObject(group.Children.Count, ownerID, pos))
{

View File

@ -406,96 +406,6 @@ namespace OpenSim.Region.Framework.Scenes
SetRootPart(part);
}
public SceneObjectGroup(string xmlData, bool isOriginalXmlFormat)
: this(UUID.Zero, xmlData, isOriginalXmlFormat)
{
}
/// <summary>
/// Create an object using serialized data in OpenSim's original xml format.
/// </summary>
/// <param name="fromUserInventoryItemID">
/// If applicable, the user inventory item id from which this object was rezzed. If not applicable then this
/// should be UUID.Zero
/// </param>
/// <param name="xmlData"></param>
/// <param name="isOriginalXmlFormat">
/// This parameter only exists to separate the two different xml constructors. In the future, versions should
/// be specified within the xml itself.
/// </param>
public SceneObjectGroup(UUID fromUserInventoryItemID, string xmlData, bool isOriginalXmlFormat)
{
if (!isOriginalXmlFormat)
throw new Exception("This constructor must specify the xml is in OpenSim's original format");
//m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
//int time = System.Environment.TickCount;
// libomv.types changes UUID to Guid
xmlData = xmlData.Replace("<UUID>", "<Guid>");
xmlData = xmlData.Replace("</UUID>", "</Guid>");
// Handle Nested <UUID><UUID> property
xmlData = xmlData.Replace("<Guid><Guid>", "<UUID><Guid>");
xmlData = xmlData.Replace("</Guid></Guid>", "</Guid></UUID>");
try
{
StringReader sr;
XmlTextReader reader;
XmlNodeList parts;
XmlDocument doc;
int linkNum;
doc = new XmlDocument();
doc.LoadXml(xmlData);
parts = doc.GetElementsByTagName("RootPart");
if (parts.Count == 0)
{
throw new Exception("[SCENE] Invalid Xml format - no root part");
}
else
{
sr = new StringReader(parts[0].InnerXml);
reader = new XmlTextReader(sr);
SetRootPart(SceneObjectPart.FromXml(fromUserInventoryItemID, reader));
reader.Close();
sr.Close();
}
parts = doc.GetElementsByTagName("Part");
for (int i=0; i<parts.Count ; i++)
{
sr = new StringReader(parts[i].InnerXml);
reader = new XmlTextReader(sr);
SceneObjectPart part = SceneObjectPart.FromXml(reader);
linkNum = part.LinkNum;
AddPart(part);
part.LinkNum = linkNum;
part.TrimPermissions();
part.StoreUndoState();
reader.Close();
sr.Close();
}
// Script state may, or may not, exist. Not having any, is NOT
// ever a problem.
LoadScriptState(doc);
}
catch (Exception e)
{
m_log.ErrorFormat("[SCENE]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData);
}
//m_log.DebugFormat("[SOG]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
/// <summary>
/// Create an object using serialized data in OpenSim's xml2 format.
/// </summary>
@ -585,7 +495,7 @@ namespace OpenSim.Region.Framework.Scenes
{
}
private void LoadScriptState(XmlDocument doc)
public void LoadScriptState(XmlDocument doc)
{
XmlNodeList nodes = doc.GetElementsByTagName("SavedScriptState");
if (nodes.Count > 0)
@ -745,7 +655,6 @@ namespace OpenSim.Region.Framework.Scenes
#endregion
public string ToXmlString()
{
using (StringWriter sw = new StringWriter())

View File

@ -33,6 +33,7 @@ using System.Xml;
using OpenMetaverse;
using log4net;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes.Serialization;
using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Framework.Scenes
@ -58,7 +59,7 @@ namespace OpenSim.Region.Framework.Scenes
rootNode = doc.FirstChild;
foreach (XmlNode aPrimNode in rootNode.ChildNodes)
{
SceneObjectGroup obj = new SceneObjectGroup(aPrimNode.OuterXml, true);
SceneObjectGroup obj = SceneObjectSerializer.DeserializeOriginalXmlFormat(aPrimNode.OuterXml);
if (newIDS)
{

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.IO;
using System.Reflection;
using System.Xml;
using log4net;
using OpenMetaverse;
using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.Framework.Scenes.Serialization
{
/// <summary>
/// Serialize and deserialize scene objects.
/// </summary>
/// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
/// right now - hopefully this isn't forever.
public class SceneObjectSerializer
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// Deserialize a scene object from the original xml format
/// </summary>
/// <param name="serialization"></param>
/// <returns></returns>
public static SceneObjectGroup DeserializeOriginalXmlFormat(string serialization)
{
return DeserializeOriginalXmlFormat(UUID.Zero, serialization);
}
/// <summary>
/// Deserialize a scene object from the original xml format
/// </summary>
/// <param name="serialization"></param>
/// <returns></returns>
public static SceneObjectGroup DeserializeOriginalXmlFormat(UUID fromUserInventoryItemID, string serialization)
{
//m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
//int time = System.Environment.TickCount;
SceneObjectGroup so = new SceneObjectGroup();
// libomv.types changes UUID to Guid
serialization = serialization.Replace("<UUID>", "<Guid>");
serialization = serialization.Replace("</UUID>", "</Guid>");
// Handle Nested <UUID><UUID> property
serialization = serialization.Replace("<Guid><Guid>", "<UUID><Guid>");
serialization = serialization.Replace("</Guid></Guid>", "</Guid></UUID>");
try
{
StringReader sr;
XmlTextReader reader;
XmlNodeList parts;
XmlDocument doc;
int linkNum;
doc = new XmlDocument();
doc.LoadXml(serialization);
parts = doc.GetElementsByTagName("RootPart");
if (parts.Count == 0)
{
throw new Exception("Invalid Xml format - no root part");
}
else
{
sr = new StringReader(parts[0].InnerXml);
reader = new XmlTextReader(sr);
so.SetRootPart(SceneObjectPart.FromXml(fromUserInventoryItemID, reader));
reader.Close();
sr.Close();
}
parts = doc.GetElementsByTagName("Part");
for (int i = 0; i < parts.Count; i++)
{
sr = new StringReader(parts[i].InnerXml);
reader = new XmlTextReader(sr);
SceneObjectPart part = SceneObjectPart.FromXml(reader);
linkNum = part.LinkNum;
so.AddPart(part);
part.LinkNum = linkNum;
part.TrimPermissions();
part.StoreUndoState();
reader.Close();
sr.Close();
}
// Script state may, or may not, exist. Not having any, is NOT
// ever a problem.
so.LoadScriptState(doc);
}
catch (Exception e)
{
m_log.ErrorFormat(
"[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, serialization);
}
//m_log.DebugFormat("[SERIALIZER]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
return so;
}
}
}

View File

@ -33,6 +33,7 @@ using System.Threading;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes.Serialization;
namespace OpenSim.Region.Framework.Scenes
{
@ -263,7 +264,7 @@ namespace OpenSim.Region.Framework.Scenes
if (null != objectAsset)
{
string xml = Utils.BytesToString(objectAsset.Data);
SceneObjectGroup sog = new SceneObjectGroup(xml, true);
SceneObjectGroup sog = SceneObjectSerializer.DeserializeOriginalXmlFormat(xml);
GatherAssetUuids(sog, assetUuids);
}
}