aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/DAMap.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/DAMap.cs')
-rw-r--r--OpenSim/Framework/DAMap.cs173
1 files changed, 173 insertions, 0 deletions
diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs
new file mode 100644
index 0000000..a6fdf61
--- /dev/null
+++ b/OpenSim/Framework/DAMap.cs
@@ -0,0 +1,173 @@
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 OpenSimulator 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.Collections;
30using System.Collections.Generic;
31using System.IO;
32using System.Text;
33using System.Xml;
34using System.Xml.Schema;
35using System.Xml.Serialization;
36using OpenMetaverse;
37using OpenMetaverse.StructuredData;
38
39namespace OpenSim.Framework
40{
41 /// <summary>
42 /// This is the map for storing and retrieving dynamic attributes.
43 /// </summary>
44 public class DAMap : IDictionary<string, OSD>, IXmlSerializable
45 {
46 protected OSDMap m_map;
47
48 public DAMap() { m_map = new OSDMap(); }
49
50 public XmlSchema GetSchema() { return null; }
51
52 public static DAMap FromXml(string rawXml)
53 {
54 DAMap map = new DAMap();
55 map.ReadXml(rawXml);
56 return map;
57 }
58
59 public void ReadXml(string rawXml)
60 {
61 //System.Console.WriteLine("Trying to deserialize [{0}]", rawXml);
62
63 m_map = (OSDMap)OSDParser.DeserializeLLSDXml(rawXml);
64 }
65
66 public void ReadXml(XmlReader reader)
67 {
68 ReadXml(reader.ReadInnerXml());
69 }
70
71 public string ToXml()
72 {
73 lock (m_map)
74 return OSDParser.SerializeLLSDXmlString(m_map);
75 }
76
77 public void WriteXml(XmlWriter writer)
78 {
79 writer.WriteRaw(ToXml());
80 }
81
82 public int Count { get { lock (m_map) { return m_map.Count; } } }
83 public bool IsReadOnly { get { return false; } }
84 public ICollection<string> Keys { get { lock (m_map) { return m_map.Keys; } } }
85 public ICollection<OSD> Values { get { lock (m_map) { return m_map.Values; } } }
86 public OSD this[string key]
87 {
88 get
89 {
90 OSD llsd;
91
92 lock (m_map)
93 {
94 if (m_map.TryGetValue(key, out llsd))
95 return llsd;
96 else
97 return null;
98 }
99 }
100 set { lock (m_map) { m_map[key] = value; } }
101 }
102
103 public bool ContainsKey(string key)
104 {
105 lock (m_map)
106 return m_map.ContainsKey(key);
107 }
108
109 public void Add(string key, OSD llsd)
110 {
111 lock (m_map)
112 m_map.Add(key, llsd);
113 }
114
115 public void Add(KeyValuePair<string, OSD> kvp)
116 {
117 lock (m_map)
118 m_map.Add(kvp.Key, kvp.Value);
119 }
120
121 public bool Remove(string key)
122 {
123 lock (m_map)
124 return m_map.Remove(key);
125 }
126
127 public bool TryGetValue(string key, out OSD llsd)
128 {
129 lock (m_map)
130 return m_map.TryGetValue(key, out llsd);
131 }
132
133 public void Clear()
134 {
135 lock (m_map)
136 m_map.Clear();
137 }
138
139 public bool Contains(KeyValuePair<string, OSD> kvp)
140 {
141 lock (m_map)
142 return m_map.ContainsKey(kvp.Key);
143 }
144
145 public void CopyTo(KeyValuePair<string, OSD>[] array, int index)
146 {
147 throw new NotImplementedException();
148 }
149
150 public bool Remove(KeyValuePair<string, OSD> kvp)
151 {
152 lock (m_map)
153 return m_map.Remove(kvp.Key);
154 }
155
156 public System.Collections.IDictionaryEnumerator GetEnumerator()
157 {
158 lock (m_map)
159 return m_map.GetEnumerator();
160 }
161
162 IEnumerator<KeyValuePair<string, OSD>> IEnumerable<KeyValuePair<string, OSD>>.GetEnumerator()
163 {
164 return null;
165 }
166
167 IEnumerator IEnumerable.GetEnumerator()
168 {
169 lock (m_map)
170 return m_map.GetEnumerator();
171 }
172 }
173} \ No newline at end of file