diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | 391 |
1 files changed, 328 insertions, 63 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 34894ba..e498c6a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -49,7 +49,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
49 | private static readonly ILog m_log = | 49 | private static readonly ILog m_log = |
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
51 | 51 | ||
52 | private OSD m_ValueStore; | 52 | protected virtual OSD ValueStore { get; set; } |
53 | 53 | ||
54 | protected class TakeValueCallbackClass | 54 | protected class TakeValueCallbackClass |
55 | { | 55 | { |
@@ -68,42 +68,141 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
68 | protected List<TakeValueCallbackClass> m_TakeStore; | 68 | protected List<TakeValueCallbackClass> m_TakeStore; |
69 | protected List<TakeValueCallbackClass> m_ReadStore; | 69 | protected List<TakeValueCallbackClass> m_ReadStore; |
70 | 70 | ||
71 | // add separators for quoted paths and array references | ||
72 | protected static Regex m_ParsePassOne = new Regex("({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])"); | ||
71 | 73 | ||
74 | // add quotes to bare identifiers which are limited to alphabetic characters | ||
75 | protected static Regex m_ParsePassThree = new Regex("(?<!{[^}]*)\\.([a-zA-Z]+)(?=\\.)"); | ||
76 | |||
77 | // remove extra separator characters | ||
78 | protected static Regex m_ParsePassFour = new Regex("\\.+"); | ||
79 | |||
80 | // expression used to validate the full path, this is canonical representation | ||
81 | protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$"); | ||
82 | |||
83 | // expression used to match path components | ||
84 | protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])"); | ||
85 | |||
86 | // extract the internals of an array reference | ||
87 | protected static Regex m_SimpleArrayPattern = new Regex("^\\[([0-9]+)\\]$"); | ||
88 | protected static Regex m_ArrayPattern = new Regex("^\\[([0-9]+|\\+)\\]$"); | ||
89 | |||
90 | // extract the internals of a has reference | ||
91 | protected static Regex m_HashPattern = new Regex("^{([^}]+)}$"); | ||
92 | |||
93 | // ----------------------------------------------------------------- | ||
94 | /// <summary> | ||
95 | /// This is a simple estimator for the size of the stored data, it | ||
96 | /// is not precise, but should be close enough to implement reasonable | ||
97 | /// limits on the storage space used | ||
98 | /// </summary> | ||
99 | // ----------------------------------------------------------------- | ||
100 | public int StringSpace { get; set; } | ||
101 | |||
72 | // ----------------------------------------------------------------- | 102 | // ----------------------------------------------------------------- |
73 | /// <summary> | 103 | /// <summary> |
74 | /// | 104 | /// |
75 | /// </summary> | 105 | /// </summary> |
76 | // ----------------------------------------------------------------- | 106 | // ----------------------------------------------------------------- |
77 | public JsonStore() : this("") {} | 107 | public static bool CanonicalPathExpression(string ipath, out string opath) |
108 | { | ||
109 | Stack<string> path; | ||
110 | if (! ParsePathExpression(ipath,out path)) | ||
111 | { | ||
112 | opath = ""; | ||
113 | return false; | ||
114 | } | ||
115 | |||
116 | opath = PathExpressionToKey(path); | ||
117 | return true; | ||
118 | } | ||
78 | 119 | ||
79 | public JsonStore(string value) | 120 | // ----------------------------------------------------------------- |
121 | /// <summary> | ||
122 | /// | ||
123 | /// </summary> | ||
124 | // ----------------------------------------------------------------- | ||
125 | public JsonStore() | ||
80 | { | 126 | { |
127 | StringSpace = 0; | ||
81 | m_TakeStore = new List<TakeValueCallbackClass>(); | 128 | m_TakeStore = new List<TakeValueCallbackClass>(); |
82 | m_ReadStore = new List<TakeValueCallbackClass>(); | 129 | m_ReadStore = new List<TakeValueCallbackClass>(); |
83 | 130 | } | |
131 | |||
132 | public JsonStore(string value) : this() | ||
133 | { | ||
134 | // This is going to throw an exception if the value is not | ||
135 | // a valid JSON chunk. Calling routines should catch the | ||
136 | // exception and handle it appropriately | ||
84 | if (String.IsNullOrEmpty(value)) | 137 | if (String.IsNullOrEmpty(value)) |
85 | m_ValueStore = new OSDMap(); | 138 | ValueStore = new OSDMap(); |
86 | else | 139 | else |
87 | m_ValueStore = OSDParser.DeserializeJson(value); | 140 | ValueStore = OSDParser.DeserializeJson(value); |
88 | } | 141 | } |
142 | |||
143 | // ----------------------------------------------------------------- | ||
144 | /// <summary> | ||
145 | /// | ||
146 | /// </summary> | ||
147 | // ----------------------------------------------------------------- | ||
148 | public JsonStoreNodeType GetNodeType(string expr) | ||
149 | { | ||
150 | Stack<string> path; | ||
151 | if (! ParsePathExpression(expr,out path)) | ||
152 | return JsonStoreNodeType.Undefined; | ||
153 | |||
154 | OSD result = ProcessPathExpression(ValueStore,path); | ||
89 | 155 | ||
156 | if (result == null) | ||
157 | return JsonStoreNodeType.Undefined; | ||
158 | |||
159 | if (result is OSDMap) | ||
160 | return JsonStoreNodeType.Object; | ||
161 | |||
162 | if (result is OSDArray) | ||
163 | return JsonStoreNodeType.Array; | ||
164 | |||
165 | if (OSDBaseType(result.Type)) | ||
166 | return JsonStoreNodeType.Value; | ||
167 | |||
168 | return JsonStoreNodeType.Undefined; | ||
169 | } | ||
170 | |||
90 | // ----------------------------------------------------------------- | 171 | // ----------------------------------------------------------------- |
91 | /// <summary> | 172 | /// <summary> |
92 | /// | 173 | /// |
93 | /// </summary> | 174 | /// </summary> |
94 | // ----------------------------------------------------------------- | 175 | // ----------------------------------------------------------------- |
95 | public bool TestPath(string expr, bool useJson) | 176 | public JsonStoreValueType GetValueType(string expr) |
96 | { | 177 | { |
97 | Stack<string> path = ParsePathExpression(expr); | 178 | Stack<string> path; |
98 | OSD result = ProcessPathExpression(m_ValueStore,path); | 179 | if (! ParsePathExpression(expr,out path)) |
180 | return JsonStoreValueType.Undefined; | ||
181 | |||
182 | OSD result = ProcessPathExpression(ValueStore,path); | ||
99 | 183 | ||
100 | if (result == null) | 184 | if (result == null) |
101 | return false; | 185 | return JsonStoreValueType.Undefined; |
102 | 186 | ||
103 | if (useJson || result.Type == OSDType.String) | 187 | if (result is OSDMap) |
104 | return true; | 188 | return JsonStoreValueType.Undefined; |
105 | 189 | ||
106 | return false; | 190 | if (result is OSDArray) |
191 | return JsonStoreValueType.Undefined; | ||
192 | |||
193 | if (result is OSDBoolean) | ||
194 | return JsonStoreValueType.Boolean; | ||
195 | |||
196 | if (result is OSDInteger) | ||
197 | return JsonStoreValueType.Integer; | ||
198 | |||
199 | if (result is OSDReal) | ||
200 | return JsonStoreValueType.Float; | ||
201 | |||
202 | if (result is OSDString) | ||
203 | return JsonStoreValueType.String; | ||
204 | |||
205 | return JsonStoreValueType.Undefined; | ||
107 | } | 206 | } |
108 | 207 | ||
109 | // ----------------------------------------------------------------- | 208 | // ----------------------------------------------------------------- |
@@ -111,10 +210,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
111 | /// | 210 | /// |
112 | /// </summary> | 211 | /// </summary> |
113 | // ----------------------------------------------------------------- | 212 | // ----------------------------------------------------------------- |
213 | public int ArrayLength(string expr) | ||
214 | { | ||
215 | Stack<string> path; | ||
216 | if (! ParsePathExpression(expr,out path)) | ||
217 | return -1; | ||
218 | |||
219 | OSD result = ProcessPathExpression(ValueStore,path); | ||
220 | if (result != null && result.Type == OSDType.Array) | ||
221 | { | ||
222 | OSDArray arr = result as OSDArray; | ||
223 | return arr.Count; | ||
224 | } | ||
225 | |||
226 | return -1; | ||
227 | } | ||
228 | |||
229 | // ----------------------------------------------------------------- | ||
230 | /// <summary> | ||
231 | /// | ||
232 | /// </summary> | ||
233 | // ----------------------------------------------------------------- | ||
114 | public bool GetValue(string expr, out string value, bool useJson) | 234 | public bool GetValue(string expr, out string value, bool useJson) |
115 | { | 235 | { |
116 | Stack<string> path = ParsePathExpression(expr); | 236 | Stack<string> path; |
117 | OSD result = ProcessPathExpression(m_ValueStore,path); | 237 | if (! ParsePathExpression(expr,out path)) |
238 | { | ||
239 | value = ""; | ||
240 | return false; | ||
241 | } | ||
242 | |||
243 | OSD result = ProcessPathExpression(ValueStore,path); | ||
118 | return ConvertOutputValue(result,out value,useJson); | 244 | return ConvertOutputValue(result,out value,useJson); |
119 | } | 245 | } |
120 | 246 | ||
@@ -136,7 +262,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
136 | // ----------------------------------------------------------------- | 262 | // ----------------------------------------------------------------- |
137 | public bool SetValue(string expr, string value, bool useJson) | 263 | public bool SetValue(string expr, string value, bool useJson) |
138 | { | 264 | { |
139 | OSD ovalue = useJson ? OSDParser.DeserializeJson(value) : new OSDString(value); | 265 | OSD ovalue; |
266 | |||
267 | // One note of caution... if you use an empty string in the | ||
268 | // structure it will be assumed to be a default value and will | ||
269 | // not be seialized in the json | ||
270 | |||
271 | if (useJson) | ||
272 | { | ||
273 | // There doesn't appear to be a good way to determine if the | ||
274 | // value is valid Json other than to let the parser crash | ||
275 | try | ||
276 | { | ||
277 | ovalue = OSDParser.DeserializeJson(value); | ||
278 | } | ||
279 | catch (Exception e) | ||
280 | { | ||
281 | if (value.StartsWith("'") && value.EndsWith("'")) | ||
282 | { | ||
283 | ovalue = new OSDString(value.Substring(1,value.Length - 2)); | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | return false; | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | ovalue = new OSDString(value); | ||
294 | } | ||
295 | |||
140 | return SetValueFromExpression(expr,ovalue); | 296 | return SetValueFromExpression(expr,ovalue); |
141 | } | 297 | } |
142 | 298 | ||
@@ -147,10 +303,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
147 | // ----------------------------------------------------------------- | 303 | // ----------------------------------------------------------------- |
148 | public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) | 304 | public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) |
149 | { | 305 | { |
150 | Stack<string> path = ParsePathExpression(expr); | 306 | Stack<string> path; |
307 | if (! ParsePathExpression(expr,out path)) | ||
308 | return false; | ||
309 | |||
151 | string pexpr = PathExpressionToKey(path); | 310 | string pexpr = PathExpressionToKey(path); |
152 | 311 | ||
153 | OSD result = ProcessPathExpression(m_ValueStore,path); | 312 | OSD result = ProcessPathExpression(ValueStore,path); |
154 | if (result == null) | 313 | if (result == null) |
155 | { | 314 | { |
156 | m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); | 315 | m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); |
@@ -178,10 +337,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
178 | // ----------------------------------------------------------------- | 337 | // ----------------------------------------------------------------- |
179 | public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) | 338 | public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) |
180 | { | 339 | { |
181 | Stack<string> path = ParsePathExpression(expr); | 340 | Stack<string> path; |
341 | if (! ParsePathExpression(expr,out path)) | ||
342 | return false; | ||
343 | |||
182 | string pexpr = PathExpressionToKey(path); | 344 | string pexpr = PathExpressionToKey(path); |
183 | 345 | ||
184 | OSD result = ProcessPathExpression(m_ValueStore,path); | 346 | OSD result = ProcessPathExpression(ValueStore,path); |
185 | if (result == null) | 347 | if (result == null) |
186 | { | 348 | { |
187 | m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); | 349 | m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); |
@@ -208,25 +370,30 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
208 | // ----------------------------------------------------------------- | 370 | // ----------------------------------------------------------------- |
209 | protected bool SetValueFromExpression(string expr, OSD ovalue) | 371 | protected bool SetValueFromExpression(string expr, OSD ovalue) |
210 | { | 372 | { |
211 | Stack<string> path = ParsePathExpression(expr); | 373 | Stack<string> path; |
374 | if (! ParsePathExpression(expr,out path)) | ||
375 | return false; | ||
376 | |||
212 | if (path.Count == 0) | 377 | if (path.Count == 0) |
213 | { | 378 | { |
214 | m_ValueStore = ovalue; | 379 | ValueStore = ovalue; |
380 | StringSpace = 0; | ||
215 | return true; | 381 | return true; |
216 | } | 382 | } |
217 | 383 | ||
384 | // pkey will be the final element in the path, we pull it out here to make sure | ||
385 | // that the assignment works correctly | ||
218 | string pkey = path.Pop(); | 386 | string pkey = path.Pop(); |
219 | string pexpr = PathExpressionToKey(path); | 387 | string pexpr = PathExpressionToKey(path); |
220 | if (pexpr != "") | 388 | if (pexpr != "") |
221 | pexpr += "."; | 389 | pexpr += "."; |
222 | 390 | ||
223 | OSD result = ProcessPathExpression(m_ValueStore,path); | 391 | OSD result = ProcessPathExpression(ValueStore,path); |
224 | if (result == null) | 392 | if (result == null) |
225 | return false; | 393 | return false; |
226 | 394 | ||
227 | Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]"); | 395 | // Check pkey, the last element in the path, for and extract array references |
228 | MatchCollection amatches = aPattern.Matches(pkey,0); | 396 | MatchCollection amatches = m_ArrayPattern.Matches(pkey,0); |
229 | |||
230 | if (amatches.Count > 0) | 397 | if (amatches.Count > 0) |
231 | { | 398 | { |
232 | if (result.Type != OSDType.Array) | 399 | if (result.Type != OSDType.Array) |
@@ -242,8 +409,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
242 | { | 409 | { |
243 | string npkey = String.Format("[{0}]",amap.Count); | 410 | string npkey = String.Format("[{0}]",amap.Count); |
244 | 411 | ||
245 | amap.Add(ovalue); | 412 | if (ovalue != null) |
246 | InvokeNextCallback(pexpr + npkey); | 413 | { |
414 | StringSpace += ComputeSizeOf(ovalue); | ||
415 | |||
416 | amap.Add(ovalue); | ||
417 | InvokeNextCallback(pexpr + npkey); | ||
418 | } | ||
247 | return true; | 419 | return true; |
248 | } | 420 | } |
249 | 421 | ||
@@ -251,9 +423,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
251 | if (0 <= aval && aval < amap.Count) | 423 | if (0 <= aval && aval < amap.Count) |
252 | { | 424 | { |
253 | if (ovalue == null) | 425 | if (ovalue == null) |
426 | { | ||
427 | StringSpace -= ComputeSizeOf(amap[aval]); | ||
254 | amap.RemoveAt(aval); | 428 | amap.RemoveAt(aval); |
429 | } | ||
255 | else | 430 | else |
256 | { | 431 | { |
432 | StringSpace -= ComputeSizeOf(amap[aval]); | ||
433 | StringSpace += ComputeSizeOf(ovalue); | ||
257 | amap[aval] = ovalue; | 434 | amap[aval] = ovalue; |
258 | InvokeNextCallback(pexpr + pkey); | 435 | InvokeNextCallback(pexpr + pkey); |
259 | } | 436 | } |
@@ -263,9 +440,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
263 | return false; | 440 | return false; |
264 | } | 441 | } |
265 | 442 | ||
266 | Regex hPattern = new Regex("{([^}]+)}"); | 443 | // Check for and extract hash references |
267 | MatchCollection hmatches = hPattern.Matches(pkey,0); | 444 | MatchCollection hmatches = m_HashPattern.Matches(pkey,0); |
268 | |||
269 | if (hmatches.Count > 0) | 445 | if (hmatches.Count > 0) |
270 | { | 446 | { |
271 | Match match = hmatches[0]; | 447 | Match match = hmatches[0]; |
@@ -274,16 +450,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
274 | 450 | ||
275 | if (result is OSDMap) | 451 | if (result is OSDMap) |
276 | { | 452 | { |
453 | // this is the assignment case | ||
277 | OSDMap hmap = result as OSDMap; | 454 | OSDMap hmap = result as OSDMap; |
278 | if (ovalue != null) | 455 | if (ovalue != null) |
279 | { | 456 | { |
457 | StringSpace -= ComputeSizeOf(hmap[hkey]); | ||
458 | StringSpace += ComputeSizeOf(ovalue); | ||
459 | |||
280 | hmap[hkey] = ovalue; | 460 | hmap[hkey] = ovalue; |
281 | InvokeNextCallback(pexpr + pkey); | 461 | InvokeNextCallback(pexpr + pkey); |
462 | return true; | ||
282 | } | 463 | } |
283 | else if (hmap.ContainsKey(hkey)) | 464 | |
465 | // this is the remove case | ||
466 | if (hmap.ContainsKey(hkey)) | ||
467 | { | ||
468 | StringSpace -= ComputeSizeOf(hmap[hkey]); | ||
284 | hmap.Remove(hkey); | 469 | hmap.Remove(hkey); |
285 | 470 | return true; | |
286 | return true; | 471 | } |
472 | |||
473 | return false; | ||
287 | } | 474 | } |
288 | 475 | ||
289 | return false; | 476 | return false; |
@@ -332,39 +519,33 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
332 | /// use a stack because we process the path in inverse order later | 519 | /// use a stack because we process the path in inverse order later |
333 | /// </summary> | 520 | /// </summary> |
334 | // ----------------------------------------------------------------- | 521 | // ----------------------------------------------------------------- |
335 | protected static Stack<string> ParsePathExpression(string path) | 522 | protected static bool ParsePathExpression(string expr, out Stack<string> path) |
336 | { | 523 | { |
337 | Stack<string> m_path = new Stack<string>(); | 524 | path = new Stack<string>(); |
338 | 525 | ||
339 | // add front and rear separators | 526 | // add front and rear separators |
340 | path = "." + path + "."; | 527 | expr = "." + expr + "."; |
341 | 528 | ||
342 | // add separators for quoted paths | 529 | // add separators for quoted exprs and array references |
343 | Regex pass1 = new Regex("{[^}]+}"); | 530 | expr = m_ParsePassOne.Replace(expr,".$1.",-1,0); |
344 | path = pass1.Replace(path,".$0.",-1,0); | ||
345 | |||
346 | // add separators for array references | ||
347 | Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); | ||
348 | path = pass2.Replace(path,".$0.",-1,0); | ||
349 | 531 | ||
350 | // add quotes to bare identifier | 532 | // add quotes to bare identifier |
351 | Regex pass3 = new Regex("\\.([a-zA-Z]+)"); | 533 | expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0); |
352 | path = pass3.Replace(path,".{$1}",-1,0); | ||
353 | 534 | ||
354 | // remove extra separators | 535 | // remove extra separators |
355 | Regex pass4 = new Regex("\\.+"); | 536 | expr = m_ParsePassFour.Replace(expr,".",-1,0); |
356 | path = pass4.Replace(path,".",-1,0); | ||
357 | 537 | ||
358 | Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); | 538 | // validate the results (catches extra quote characters for example) |
359 | if (validate.IsMatch(path)) | 539 | if (m_ValidatePath.IsMatch(expr)) |
360 | { | 540 | { |
361 | Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); | 541 | MatchCollection matches = m_PathComponent.Matches(expr,0); |
362 | MatchCollection matches = parser.Matches(path,0); | ||
363 | foreach (Match match in matches) | 542 | foreach (Match match in matches) |
364 | m_path.Push(match.Groups[1].Value); | 543 | path.Push(match.Groups[1].Value); |
544 | |||
545 | return true; | ||
365 | } | 546 | } |
366 | 547 | ||
367 | return m_path; | 548 | return false; |
368 | } | 549 | } |
369 | 550 | ||
370 | // ----------------------------------------------------------------- | 551 | // ----------------------------------------------------------------- |
@@ -385,9 +566,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
385 | return null; | 566 | return null; |
386 | 567 | ||
387 | // ---------- Check for an array index ---------- | 568 | // ---------- Check for an array index ---------- |
388 | Regex aPattern = new Regex("\\[([0-9]+)\\]"); | 569 | MatchCollection amatches = m_SimpleArrayPattern.Matches(pkey,0); |
389 | MatchCollection amatches = aPattern.Matches(pkey,0); | 570 | |
390 | |||
391 | if (amatches.Count > 0) | 571 | if (amatches.Count > 0) |
392 | { | 572 | { |
393 | if (rmap.Type != OSDType.Array) | 573 | if (rmap.Type != OSDType.Array) |
@@ -410,9 +590,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
410 | } | 590 | } |
411 | 591 | ||
412 | // ---------- Check for a hash index ---------- | 592 | // ---------- Check for a hash index ---------- |
413 | Regex hPattern = new Regex("{([^}]+)}"); | 593 | MatchCollection hmatches = m_HashPattern.Matches(pkey,0); |
414 | MatchCollection hmatches = hPattern.Matches(pkey,0); | 594 | |
415 | |||
416 | if (hmatches.Count > 0) | 595 | if (hmatches.Count > 0) |
417 | { | 596 | { |
418 | if (rmap.Type != OSDType.Map) | 597 | if (rmap.Type != OSDType.Map) |
@@ -456,14 +635,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
456 | // The path pointed to an intermediate hash structure | 635 | // The path pointed to an intermediate hash structure |
457 | if (result.Type == OSDType.Map) | 636 | if (result.Type == OSDType.Map) |
458 | { | 637 | { |
459 | value = OSDParser.SerializeJsonString(result as OSDMap); | 638 | value = OSDParser.SerializeJsonString(result as OSDMap,true); |
460 | return true; | 639 | return true; |
461 | } | 640 | } |
462 | 641 | ||
463 | // The path pointed to an intermediate hash structure | 642 | // The path pointed to an intermediate hash structure |
464 | if (result.Type == OSDType.Array) | 643 | if (result.Type == OSDType.Array) |
465 | { | 644 | { |
466 | value = OSDParser.SerializeJsonString(result as OSDArray); | 645 | value = OSDParser.SerializeJsonString(result as OSDArray,true); |
467 | return true; | 646 | return true; |
468 | } | 647 | } |
469 | 648 | ||
@@ -471,7 +650,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
471 | return true; | 650 | return true; |
472 | } | 651 | } |
473 | 652 | ||
474 | if (result.Type == OSDType.String) | 653 | if (OSDBaseType(result.Type)) |
475 | { | 654 | { |
476 | value = result.AsString(); | 655 | value = result.AsString(); |
477 | return true; | 656 | return true; |
@@ -496,5 +675,91 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | |||
496 | 675 | ||
497 | return pkey; | 676 | return pkey; |
498 | } | 677 | } |
678 | |||
679 | // ----------------------------------------------------------------- | ||
680 | /// <summary> | ||
681 | /// | ||
682 | /// </summary> | ||
683 | // ----------------------------------------------------------------- | ||
684 | protected static bool OSDBaseType(OSDType type) | ||
685 | { | ||
686 | // Should be the list of base types for which AsString() returns | ||
687 | // something useful | ||
688 | if (type == OSDType.Boolean) | ||
689 | return true; | ||
690 | if (type == OSDType.Integer) | ||
691 | return true; | ||
692 | if (type == OSDType.Real) | ||
693 | return true; | ||
694 | if (type == OSDType.String) | ||
695 | return true; | ||
696 | if (type == OSDType.UUID) | ||
697 | return true; | ||
698 | if (type == OSDType.Date) | ||
699 | return true; | ||
700 | if (type == OSDType.URI) | ||
701 | return true; | ||
702 | |||
703 | return false; | ||
704 | } | ||
705 | |||
706 | // ----------------------------------------------------------------- | ||
707 | /// <summary> | ||
708 | /// | ||
709 | /// </summary> | ||
710 | // ----------------------------------------------------------------- | ||
711 | protected static int ComputeSizeOf(OSD value) | ||
712 | { | ||
713 | string sval; | ||
714 | |||
715 | if (ConvertOutputValue(value,out sval,true)) | ||
716 | return sval.Length; | ||
717 | |||
718 | return 0; | ||
719 | } | ||
720 | } | ||
721 | |||
722 | // ----------------------------------------------------------------- | ||
723 | /// <summary> | ||
724 | /// </summary> | ||
725 | // ----------------------------------------------------------------- | ||
726 | public class JsonObjectStore : JsonStore | ||
727 | { | ||
728 | private static readonly ILog m_log = | ||
729 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
730 | |||
731 | private Scene m_scene; | ||
732 | private UUID m_objectID; | ||
733 | |||
734 | protected override OSD ValueStore | ||
735 | { | ||
736 | get | ||
737 | { | ||
738 | SceneObjectPart sop = m_scene.GetSceneObjectPart(m_objectID); | ||
739 | if (sop == null) | ||
740 | { | ||
741 | // This is bad | ||
742 | return null; | ||
743 | } | ||
744 | |||
745 | return sop.DynAttrs.TopLevelMap; | ||
746 | } | ||
747 | |||
748 | // cannot set the top level | ||
749 | set | ||
750 | { | ||
751 | m_log.InfoFormat("[JsonStore] cannot set top level value in object store"); | ||
752 | } | ||
753 | } | ||
754 | |||
755 | public JsonObjectStore(Scene scene, UUID oid) : base() | ||
756 | { | ||
757 | m_scene = scene; | ||
758 | m_objectID = oid; | ||
759 | |||
760 | // the size limit is imposed on whatever is already in the store | ||
761 | StringSpace = ComputeSizeOf(ValueStore); | ||
762 | } | ||
499 | } | 763 | } |
764 | |||
500 | } | 765 | } |