1. /*
  2. * @(#)Attribute.java 4.22 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. package javax.management;
  8. // java import
  9. import java.io.Serializable;
  10. /**
  11. * Represents an MBean attribute by associating its name with its value.
  12. * The MBean server and other objects use this class to get and set attributes values.
  13. *
  14. * @since 1.5
  15. */
  16. public class Attribute implements Serializable {
  17. /* Serial version */
  18. private static final long serialVersionUID = 2484220110589082382L;
  19. /**
  20. * @serial Attribute name.
  21. */
  22. private String name;
  23. /**
  24. * @serial Attribute value
  25. */
  26. private Object value= null;
  27. /**
  28. * Constructs an Attribute object which associates the given attribute name with the given value.
  29. *
  30. * @param name A String containing the name of the attribute to be created. Cannot be null.
  31. * @param value The Object which is assigned to the attribute. This object must be of the same type as the attribute.
  32. *
  33. */
  34. public Attribute(String name, Object value) {
  35. if (name == null) {
  36. throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null "));
  37. }
  38. this.name = name;
  39. this.value = value;
  40. }
  41. /**
  42. * Returns a String containing the name of the attribute.
  43. *
  44. * @return the name of the attribute.
  45. */
  46. public String getName() {
  47. return name;
  48. }
  49. /**
  50. * Returns an Object that is the value of this attribute.
  51. *
  52. * @return the value of the attribute.
  53. */
  54. public Object getValue() {
  55. return value;
  56. }
  57. /**
  58. * Compares the current Attribute Object with another Attribute Object.
  59. *
  60. * @param object The Attribute that the current Attribute is to be compared with.
  61. *
  62. * @return True if the two Attribute objects are equal, otherwise false.
  63. */
  64. public boolean equals(Object object) {
  65. if (!(object instanceof Attribute)) {
  66. return false;
  67. }
  68. Attribute val = (Attribute) object;
  69. if (value == null) {
  70. if (val.getValue() == null) {
  71. return name.equals(val.getName());
  72. } else {
  73. return false;
  74. }
  75. }
  76. return ((name.equals(val.getName())) &&
  77. (value.equals(val.getValue())));
  78. }
  79. }