[xbuild] Implements property functions using constructor syntax. Fixes #12999
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapSearchResult.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.LdapSearchResult.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.Asn1;
34 using Novell.Directory.Ldap.Rfc2251;
35
36 namespace Novell.Directory.Ldap
37 {
38         
39         /// <summary>  Encapsulates a single search result that is in response to an asynchronous
40         /// search operation.
41         /// </summary>
42         /// <seealso cref="LdapConnection.Search">
43         /// </seealso>
44         public class LdapSearchResult:LdapMessage
45         {
46                 /// <summary> Returns the entry of a server's search response.
47                 /// 
48                 /// </summary>
49                 /// <returns> The LdapEntry associated with this LdapSearchResult
50                 /// </returns>
51                 virtual public LdapEntry Entry
52                 {
53                         get
54                         {
55                                 if (entry == null)
56                                 {
57                                         LdapAttributeSet attrs = new LdapAttributeSet();
58                                         
59                                         Asn1Sequence attrList = ((RfcSearchResultEntry) message.Response).Attributes;
60                                         
61                                         Asn1Object[] seqArray = attrList.toArray();
62                                         for (int i = 0; i < seqArray.Length; i++)
63                                         {
64                                                 Asn1Sequence seq = (Asn1Sequence) seqArray[i];
65                                                 LdapAttribute attr = new LdapAttribute(((Asn1OctetString) seq.get_Renamed(0)).stringValue());
66                                                 
67                                                 Asn1Set set_Renamed = (Asn1Set) seq.get_Renamed(1);
68                                                 System.Object[] setArray = set_Renamed.toArray();
69                                                 for (int j = 0; j < setArray.Length; j++)
70                                                 {
71                                                         attr.addValue(((Asn1OctetString) setArray[j]).byteValue());
72                                                 }
73                                                 attrs.Add(attr);
74                                         }
75                                         
76                                         entry = new LdapEntry(((RfcSearchResultEntry) message.Response).ObjectName.stringValue(), attrs);
77                                 }
78                                 return entry;
79                         }
80                         
81                 }
82                 
83                 private LdapEntry entry = null;
84                 
85                 /// <summary> Constructs an LdapSearchResult object.
86                 /// 
87                 /// </summary>
88                 /// <param name="message">The RfcLdapMessage with a search result.
89                 /// </param>
90                 /*package*/
91                 internal LdapSearchResult(RfcLdapMessage message):base(message)
92                 {
93                         return ;
94                 }
95                 
96                 /// <summary> Constructs an LdapSearchResult object from an LdapEntry.
97                 /// 
98                 /// </summary>
99                 /// <param name="entry">the LdapEntry represented by this search result.
100                 /// 
101                 /// </param>
102                 /// <param name="cont">controls associated with the search result
103                 /// </param>
104                 public LdapSearchResult(LdapEntry entry, LdapControl[] cont):base()
105                 {
106                         if (entry == null)
107                         {
108                                 throw new System.ArgumentException("Argument \"entry\" cannot be null");
109                         }
110                         this.entry = entry;
111                         return ;
112                 }
113                 
114                 /// <summary> Return a String representation of this object.
115                 /// 
116                 /// </summary>
117                 /// <returns> a String representing this object.
118                 /// </returns>
119                 public override System.String ToString()
120                 {
121                         System.String str;
122                         if (entry == null)
123                         {
124                                 str = base.ToString();
125                         }
126                         else
127                         {
128                                 str = entry.ToString();
129                         }
130                         return str;
131                 }
132         }
133 }