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