* MainsoftWebApp20.Tomcat.vmwcsproj: converted to csproj
[mono.git] / mcs / class / System.Web / System.Web / SiteMapNodeCollection.cs
1 //
2 // System.Web.SiteMapNodeCollection
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Lluis Sanchez Gual (lluis@novell.com)
7 //
8 //  (C) 2003 Ben Maurer
9 //  (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 #if NET_2_0
34 using System.Collections;
35 using System.Collections.Specialized;
36 using System.Text;
37 using System.Web.UI;
38 using System.Web.UI.WebControls;
39
40 namespace System.Web
41 {
42         public class SiteMapNodeCollection : IList, IHierarchicalEnumerable
43         {
44                 ArrayList list;
45 #if TARGET_JVM
46                 const string _siteMapNodeCollection_EmptyList = "SiteMapNodeCollection.EmptyList";
47                 internal static SiteMapNodeCollection EmptyList
48                 {
49                         get { return (SiteMapNodeCollection) AppDomain.CurrentDomain.GetData (_siteMapNodeCollection_EmptyList); }
50                         set { AppDomain.CurrentDomain.SetData (_siteMapNodeCollection_EmptyList, value); }
51                 }
52 #else
53                 internal static SiteMapNodeCollection EmptyList;
54 #endif
55                 
56                 static SiteMapNodeCollection ()
57                 {
58                         EmptyList = new SiteMapNodeCollection ();
59                         EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
60                 }
61                 
62                 public SiteMapNodeCollection ()
63                 {
64                 }
65                 
66                 public SiteMapNodeCollection (int capacity)
67                 {
68                         list = new ArrayList (capacity);
69                 }
70                 
71                 public SiteMapNodeCollection (SiteMapNode value)
72                 {
73                         Add (value);
74                 }
75                 
76                 public SiteMapNodeCollection (SiteMapNode[] values)
77                 {
78                         AddRangeInternal (values);
79                 }
80                 
81                 public SiteMapNodeCollection (SiteMapNodeCollection values)
82                 {
83                         AddRangeInternal (values);
84                 }
85                 
86                 internal static SiteMapNodeCollection EmptyCollection {
87                         get { return EmptyList; }
88                 }
89                 
90                 ArrayList List {
91                         get {
92                                 if (list == null) list = new ArrayList ();
93                                 return list;
94                         }
95                 }
96                 
97                 public virtual int Count {
98                         get { return list == null ? 0 : list.Count; }
99                 }
100                 
101                 public virtual bool IsSynchronized {
102                         get { return false; }
103                 }
104                 
105                 public virtual object SyncRoot {
106                         get { return this; }
107                 }
108                 
109                 public virtual IEnumerator GetEnumerator ()
110                 {
111                         return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
112                 }
113                 
114                 public virtual void Clear ()
115                 {
116                         if (list != null) list.Clear ();
117                 }
118                 
119                 public virtual void RemoveAt (int index)
120                 {
121                         List.RemoveAt (index);
122                 }
123                 
124                 public virtual int Add (SiteMapNode value)
125                 {
126                         if (value == null)
127                                 throw new ArgumentNullException ("value");
128                         return this.List.Add (value);
129                 }
130                 
131                 public virtual void AddRange (System.Web.SiteMapNode[] value)
132                 {
133                         this.AddRangeInternal (value);
134                 }
135                 
136                 public virtual void AddRange (SiteMapNodeCollection value)
137                 {
138                         this.AddRangeInternal (value);
139                 }
140                 
141                 internal virtual void AddRangeInternal (IList value)
142                 {
143                         if (value == null)
144                                 throw new ArgumentNullException ("value");
145
146                         List.AddRange (value);
147                 }
148
149                 public virtual bool Contains (SiteMapNode value)
150                 {
151                         return this.List.Contains (value);
152                 }
153                 
154                 public virtual void CopyTo (System.Web.SiteMapNode[] array, int index)
155                 {
156                         this.List.CopyTo (array, index);
157                 }
158                 
159                 public virtual int IndexOf (SiteMapNode value)
160                 {
161                         return this.List.IndexOf (value);
162                 }
163                 
164                 public virtual void Insert (int index, SiteMapNode value)
165                 {
166                         this.List.Insert (index, value);
167                 }
168                 
169                 protected virtual void OnValidate (object value)
170                 {
171                         if (!(value is SiteMapNode))
172                                 throw new ArgumentException ("Invalid type");
173                 }
174
175                 public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
176                 {
177                         SiteMapNodeCollection col = new SiteMapNodeCollection ();
178                         if (collection.list != null)
179                                 col.list = ArrayList.ReadOnly (collection.list);
180                         else
181                                 col.list = ArrayList.ReadOnly (new ArrayList ());
182                         return col;
183                 }
184                 
185                 public virtual void Remove (SiteMapNode value)
186                 {
187                         this.List.Remove (value);
188                 }
189                 
190                 public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
191                 {
192                         return enumeratedItem as IHierarchyData;
193                 }
194                 
195                 public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
196                 {
197                         return new SiteMapDataSourceView (owner, viewName, this);
198                 }
199                 
200                 public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
201                 {
202                         return new SiteMapHierarchicalDataSourceView (this);
203                 }
204                 
205                 public virtual SiteMapNode this [int index] {
206                         get { return (SiteMapNode) this.List [index]; }
207                         set { this.List [index] = value; }
208                 }
209                 
210                 public virtual bool IsFixedSize {
211                         get { return List.IsFixedSize; }
212                 }
213
214                 public virtual bool IsReadOnly {
215                         get { return list != null && list.IsReadOnly; }
216                 }
217
218                 #region IList Members
219
220                 object IList.this [int index] {
221                         get { return List [index]; }
222                         set { OnValidate (value); List [index] = value; }
223                 }
224                 
225                 int IList.Add (object value)
226                 {
227                         OnValidate (value);
228                         return List.Add (value);
229                 }
230                 
231                 bool IList.Contains (object value)
232                 {
233                         return List.Contains (value);
234                 }
235                 
236                 int IList.IndexOf (object value)
237                 {
238                         return List.IndexOf (value);
239                 }
240                 
241                 void IList.Insert (int index, object value)
242                 {
243                         OnValidate (value);
244                         List.Insert (index, value);
245                 }
246                 
247                 void IList.Remove (object value)
248                 {
249                         OnValidate (value);
250                         List.Remove (value);
251                 }
252                 
253                 void ICollection.CopyTo (Array array, int index)
254                 {
255                         List.CopyTo (array, index);
256                 }
257
258                 void IList.Clear () {
259                         Clear ();
260                 }
261
262                 bool IList.IsFixedSize {
263                         get { return IsFixedSize; }
264                 }
265
266                 bool IList.IsReadOnly {
267                         get { return IsReadOnly; }
268                 }
269
270                 void IList.RemoveAt (int index) {
271                         RemoveAt (index);
272                 }
273
274                 #endregion
275
276                 #region ICollection Members
277
278
279                 int ICollection.Count {
280                         get { return Count; }
281                 }
282
283                 bool ICollection.IsSynchronized {
284                         get { return IsSynchronized; }
285                 }
286
287                 object ICollection.SyncRoot {
288                         get { return SyncRoot; }
289                 }
290
291                 #endregion
292
293                 #region IEnumerable Members
294
295                 IEnumerator IEnumerable.GetEnumerator () {
296                         return GetEnumerator ();
297                 }
298
299                 #endregion
300
301                 #region IHierarchicalEnumerable Members
302
303                 IHierarchyData IHierarchicalEnumerable.GetHierarchyData (object enumeratedItem) {
304                         return GetHierarchyData (enumeratedItem);
305                 }
306
307                 #endregion
308         }
309 }
310 #endif
311