KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > ObjectInstance


1 /*
2  * @(#)ObjectInstance.java 4.21 04/03/18
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 // java import
11
import java.io.Serializable JavaDoc;
12
13 // RI import
14
import javax.management.ObjectName JavaDoc;
15
16
17 /**
18  * Used to represent the object name of an MBean and its class name.
19  * If the MBean is a Dynamic MBean the class name should be retrieved from
20  * the <CODE>MBeanInfo</CODE> it provides.
21  *
22  * @since 1.5
23  */

24 public class ObjectInstance implements Serializable JavaDoc {
25
26
27     /* Serial version */
28     private static final long serialVersionUID = -4099952623687795850L;
29
30     /**
31      * @serial Object name.
32      */

33     private ObjectName JavaDoc name;
34     
35     /**
36      * @serial Class name.
37      */

38     private String JavaDoc className;
39     
40     /**
41      * Allows an object instance to be created given a string representation of
42      * an object name and the full class name, including the package name.
43      *
44      * @param objectName A string representation of the object name.
45      * @param className The full class name, including the package
46      * name, of the object instance. If the MBean is a Dynamic MBean
47      * the class name corresponds to its {@link
48      * DynamicMBean#getMBeanInfo()
49      * getMBeanInfo()}<code>.getClassName()</code>.
50      *
51      * @exception MalformedObjectNameException The string passed as a
52      * parameter does not have the right format.
53      *
54      */

55     public ObjectInstance(String JavaDoc objectName, String JavaDoc className)
56         throws MalformedObjectNameException JavaDoc {
57     this(new ObjectName JavaDoc(objectName), className);
58     }
59
60     /**
61      * Allows an object instance to be created given an object name and
62      * the full class name, including the package name.
63      *
64      * @param objectName The object name.
65      * @param className The full class name, including the package
66      * name, of the object instance. If the MBean is a Dynamic MBean
67      * the class name corresponds to its {@link
68      * DynamicMBean#getMBeanInfo()
69      * getMBeanInfo()}<code>.getClassName()</code>.
70      * If the MBean is a Dynamic MBean the class name should be retrieved
71      * from the <CODE>MBeanInfo</CODE> it provides.
72      *
73      */

74     public ObjectInstance(ObjectName JavaDoc objectName, String JavaDoc className) {
75     if (objectName.isPattern()) {
76         final IllegalArgumentException JavaDoc iae =
77         new IllegalArgumentException JavaDoc("Invalid name->"+
78                          objectName.toString());
79         throw new RuntimeOperationsException JavaDoc(iae);
80     }
81     this.name= objectName;
82     this.className= className;
83     }
84
85     
86     /**
87      * Compares the current object instance with another object instance.
88      *
89      * @param object The object instance that the current object instance is
90      * to be compared with.
91      *
92      * @return True if the two object instances are equal, otherwise false.
93      */

94     public boolean equals(Object JavaDoc object) {
95     if (!(object instanceof ObjectInstance JavaDoc)) {
96         return false;
97     }
98     ObjectInstance JavaDoc val = (ObjectInstance JavaDoc) object;
99     if (! name.equals(val.getObjectName())) return false;
100     if (className == null)
101         return (val.getClassName() == null);
102     return className.equals(val.getClassName());
103     }
104
105     public int hashCode() {
106     final int classHash = ((className==null)?0:className.hashCode());
107     return name.hashCode() ^ classHash;
108     }
109
110     /**
111      * Returns the object name part.
112      *
113      * @return the object name.
114      */

115     public ObjectName JavaDoc getObjectName() {
116     return name;
117     }
118     
119     /**
120      * Returns the class part.
121      *
122      * @return the class name.
123      */

124     public String JavaDoc getClassName() {
125     return className;
126     }
127
128  }
129
Popular Tags