1 22 package org.jboss.mx.metadata; 23 24 import javax.management.DynamicMBean ; 25 import javax.management.NotCompliantMBeanException ; 26 27 55 public class MBeanCapability 56 { 57 public static final int DYNAMIC_MBEAN = 0x321; 58 public static final int STANDARD_MBEAN = 0x123; 59 public static final int NOT_AN_MBEAN = 0xc0de; 60 61 protected int mbeanType = NOT_AN_MBEAN; 62 63 private MBeanCapability(int type) 64 { 65 mbeanType = type; 66 } 67 68 public int getMBeanType() 69 { 70 return mbeanType; 71 } 72 73 public static MBeanCapability of(Class mbeanClass) throws NotCompliantMBeanException 74 { 75 if (null == mbeanClass) 76 { 77 throw new IllegalArgumentException ("MBean class cannot be null"); 78 } 79 80 if (DynamicMBean .class.isAssignableFrom(mbeanClass)) 82 { 83 return new MBeanCapability(DYNAMIC_MBEAN); 84 } 85 86 Class [] interfaces = mbeanClass.getInterfaces(); 88 for (int i = 0; i < interfaces.length; i++) 89 { 90 Class anInterface = interfaces[i]; 91 if (anInterface.getName().equals(mbeanClass.getName() + "MBean")) 92 { 93 return new MBeanCapability(STANDARD_MBEAN); 94 } 95 } 96 97 Class superClass = mbeanClass.getSuperclass(); 99 if (superClass != null) 100 return of(superClass); 101 102 throw new NotCompliantMBeanException ("Class does not expose a management interface: " + mbeanClass.getName()); 103 } 104 105 } 106 | Popular Tags |