01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package javax.management;
10:
11: import java.io.Serializable;
12:
13: /**
14: * Identifies an MBean registered in the MBeanServer. An ObjectInstance carries the information
15: * about MBean's ObjectName and class name.
16: *
17: * @version $Revision: 1.7 $
18: */
19: public class ObjectInstance implements Serializable {
20: private static final long serialVersionUID = -4099952623687795850L;
21:
22: /**
23: * @serial The MBean class name
24: */
25: private String className;
26: /**
27: * @serial The MBean ObjectName
28: */
29: private ObjectName name;
30:
31: /**
32: * Creates a new ObjectInstance
33: *
34: * @param objectName The ObjectName of the MBean
35: * @param className The class name of the MBean
36: * @throws MalformedObjectNameException If the ObjectName string does not represent a valid ObjectName
37: */
38: public ObjectInstance(String objectName, String className)
39: throws MalformedObjectNameException {
40: this (new ObjectName(objectName), className);
41: }
42:
43: /**
44: * Creates a new ObjectInstance
45: *
46: * @param objectName The ObjectName of the MBean
47: * @param className The class name of the MBean
48: */
49: public ObjectInstance(ObjectName objectName, String className) {
50: if (objectName == null || objectName.isPattern())
51: throw new RuntimeOperationsException(
52: new IllegalArgumentException("Invalid object name"));
53: if (className == null || className.trim().length() == 0)
54: throw new RuntimeOperationsException(
55: new IllegalArgumentException(
56: "Class name cannot be null or empty"));
57: this .name = objectName;
58: this .className = className;
59: }
60:
61: public boolean equals(Object object) {
62: if (object == null)
63: return false;
64: if (object == this )
65: return true;
66:
67: try {
68: ObjectInstance other = (ObjectInstance) object;
69: return name.equals(other.name)
70: && className.equals(other.className);
71: } catch (ClassCastException ignored) {
72: }
73: return false;
74: }
75:
76: public int hashCode() {
77: return name.hashCode() ^ className.hashCode();
78: }
79:
80: /**
81: * Returns the ObjectName of the MBean
82: */
83: public ObjectName getObjectName() {
84: return name;
85: }
86:
87: /**
88: * Returns the class name of the MBean
89: *
90: * @return
91: */
92: public String getClassName() {
93: return className;
94: }
95:
96: public String toString() {
97: return getClassName() + "@" + getObjectName();
98: }
99: }
|