1 7 8 9 package javax.management.openmbean; 10 11 12 import java.io.Serializable ; 15 import java.util.Arrays ; 16 import java.util.HashSet ; 17 18 19 import javax.management.MBeanInfo ; 22 import javax.management.MBeanAttributeInfo ; 23 import javax.management.MBeanOperationInfo ; 24 import javax.management.MBeanConstructorInfo ; 25 import javax.management.MBeanNotificationInfo ; 26 27 28 29 41 public class OpenMBeanInfoSupport 42 extends MBeanInfo 43 implements OpenMBeanInfo , Serializable { 44 45 46 static final long serialVersionUID = 4349395935420511492L; 47 48 49 private transient Integer myHashCode = null; private transient String myToString = null; 52 53 90 public OpenMBeanInfoSupport(String className, 91 String description, 92 OpenMBeanAttributeInfo [] openAttributes, 93 OpenMBeanConstructorInfo [] openConstructors, 94 OpenMBeanOperationInfo [] openOperations, 95 MBeanNotificationInfo [] notifications) { 96 97 super(className, 98 description, 99 ( openAttributes == null ? null : attributesArrayCopyCast(openAttributes) ), ( openConstructors == null ? null : constructorsArrayCopyCast(openConstructors) ), ( openOperations == null ? null : operationsArrayCopyCast(openOperations) ), ( notifications == null ? null : notificationsArrayCopy(notifications) )); 103 104 } 105 106 107 private static MBeanAttributeInfo [] attributesArrayCopyCast(OpenMBeanAttributeInfo [] src) throws ArrayStoreException { 108 109 MBeanAttributeInfo [] dst = new MBeanAttributeInfo [src.length]; 110 System.arraycopy(src, 0, dst, 0, src.length); return dst; 112 } 113 114 private static MBeanConstructorInfo [] constructorsArrayCopyCast(OpenMBeanConstructorInfo [] src) throws ArrayStoreException { 115 116 MBeanConstructorInfo [] dst = new MBeanConstructorInfo [src.length]; 117 System.arraycopy(src, 0, dst, 0, src.length); return dst; 119 } 120 121 private static MBeanOperationInfo [] operationsArrayCopyCast(OpenMBeanOperationInfo [] src) throws ArrayStoreException { 122 123 MBeanOperationInfo [] dst = new MBeanOperationInfo [src.length]; 124 System.arraycopy(src, 0, dst, 0, src.length); return dst; 126 } 127 128 private static MBeanNotificationInfo [] notificationsArrayCopy(MBeanNotificationInfo [] src) { 129 130 MBeanNotificationInfo [] dst = new MBeanNotificationInfo [src.length]; 131 System.arraycopy(src, 0, dst, 0, src.length); 132 return dst; 133 } 134 135 136 137 138 139 140 157 public boolean equals(Object obj) { 158 159 if (obj == null) { 162 return false; 163 } 164 165 OpenMBeanInfo other; 168 try { 169 other = (OpenMBeanInfo ) obj; 170 } catch (ClassCastException e) { 171 return false; 172 } 173 174 177 if ( ! this.getClassName().equals(other.getClassName()) ) { 179 return false; 180 } 181 182 if ( ! new HashSet (Arrays.asList(this.getAttributes())).equals(new HashSet (Arrays.asList(other.getAttributes()))) ) { 184 return false; 185 } 186 187 if ( ! new HashSet (Arrays.asList(this.getConstructors())).equals(new HashSet (Arrays.asList(other.getConstructors()))) ) { 189 return false; 190 } 191 192 if ( ! new HashSet (Arrays.asList(this.getOperations())).equals(new HashSet (Arrays.asList(other.getOperations()))) ) { 194 return false; 195 } 196 197 if ( ! new HashSet (Arrays.asList(this.getNotifications())).equals(new HashSet (Arrays.asList(other.getNotifications()))) ) { 199 return false; 200 } 201 202 return true; 205 } 206 207 230 public int hashCode() { 231 232 if (myHashCode == null) { 235 int value = 0; 236 value += this.getClassName().hashCode(); 237 value += new HashSet (Arrays.asList(this.getAttributes())).hashCode(); 238 value += new HashSet (Arrays.asList(this.getConstructors())).hashCode(); 239 value += new HashSet (Arrays.asList(this.getOperations())).hashCode(); 240 value += new HashSet (Arrays.asList(this.getNotifications())).hashCode(); 241 myHashCode = new Integer (value); 242 } 243 244 return myHashCode.intValue(); 247 } 248 249 262 public String toString() { 263 264 if (myToString == null) { 267 myToString = new StringBuffer () 268 .append(this.getClass().getName()) 269 .append("(mbean_class_name=") 270 .append(this.getClassName()) 271 .append(",attributes=") 272 .append(Arrays.asList(this.getAttributes()).toString()) 273 .append(",constructors=") 274 .append(Arrays.asList(this.getConstructors()).toString()) 275 .append(",operations=") 276 .append(Arrays.asList(this.getOperations()).toString()) 277 .append(",notifications=") 278 .append(Arrays.asList(this.getNotifications()).toString()) 279 .append(")") 280 .toString(); 281 } 282 283 return myToString; 286 } 287 288 } 289 | Popular Tags |