New test.
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Utilclass / RespControlVector.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.Utilclass.RespControlVector.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.Utilclass
35 {
36         
37         /// <summary> The <code>MessageVector</code> class implements extends the
38         /// existing Vector class so that it can be used to maintain a
39         /// list of currently registered control responses.
40         /// </summary>
41         public class RespControlVector:System.Collections.ArrayList
42         {
43                 public RespControlVector(int cap, int incr):base(cap)
44                 {
45                         return ;
46                 }
47                 
48                 /// <summary>Inner class defined to create a temporary object to encapsulate
49                 /// all registration information about a response control.  This class
50                 /// cannot be used outside this class 
51                 /// </summary>
52                 private class RegisteredControl
53                 {
54                         private void  InitBlock(RespControlVector enclosingInstance)
55                         {
56                                 this.enclosingInstance = enclosingInstance;
57                         }
58                         private RespControlVector enclosingInstance;
59                         public RespControlVector Enclosing_Instance
60                         {
61                                 get
62                                 {
63                                         return enclosingInstance;
64                                 }
65                                 
66                         }
67                         public System.String myOID;
68                         public System.Type myClass;
69                         
70                         public RegisteredControl(RespControlVector enclosingInstance, System.String oid, System.Type controlClass)
71                         {
72                                 InitBlock(enclosingInstance);
73                                 myOID = oid;
74                                 myClass = controlClass;
75                         }
76                 }
77                 
78                 /* Adds a control to the current list of registered response controls.
79                 *
80                 */
81                 public void  registerResponseControl(System.String oid, System.Type controlClass)
82                 {
83                         lock (this)
84                         {
85                                 
86                                 Add(new RegisteredControl(this, oid, controlClass));
87                         }
88                 }
89                 
90                 /* Searches the list of registered controls for a mathcing control.  We
91                 * search using the OID string.  If a match is found we return the
92                 * Class name that was provided to us on registration.
93                 */
94                 public System.Type findResponseControl(System.String searchOID)
95                 {
96                         lock (this)
97                         {
98                                 RegisteredControl ctl = null;
99                                 
100                                 /* loop through the contents of the vector */
101                                 for (int i = 0; i < Count; i++)
102                                 {
103                                         
104                                         /* Get next registered control */
105                                         if ((ctl = (RegisteredControl) this[i]) == null)
106                                         {
107                                                 throw new System.FieldAccessException();
108                                         }
109                                         
110                                         /* Does the stored OID match with whate we are looking for */
111                                         if (ctl.myOID.CompareTo(searchOID) == 0)
112                                         {
113                                                 
114                                                 
115                                                 /* Return the class name if we have match */
116                                                 return ctl.myClass;
117                                         }
118                                 }
119                                 /* The requested control does not have a registered response class */
120                                 return null;
121                         }
122                 }
123         }
124 }