1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapAddRequest.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using Novell
.Directory
.Ldap
.Asn1
;
34 using Novell
.Directory
.Ldap
.Rfc2251
;
35 namespace Novell
.Directory
.Ldap
38 /// <summary> Represents an Ldap Add Request.
41 /// <seealso cref="LdapConnection.SendRequest">
44 * AddRequest ::= [APPLICATION 8] SEQUENCE {
46 * attributes AttributeList }
48 public class LdapAddRequest
:LdapMessage
50 /// <summary> Constructs an LdapEntry that represents the add request
53 /// <returns> an LdapEntry that represents the add request.
55 virtual public LdapEntry Entry
59 RfcAddRequest addreq
= (RfcAddRequest
) Asn1Object
.getRequest();
61 LdapAttributeSet attrs
= new LdapAttributeSet();
63 // Build the list of attributes
64 Asn1Object
[] seqArray
= addreq
.Attributes
.toArray();
65 for (int i
= 0; i
< seqArray
.Length
; i
++)
67 RfcAttributeTypeAndValues seq
= (RfcAttributeTypeAndValues
) seqArray
[i
];
68 LdapAttribute attr
= new LdapAttribute(((Asn1OctetString
) seq
.get_Renamed(0)).stringValue());
70 // Add the values to the attribute
71 Asn1SetOf set_Renamed
= (Asn1SetOf
) seq
.get_Renamed(1);
72 System
.Object
[] setArray
= set_Renamed
.toArray();
73 for (int j
= 0; j
< setArray
.Length
; j
++)
75 attr
.addValue(((Asn1OctetString
) setArray
[j
]).byteValue());
80 return new LdapEntry(Asn1Object
.RequestDN
, attrs
);
84 /// <summary> Constructs a request to add an entry to the directory.
87 /// <param name="entry">The LdapEntry to add to the directory.
90 /// <param name="cont">Any controls that apply to the add request,
93 public LdapAddRequest(LdapEntry entry
, LdapControl
[] cont
):base(LdapMessage
.ADD_REQUEST
, new RfcAddRequest(new RfcLdapDN(entry
.DN
), makeRfcAttrList(entry
)), cont
)
98 /// <summary> Build the attribuite list from an LdapEntry.
101 /// <param name="entry">The LdapEntry associated with this add request.
103 private static RfcAttributeList
makeRfcAttrList(LdapEntry entry
)
105 // convert Java-API LdapEntry to RFC2251 AttributeList
106 LdapAttributeSet attrSet
= entry
.getAttributeSet();
107 RfcAttributeList attrList
= new RfcAttributeList(attrSet
.Count
);
108 System
.Collections
.IEnumerator itr
= attrSet
.GetEnumerator();
109 while (itr
.MoveNext())
111 LdapAttribute attr
= (LdapAttribute
) itr
.Current
;
112 Asn1SetOf vals
= new Asn1SetOf(attr
.size());
113 System
.Collections
.IEnumerator attrEnum
= attr
.ByteValues
;
114 while (attrEnum
.MoveNext())
116 vals
.add(new RfcAttributeValue((sbyte[]) attrEnum
.Current
));
118 attrList
.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr
.Name
), vals
));
123 /// <summary> Return an Asn1 representation of this add request.
125 /// #return an Asn1 representation of this object.
127 public override System
.String
ToString()
129 return Asn1Object
.ToString();