merge -r 61110:61111
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / MessageVector.cs
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc.  www.novell.com
4
5 * Permission is hereby granted, free of charge, to any person obtaining  a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including  without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
9 * copies of the Software, and to  permit persons to whom the Software is 
10 * furnished to do so, subject to the following conditions:
11
12 * The above copyright notice and this permission notice shall be included in 
13 * all copies or substantial portions of the Software.
14
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
23 //
24 // Novell.Directory.Ldap.MessageVector.cs
25 //
26 // Author:
27 //   Sunil Kumar (Sunilk@novell.com)
28 //
29 // (C) 2003 Novell, Inc (http://www.novell.com)
30 //
31
32 using System;
33
34 namespace Novell.Directory.Ldap
35 {
36         
37         /// <summary> The <code>MessageVector</code> class implements additional semantics
38         /// to Vector needed for handling messages.
39         /// </summary>
40         /* package */
41         class MessageVector:System.Collections.IList
42         {
43                 private readonly System.Collections.ArrayList _innerList;
44                 /// <summary>Returns an array containing all of the elements in this MessageVector.
45                 /// The elements returned are in the same order in the array as in the
46                 /// Vector.  The contents of the vector are cleared.
47                 /// 
48                 /// </summary>
49                 /// <returns> the array containing all of the elements.
50                 /// </returns>
51                 internal System.Object[] ObjectArray
52                 {
53                         /* package */
54                         
55                         get
56                         {
57                                 lock (this.SyncRoot)
58                                 {
59                                         System.Object[] results = ToArray();
60                                         Clear();
61                                         return results;
62                                 }
63                         }
64                         
65                 }
66                 /* package */
67                 internal MessageVector(int cap, int incr)
68                 {
69                         _innerList = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(cap));
70                         return ;
71                 }
72                 
73                 /// <summary> Finds the Message object with the given MsgID, and returns the Message
74                 /// object. It finds the object and returns it in an atomic operation.
75                 /// 
76                 /// </summary>
77                 /// <param name="msgId">The msgId of the Message object to return
78                 /// 
79                 /// </param>
80                 /// <returns> The Message object corresponding to this MsgId.
81                 /// 
82                 /// @throws NoSuchFieldException when no object with the corresponding
83                 /// value for the MsgId field can be found.
84                 /// </returns>
85                 /* package */
86                 internal Message findMessageById(int msgId)
87                 {
88                         lock (this.SyncRoot)
89                         {
90                                 Message msg = null;
91                                 for (int i = 0; i < Count; i++)
92                                 {
93                                         if ((msg = (Message) this[i]) == null)
94                                         {
95                                                 throw new System.FieldAccessException();
96                                         }
97                                         if (msg.MessageID == msgId)
98                                         {
99                                                 return msg;
100                                         }
101                                 }
102                                 throw new System.FieldAccessException();
103                         }
104                 }
105
106                 #region ArrayList members\r
107                 public object[] ToArray()\r
108                 {\r
109                         return _innerList.ToArray();\r
110                 }\r
111                 #endregion\r
112 \r
113                 #region IList Members\r
114 \r
115                 public int Add(object value)\r
116                 {\r
117                         return _innerList.Add(value);\r
118                 }\r
119 \r
120                 public void Clear()\r
121                 {\r
122                         _innerList.Clear();\r
123                 }\r
124 \r
125                 public bool Contains(object value)\r
126                 {\r
127                         return _innerList.Contains(value);\r
128                 }\r
129 \r
130                 public int IndexOf(object value)\r
131                 {\r
132                         return _innerList.IndexOf(value);\r
133                 }\r
134 \r
135                 public void Insert(int index, object value)\r
136                 {\r
137                         _innerList.Insert(index, value);\r
138                 }\r
139 \r
140                 public bool IsFixedSize\r
141                 {\r
142                         get { return _innerList.IsFixedSize; }\r
143                 }\r
144 \r
145                 public bool IsReadOnly\r
146                 {\r
147                         get { return _innerList.IsReadOnly; }\r
148                 }\r
149 \r
150                 public void Remove(object value)\r
151                 {\r
152                         _innerList.Remove(value);\r
153                 }\r
154 \r
155                 public void RemoveAt(int index)\r
156                 {\r
157                         _innerList.RemoveAt(index);\r
158                 }\r
159 \r
160                 public object this[int index]\r
161                 {\r
162                         get\r
163                         {\r
164                                 return _innerList[index];\r
165                         }\r
166                         set\r
167                         {\r
168                                 _innerList[index] = value;\r
169                         }\r
170                 }\r
171 \r
172                 #endregion\r
173 \r
174                 #region ICollection Members\r
175 \r
176                 public void CopyTo(Array array, int index)\r
177                 {\r
178                         _innerList.CopyTo(array, index);\r
179                 }\r
180 \r
181                 public int Count\r
182                 {\r
183                         get { return _innerList.Count; }\r
184                 }\r
185 \r
186                 public bool IsSynchronized\r
187                 {\r
188                         get { return _innerList.IsSynchronized; }\r
189                 }\r
190 \r
191                 public object SyncRoot\r
192                 {\r
193                         get { return _innerList.SyncRoot; }\r
194                 }\r
195 \r
196                 #endregion\r
197 \r
198                 #region IEnumerable Members\r
199 \r
200                 public System.Collections.IEnumerator GetEnumerator()\r
201                 {\r
202                         return _innerList.GetEnumerator();\r
203                 }\r
204 \r
205                 #endregion
206         }
207 }