Frames | No Frames |
1: /* OpenMBeanInfoSupport.java -- Open typed info about a bean. 2: Copyright (C) 2006 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package javax.management.openmbean; 39: 40: import java.util.Arrays; 41: import java.util.HashSet; 42: 43: import javax.management.MBeanInfo; 44: import javax.management.MBeanAttributeInfo; 45: import javax.management.MBeanConstructorInfo; 46: import javax.management.MBeanNotificationInfo; 47: import javax.management.MBeanOperationInfo; 48: 49: /** 50: * Describes an open management bean. 51: * 52: * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 53: * @since 1.5 54: */ 55: public class OpenMBeanInfoSupport 56: extends MBeanInfo 57: implements OpenMBeanInfo 58: { 59: 60: /** 61: * Compatible with JDK 1.5 62: */ 63: private static final long serialVersionUID = 4349395935420511492L; 64: 65: /** 66: * The hash code of this instance. 67: */ 68: private transient Integer hashCode; 69: 70: /** 71: * The <code>toString()</code> result of this instance. 72: */ 73: private transient String string; 74: 75: /** 76: * Constructs a new {@link OpenMBeanInfo} using the supplied 77: * class name and description with the given attributes, 78: * operations, constructors and notifications. The class 79: * name does not have to actually specify a valid class that 80: * can be loaded by the MBean server or class loader; it merely 81: * has to be a syntactically correct class name. Any of the 82: * arrays may be <code>null</code>; this will be treated as if 83: * an empty array was supplied. A copy of the arrays is 84: * taken, so later changes have no effect. 85: * 86: * @param name the name of the class this instance describes. 87: * @param desc a description of the bean. 88: * @param attribs the attribute descriptions for the bean, 89: * or <code>null</code>. 90: * @param cons the constructor descriptions for the bean, 91: * or <code>null</code>. 92: * @param ops the operation descriptions for the bean, 93: * or <code>null</code>. 94: * @param notifs the notification descriptions for the bean, 95: * or <code>null</code>. 96: * @throws ArrayStoreException if a members of an array 97: * is not assignable to the equivalent 98: * <code>MBeanXXXInfo</code> class. 99: */ 100: public OpenMBeanInfoSupport(String name, String desc, 101: OpenMBeanAttributeInfo[] attribs, 102: OpenMBeanConstructorInfo[] cons, 103: OpenMBeanOperationInfo[] ops, 104: MBeanNotificationInfo[] notifs) 105: { 106: super(name, desc, (MBeanAttributeInfo[]) attribs, 107: (MBeanConstructorInfo[]) cons, 108: (MBeanOperationInfo[]) ops, 109: notifs); 110: } 111: 112: /** 113: * Compares this attribute with the supplied object. This returns 114: * true iff the object is an instance of {@link OpenMBeanInfo} 115: * with the same class name and equal instances of the info classes. 116: * 117: * @param obj the object to compare. 118: * @return true if the object is a {@link OpenMBeanInfo} 119: * instance, 120: * <code>className.equals(object.getClassName())</code> 121: * and each info class has an equal in the other object. 122: */ 123: public boolean equals(Object obj) 124: { 125: if (!(obj instanceof OpenMBeanInfo)) 126: return false; 127: OpenMBeanInfo o = (OpenMBeanInfo) obj; 128: return getClassName().equals(o.getClassName()) && 129: getAttributes().equals(o.getAttributes()) && 130: getConstructors().equals(o.getConstructors()) && 131: getNotifications().equals(o.getNotifications()) && 132: getOperations().equals(o.getOperations()); 133: } 134: 135: /** 136: * <p> 137: * Returns the hashcode of the bean information as the sum of the 138: * hashcodes of the class name and each array (calculated using 139: * java.util.HashSet(<code>java.util.Arrays.asList(signature)).hashCode()</code>). 140: * </p> 141: * <p> 142: * As instances of this class are immutable, the return value 143: * is computed just once for each instance and reused 144: * throughout its life. 145: * </p> 146: * 147: * @return the hashcode of the bean information. 148: */ 149: public int hashCode() 150: { 151: if (hashCode == null) 152: hashCode = 153: Integer.valueOf(getClassName().hashCode() + 154: new HashSet<MBeanAttributeInfo>(Arrays.asList(getAttributes())).hashCode() + 155: new HashSet<MBeanConstructorInfo>(Arrays.asList(getConstructors())).hashCode() + 156: new HashSet<MBeanNotificationInfo>(Arrays.asList(getNotifications())).hashCode() + 157: new HashSet<MBeanOperationInfo>(Arrays.asList(getOperations())).hashCode()); 158: return hashCode.intValue(); 159: } 160: 161: /** 162: * <p> 163: * Returns a textual representation of this instance. This 164: * is constructed using the class name 165: * (<code>javax.management.openmbean.OpenMBeanInfo</code>) 166: * along with the class name and textual representations 167: * of each array. 168: * </p> 169: * <p> 170: * As instances of this class are immutable, the return value 171: * is computed just once for each instance and reused 172: * throughout its life. 173: * </p> 174: * 175: * @return a @link{java.lang.String} instance representing 176: * the instance in textual form. 177: */ 178: public String toString() 179: { 180: if (string == null) 181: string = getClass().getName() 182: + "[className=" + getClassName() 183: + ",attributes=" + Arrays.toString(getAttributes()) 184: + ",constructors=" + Arrays.toString(getConstructors()) 185: + ",notifications=" + Arrays.toString(getNotifications()) 186: + ",operations=" + Arrays.toString(getOperations()) 187: + "]"; 188: return string; 189: } 190: 191: }