KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > naming > directory > ModificationItem


1 /*
2  * @(#)ModificationItem.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.naming.directory;
9
10 /**
11   * This class represents a modification item.
12   * It consists of a modification code and an attribute on which to operate.
13   *<p>
14   * A ModificationItem instance is not synchronized against concurrent
15   * multithreaded access. Multiple threads trying to access and modify
16   * a single ModificationItem instance should lock the object.
17   *
18   * @author Rosanna Lee
19   * @author Scott Seligman
20   * @version 1.8 03/12/19
21   * @since 1.3
22   */

23
24 /*
25   *<p>
26   * The serialized form of a ModificationItem object consists of the
27   * modification op (and int) and the corresponding Attribute.
28 */

29
30 public class ModificationItem implements java.io.Serializable JavaDoc {
31     /**
32      * Contains an integer identify the modification
33      * to be performed.
34      * @serial
35      */

36     private int mod_op;
37     /**
38      * Contains the attribute identifying
39      * the attribute and/or its value to be applied for the modification.
40      * @serial
41      */

42     private Attribute JavaDoc attr;
43
44     /**
45       * Creates a new instance of ModificationItem.
46       * @param mod_op Modification to apply. It must be one of:
47       * DirContext.ADD_ATTRIBUTE
48       * DirContext.REPLACE_ATTRIBUTE
49       * DirContext.REMOVE_ATTRIBUTE
50       * @param attr The non-null attribute to use for modification.
51       * @exception IllegalArgumentException If attr is null, or if mod_op is
52       * not one of the ones specified above.
53       */

54     public ModificationItem(int mod_op, Attribute JavaDoc attr) {
55     switch (mod_op) {
56     case DirContext.ADD_ATTRIBUTE:
57     case DirContext.REPLACE_ATTRIBUTE:
58     case DirContext.REMOVE_ATTRIBUTE:
59         if (attr == null)
60         throw new IllegalArgumentException JavaDoc("Must specify non-null attribute for modification");
61         
62         this.mod_op = mod_op;
63         this.attr = attr;
64         break;
65
66     default:
67         throw new IllegalArgumentException JavaDoc("Invalid modification code " + mod_op);
68     }
69     }
70
71     /**
72       * Retrieves the modification code of this modification item.
73       * @return The modification code. It is one of:
74       * DirContext.ADD_ATTRIBUTE
75       * DirContext.REPLACE_ATTRIBUTE
76       * DirContext.REMOVE_ATTRIBUTE
77       */

78     public int getModificationOp() {
79     return mod_op;
80     }
81
82     /**
83       * Retrieves the attribute associated with this modification item.
84       * @return The non-null attribute to use for the modification.
85       */

86     public Attribute JavaDoc getAttribute() {
87     return attr;
88     }
89
90     /**
91       * Generates the string representation of this modification item,
92       * which consists of the modification operation and its related attribute.
93       * The string representation is meant for debugging and not to be
94       * interpreted programmatically.
95       *
96       * @return The non-null string representation of this modification item.
97       */

98     public String JavaDoc toString() {
99     switch (mod_op) {
100     case DirContext.ADD_ATTRIBUTE:
101         return ("Add attribute: " + attr.toString());
102         
103     case DirContext.REPLACE_ATTRIBUTE:
104         return ("Replace attribute: " + attr.toString());
105
106     case DirContext.REMOVE_ATTRIBUTE:
107         return ("Remove attribute: " + attr.toString());
108     }
109     return ""; // should never happen
110
}
111
112     /**
113      * Use serialVersionUID from JNDI 1.1.1 for interoperability
114      */

115     private static final long serialVersionUID = 7573258562534746850L;
116 }
117
118
Popular Tags