2 // System.Web.SiteMapNodeCollection
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Lluis Sanchez Gual (lluis@novell.com)
9 // (C) 2005 Novell, Inc (http://www.novell.com)
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
34 using System.Collections;
35 using System.Collections.Specialized;
38 using System.Web.UI.WebControls;
42 public class SiteMapNodeCollection : IList, IHierarchicalEnumerable
46 const string _siteMapNodeCollection_EmptyList = "SiteMapNodeCollection.EmptyList";
47 internal static SiteMapNodeCollection EmptyList
49 get { return (SiteMapNodeCollection) AppDomain.CurrentDomain.GetData (_siteMapNodeCollection_EmptyList); }
50 set { AppDomain.CurrentDomain.SetData (_siteMapNodeCollection_EmptyList, value); }
53 internal static SiteMapNodeCollection EmptyList;
56 static SiteMapNodeCollection ()
58 EmptyList = new SiteMapNodeCollection ();
59 EmptyList.list = ArrayList.ReadOnly (new ArrayList ());
62 public SiteMapNodeCollection ()
66 public SiteMapNodeCollection (int capacity)
68 list = new ArrayList (capacity);
71 public SiteMapNodeCollection (SiteMapNode value)
76 public SiteMapNodeCollection (SiteMapNode[] values)
78 AddRangeInternal (values);
81 public SiteMapNodeCollection (SiteMapNodeCollection values)
83 AddRangeInternal (values);
86 internal static SiteMapNodeCollection EmptyCollection {
87 get { return EmptyList; }
92 if (list == null) list = new ArrayList ();
97 public virtual int Count {
98 get { return list == null ? 0 : list.Count; }
101 public virtual bool IsSynchronized {
102 get { return false; }
105 public virtual object SyncRoot {
109 public virtual IEnumerator GetEnumerator ()
111 return list != null ? list.GetEnumerator () : Type.EmptyTypes.GetEnumerator ();
114 public virtual void Clear ()
116 if (list != null) list.Clear ();
119 public virtual void RemoveAt (int index)
121 List.RemoveAt (index);
124 public virtual int Add (SiteMapNode value)
127 throw new ArgumentNullException ("value");
128 return this.List.Add (value);
131 public virtual void AddRange (System.Web.SiteMapNode[] value)
133 this.AddRangeInternal (value);
136 public virtual void AddRange (SiteMapNodeCollection value)
138 this.AddRangeInternal (value);
141 internal virtual void AddRangeInternal (IList value)
144 throw new ArgumentNullException ("value");
146 List.AddRange (value);
149 public virtual bool Contains (SiteMapNode value)
151 return this.List.Contains (value);
154 public virtual void CopyTo (System.Web.SiteMapNode[] array, int index)
156 this.List.CopyTo (array, index);
159 public virtual int IndexOf (SiteMapNode value)
161 return this.List.IndexOf (value);
164 public virtual void Insert (int index, SiteMapNode value)
166 this.List.Insert (index, value);
169 protected virtual void OnValidate (object value)
171 if (!(value is SiteMapNode))
172 throw new ArgumentException ("Invalid type");
175 public static SiteMapNodeCollection ReadOnly (SiteMapNodeCollection collection)
177 SiteMapNodeCollection col = new SiteMapNodeCollection ();
178 if (collection.list != null)
179 col.list = ArrayList.ReadOnly (collection.list);
181 col.list = ArrayList.ReadOnly (new ArrayList ());
185 public virtual void Remove (SiteMapNode value)
187 this.List.Remove (value);
190 public virtual IHierarchyData GetHierarchyData (object enumeratedItem)
192 return enumeratedItem as IHierarchyData;
195 public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
197 return new SiteMapDataSourceView (owner, viewName, this);
200 public SiteMapHierarchicalDataSourceView GetHierarchicalDataSourceView ()
202 return new SiteMapHierarchicalDataSourceView (this);
205 public virtual SiteMapNode this [int index] {
206 get { return (SiteMapNode) this.List [index]; }
207 set { this.List [index] = value; }
210 public virtual bool IsFixedSize {
211 get { return List.IsFixedSize; }
214 public virtual bool IsReadOnly {
215 get { return list != null && list.IsReadOnly; }
218 #region IList Members
220 object IList.this [int index] {
221 get { return List [index]; }
222 set { OnValidate (value); List [index] = value; }
225 int IList.Add (object value)
228 return List.Add (value);
231 bool IList.Contains (object value)
233 return List.Contains (value);
236 int IList.IndexOf (object value)
238 return List.IndexOf (value);
241 void IList.Insert (int index, object value)
244 List.Insert (index, value);
247 void IList.Remove (object value)
253 void ICollection.CopyTo (Array array, int index)
255 List.CopyTo (array, index);
258 void IList.Clear () {
262 bool IList.IsFixedSize {
263 get { return IsFixedSize; }
266 bool IList.IsReadOnly {
267 get { return IsReadOnly; }
270 void IList.RemoveAt (int index) {
276 #region ICollection Members
279 int ICollection.Count {
280 get { return Count; }
283 bool ICollection.IsSynchronized {
284 get { return IsSynchronized; }
287 object ICollection.SyncRoot {
288 get { return SyncRoot; }
293 #region IEnumerable Members
295 IEnumerator IEnumerable.GetEnumerator () {
296 return GetEnumerator ();
301 #region IHierarchicalEnumerable Members
303 IHierarchyData IHierarchicalEnumerable.GetHierarchyData (object enumeratedItem) {
304 return GetHierarchyData (enumeratedItem);