5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using Microsoft.JScript.Vsa;
36 namespace Microsoft.JScript {
38 public class VsaItems : IVsaItems {
40 private ArrayList items;
41 private VsaEngine engine;
42 private ArrayList names;
44 public VsaItems (VsaEngine engine)
46 this.items = new ArrayList ();
48 this.names = new ArrayList ();
51 public IVsaItem this [int index] {
54 int size = items.Count;
56 if (index < 0 || index > size)
57 throw new VsaException (VsaError.ItemNotFound);
58 return (IVsaItem) items [index];
62 public IVsaItem this [string name] {
65 int size = items.Count;
68 for (i = 0; i < size; i++) {
69 item = (IVsaItem) items [i];
71 if (item.Name == name)
75 throw new VsaException (VsaError.ItemNotFound);
79 public virtual int Count {
82 throw new VsaException (VsaError.EngineClosed);
83 else if (!engine.InitNewCalled)
84 throw new VsaException (VsaError.EngineNotInitialized);
90 public virtual void Close ()
92 throw new NotImplementedException ();
95 public virtual IVsaItem CreateItem (string name,
99 if (names.Contains (name))
100 throw new VsaException (VsaError.ItemNameInUse);
102 IVsaItem item = null;
105 case VsaItemType.AppGlobal:
106 if (itemFlag != VsaItemFlag.None)
107 throw new VsaException (VsaError.ItemFlagNotSupported);
108 item = new VsaGlobalItem (engine, name, itemFlag);
111 case VsaItemType.Code:
112 item = new VsaCodeItem (engine, name, itemFlag);
115 case VsaItemType.Reference:
116 if (itemFlag != VsaItemFlag.None)
117 throw new VsaException (VsaError.ItemFlagNotSupported);
118 item = new VsaReferenceItem (engine, name, itemFlag);
127 engine.IsDirty = true;
132 public virtual IEnumerator GetEnumerator ()
134 return items.GetEnumerator ();
137 public virtual void Remove (string itemName)
140 int size = items.Count;
142 for (i = 0; i < size; i++)
143 if (((IVsaItem) items[i]).Name == itemName) {
148 throw new VsaException (VsaError.ItemNotFound);
151 public virtual void Remove (int itemIndex)
153 if (itemIndex < 0 || itemIndex > items.Count)
154 throw new VsaException (VsaError.ItemNotFound);
156 items.RemoveAt (itemIndex);