1 7 8 package javax.management; 9 10 import java.lang.reflect.Method ; 11 import java.util.Arrays ; 12 13 20 public class MBeanOperationInfo extends MBeanFeatureInfo implements java.io.Serializable , Cloneable { 21 22 23 static final long serialVersionUID = -6178860474881375330L; 24 25 static final MBeanOperationInfo [] NO_OPERATIONS = 26 new MBeanOperationInfo [0]; 27 28 32 public static final int INFO = 0; 33 34 39 public static final int ACTION = 1 ; 40 41 44 public static final int ACTION_INFO = 2; 45 46 49 public static final int UNKNOWN = 3; 50 51 54 private final String type; 55 56 60 private final MBeanParameterInfo [] signature; 61 62 69 private final int impact; 70 71 72 private final transient boolean immutable; 73 74 75 82 public MBeanOperationInfo(String description, 83 Method method) 84 throws IllegalArgumentException { 85 86 this(method.getName(), 87 description, 88 methodSignature(method), 89 method.getReturnType().getName(), 90 UNKNOWN); 91 } 92 93 105 public MBeanOperationInfo(String name, 106 String description, 107 MBeanParameterInfo [] signature, 108 String type, 109 int impact) 110 throws IllegalArgumentException { 111 112 super(name, description); 113 114 if (signature == null || signature.length == 0) 115 signature = MBeanParameterInfo.NO_PARAMS; 116 else 117 signature = (MBeanParameterInfo []) signature.clone(); 118 this.signature = signature; 119 this.type = type; 120 this.impact = impact; 121 this.immutable = 122 MBeanInfo.isImmutableClass(this.getClass(), 123 MBeanOperationInfo .class); 124 } 125 126 136 public Object clone () { 137 try { 138 return super.clone() ; 139 } catch (CloneNotSupportedException e) { 140 return null; 142 } 143 } 144 145 150 public String getReturnType() { 151 return type; 152 } 153 154 167 public MBeanParameterInfo [] getSignature() { 168 if (signature.length == 0) 169 return signature; 170 else 171 return (MBeanParameterInfo []) signature.clone(); 172 } 173 174 private MBeanParameterInfo [] fastGetSignature() { 175 if (immutable) 176 return signature; 177 else 178 return getSignature(); 179 } 180 181 187 public int getImpact() { 188 return impact; 189 } 190 191 203 public boolean equals(Object o) { 204 if (o == this) 205 return true; 206 if (!(o instanceof MBeanOperationInfo )) 207 return false; 208 MBeanOperationInfo p = (MBeanOperationInfo ) o; 209 return (p.getName().equals(getName()) && 210 p.getReturnType().equals(getReturnType()) && 211 p.getDescription().equals(getDescription()) && 212 p.getImpact() == getImpact() && 213 Arrays.equals(p.fastGetSignature(), fastGetSignature())); 214 } 215 216 222 public int hashCode() { 223 return getName().hashCode() ^ getReturnType().hashCode(); 224 } 225 226 private static MBeanParameterInfo [] methodSignature(Method method) { 227 final Class [] classes = method.getParameterTypes(); 228 final MBeanParameterInfo [] params = 229 new MBeanParameterInfo [classes.length]; 230 231 for (int i = 0; i < classes.length; i++) { 232 final String pn = "p" + (i + 1); 233 params[i] = new MBeanParameterInfo (pn, classes[i].getName(), ""); 234 } 235 236 return params; 237 } 238 } 239 | Popular Tags |