System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / System / System.Net / HttpListenerPrefixCollection.cs
1 //
2 // System.Net.HttpListenerPrefixCollection.cs
3 //
4 // Author:
5 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
6 //
7 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 #if NET_2_0 && SECURITY_DEP || EMBEDDED_IN_1_0
29
30 using System.Collections;
31 using System.Collections.Generic;
32 namespace System.Net {
33 #if EMBEDDED_IN_1_0
34         public class HttpListenerPrefixCollection : IEnumerable, ICollection {
35                 ArrayList prefixes;
36                 
37 #else
38         public class HttpListenerPrefixCollection : ICollection<string>, IEnumerable<string>, IEnumerable {
39                 List<string> prefixes = new List<string> ();
40 #endif
41                 HttpListener listener;
42
43                 internal HttpListenerPrefixCollection (HttpListener listener)
44                 {
45                         this.listener = listener;
46                 }
47
48                 public int Count {
49                         get { return prefixes.Count; }
50                 }
51
52                 public bool IsReadOnly {
53                         get { return false; }
54                 }
55
56                 public bool IsSynchronized {
57                         get { return false; }
58                 }
59
60                 public void Add (string uriPrefix)
61                 {
62                         listener.CheckDisposed ();
63                         ListenerPrefix.CheckUri (uriPrefix);
64                         if (prefixes.Contains (uriPrefix))
65                                 return;
66
67                         prefixes.Add (uriPrefix);
68                         if (listener.IsListening)
69                                 EndPointManager.AddPrefix (uriPrefix, listener);
70                 }
71
72                 public void Clear ()
73                 {
74                         listener.CheckDisposed ();
75                         prefixes.Clear ();
76                         if (listener.IsListening)
77                                 EndPointManager.RemoveListener (listener);
78                 }
79
80                 public bool Contains (string uriPrefix)
81                 {
82                         listener.CheckDisposed ();
83                         return prefixes.Contains (uriPrefix);
84                 }
85
86                 public void CopyTo (string [] array, int offset)
87                 {
88                         listener.CheckDisposed ();
89                         prefixes.CopyTo (array, offset);
90                 }
91
92                 public void CopyTo (Array array, int offset)
93                 {
94                         listener.CheckDisposed ();
95                         ((ICollection) prefixes).CopyTo (array, offset);
96                 }
97
98 #if !EMBEDDED_IN_1_0
99                 public IEnumerator<string> GetEnumerator ()
100                 {
101                         return prefixes.GetEnumerator ();
102                 }
103 #endif
104         
105                 IEnumerator IEnumerable.GetEnumerator ()
106                 {
107                         return prefixes.GetEnumerator ();
108                 }
109
110                 public bool Remove (string uriPrefix)
111                 {
112                         listener.CheckDisposed ();
113                         if (uriPrefix == null)
114                                 throw new ArgumentNullException ("uriPrefix");
115
116                         bool result = prefixes.Remove (uriPrefix);
117                         if (result && listener.IsListening)
118                                 EndPointManager.RemovePrefix (uriPrefix, listener);
119
120                         return result;
121                 }
122         }
123 }
124 #endif
125