* refactor: move bottom part of 'xml2' serializaton to separate class

0.6.5-rc1
Justin Clarke Casey 2009-05-14 18:08:54 +00:00
parent d10b5e29bc
commit 303aa4b65e
7 changed files with 70 additions and 73 deletions

View File

@ -66,7 +66,6 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
protected OpenSimBase m_openSim;
public void Initialise()
{
m_log.Info("[LOADREGIONS]: " + Name + " cannot be default-initialized!");

View File

@ -32,9 +32,8 @@ namespace OpenSim.Framework
{
public interface ISceneObject
{
UUID UUID { get; }
UUID UUID { get; }
ISceneObject CloneForNewScene();
void ToXml2(XmlTextWriter writer);
string ExtraToXmlString();
void ExtraFromXmlString(string xmlstr);
string GetStateSnapshot();

View File

@ -220,7 +220,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Interregion
* Object-related communications
*/
public bool SendCreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall)
public bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall)
{
foreach (Scene s in m_sceneList)
{

View File

@ -261,7 +261,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Interregion
* Object-related communications
*/
public bool SendCreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall)
public bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall)
{
// Try local first
if (m_localBackend.SendCreateObject(regionHandle, sog, true))

View File

@ -35,7 +35,6 @@ namespace OpenSim.Region.Framework.Interfaces
public interface IInterregionCommsOut
{
#region Agents
bool SendCreateChildAgent(ulong regionHandle, AgentCircuitData aCircuit, out string reason);
@ -87,7 +86,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="sog"></param>
/// <param name="isLocalCall"></param>
/// <returns></returns>
bool SendCreateObject(ulong regionHandle, ISceneObject sog, bool isLocalCall);
bool SendCreateObject(ulong regionHandle, SceneObjectGroup sog, bool isLocalCall);
/// <summary>
/// Create an object from the user's inventory in the destination region.

View File

@ -583,33 +583,6 @@ namespace OpenSim.Region.Framework.Scenes
#endregion
public void ToXml2(XmlTextWriter writer)
{
//m_log.DebugFormat("[SOG]: Starting serialization of SOG {0} to XML2", Name);
//int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
m_rootPart.ToXml(writer);
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
lock (m_parts)
{
foreach (SceneObjectPart part in m_parts.Values)
{
if (part.UUID != m_rootPart.UUID)
{
part.ToXml(writer);
}
}
}
writer.WriteEndElement(); // End of OtherParts
SaveScriptedState(writer);
writer.WriteEndElement(); // End of SceneObjectGroup
//m_log.DebugFormat("[SOG]: Finished serialization of SOG {0} to XML2, {1}ms", Name, System.Environment.TickCount - time);
}
public void SaveScriptedState(XmlTextWriter writer)
{
XmlDocument doc = new XmlDocument();

View File

@ -129,13 +129,62 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
//m_log.DebugFormat("[SERIALIZER]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
return sceneObject;
}
}
/// <summary>
/// Deserialize a scene object from the 'xml2' format
/// Serialize a scene object to the original xml format
/// </summary>
/// <param name="serialization"></param>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
ToOriginalXmlFormat(sceneObject, writer);
}
return sw.ToString();
}
}
/// <summary>
/// Serialize a scene object to the original xml format
/// </summary>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer)
{
//m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name);
//int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
sceneObject.RootPart.ToXml(writer);
writer.WriteEndElement();
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
lock (sceneObject.Children)
{
foreach (SceneObjectPart part in sceneObject.Children.Values)
{
if (part.UUID != sceneObject.RootPart.UUID)
{
writer.WriteStartElement(String.Empty, "Part", String.Empty);
part.ToXml(writer);
writer.WriteEndElement();
}
}
}
writer.WriteEndElement(); // OtherParts
sceneObject.SaveScriptedState(writer);
writer.WriteEndElement(); // SceneObjectGroup
//m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
public static SceneObjectGroup FromXml2Format(string xmlData)
{
//m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
@ -193,40 +242,38 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
//m_log.DebugFormat("[SERIALIZER]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
return sceneObject;
}
}
/// <summary>
/// Serialize a scene object to the original xml format
/// Serialize a scene object to the 'xml2' format.
/// </summary>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
/// <returns></returns>
public static string ToXml2Format(SceneObjectGroup sceneObject)
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
ToOriginalXmlFormat(sceneObject, writer);
ToXml2Format(sceneObject, writer);
}
return sw.ToString();
}
}
}
/// <summary>
/// Serialize a scene object to the original xml format
/// Serialize a scene object to the 'xml2' format.
/// </summary>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer)
/// <returns></returns>
public static void ToXml2Format(SceneObjectGroup sceneObject, XmlTextWriter writer)
{
//m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", Name);
//m_log.DebugFormat("[SERIALIZER]: Starting serialization of SOG {0} to XML2", Name);
//int time = System.Environment.TickCount;
writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
sceneObject.RootPart.ToXml(writer);
writer.WriteEndElement();
writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
lock (sceneObject.Children)
@ -235,36 +282,16 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
{
if (part.UUID != sceneObject.RootPart.UUID)
{
writer.WriteStartElement(String.Empty, "Part", String.Empty);
part.ToXml(writer);
writer.WriteEndElement();
}
}
}
writer.WriteEndElement(); // OtherParts
writer.WriteEndElement(); // End of OtherParts
sceneObject.SaveScriptedState(writer);
writer.WriteEndElement(); // SceneObjectGroup
writer.WriteEndElement(); // End of SceneObjectGroup
//m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time);
}
/// <summary>
/// Serialize a scene object to the 'xml2' format.
/// </summary>
/// <param name="sceneObject"></param>
/// <returns></returns>
public static string ToXml2Format(ISceneObject sceneObject)
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
sceneObject.ToXml2(writer);
}
return sw.ToString();
}
}
//m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0} to XML2, {1}ms", Name, System.Environment.TickCount - time);
}
}
}