001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management;
023:
024: import java.io.Serializable;
025:
026: /**
027: * Information about an object registered in the MBeanServer. An
028: * <tt>ObjectInstance</tt> represents an MBean's object name and class name.
029: * If the MBean is a Dynamic MBean the class name should be retrieved from the
030: * <tt>MBeanInfo</tt> it provides.
031: *
032: * @see javax.management.ObjectName
033: *
034: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>
035: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
036: * @version $Revision: 57200 $
037: *
038: * <p><b>Revisions:</b>
039: * <p><b>20020710 Adrian Brock:</b>
040: * <ul>
041: * <li> Serialization </li>
042: * </ul>
043: * <p><b>20030220 Juha Lindfors:</b>
044: * <ul>
045: * <li> Added hashCode override.</li>
046: * </ul>
047: */
048: public class ObjectInstance extends Object implements Serializable {
049:
050: // Attributes ----------------------------------------------------
051:
052: private ObjectName name = null;
053: private String className = null;
054:
055: // Static --------------------------------------------------------
056:
057: private static final long serialVersionUID = -4099952623687795850L;
058:
059: // Constructors --------------------------------------------------
060:
061: /**
062: * Creates a new object instance with a given object name and a fully
063: * qualified class name.
064: *
065: * @param name object name
066: * @param className fully qualified class name
067: *
068: * @throws MalformedObjectNameException the object name string is invalid
069: */
070: public ObjectInstance(String name, String className)
071: throws MalformedObjectNameException {
072: if (name == null)
073: throw new MalformedObjectNameException("Null name");
074:
075: this .name = new ObjectName(name);
076: this .className = className;
077: }
078:
079: /**
080: * Creates a new object instance with a given object name and a fully
081: * qualified class name.
082: *
083: * @param name object name
084: * @param className fully qualified class name
085: */
086: public ObjectInstance(ObjectName name, String className) {
087: this .name = name;
088: this .className = className;
089: }
090:
091: // Public --------------------------------------------------------
092:
093: /**
094: * Returns the object name of this instance.
095: *
096: * @return object name
097: */
098: public ObjectName getObjectName() {
099: return name;
100: }
101:
102: /**
103: * Returns the class name of this instance.
104: *
105: * @return class name
106: */
107: public String getClassName() {
108: return className;
109: }
110:
111: // Object overrides ----------------------------------------------
112:
113: public boolean equals(Object object) {
114: if (!(object instanceof ObjectInstance))
115: return false;
116:
117: ObjectInstance oi = (ObjectInstance) object;
118: return ((name.equals(oi.getObjectName())) && (className
119: .equals(oi.getClassName())));
120: }
121:
122: public int hashCode() {
123: return name.hashCode() + className.hashCode();
124: }
125:
126: public String toString() {
127: return "ObjectInstance[" + name + ", " + className + "]";
128: }
129:
130: }
|