(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Microsoft.JScript / Microsoft.JScript / VsaItems.cs
blob8267509b1053e0b3b304e8fd989ddde117e58e2d
1 //
2 // VsaItems.cs:
3 //
4 // Author:
5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
6 //
7 // (C) 2003, Cesar Lopez Nataren
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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;
33 using Microsoft.Vsa;
34 using System;
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 ();
47 this.engine = engine;
48 this.names = new ArrayList ();
51 public IVsaItem this [int index] {
53 get {
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] {
63 get {
64 int i;
65 int size = items.Count;
66 IVsaItem item;
68 for (i = 0; i < size; i++) {
69 item = (IVsaItem) items [i];
71 if (item.Name == name)
72 return item;
73 continue;
75 throw new VsaException (VsaError.ItemNotFound);
79 public virtual int Count {
80 get {
81 if (engine.Closed)
82 throw new VsaException (VsaError.EngineClosed);
83 else if (!engine.InitNewCalled)
84 throw new VsaException (VsaError.EngineNotInitialized);
86 return items.Count;
90 public virtual void Close ()
92 throw new NotImplementedException ();
95 public virtual IVsaItem CreateItem (string name,
96 VsaItemType itemType,
97 VsaItemFlag itemFlag)
99 if (names.Contains (name))
100 throw new VsaException (VsaError.ItemNameInUse);
102 IVsaItem item = null;
104 switch (itemType) {
105 case VsaItemType.AppGlobal:
106 if (itemFlag != VsaItemFlag.None)
107 throw new VsaException (VsaError.ItemFlagNotSupported);
108 item = new VsaGlobalItem (engine, name, itemFlag);
109 break;
111 case VsaItemType.Code:
112 item = new VsaCodeItem (engine, name, itemFlag);
113 break;
115 case VsaItemType.Reference:
116 if (itemFlag != VsaItemFlag.None)
117 throw new VsaException (VsaError.ItemFlagNotSupported);
118 item = new VsaReferenceItem (engine, name, itemFlag);
119 break;
122 if (item != null) {
123 items.Add (item);
124 names.Add (name);
127 engine.IsDirty = true;
129 return item;
132 public virtual IEnumerator GetEnumerator ()
134 return items.GetEnumerator ();
137 public virtual void Remove (string itemName)
139 int i;
140 int size = items.Count;
142 for (i = 0; i < size; i++)
143 if (((IVsaItem) items[i]).Name == itemName) {
144 items.RemoveAt (i);
145 return;
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);