aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Base/ServerUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Server/Base/ServerUtils.cs96
1 files changed, 29 insertions, 67 deletions
diff --git a/OpenSim/Server/Base/ServerUtils.cs b/OpenSim/Server/Base/ServerUtils.cs
index a5d28a4..a399672 100644
--- a/OpenSim/Server/Base/ServerUtils.cs
+++ b/OpenSim/Server/Base/ServerUtils.cs
@@ -34,55 +34,13 @@ using System.Text;
34using System.Collections.Generic; 34using System.Collections.Generic;
35using log4net; 35using log4net;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenMetaverse;
37 38
38namespace OpenSim.Server.Base 39namespace OpenSim.Server.Base
39{ 40{
40 public static class ServerUtils 41 public static class ServerUtils
41 { 42 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 public static string SLAssetTypeToContentType(int assetType)
45 {
46 switch (assetType)
47 {
48 case 0:
49 return "image/jp2";
50 case 1:
51 return "application/ogg";
52 case 2:
53 return "application/x-metaverse-callingcard";
54 case 3:
55 return "application/x-metaverse-landmark";
56 case 5:
57 return "application/x-metaverse-clothing";
58 case 6:
59 return "application/x-metaverse-primitive";
60 case 7:
61 return "application/x-metaverse-notecard";
62 case 8:
63 return "application/x-metaverse-folder";
64 case 10:
65 return "application/x-metaverse-lsl";
66 case 11:
67 return "application/x-metaverse-lso";
68 case 12:
69 return "image/tga";
70 case 13:
71 return "application/x-metaverse-bodypart";
72 case 17:
73 return "audio/x-wav";
74 case 19:
75 return "image/jpeg";
76 case 20:
77 return "application/x-metaverse-animation";
78 case 21:
79 return "application/x-metaverse-gesture";
80 case 22:
81 return "application/x-metaverse-simstate";
82 default:
83 return "application/octet-stream";
84 }
85 }
86 44
87 public static byte[] SerializeResult(XmlSerializer xs, object data) 45 public static byte[] SerializeResult(XmlSerializer xs, object data)
88 { 46 {
@@ -99,6 +57,12 @@ namespace OpenSim.Server.Base
99 return ret; 57 return ret;
100 } 58 }
101 59
60 /// <summary>
61 /// Load a plugin from a dll with the given class or interface
62 /// </summary>
63 /// <param name="dllName"></param>
64 /// <param name="args">The arguments which control which constructor is invoked on the plugin</param>
65 /// <returns></returns>
102 public static T LoadPlugin<T>(string dllName, Object[] args) where T:class 66 public static T LoadPlugin<T>(string dllName, Object[] args) where T:class
103 { 67 {
104 string[] parts = dllName.Split(new char[] {':'}); 68 string[] parts = dllName.Split(new char[] {':'});
@@ -113,6 +77,13 @@ namespace OpenSim.Server.Base
113 return LoadPlugin<T>(dllName, className, args); 77 return LoadPlugin<T>(dllName, className, args);
114 } 78 }
115 79
80 /// <summary>
81 /// Load a plugin from a dll with the given class or interface
82 /// </summary>
83 /// <param name="dllName"></param>
84 /// <param name="className"></param>
85 /// <param name="args">The arguments which control which constructor is invoked on the plugin</param>
86 /// <returns></returns>
116 public static T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class 87 public static T LoadPlugin<T>(string dllName, string className, Object[] args) where T:class
117 { 88 {
118 string interfaceName = typeof(T).ToString(); 89 string interfaceName = typeof(T).ToString();
@@ -125,28 +96,15 @@ namespace OpenSim.Server.Base
125 { 96 {
126 if (pluginType.IsPublic) 97 if (pluginType.IsPublic)
127 { 98 {
128 if (className != String.Empty && 99 if (className != String.Empty
129 pluginType.ToString() != 100 && pluginType.ToString() != pluginType.Namespace + "." + className)
130 pluginType.Namespace + "." + className)
131 continue; 101 continue;
132 Type typeInterface = 102
133 pluginType.GetInterface(interfaceName, true); 103 Type typeInterface = pluginType.GetInterface(interfaceName, true);
104
134 if (typeInterface != null) 105 if (typeInterface != null)
135 { 106 {
136 T plug = null; 107 return (T)Activator.CreateInstance(pluginType, args);
137 try
138 {
139 plug = (T)Activator.CreateInstance(pluginType,
140 args);
141 }
142 catch (Exception e)
143 {
144 if (!(e is System.MissingMethodException))
145 m_log.ErrorFormat("Error loading plugin from {0}, exception {1}", dllName, e.InnerException);
146 return null;
147 }
148
149 return plug;
150 } 108 }
151 } 109 }
152 } 110 }
@@ -155,7 +113,7 @@ namespace OpenSim.Server.Base
155 } 113 }
156 catch (Exception e) 114 catch (Exception e)
157 { 115 {
158 m_log.ErrorFormat("Error loading plugin from {0}, exception {1}", dllName, e); 116 m_log.Error(string.Format("Error loading plugin from {0}", dllName), e);
159 return null; 117 return null;
160 } 118 }
161 } 119 }
@@ -182,12 +140,13 @@ namespace OpenSim.Server.Base
182 140
183 if (name.EndsWith("[]")) 141 if (name.EndsWith("[]"))
184 { 142 {
185 if (result.ContainsKey(name)) 143 string cleanName = name.Substring(0, name.Length - 2);
144 if (result.ContainsKey(cleanName))
186 { 145 {
187 if (!(result[name] is List<string>)) 146 if (!(result[cleanName] is List<string>))
188 continue; 147 continue;
189 148
190 List<string> l = (List<string>)result[name]; 149 List<string> l = (List<string>)result[cleanName];
191 150
192 l.Add(value); 151 l.Add(value);
193 } 152 }
@@ -197,7 +156,7 @@ namespace OpenSim.Server.Base
197 156
198 newList.Add(value); 157 newList.Add(value);
199 158
200 result[name] = newList; 159 result[cleanName] = newList;
201 } 160 }
202 } 161 }
203 else 162 else
@@ -278,6 +237,9 @@ namespace OpenSim.Server.Base
278 { 237 {
279 foreach (KeyValuePair<string, object> kvp in data) 238 foreach (KeyValuePair<string, object> kvp in data)
280 { 239 {
240 if (kvp.Value == null)
241 continue;
242
281 XmlElement elem = parent.OwnerDocument.CreateElement("", 243 XmlElement elem = parent.OwnerDocument.CreateElement("",
282 kvp.Key, ""); 244 kvp.Key, "");
283 245