Modified Comments to Support XML Documentation
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Controls / LdapSortControl.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.Controls.LdapSortControl.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 using Novell.Directory.Ldap;
34 using Novell.Directory.Ldap.Asn1;
35
36 namespace Novell.Directory.Ldap.Controls
37 {
38         
39         /// <summary>  LdapSortControl is a Server Control to specify how search results are
40         /// to be sorted by the server. If a server does not support
41         /// sorting in general or for a particular query, the results will be
42         /// returned unsorted, along with a control indicating why they were not
43         /// sorted (or that sort controls are not supported). If the control was
44         /// marked "critical", the whole search operation will fail if the sort
45         /// control is not supported.
46         /// </summary>
47         public class LdapSortControl:LdapControl
48         {
49                 
50                 private static int ORDERING_RULE = 0;
51                 private static int REVERSE_ORDER = 1;
52                 /// <summary> The requestOID of the sort control</summary>
53                 private static System.String requestOID = "1.2.840.113556.1.4.473";
54                 
55                 /// <summary> The responseOID of the sort control</summary>
56                 private static System.String responseOID = "1.2.840.113556.1.4.474";
57                 /// <summary> Constructs a sort control with a single key.
58                 /// 
59                 /// </summary>
60                 /// <param name="key">    A sort key object, which specifies attribute,
61                 /// order, and optional matching rule.
62                 /// 
63                 /// </param>
64                 /// <param name="critical       True">if the search operation is to fail if the
65                 /// server does not support this control.
66                 /// </param>
67                 public LdapSortControl(LdapSortKey key, bool critical):this(new LdapSortKey[]{key}, critical)
68                 {
69                         return ;
70                 }
71                 
72                 /// <summary> Constructs a sort control with multiple sort keys.
73                 /// 
74                 /// </summary>
75                 /// <param name="keys           An">array of sort key objects, to be processed in
76                 /// order.
77                 /// 
78                 /// </param>
79                 /// <param name="critical       True">if the search operation is to fail if the
80                 /// server does not support this control.
81                 /// </param>
82                 public LdapSortControl(LdapSortKey[] keys, bool critical):base(requestOID, critical, null)
83                 {
84                         
85                         Asn1SequenceOf sortKeyList = new Asn1SequenceOf();
86                         
87                         for (int i = 0; i < keys.Length; i++)
88                         {
89                                 
90                                 Asn1Sequence key = new Asn1Sequence();
91                                 
92                                 key.add(new Asn1OctetString(keys[i].Key));
93                                 
94                                 if ((System.Object) keys[i].MatchRule != null)
95                                 {
96                                         key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, ORDERING_RULE), new Asn1OctetString(keys[i].MatchRule), false));
97                                 }
98                                 
99                                 if (keys[i].Reverse == true)
100                                 {
101                                         // only add if true
102                                         key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, REVERSE_ORDER), new Asn1Boolean(true), false));
103                                 }
104                                 
105                                 sortKeyList.add(key);
106                         }
107                         
108                         setValue(sortKeyList.getEncoding(new LBEREncoder()));
109                         return ;
110                 }
111                 static LdapSortControl()
112                 {
113                         /*
114                         * This is where we register the control responses
115                         */
116                         {
117                                 /*
118                                 * Register the Server Sort Control class which is returned by the
119                                 * server in response to a Sort Request
120                                 */
121                                 try
122                                 {
123                                         LdapControl.register(responseOID, System.Type.GetType("Novell.Directory.Ldap.Controls.LdapSortResponse"));
124                                 }
125                                 catch (System.Exception e)
126                                 {
127                                 }
128                         }
129                 }
130         }
131 }