01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.org
04: * Distributable under LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package javax.management;
09:
10: import java.io.Serializable;
11: import javax.management.RuntimeOperationsException;
12:
13: /**
14: * Represents an MBean attribute by associating its name with its value.
15: * The MBean server and other objects use this class to get and set attributes values.
16: *
17: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
18: */
19:
20: public class Attribute implements Serializable {
21:
22: private String name = null;
23:
24: private Object value = null;
25:
26: /**
27: * Constructs an Attribute object which associates the given attribute name with the given value.
28: *
29: * @param name A String containing the name of the attribute to be created. Cannot be null.
30: * @param value The Object which is assigned to the attribute. This object must be of the same type as the attribute. Cannot be null.
31: *
32: */
33: public Attribute(String name, Object value) {
34: if (name == null) {
35: throw new RuntimeOperationsException(
36: new IllegalArgumentException(
37: "Attribute name cannot be null "));
38: }
39: this .name = name;
40: this .value = value;
41: }
42:
43: /**
44: * Returns a String containing the name of the attribute.
45: */
46: public String getName() {
47: return name;
48: }
49:
50: /**
51: * Returns an Object that is the value of this attribute.
52: */
53: public Object getValue() {
54: return value;
55: }
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:
65: public boolean equals(Object object) {
66: if (!(object instanceof Attribute)) {
67: return false;
68: }
69: Attribute val = (Attribute) object;
70:
71: if (value == null) {
72: if (val.getValue() == null) {
73: return name.equals(val.getName());
74: } else {
75: return false;
76: }
77: }
78:
79: return ((name.equals(val.getName())) && (value.equals(val
80: .getValue())));
81: }
82:
83: }
|