1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
/* * @(#)ObjectInstance.java 4.23 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.management; // java import import java.io.Serializable; // RI import import javax.management.ObjectName; /** * Used to represent the object name of an MBean and its class name. * If the MBean is a Dynamic MBean the class name should be retrieved from * the <CODE>MBeanInfo</CODE> it provides. * * @since 1.5 */ public class ObjectInstance implements Serializable { /* Serial version */ private static final long serialVersionUID = -4099952623687795850L; /** * @serial Object name. */ private ObjectName name; /** * @serial Class name. */ private String className; /** * Allows an object instance to be created given a string representation of * an object name and the full class name, including the package name. * * @param objectName A string representation of the object name. * @param className The full class name, including the package * name, of the object instance. If the MBean is a Dynamic MBean * the class name corresponds to its {@link * DynamicMBean#getMBeanInfo() * getMBeanInfo()}<code>.getClassName()</code>. * * @exception MalformedObjectNameException The string passed as a * parameter does not have the right format. * */ public ObjectInstance(String objectName, String className) throws MalformedObjectNameException { this(new ObjectName(objectName), className); } /** * Allows an object instance to be created given an object name and * the full class name, including the package name. * * @param objectName The object name. * @param className The full class name, including the package * name, of the object instance. If the MBean is a Dynamic MBean * the class name corresponds to its {@link * DynamicMBean#getMBeanInfo() * getMBeanInfo()}<code>.getClassName()</code>. * If the MBean is a Dynamic MBean the class name should be retrieved * from the <CODE>MBeanInfo</CODE> it provides. * */ public ObjectInstance(ObjectName objectName, String className) { if (objectName.isPattern()) { final IllegalArgumentException iae = new IllegalArgumentException("Invalid name->"+ objectName.toString()); throw new RuntimeOperationsException(iae); } this.name= objectName; this.className= className; } /** * Compares the current object instance with another object instance. * * @param object The object instance that the current object instance is * to be compared with. * * @return True if the two object instances are equal, otherwise false. */ public boolean equals(Object object) { if (!(object instanceof ObjectInstance)) { return false; } ObjectInstance val = (ObjectInstance) object; if (! name.equals(val.getObjectName())) return false; if (className == null) return (val.getClassName() == null); return className.equals(val.getClassName()); } public int hashCode() { final int classHash = ((className==null)?0:className.hashCode()); return name.hashCode() ^ classHash; } /** * Returns the object name part. * * @return the object name. */ public ObjectName getObjectName() { return name; } /** * Returns the class part. * * @return the class name. */ public String getClassName() { return className; } /** * Returns a string representing this ObjectInstance object. The format of this string * is not specified, but users can expect that two ObjectInstances return the same * string if and only if they are equal. */ public String toString() { return getClassName() + "[" + getObjectName() + "]"; } }