diff options
Diffstat (limited to 'OpenSim/Framework/TaskInventoryDictionary.cs')
-rw-r--r-- | OpenSim/Framework/TaskInventoryDictionary.cs | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/OpenSim/Framework/TaskInventoryDictionary.cs b/OpenSim/Framework/TaskInventoryDictionary.cs new file mode 100644 index 0000000..16ea042 --- /dev/null +++ b/OpenSim/Framework/TaskInventoryDictionary.cs | |||
@@ -0,0 +1,138 @@ | |||
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.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Xml; | ||
32 | using System.Xml.Schema; | ||
33 | using System.Xml.Serialization; | ||
34 | using OpenMetaverse; | ||
35 | using log4net; | ||
36 | |||
37 | namespace OpenSim.Framework | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A dictionary for task inventory. | ||
41 | /// | ||
42 | /// This class is not thread safe. Callers must synchronize on Dictionary methods. | ||
43 | /// </summary> | ||
44 | public class TaskInventoryDictionary : Dictionary<UUID, TaskInventoryItem>, | ||
45 | ICloneable, IXmlSerializable | ||
46 | { | ||
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private static XmlSerializer tiiSerializer = new XmlSerializer(typeof (TaskInventoryItem)); | ||
50 | |||
51 | #region ICloneable Members | ||
52 | |||
53 | public Object Clone() | ||
54 | { | ||
55 | TaskInventoryDictionary clone = new TaskInventoryDictionary(); | ||
56 | |||
57 | lock (this) | ||
58 | { | ||
59 | foreach (UUID uuid in Keys) | ||
60 | { | ||
61 | clone.Add(uuid, (TaskInventoryItem) this[uuid].Clone()); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | return clone; | ||
66 | } | ||
67 | |||
68 | #endregion | ||
69 | |||
70 | // The alternative of simply serializing the list doesn't appear to work on mono, since | ||
71 | // we get a | ||
72 | // | ||
73 | // System.TypeInitializationException: An exception was thrown by the type initializer for OpenSim.Framework.TaskInventoryDictionary ---> System.ArgumentOutOfRangeException: < 0 | ||
74 | // Parameter name: length | ||
75 | // at System.String.Substring (Int32 startIndex, Int32 length) [0x00088] in /build/buildd/mono-1.2.4/mcs/class/corlib/System/String.cs:381 | ||
76 | // at System.Xml.Serialization.TypeTranslator.GetTypeData (System.Type runtimeType, System.String xmlDataType) [0x001f6] in /build/buildd/mono-1.2.4/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs:217 | ||
77 | // ... | ||
78 | // private static XmlSerializer tiiSerializer | ||
79 | // = new XmlSerializer(typeof(Dictionary<UUID, TaskInventoryItem>.ValueCollection)); | ||
80 | |||
81 | // see IXmlSerializable | ||
82 | |||
83 | #region IXmlSerializable Members | ||
84 | |||
85 | public XmlSchema GetSchema() | ||
86 | { | ||
87 | return null; | ||
88 | } | ||
89 | |||
90 | // see IXmlSerializable | ||
91 | public void ReadXml(XmlReader reader) | ||
92 | { | ||
93 | // m_log.DebugFormat("[TASK INVENTORY]: ReadXml current node before actions, {0}", reader.Name); | ||
94 | |||
95 | if (!reader.IsEmptyElement) | ||
96 | { | ||
97 | reader.Read(); | ||
98 | while (tiiSerializer.CanDeserialize(reader)) | ||
99 | { | ||
100 | TaskInventoryItem item = (TaskInventoryItem) tiiSerializer.Deserialize(reader); | ||
101 | Add(item.ItemID, item); | ||
102 | |||
103 | //m_log.DebugFormat("[TASK INVENTORY]: Instanted prim item {0}, {1} from xml", item.Name, item.ItemID); | ||
104 | } | ||
105 | |||
106 | // m_log.DebugFormat("[TASK INVENTORY]: Instantiated {0} prim items in total from xml", Count); | ||
107 | } | ||
108 | // else | ||
109 | // { | ||
110 | // m_log.DebugFormat("[TASK INVENTORY]: Skipping empty element {0}", reader.Name); | ||
111 | // } | ||
112 | |||
113 | // For some .net implementations, this last read is necessary so that we advance beyond the end tag | ||
114 | // of the element wrapping this object so that the rest of the serialization can complete normally. | ||
115 | reader.Read(); | ||
116 | |||
117 | // m_log.DebugFormat("[TASK INVENTORY]: ReadXml current node after actions, {0}", reader.Name); | ||
118 | } | ||
119 | |||
120 | // see IXmlSerializable | ||
121 | public void WriteXml(XmlWriter writer) | ||
122 | { | ||
123 | lock (this) | ||
124 | { | ||
125 | foreach (TaskInventoryItem item in Values) | ||
126 | { | ||
127 | tiiSerializer.Serialize(writer, item); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | //tiiSerializer.Serialize(writer, Values); | ||
132 | } | ||
133 | |||
134 | #endregion | ||
135 | |||
136 | // see ICloneable | ||
137 | } | ||
138 | } | ||