Debian Codegraph @

java-sdk/ietfldap/org/ietf/ldap/LDAPModification.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) 2001
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;
39
40 import java.io.Serializable;
41
42 import org.ietf.ldap.ber.stream.BERElement;
43 import org.ietf.ldap.ber.stream.BEREnumerated;
44 import org.ietf.ldap.ber.stream.BERSequence;
45
46 /**
47 * Specifies changes to be made to the values of an attribute. The change is
48 * specified in terms of the following aspects:
49 * <P>
50 *
51 * <UL>
52 * <LI>the type of modification (add, replace, or delete the value of an attribute)
53 * <LI>the type of value being modified (string or binary)
54 * <LI>the name of the attribute being modified
55 * <LI>the actual value
56 * </UL>
57 * <P>
58 *
59 * After you specify a change to an attribute, you can execute the change
60 * by calling the <CODE>LDAPConnection.modify</CODE> method and specifying
61 * the DN of the entry that you want to modify.
62 * <P>
63 *
64 * @version 1.0
65 * @see org.ietf.ldap.LDAPConnection#modify(java.lang.String, org.ietf.ldap.LDAPModification)
66 */
67 public class LDAPModification implements Serializable {
68
69 static final long serialVersionUID = 4836472112866826595L;
70
71 /**
72 * Specifies that a value should be added to an attribute.
73 */
74 public static final int ADD = 0;
75
76 /**
77 * Specifies that a value should be removed from an attribute.
78 */
79 public static final int DELETE = 1;
80
81 /**
82 * Specifies that a value should replace the existing value in an attribute.
83 */
84 public static final int REPLACE = 2;
85
86 /**
87 * Internal variables
88 */
89 private int operation;
90 private LDAPAttribute attribute;
91
92 /**
93 * Specifies a modification to be made to an attribute.
94 * @param op the type of modification to make. This can be one of the following:
95 * <P>
96 * <UL>
97 * <LI><CODE>LDAPModification.ADD</CODE> (the value should be added to the attribute)
98 * <LI><CODE>LDAPModification.DELETE</CODE> (the value should be removed from the attribute)
99 * <LI><CODE>LDAPModification.REPLACE</CODE> (the value should replace the existing value of the attribute)
100 * </UL><P>
101 * @param attr the attribute (possibly with values) to modify
102 * @see org.ietf.ldap.LDAPAttribute
103 */
104 public LDAPModification( int op, LDAPAttribute attr ) {
105 operation = op;
106 attribute = attr;
107 }
108
109 /**
110 * Returns the attribute (possibly with values) to be modified.
111 * @return the attribute to be modified.
112 * @see org.ietf.ldap.LDAPAttribute
113 */
114 public LDAPAttribute getAttribute() {
115 return attribute;
116 }
117
118 /**
119 * Returns the type of modification specified by this object.
120 * @return one of the following types of modifications:
121 * <P>
122 * <UL>
123 * <LI><CODE>LDAPModification.ADD</CODE> (the value should be added to the attribute)
124 * <LI><CODE>LDAPModification.DELETE</CODE> (the value should be removed from the attribute)
125 * <LI><CODE>LDAPModification.REPLACE</CODE> (the value should replace the existing value of the attribute)
126 * </UL><P>
127 */
128 public int getOp() {
129 return operation;
130 }
131
132 /**
133 * Retrieves the BER (Basic Encoding Rules) representation
134 * of the current modification.
135 * @return BER representation of the modification.
136 */
137 public BERElement getBERElement() {
138 BERSequence seq = new BERSequence();
139 seq.addElement(new BEREnumerated(operation));
140 seq.addElement(attribute.getBERElement());
141 return seq;
142 }
143
144 /**
145 * Retrieves the string representation of the current
146 * modification. For example:
147 *
148 * <PRE>
149 * LDAPModification: REPLACE, LDAPAttribute {type='mail', values='[email protected]'}
150 * LDAPModification: ADD, LDAPAttribute {type='description', values='This entry was modified with the modattrs program'}
151 * </PRE>
152 *
153 * @return string representation of the current modification.
154 */
155 public String toString() {
156 String s = "LDAPModification: ";
157 if ( operation == ADD )
158 s += "ADD, ";
159 else if ( operation == DELETE )
160 s += "DELETE, ";
161 else if ( operation == REPLACE )
162 s += "REPLACE, ";
163 else
164 s += "INVALID OP, ";
165 s += attribute;
166 return s;
167 }
168 }