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