Path: blob/master/src/java.naming/share/classes/javax/naming/directory/ModificationItem.java
41159 views
/*1* Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.directory;2627/**28* This class represents a modification item.29* It consists of a modification code and an attribute on which to operate.30*<p>31* A ModificationItem instance is not synchronized against concurrent32* multithreaded access. Multiple threads trying to access and modify33* a single ModificationItem instance should lock the object.34*35* @author Rosanna Lee36* @author Scott Seligman37* @since 1.338*/3940/*41*<p>42* The serialized form of a ModificationItem object consists of the43* modification op (and int) and the corresponding Attribute.44*/4546public class ModificationItem implements java.io.Serializable {47/**48* Contains an integer identify the modification49* to be performed.50* @serial51*/52private int mod_op;53/**54* Contains the attribute identifying55* the attribute and/or its value to be applied for the modification.56* @serial57*/58private Attribute attr;5960/**61* Creates a new instance of ModificationItem.62* @param mod_op Modification to apply. It must be one of:63* DirContext.ADD_ATTRIBUTE64* DirContext.REPLACE_ATTRIBUTE65* DirContext.REMOVE_ATTRIBUTE66* @param attr The non-null attribute to use for modification.67* @exception IllegalArgumentException If attr is null, or if mod_op is68* not one of the ones specified above.69*/70public ModificationItem(int mod_op, Attribute attr) {71switch (mod_op) {72case DirContext.ADD_ATTRIBUTE:73case DirContext.REPLACE_ATTRIBUTE:74case DirContext.REMOVE_ATTRIBUTE:75if (attr == null)76throw new IllegalArgumentException("Must specify non-null attribute for modification");7778this.mod_op = mod_op;79this.attr = attr;80break;8182default:83throw new IllegalArgumentException("Invalid modification code " + mod_op);84}85}8687/**88* Retrieves the modification code of this modification item.89* @return The modification code. It is one of:90* DirContext.ADD_ATTRIBUTE91* DirContext.REPLACE_ATTRIBUTE92* DirContext.REMOVE_ATTRIBUTE93*/94public int getModificationOp() {95return mod_op;96}9798/**99* Retrieves the attribute associated with this modification item.100* @return The non-null attribute to use for the modification.101*/102public Attribute getAttribute() {103return attr;104}105106/**107* Generates the string representation of this modification item,108* which consists of the modification operation and its related attribute.109* The string representation is meant for debugging and not to be110* interpreted programmatically.111*112* @return The non-null string representation of this modification item.113*/114public String toString() {115switch (mod_op) {116case DirContext.ADD_ATTRIBUTE:117return ("Add attribute: " + attr.toString());118119case DirContext.REPLACE_ATTRIBUTE:120return ("Replace attribute: " + attr.toString());121122case DirContext.REMOVE_ATTRIBUTE:123return ("Remove attribute: " + attr.toString());124}125return ""; // should never happen126}127128/**129* Use serialVersionUID from JNDI 1.1.1 for interoperability130*/131private static final long serialVersionUID = 7573258562534746850L;132}133134135