diff options
author | Justin Clarke Casey | 2009-05-08 15:47:59 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2009-05-08 15:47:59 +0000 |
commit | 032e3b49eb4f669ffb74a0209aefafcc86f4f6c7 (patch) | |
tree | d275e8445ac33074727e2b0adbc5582b7cbc1aba | |
parent | * Extracted common superclass for GetAssetStreamHandler and CachedGetAssetStr... (diff) | |
download | opensim-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
6 files changed, 144 insertions, 98 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs index 1186bee..3399504 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs | |||
@@ -34,6 +34,7 @@ using OpenMetaverse; | |||
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Communications.Cache; | 35 | using OpenSim.Framework.Communications.Cache; |
36 | using OpenSim.Framework.Communications.Clients; | 36 | using OpenSim.Framework.Communications.Clients; |
37 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
37 | 38 | ||
38 | //using HyperGrid.Framework; | 39 | //using HyperGrid.Framework; |
39 | //using OpenSim.Region.Communications.Hypergrid; | 40 | //using OpenSim.Region.Communications.Hypergrid; |
@@ -254,13 +255,12 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid | |||
254 | if ((asset != null) && ((AssetType)asset.Type == AssetType.Object)) | 255 | if ((asset != null) && ((AssetType)asset.Type == AssetType.Object)) |
255 | { | 256 | { |
256 | string ass_str = Utils.BytesToString(asset.Data); | 257 | string ass_str = Utils.BytesToString(asset.Data); |
257 | SceneObjectGroup sog = new SceneObjectGroup(ass_str, true); | 258 | SceneObjectGroup sog = SceneObjectSerializer.DeserializeOriginalXmlFormat(ass_str); |
258 | 259 | ||
259 | SniffTextureUUIDs(uuids, sog); | 260 | SniffTextureUUIDs(uuids, sog); |
260 | 261 | ||
261 | // We need to sniff further... | 262 | // We need to sniff further... |
262 | SniffTaskInventoryUUIDs(uuids, sog); | 263 | SniffTaskInventoryUUIDs(uuids, sog); |
263 | |||
264 | } | 264 | } |
265 | 265 | ||
266 | return uuids; | 266 | return uuids; |
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index bebf234..f3d5a7c 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | |||
@@ -37,6 +37,7 @@ using OpenSim.Framework; | |||
37 | using OpenSim.Framework.Communications.Cache; | 37 | using OpenSim.Framework.Communications.Cache; |
38 | using OpenSim.Region.Framework; | 38 | using OpenSim.Region.Framework; |
39 | using OpenSim.Region.Framework.Interfaces; | 39 | using OpenSim.Region.Framework.Interfaces; |
40 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
40 | 41 | ||
41 | namespace OpenSim.Region.Framework.Scenes | 42 | namespace OpenSim.Region.Framework.Scenes |
42 | { | 43 | { |
@@ -2263,7 +2264,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2263 | } | 2264 | } |
2264 | 2265 | ||
2265 | string xmlData = Utils.BytesToString(rezAsset.Data); | 2266 | string xmlData = Utils.BytesToString(rezAsset.Data); |
2266 | SceneObjectGroup group = new SceneObjectGroup(itemId, xmlData, true); | 2267 | SceneObjectGroup group |
2268 | = SceneObjectSerializer.DeserializeOriginalXmlFormat(itemId, xmlData); | ||
2267 | 2269 | ||
2268 | if (!Permissions.CanRezObject( | 2270 | if (!Permissions.CanRezObject( |
2269 | group.Children.Count, remoteClient.AgentId, pos) | 2271 | group.Children.Count, remoteClient.AgentId, pos) |
@@ -2419,7 +2421,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2419 | if (rezAsset != null) | 2421 | if (rezAsset != null) |
2420 | { | 2422 | { |
2421 | string xmlData = Utils.BytesToString(rezAsset.Data); | 2423 | string xmlData = Utils.BytesToString(rezAsset.Data); |
2422 | SceneObjectGroup group = new SceneObjectGroup(xmlData, true); | 2424 | SceneObjectGroup group = SceneObjectSerializer.DeserializeOriginalXmlFormat(xmlData); |
2423 | 2425 | ||
2424 | if (!Permissions.CanRezObject(group.Children.Count, ownerID, pos)) | 2426 | if (!Permissions.CanRezObject(group.Children.Count, ownerID, pos)) |
2425 | { | 2427 | { |
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 99e6e1e..b0de405 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | |||
@@ -406,96 +406,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
406 | SetRootPart(part); | 406 | SetRootPart(part); |
407 | } | 407 | } |
408 | 408 | ||
409 | public SceneObjectGroup(string xmlData, bool isOriginalXmlFormat) | ||
410 | : this(UUID.Zero, xmlData, isOriginalXmlFormat) | ||
411 | { | ||
412 | } | ||
413 | |||
414 | /// <summary> | ||
415 | /// Create an object using serialized data in OpenSim's original xml format. | ||
416 | /// </summary> | ||
417 | /// <param name="fromUserInventoryItemID"> | ||
418 | /// If applicable, the user inventory item id from which this object was rezzed. If not applicable then this | ||
419 | /// should be UUID.Zero | ||
420 | /// </param> | ||
421 | /// <param name="xmlData"></param> | ||
422 | /// <param name="isOriginalXmlFormat"> | ||
423 | /// This parameter only exists to separate the two different xml constructors. In the future, versions should | ||
424 | /// be specified within the xml itself. | ||
425 | /// </param> | ||
426 | public SceneObjectGroup(UUID fromUserInventoryItemID, string xmlData, bool isOriginalXmlFormat) | ||
427 | { | ||
428 | |||
429 | if (!isOriginalXmlFormat) | ||
430 | throw new Exception("This constructor must specify the xml is in OpenSim's original format"); | ||
431 | |||
432 | //m_log.DebugFormat("[SOG]: Starting deserialization of SOG"); | ||
433 | //int time = System.Environment.TickCount; | ||
434 | |||
435 | // libomv.types changes UUID to Guid | ||
436 | xmlData = xmlData.Replace("<UUID>", "<Guid>"); | ||
437 | xmlData = xmlData.Replace("</UUID>", "</Guid>"); | ||
438 | |||
439 | // Handle Nested <UUID><UUID> property | ||
440 | xmlData = xmlData.Replace("<Guid><Guid>", "<UUID><Guid>"); | ||
441 | xmlData = xmlData.Replace("</Guid></Guid>", "</Guid></UUID>"); | ||
442 | |||
443 | try | ||
444 | { | ||
445 | |||
446 | StringReader sr; | ||
447 | XmlTextReader reader; | ||
448 | XmlNodeList parts; | ||
449 | XmlDocument doc; | ||
450 | int linkNum; | ||
451 | |||
452 | doc = new XmlDocument(); | ||
453 | doc.LoadXml(xmlData); | ||
454 | parts = doc.GetElementsByTagName("RootPart"); | ||
455 | |||
456 | if (parts.Count == 0) | ||
457 | { | ||
458 | throw new Exception("[SCENE] Invalid Xml format - no root part"); | ||
459 | } | ||
460 | else | ||
461 | { | ||
462 | sr = new StringReader(parts[0].InnerXml); | ||
463 | reader = new XmlTextReader(sr); | ||
464 | SetRootPart(SceneObjectPart.FromXml(fromUserInventoryItemID, reader)); | ||
465 | reader.Close(); | ||
466 | sr.Close(); | ||
467 | } | ||
468 | |||
469 | parts = doc.GetElementsByTagName("Part"); | ||
470 | |||
471 | for (int i=0; i<parts.Count ; i++) | ||
472 | { | ||
473 | sr = new StringReader(parts[i].InnerXml); | ||
474 | reader = new XmlTextReader(sr); | ||
475 | SceneObjectPart part = SceneObjectPart.FromXml(reader); | ||
476 | linkNum = part.LinkNum; | ||
477 | AddPart(part); | ||
478 | part.LinkNum = linkNum; | ||
479 | part.TrimPermissions(); | ||
480 | part.StoreUndoState(); | ||
481 | reader.Close(); | ||
482 | sr.Close(); | ||
483 | } | ||
484 | |||
485 | // Script state may, or may not, exist. Not having any, is NOT | ||
486 | // ever a problem. | ||
487 | |||
488 | LoadScriptState(doc); | ||
489 | |||
490 | } | ||
491 | catch (Exception e) | ||
492 | { | ||
493 | m_log.ErrorFormat("[SCENE]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData); | ||
494 | } | ||
495 | |||
496 | //m_log.DebugFormat("[SOG]: Finished deserialization of SOG {0}, {1}ms", Name, System.Environment.TickCount - time); | ||
497 | } | ||
498 | |||
499 | /// <summary> | 409 | /// <summary> |
500 | /// Create an object using serialized data in OpenSim's xml2 format. | 410 | /// Create an object using serialized data in OpenSim's xml2 format. |
501 | /// </summary> | 411 | /// </summary> |
@@ -585,7 +495,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
585 | { | 495 | { |
586 | } | 496 | } |
587 | 497 | ||
588 | private void LoadScriptState(XmlDocument doc) | 498 | public void LoadScriptState(XmlDocument doc) |
589 | { | 499 | { |
590 | XmlNodeList nodes = doc.GetElementsByTagName("SavedScriptState"); | 500 | XmlNodeList nodes = doc.GetElementsByTagName("SavedScriptState"); |
591 | if (nodes.Count > 0) | 501 | if (nodes.Count > 0) |
@@ -745,7 +655,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
745 | 655 | ||
746 | #endregion | 656 | #endregion |
747 | 657 | ||
748 | |||
749 | public string ToXmlString() | 658 | public string ToXmlString() |
750 | { | 659 | { |
751 | using (StringWriter sw = new StringWriter()) | 660 | using (StringWriter sw = new StringWriter()) |
diff --git a/OpenSim/Region/Framework/Scenes/SceneXmlLoader.cs b/OpenSim/Region/Framework/Scenes/SceneXmlLoader.cs index 7d9d247..1a4efe7 100644 --- a/OpenSim/Region/Framework/Scenes/SceneXmlLoader.cs +++ b/OpenSim/Region/Framework/Scenes/SceneXmlLoader.cs | |||
@@ -33,6 +33,7 @@ using System.Xml; | |||
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using log4net; | 34 | using log4net; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
36 | using OpenSim.Region.Physics.Manager; | 37 | using OpenSim.Region.Physics.Manager; |
37 | 38 | ||
38 | namespace OpenSim.Region.Framework.Scenes | 39 | namespace OpenSim.Region.Framework.Scenes |
@@ -58,7 +59,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
58 | rootNode = doc.FirstChild; | 59 | rootNode = doc.FirstChild; |
59 | foreach (XmlNode aPrimNode in rootNode.ChildNodes) | 60 | foreach (XmlNode aPrimNode in rootNode.ChildNodes) |
60 | { | 61 | { |
61 | SceneObjectGroup obj = new SceneObjectGroup(aPrimNode.OuterXml, true); | 62 | SceneObjectGroup obj = SceneObjectSerializer.DeserializeOriginalXmlFormat(aPrimNode.OuterXml); |
62 | 63 | ||
63 | if (newIDS) | 64 | if (newIDS) |
64 | { | 65 | { |
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Xml; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | |||
36 | namespace 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 | } | ||
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 07a1cc7..a839829 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs | |||
@@ -33,6 +33,7 @@ using System.Threading; | |||
33 | using log4net; | 33 | using log4net; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
36 | 37 | ||
37 | namespace OpenSim.Region.Framework.Scenes | 38 | namespace OpenSim.Region.Framework.Scenes |
38 | { | 39 | { |
@@ -263,7 +264,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
263 | if (null != objectAsset) | 264 | if (null != objectAsset) |
264 | { | 265 | { |
265 | string xml = Utils.BytesToString(objectAsset.Data); | 266 | string xml = Utils.BytesToString(objectAsset.Data); |
266 | SceneObjectGroup sog = new SceneObjectGroup(xml, true); | 267 | SceneObjectGroup sog = SceneObjectSerializer.DeserializeOriginalXmlFormat(xml); |
267 | GatherAssetUuids(sog, assetUuids); | 268 | GatherAssetUuids(sog, assetUuids); |
268 | } | 269 | } |
269 | } | 270 | } |