aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Capabilities/LLSDHelpers.cs
diff options
context:
space:
mode:
authordiva2009-06-18 00:48:39 +0000
committerdiva2009-06-18 00:48:39 +0000
commit913bc3bdb380cebebd11b657966486448962ab47 (patch)
treef41837093cd692b9fe42a21c9cb1473ef81dd0f1 /OpenSim/Framework/Capabilities/LLSDHelpers.cs
parentFix an uninitialized data block. Thanks, jhurliman (diff)
downloadopensim-SC_OLD-913bc3bdb380cebebd11b657966486448962ab47.zip
opensim-SC_OLD-913bc3bdb380cebebd11b657966486448962ab47.tar.gz
opensim-SC_OLD-913bc3bdb380cebebd11b657966486448962ab47.tar.bz2
opensim-SC_OLD-913bc3bdb380cebebd11b657966486448962ab47.tar.xz
Moved OpenSim/Framework/Communications/Capabilities up to OpenSim/Framework/Capabilities. Didn't change the namespace because VC# is not helping, and this would imply manually changing more than 50 files. So the namespace is still OpenSim.Framework.Communications.Capabilities, to be cleaned up later by someone with more energy.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Capabilities/LLSDHelpers.cs (renamed from OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs)344
1 files changed, 172 insertions, 172 deletions
diff --git a/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs b/OpenSim/Framework/Capabilities/LLSDHelpers.cs
index 3316b3f..596dfc3 100644
--- a/OpenSim/Framework/Communications/Capabilities/LLSDHelpers.cs
+++ b/OpenSim/Framework/Capabilities/LLSDHelpers.cs
@@ -1,172 +1,172 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.IO; 30using System.IO;
31using System.Reflection; 31using System.Reflection;
32using System.Xml; 32using System.Xml;
33 33
34namespace OpenSim.Framework.Communications.Capabilities 34namespace OpenSim.Framework.Communications.Capabilities
35{ 35{
36 public class LLSDHelpers 36 public class LLSDHelpers
37 { 37 {
38// private static readonly log4net.ILog m_log 38// private static readonly log4net.ILog m_log
39// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 39// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
40 40
41 public static string SerialiseLLSDReply(object obj) 41 public static string SerialiseLLSDReply(object obj)
42 { 42 {
43 StringWriter sw = new StringWriter(); 43 StringWriter sw = new StringWriter();
44 XmlTextWriter writer = new XmlTextWriter(sw); 44 XmlTextWriter writer = new XmlTextWriter(sw);
45 writer.Formatting = Formatting.None; 45 writer.Formatting = Formatting.None;
46 writer.WriteStartElement(String.Empty, "llsd", String.Empty); 46 writer.WriteStartElement(String.Empty, "llsd", String.Empty);
47 SerializeOSDType(writer, obj); 47 SerializeOSDType(writer, obj);
48 writer.WriteEndElement(); 48 writer.WriteEndElement();
49 writer.Close(); 49 writer.Close();
50 50
51 //m_log.DebugFormat("[LLSD Helpers]: Generated serialized LLSD reply {0}", sw.ToString()); 51 //m_log.DebugFormat("[LLSD Helpers]: Generated serialized LLSD reply {0}", sw.ToString());
52 52
53 return sw.ToString(); 53 return sw.ToString();
54 } 54 }
55 55
56 private static void SerializeOSDType(XmlTextWriter writer, object obj) 56 private static void SerializeOSDType(XmlTextWriter writer, object obj)
57 { 57 {
58 Type myType = obj.GetType(); 58 Type myType = obj.GetType();
59 LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false); 59 LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false);
60 if (llsdattributes.Length > 0) 60 if (llsdattributes.Length > 0)
61 { 61 {
62 switch (llsdattributes[0].ObjectType) 62 switch (llsdattributes[0].ObjectType)
63 { 63 {
64 case "MAP": 64 case "MAP":
65 writer.WriteStartElement(String.Empty, "map", String.Empty); 65 writer.WriteStartElement(String.Empty, "map", String.Empty);
66 FieldInfo[] fields = myType.GetFields(); 66 FieldInfo[] fields = myType.GetFields();
67 for (int i = 0; i < fields.Length; i++) 67 for (int i = 0; i < fields.Length; i++)
68 { 68 {
69 if (fields[i] != null && fields[i].GetValue(obj) != null) 69 if (fields[i] != null && fields[i].GetValue(obj) != null)
70 { 70 {
71 object fieldValue = fields[i].GetValue(obj); 71 object fieldValue = fields[i].GetValue(obj);
72 LLSDType[] fieldAttributes = 72 LLSDType[] fieldAttributes =
73 (LLSDType[]) fieldValue.GetType().GetCustomAttributes(typeof (LLSDType), false); 73 (LLSDType[]) fieldValue.GetType().GetCustomAttributes(typeof (LLSDType), false);
74 if (fieldAttributes.Length > 0) 74 if (fieldAttributes.Length > 0)
75 { 75 {
76 writer.WriteStartElement(String.Empty, "key", String.Empty); 76 writer.WriteStartElement(String.Empty, "key", String.Empty);
77 string fieldName = fields[i].Name; 77 string fieldName = fields[i].Name;
78 fieldName = fieldName.Replace("___", "-"); 78 fieldName = fieldName.Replace("___", "-");
79 writer.WriteString(fieldName); 79 writer.WriteString(fieldName);
80 writer.WriteEndElement(); 80 writer.WriteEndElement();
81 SerializeOSDType(writer, fieldValue); 81 SerializeOSDType(writer, fieldValue);
82 } 82 }
83 else 83 else
84 { 84 {
85 writer.WriteStartElement(String.Empty, "key", String.Empty); 85 writer.WriteStartElement(String.Empty, "key", String.Empty);
86 string fieldName = fields[i].Name; 86 string fieldName = fields[i].Name;
87 fieldName = fieldName.Replace("___", "-"); 87 fieldName = fieldName.Replace("___", "-");
88 writer.WriteString(fieldName); 88 writer.WriteString(fieldName);
89 writer.WriteEndElement(); 89 writer.WriteEndElement();
90 LLSD.LLSDWriteOne(writer, fieldValue); 90 LLSD.LLSDWriteOne(writer, fieldValue);
91 // OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement( 91 // OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement(
92 // writer, OpenMetaverse.StructuredData.OSD.FromObject(fieldValue)); 92 // writer, OpenMetaverse.StructuredData.OSD.FromObject(fieldValue));
93 } 93 }
94 } 94 }
95 else 95 else
96 { 96 {
97 // TODO from ADAM: There is a nullref being caused by fields[i] being null 97 // TODO from ADAM: There is a nullref being caused by fields[i] being null
98 // on some computers. Unsure what is causing this, but would appreciate 98 // on some computers. Unsure what is causing this, but would appreciate
99 // if sdague could take a look at this. 99 // if sdague could take a look at this.
100 } 100 }
101 } 101 }
102 writer.WriteEndElement(); 102 writer.WriteEndElement();
103 break; 103 break;
104 case "ARRAY": 104 case "ARRAY":
105 // OSDArray arrayObject = obj as OSDArray; 105 // OSDArray arrayObject = obj as OSDArray;
106 // ArrayList a = arrayObject.Array; 106 // ArrayList a = arrayObject.Array;
107 ArrayList a = (ArrayList) obj.GetType().GetField("Array").GetValue(obj); 107 ArrayList a = (ArrayList) obj.GetType().GetField("Array").GetValue(obj);
108 if (a != null) 108 if (a != null)
109 { 109 {
110 writer.WriteStartElement(String.Empty, "array", String.Empty); 110 writer.WriteStartElement(String.Empty, "array", String.Empty);
111 foreach (object item in a) 111 foreach (object item in a)
112 { 112 {
113 SerializeOSDType(writer, item); 113 SerializeOSDType(writer, item);
114 } 114 }
115 writer.WriteEndElement(); 115 writer.WriteEndElement();
116 } 116 }
117 break; 117 break;
118 } 118 }
119 } 119 }
120 else 120 else
121 { 121 {
122 LLSD.LLSDWriteOne(writer, obj); 122 LLSD.LLSDWriteOne(writer, obj);
123 //OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement( 123 //OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement(
124 // writer, OpenMetaverse.StructuredData.OSD.FromObject(obj)); 124 // writer, OpenMetaverse.StructuredData.OSD.FromObject(obj));
125 } 125 }
126 } 126 }
127 127
128 public static object DeserialiseOSDMap(Hashtable llsd, object obj) 128 public static object DeserialiseOSDMap(Hashtable llsd, object obj)
129 { 129 {
130 Type myType = obj.GetType(); 130 Type myType = obj.GetType();
131 LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false); 131 LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false);
132 if (llsdattributes.Length > 0) 132 if (llsdattributes.Length > 0)
133 { 133 {
134 switch (llsdattributes[0].ObjectType) 134 switch (llsdattributes[0].ObjectType)
135 { 135 {
136 case "MAP": 136 case "MAP":
137 IDictionaryEnumerator enumerator = llsd.GetEnumerator(); 137 IDictionaryEnumerator enumerator = llsd.GetEnumerator();
138 while (enumerator.MoveNext()) 138 while (enumerator.MoveNext())
139 { 139 {
140 string keyName = (string)enumerator.Key; 140 string keyName = (string)enumerator.Key;
141 keyName = keyName.Replace("-","_"); 141 keyName = keyName.Replace("-","_");
142 FieldInfo field = myType.GetField(keyName); 142 FieldInfo field = myType.GetField(keyName);
143 if (field != null) 143 if (field != null)
144 { 144 {
145 // if (enumerator.Value is OpenMetaverse.StructuredData.OSDMap) 145 // if (enumerator.Value is OpenMetaverse.StructuredData.OSDMap)
146 if (enumerator.Value is Hashtable) 146 if (enumerator.Value is Hashtable)
147 { 147 {
148 object fieldValue = field.GetValue(obj); 148 object fieldValue = field.GetValue(obj);
149 DeserialiseOSDMap((Hashtable) enumerator.Value, fieldValue); 149 DeserialiseOSDMap((Hashtable) enumerator.Value, fieldValue);
150 // DeserialiseOSDMap((OpenMetaverse.StructuredData.OSDMap) enumerator.Value, fieldValue); 150 // DeserialiseOSDMap((OpenMetaverse.StructuredData.OSDMap) enumerator.Value, fieldValue);
151 } 151 }
152 else if (enumerator.Value is ArrayList) 152 else if (enumerator.Value is ArrayList)
153 { 153 {
154 object fieldValue = field.GetValue(obj); 154 object fieldValue = field.GetValue(obj);
155 fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value); 155 fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value);
156 //TODO 156 //TODO
157 // the LLSD map/array types in the array need to be deserialised 157 // the LLSD map/array types in the array need to be deserialised
158 // but first we need to know the right class to deserialise them into. 158 // but first we need to know the right class to deserialise them into.
159 } 159 }
160 else 160 else
161 { 161 {
162 field.SetValue(obj, enumerator.Value); 162 field.SetValue(obj, enumerator.Value);
163 } 163 }
164 } 164 }
165 } 165 }
166 break; 166 break;
167 } 167 }
168 } 168 }
169 return obj; 169 return obj;
170 } 170 }
171 } 171 }
172} 172}