Standardized Mainsoft ConstraintCollection tests.
[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                 internal static SiteMapNodeCollection EmptyList;
46                 
47                 static SiteMapNodeCollection ()
48                 {
49                         EmptyList = new SiteMapNodeCollection ();
50                         EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
51                 }
52                 
53                 public SiteMapNodeCollection ()
54                 {
55                 }
56                 
57                 public SiteMapNodeCollection (int capacity)
58                 {
59                         list = new ArrayList (capacity);
60                 }
61                 
62                 public SiteMapNodeCollection (SiteMapNode value)
63                 {
64                         Add (value);
65                 }
66                 
67                 public SiteMapNodeCollection (SiteMapNode[] values)
68                 {
69                         AddRangeInternal (values);
70                 }
71                 
72                 public SiteMapNodeCollection (SiteMapNodeCollection values)
73                 {
74                         AddRangeInternal (values);
75                 }
76                 
77                 internal static SiteMapNodeCollection EmptyCollection {
78                         get { return EmptyList; }
79                 }
80                 
81                 ArrayList List {
82                         get {
83                                 if (list == null) list = new ArrayList ();
84                                 return list;
85                         }
86                 }
87                 
88                 public virtual int Count {
89                         get { return list == null ? 0 : list.Count; }
90                 }
91                 
92                 public virtual bool IsSynchronized {
93                         get { return false; }
94                 }
95                 
96                 public virtual object SyncRoot {
97                         get { return this; }
98                 }
99                 
100                 public virtual IEnumerator GetEnumerator ()
101                 {
102                         return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
103                 }
104                 
105                 public virtual void Clear ()
106                 {
107                         if (list != null) list.Clear ();
108                 }
109                 
110                 public virtual void RemoveAt (int index)
111                 {
112                         List.RemoveAt (index);
113                 }
114                 
115                 public virtual int Add (SiteMapNode value)
116                 {
117                         if (value == null)
118                                 throw new ArgumentNullException ("value");
119                         return this.List.Add (value);
120                 }
121                 
122                 public virtual void AddRange (System.Web.SiteMapNode[] value)
123                 {
124                         this.AddRangeInternal (value);
125                 }
126                 
127                 public virtual void AddRange (SiteMapNodeCollection value)
128                 {
129                         this.AddRangeInternal (value);
130                 }
131                 
132                 internal virtual void AddRangeInternal (IList value)
133                 {
134                         if (value == null)
135                                 throw new ArgumentNullException ("value");
136
137                         List.AddRange (value);
138                 }
139
140                 public bool Contains (SiteMapNode value)
141                 {
142                         return this.List.Contains (value);
143                 }
144                 
145                 public void CopyTo (System.Web.SiteMapNode[] array, int index)
146                 {
147                         this.List.CopyTo (array, index);
148                 }
149                 
150                 public int IndexOf (SiteMapNode value)
151                 {
152                         return this.List.IndexOf (value);
153                 }
154                 
155                 public virtual void Insert (int index, SiteMapNode value)
156                 {
157                         this.List.Insert (index, value);
158                 }
159                 
160                 protected virtual void OnValidate (object value)
161                 {
162                         if (!(value is SiteMapNode))
163                                 throw new ArgumentException ("Invalid type");
164                 }
165
166                 public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
167                 {
168                         SiteMapNodeCollection col = new SiteMapNodeCollection ();
169                         if (collection.list != null)
170                                 col.list = ArrayList.ReadOnly (collection.list);
171                         else
172                                 col.list = ArrayList.ReadOnly (new ArrayList ());
173                         return col;
174                 }
175                 
176                 public virtual void Remove (SiteMapNode value)
177                 {
178                         this.List.Remove (value);
179                 }
180                 
181                 public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
182                 {
183                         return enumeratedItem as IHierarchyData;
184                 }
185                 
186                 public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
187                 {
188                         return new SiteMapDataSourceView (owner, viewName, this);
189                 }
190                 
191                 public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
192                 {
193                         return new SiteMapHierarchicalDataSourceView (this);
194                 }
195                 
196                 public virtual SiteMapNode this [int index] {
197                         get { return (SiteMapNode) this.List [index]; }
198                         set { this.List [index] = value; }
199                 }
200                 
201                 public virtual bool IsFixedSize {
202                         get { return List.IsFixedSize; }
203                 }
204
205                 public virtual bool IsReadOnly {
206                         get { return list != null && list.IsReadOnly; }
207                 }
208                 
209                 object IList.this [int index] {
210                         get { return List [index]; }
211                         set { OnValidate (value); List [index] = value; }
212                 }
213                 
214                 int IList.Add (object value)
215                 {
216                         OnValidate (value);
217                         return List.Add (value);
218                 }
219                 
220                 bool IList.Contains (object value)
221                 {
222                         return List.Contains (value);
223                 }
224                 
225                 int IList.IndexOf (object value)
226                 {
227                         return List.IndexOf (value);
228                 }
229                 
230                 void IList.Insert (int index, object value)
231                 {
232                         OnValidate (value);
233                         List.Insert (index, value);
234                 }
235                 
236                 void IList.Remove (object value)
237                 {
238                         OnValidate (value);
239                         List.Remove (value);
240                 }
241                 
242                 void ICollection.CopyTo (Array array, int index)
243                 {
244                         List.CopyTo (array, index);
245                 }
246         }
247 }
248 #endif
249