Frames | No Frames |
1: /* MBeanConstructorInfo.java -- Information about a bean's constructor. 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; 39: 40: import java.lang.reflect.Constructor; 41: 42: import java.util.Arrays; 43: 44: /** 45: * Describes the constructors of a management bean. 46: * The information in this class is immutable as standard. 47: * Of course, subclasses may change this, but this 48: * behaviour is not recommended. 49: * 50: * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 51: * @since 1.5 52: */ 53: public class MBeanConstructorInfo 54: extends MBeanFeatureInfo 55: implements Cloneable 56: { 57: 58: /** 59: * Compatible with JDK 1.5 60: */ 61: private static final long serialVersionUID = 4433990064191844427L; 62: 63: /** 64: * The signature of the constructor i.e. the argument types. 65: */ 66: private MBeanParameterInfo[] signature; 67: 68: /** 69: * Constructs a @link{MBeanConstructorInfo} with the specified 70: * description using the given constructor. Each parameter is 71: * described merely by its type; the name and description are 72: * <code>null</code>. 73: * 74: * @param desc a description of the attribute. 75: * @param cons the constructor. 76: */ 77: public MBeanConstructorInfo(String desc, Constructor cons) 78: { 79: super(cons.getName(), desc); 80: Class[] paramTypes = cons.getParameterTypes(); 81: signature = new MBeanParameterInfo[paramTypes.length]; 82: for (int a = 0; a < paramTypes.length; ++a) 83: signature[a] = new MBeanParameterInfo(null, 84: paramTypes[a].getName(), 85: null); 86: } 87: 88: /** 89: * Constructs a @link{MBeanConstructorInfo} with the specified 90: * name, description and parameter information. A <code>null</code> 91: * value for the parameter information is the same as passing in 92: * an empty array. 93: * 94: * @param name the name of the constructor. 95: * @param desc a description of the attribute. 96: * @param sig the signature of the constructor, as a series 97: * of {@link MBeanParameterInfo} objects, one for 98: * each parameter. 99: */ 100: public MBeanConstructorInfo(String name, String desc, 101: MBeanParameterInfo[] sig) 102: { 103: super(name, desc); 104: if (sig == null) 105: signature = new MBeanParameterInfo[0]; 106: else 107: signature = sig; 108: } 109: 110: /** 111: * Returns a clone of this instance. The clone is created 112: * using just the method provided by {@link java.lang.Object}. 113: * Thus, the clone is just a shallow clone as returned by 114: * that method, and does not contain any deeper cloning based 115: * on the subject of this class. 116: * 117: * @return a clone of this instance. 118: * @see java.lang.Cloneable 119: */ 120: public Object clone() 121: { 122: try 123: { 124: return super.clone(); 125: } 126: catch (CloneNotSupportedException e) 127: { 128: /* This shouldn't happen; we implement Cloneable */ 129: throw new IllegalStateException("clone() called on " + 130: "non-cloneable object."); 131: } 132: } 133: 134: /** 135: * Compares this feature with the supplied object. This returns 136: * true iff the object is an instance of {@link 137: * MBeanConstructorInfo}, {@link Object#equals()} returns true for a 138: * comparison of both the name and description of this notification 139: * with that of the specified object (performed by the superclass), 140: * and the two signature arrays contain the same elements in the 141: * same order (but one may be longer than the other). 142: * 143: * @param obj the object to compare. 144: * @return true if the object is a {@link MBeanConstructorInfo} 145: * instance, 146: * <code>name.equals(object.getName())</code>, 147: * <code>description.equals(object.getDescription())</code> 148: * and the corresponding elements of the signature arrays are 149: * equal. 150: */ 151: public boolean equals(Object obj) 152: { 153: if (!(obj instanceof MBeanConstructorInfo)) 154: return false; 155: if (!(super.equals(obj))) 156: return false; 157: MBeanConstructorInfo o = (MBeanConstructorInfo) obj; 158: MBeanParameterInfo[] sig = o.getSignature(); 159: for (int a = 0; a < signature.length; ++a) 160: { 161: if (a == sig.length) 162: return true; 163: if (!(signature[a].equals(sig[a]))) 164: return false; 165: } 166: return true; 167: } 168: 169: /** 170: * Returns the constructor's signature, in the form of 171: * information on each parameter. Each parameter is 172: * described by an instance of {@link MBeanParameterInfo}. 173: * The returned array is a shallow copy of the array used 174: * by this instance, so changing which elements are stored 175: * in the array won't affect the array used by this, but 176: * changing the actual elements will affect the ones used 177: * here. 178: * 179: * @return an array of {@link MBeanParameterInfo} objects, 180: * describing the constructor parameters. 181: */ 182: public MBeanParameterInfo[] getSignature() 183: { 184: return (MBeanParameterInfo[]) signature.clone(); 185: } 186: 187: /** 188: * Returns the hashcode of the constructor information as the sum 189: * of the hashcode of the superclass and the hashcode of the parameter 190: * array. 191: * 192: * @return the hashcode of the constructor information. 193: */ 194: public int hashCode() 195: { 196: return super.hashCode() + Arrays.hashCode(signature); 197: } 198: 199: /** 200: * <p> 201: * Returns a textual representation of this instance. This 202: * is constructed using the class name 203: * (<code>javax.management.MBeanConstructorInfo</code>), 204: * the name and description of the constructor and the 205: * contents of the array of parameters. 206: * </p> 207: * <p> 208: * As instances of this class are immutable, the return value 209: * is computed just once for each instance and reused 210: * throughout its life. 211: * </p> 212: * 213: * @return a @link{java.lang.String} instance representing 214: * the instance in textual form. 215: */ 216: public String toString() 217: { 218: if (string == null) 219: { 220: super.toString(); 221: string = string.substring(0, string.length() - 1) 222: + ",signature=" + Arrays.toString(signature) 223: + "]"; 224: } 225: return string; 226: } 227: 228: }