1. /*
  2. * @(#)ModificationItem.java 1.4 00/02/02
  3. *
  4. * Copyright 1999, 2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming.directory;
  11. /**
  12. * This class represents a modification item.
  13. * It consists of a modification code and an attribute on which to operate.
  14. *<p>
  15. * A ModificationItem instance is not synchronized against concurrent
  16. * multithreaded access. Multiple threads trying to access and modify
  17. * a single ModificationItem instance should lock the object.
  18. *
  19. * @author Rosanna Lee
  20. * @author Scott Seligman
  21. * @version 1.4 00/02/02
  22. * @since 1.3
  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. public class ModificationItem implements java.io.Serializable {
  30. /**
  31. * Contains an integer identify the modification
  32. * to be performed.
  33. * @serial
  34. */
  35. private int mod_op;
  36. /**
  37. * Contains the attribute identifying
  38. * the attribute and/or its value to be applied for the modification.
  39. * @serial
  40. */
  41. private Attribute attr;
  42. /**
  43. * Creates a new instance of ModificationItem.
  44. * @param mod_op Modification to apply. It must be one of:
  45. * DirContext.ADD_ATTRIBUTE
  46. * DirContext.REPLACE_ATTRIBUTE
  47. * DirContext.REMOVE_ATTRIBUTE
  48. * @param attr The non-null attribute to use for modification.
  49. * @exception IllegalArgumentException If attr is null, or if mod_op is
  50. * not one of the ones specified above.
  51. */
  52. public ModificationItem(int mod_op, Attribute attr) {
  53. switch (mod_op) {
  54. case DirContext.ADD_ATTRIBUTE:
  55. case DirContext.REPLACE_ATTRIBUTE:
  56. case DirContext.REMOVE_ATTRIBUTE:
  57. if (attr == null)
  58. throw new IllegalArgumentException("Must specify non-null attribute for modification");
  59. this.mod_op = mod_op;
  60. this.attr = attr;
  61. break;
  62. default:
  63. throw new IllegalArgumentException("Invalid modification code " + mod_op);
  64. }
  65. }
  66. /**
  67. * Retrieves the modification code of this modification item.
  68. * @return The modification code. It is one of:
  69. * DirContext.ADD_ATTRIBUTE
  70. * DirContext.REPLACE_ATTRIBUTE
  71. * DirContext.REMOVE_ATTRIBUTE
  72. */
  73. public int getModificationOp() {
  74. return mod_op;
  75. }
  76. /**
  77. * Retrieves the attribute associated with this modification item.
  78. * @return The non-null attribute to use for the modification.
  79. */
  80. public Attribute getAttribute() {
  81. return attr;
  82. }
  83. /**
  84. * Generates the string representation of this modification item,
  85. * which consists of the modification operation and its related attribute.
  86. * The string representation is meant for debugging and not to be
  87. * interpreted programmatically.
  88. *
  89. * @return The non-null string representation of this modification item.
  90. */
  91. public String toString() {
  92. switch (mod_op) {
  93. case DirContext.ADD_ATTRIBUTE:
  94. return ("Add attribute: " + attr.toString());
  95. case DirContext.REPLACE_ATTRIBUTE:
  96. return ("Replace attribute: " + attr.toString());
  97. case DirContext.REMOVE_ATTRIBUTE:
  98. return ("Remove attribute: " + attr.getID().toString());
  99. }
  100. return ""; // should never happen
  101. }
  102. /**
  103. * Use serialVersionUID from JNDI 1.1.1 for interoperability
  104. */
  105. private static final long serialVersionUID = 7573258562534746850L;
  106. }