KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > Attribute


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
8 package javax.management;
9
10
11 // java import
12
import java.io.Serializable JavaDoc;
13
14
15 /**
16  * Represents an MBean attribute by associating its name with its value.
17  * The MBean server and other objects use this class to get and set attributes values.
18  *
19  * @since 1.5
20  */

21 public class Attribute implements Serializable JavaDoc {
22
23     /* Serial version */
24     private static final long serialVersionUID = 2484220110589082382L;
25     
26     /**
27      * @serial Attribute name.
28      */

29     private String JavaDoc name;
30     
31     /**
32      * @serial Attribute value
33      */

34     private Object JavaDoc value= null;
35
36
37     /**
38      * Constructs an Attribute object which associates the given attribute name with the given value.
39      *
40      * @param name A String containing the name of the attribute to be created. Cannot be null.
41      * @param value The Object which is assigned to the attribute. This object must be of the same type as the attribute.
42      *
43      */

44     public Attribute(String JavaDoc name, Object JavaDoc value) {
45
46     if (name == null) {
47         throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc("Attribute name cannot be null "));
48     }
49
50     this.name = name;
51     this.value = value;
52     }
53
54
55     /**
56      * Returns a String containing the name of the attribute.
57      *
58      * @return the name of the attribute.
59      */

60     public String JavaDoc getName() {
61     return name;
62     }
63     
64     /**
65      * Returns an Object that is the value of this attribute.
66      *
67      * @return the value of the attribute.
68      */

69     public Object JavaDoc getValue() {
70     return value;
71     }
72     
73     /**
74      * Compares the current Attribute Object with another Attribute Object.
75      *
76      * @param object The Attribute that the current Attribute is to be compared with.
77      *
78      * @return True if the two Attribute objects are equal, otherwise false.
79      */

80     
81     
82     public boolean equals(Object JavaDoc object) {
83     if (!(object instanceof Attribute JavaDoc)) {
84         return false;
85     }
86     Attribute JavaDoc val = (Attribute JavaDoc) object;
87
88     if (value == null) {
89         if (val.getValue() == null) {
90         return name.equals(val.getName());
91         } else {
92         return false;
93         }
94     }
95
96     return ((name.equals(val.getName())) &&
97         (value.equals(val.getValue())));
98     }
99    
100  }
101
Popular Tags