|
1 /* |
|
2 * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package javax.naming.directory; |
|
27 |
|
28 /** |
|
29 * This class represents a modification item. |
|
30 * It consists of a modification code and an attribute on which to operate. |
|
31 *<p> |
|
32 * A ModificationItem instance is not synchronized against concurrent |
|
33 * multithreaded access. Multiple threads trying to access and modify |
|
34 * a single ModificationItem instance should lock the object. |
|
35 * |
|
36 * @author Rosanna Lee |
|
37 * @author Scott Seligman |
|
38 * @since 1.3 |
|
39 */ |
|
40 |
|
41 /* |
|
42 *<p> |
|
43 * The serialized form of a ModificationItem object consists of the |
|
44 * modification op (and int) and the corresponding Attribute. |
|
45 */ |
|
46 |
|
47 public class ModificationItem implements java.io.Serializable { |
|
48 /** |
|
49 * Contains an integer identify the modification |
|
50 * to be performed. |
|
51 * @serial |
|
52 */ |
|
53 private int mod_op; |
|
54 /** |
|
55 * Contains the attribute identifying |
|
56 * the attribute and/or its value to be applied for the modification. |
|
57 * @serial |
|
58 */ |
|
59 private Attribute attr; |
|
60 |
|
61 /** |
|
62 * Creates a new instance of ModificationItem. |
|
63 * @param mod_op Modification to apply. It must be one of: |
|
64 * DirContext.ADD_ATTRIBUTE |
|
65 * DirContext.REPLACE_ATTRIBUTE |
|
66 * DirContext.REMOVE_ATTRIBUTE |
|
67 * @param attr The non-null attribute to use for modification. |
|
68 * @exception IllegalArgumentException If attr is null, or if mod_op is |
|
69 * not one of the ones specified above. |
|
70 */ |
|
71 public ModificationItem(int mod_op, Attribute attr) { |
|
72 switch (mod_op) { |
|
73 case DirContext.ADD_ATTRIBUTE: |
|
74 case DirContext.REPLACE_ATTRIBUTE: |
|
75 case DirContext.REMOVE_ATTRIBUTE: |
|
76 if (attr == null) |
|
77 throw new IllegalArgumentException("Must specify non-null attribute for modification"); |
|
78 |
|
79 this.mod_op = mod_op; |
|
80 this.attr = attr; |
|
81 break; |
|
82 |
|
83 default: |
|
84 throw new IllegalArgumentException("Invalid modification code " + mod_op); |
|
85 } |
|
86 } |
|
87 |
|
88 /** |
|
89 * Retrieves the modification code of this modification item. |
|
90 * @return The modification code. It is one of: |
|
91 * DirContext.ADD_ATTRIBUTE |
|
92 * DirContext.REPLACE_ATTRIBUTE |
|
93 * DirContext.REMOVE_ATTRIBUTE |
|
94 */ |
|
95 public int getModificationOp() { |
|
96 return mod_op; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Retrieves the attribute associated with this modification item. |
|
101 * @return The non-null attribute to use for the modification. |
|
102 */ |
|
103 public Attribute getAttribute() { |
|
104 return attr; |
|
105 } |
|
106 |
|
107 /** |
|
108 * Generates the string representation of this modification item, |
|
109 * which consists of the modification operation and its related attribute. |
|
110 * The string representation is meant for debugging and not to be |
|
111 * interpreted programmatically. |
|
112 * |
|
113 * @return The non-null string representation of this modification item. |
|
114 */ |
|
115 public String toString() { |
|
116 switch (mod_op) { |
|
117 case DirContext.ADD_ATTRIBUTE: |
|
118 return ("Add attribute: " + attr.toString()); |
|
119 |
|
120 case DirContext.REPLACE_ATTRIBUTE: |
|
121 return ("Replace attribute: " + attr.toString()); |
|
122 |
|
123 case DirContext.REMOVE_ATTRIBUTE: |
|
124 return ("Remove attribute: " + attr.toString()); |
|
125 } |
|
126 return ""; // should never happen |
|
127 } |
|
128 |
|
129 /** |
|
130 * Use serialVersionUID from JNDI 1.1.1 for interoperability |
|
131 */ |
|
132 private static final long serialVersionUID = 7573258562534746850L; |
|
133 } |