1 7 8 package javax.management; 9 10 import java.lang.reflect.Constructor ; 11 import java.util.Arrays ; 12 13 20 public class MBeanConstructorInfo extends MBeanFeatureInfo implements java.io.Serializable , Cloneable { 21 22 23 static final long serialVersionUID = 4433990064191844427L; 24 25 static final MBeanConstructorInfo [] NO_CONSTRUCTORS = 26 new MBeanConstructorInfo [0]; 27 28 29 private final transient boolean immutable; 30 31 34 private final MBeanParameterInfo [] signature; 35 36 43 public MBeanConstructorInfo(String description, Constructor constructor) { 44 this(constructor.getName(), description, 45 constructorSignature(constructor)); 46 } 47 48 57 public MBeanConstructorInfo(String name, 58 String description, 59 MBeanParameterInfo [] signature) 60 throws IllegalArgumentException { 61 super(name, description); 62 63 64 if (signature == null || signature.length == 0) 65 signature = MBeanParameterInfo.NO_PARAMS; 66 else 67 signature = (MBeanParameterInfo []) signature.clone(); 68 this.signature = signature; 69 this.immutable = 70 MBeanInfo.isImmutableClass(this.getClass(), 71 MBeanConstructorInfo .class); 72 } 73 74 75 85 public Object clone () { 86 try { 87 return super.clone() ; 88 } catch (CloneNotSupportedException e) { 89 return null; 91 } 92 } 93 94 107 public MBeanParameterInfo [] getSignature() { 108 if (signature.length == 0) 109 return signature; 110 else 111 return (MBeanParameterInfo []) signature.clone(); 112 } 113 114 private MBeanParameterInfo [] fastGetSignature() { 115 if (immutable) 116 return signature; 117 else 118 return getSignature(); 119 } 120 121 133 public boolean equals(Object o) { 134 if (o == this) 135 return true; 136 if (!(o instanceof MBeanConstructorInfo )) 137 return false; 138 MBeanConstructorInfo p = (MBeanConstructorInfo ) o; 139 return (p.getName().equals(getName()) && 140 p.getDescription().equals(getDescription()) && 141 Arrays.equals(p.fastGetSignature(), fastGetSignature())); 142 } 143 144 149 public int hashCode() { 150 int hash = getName().hashCode(); 151 MBeanParameterInfo [] sig = fastGetSignature(); 152 for (int i = 0; i < sig.length; i++) 153 hash ^= sig[i].hashCode(); 154 return hash; 155 } 156 157 private static MBeanParameterInfo [] constructorSignature(Constructor cn) { 158 final Class [] classes = cn.getParameterTypes(); 159 final MBeanParameterInfo [] params = 160 new MBeanParameterInfo [classes.length]; 161 162 for (int i = 0; i < classes.length; i++) { 163 final String pn = "p" + (i + 1); 164 params[i] = new MBeanParameterInfo (pn, classes[i].getName(), ""); 165 } 166 167 return params; 168 } 169 } 170 | Popular Tags |