Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/client/opers/JDAPAddRequest.java

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is mozilla.org code.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38 package org.ietf.ldap.client.opers;
39
40 import org.ietf.ldap.LDAPAttribute;
41 import org.ietf.ldap.ber.stream.BERElement;
42 import org.ietf.ldap.ber.stream.BEROctetString;
43 import org.ietf.ldap.ber.stream.BERSequence;
44 import org.ietf.ldap.ber.stream.BERTag;
45
46 /**
47 * This class implements the add request. This object
48 * is sent to the ldap server.
49 * <P>See RFC 1777.
50 *
51 * <pre>
52 * AddRequest ::= [APPLICATION 8] SEQUENCE {
53 * entry LDAPDN,
54 * attrs SEQUENCE OF SEQUENCE {
55 * type AttributeType,
56 * values SET OF AttributeValue
57 * }
58 * }
59 * </pre>
60 *
61 * @version 1.0
62 */
63 public class JDAPAddRequest extends JDAPBaseDNRequest
64 implements JDAPProtocolOp {
65 /**
66 * Internal variables
67 */
68 protected String m_dn = null;
69 protected LDAPAttribute m_attrs[] = null;
70
71 /**
72 * Constructs add request.
73 * @param dn distinguished name of adding entry
74 * @param attrs list of attribute associated with entry
75 */
76 public JDAPAddRequest(String dn, LDAPAttribute attrs[]) {
77 m_dn = dn;
78 m_attrs = attrs;
79 }
80
81 /**
82 * Retrieves protocol operation type.
83 * @return protcol type
84 */
85 public int getType() {
86 return JDAPProtocolOp.ADD_REQUEST;
87 }
88
89 /**
90 * Sets the base dn component.
91 * @param basedn base dn
92 */
93 public void setBaseDN(String basedn) {
94 m_dn = basedn;
95 }
96
97 /**
98 * Gets the base dn component.
99 * @return base dn
100 */
101 public String getBaseDN() {
102 return m_dn;
103 }
104
105 /**
106 * Gets the ber representation of add request.
107 * @return ber representation of request
108 */
109 public BERElement getBERElement() {
110 /* Assumed that adding cn=patrick,o=ncware,c=ca with
111 * following attributes:
112 * cn: patrick
113 * title: programmer
114 * [*] umich-ldap-v3.3:
115 * 0x68 0x46 ([APPLICATION8])
116 * 0x04 0x1a c n = p a t r i c k , 0x20
117 * o = n c w a r e , 0x20 c =
118 * c a (entry - OctetString)
119 * 0x30 0x28 (SEQUENCE)
120 * 0x30 0x0f (SEQUENCE)
121 * 0x04 0x02 c n (attribute type - OctetString)
122 * 0x31 0x09 (SET OF)
123 * 0x04 0x07 p a t r i c k (attribute value - OctetString)
124 * 0x30 0x15
125 * 0x04 0x05 t i t l e
126 * 0x31 0x0c (SET OF)
127 * 0x04 0x0a p r o g r a m m e r
128 */
129 BERSequence seq = new BERSequence();
130 seq.addElement(new BEROctetString (m_dn));
131 BERSequence attrs_list = new BERSequence();
132 for (int i = 0; i < m_attrs.length; i++) {
133 attrs_list.addElement(m_attrs[i].getBERElement());
134 }
135 seq.addElement(attrs_list);
136 BERTag element = new BERTag(BERTag.APPLICATION|BERTag.CONSTRUCTED|8,
137 seq, true);
138 return element;
139 }
140
141 /**
142 * Retrieves the string representation of add request parameters.
143 * @return string representation of add request parameters
144 */
145 public String getParamString() {
146 String s = "";
147 for (int i = 0; i < m_attrs.length; i++) {
148 if (i != 0)
149 s = s + " ";
150 s = s + m_attrs[i].toString();
151 }
152 return "{entry='" + m_dn + "', attrs='" + s + "'}";
153 }
154
155 /**
156 * Retrieves the string representation of add request.
157 * @return string representation of add request
158 */
159 public String toString() {
160 return "AddRequest " + getParamString();
161 }
162 }