1 16 17 package org.springframework.jmx.export.assembler; 18 19 import javax.management.Descriptor ; 20 import javax.management.JMException ; 21 import javax.management.modelmbean.ModelMBeanAttributeInfo ; 22 import javax.management.modelmbean.ModelMBeanConstructorInfo ; 23 import javax.management.modelmbean.ModelMBeanInfo ; 24 import javax.management.modelmbean.ModelMBeanInfoSupport ; 25 import javax.management.modelmbean.ModelMBeanNotificationInfo ; 26 import javax.management.modelmbean.ModelMBeanOperationInfo ; 27 28 import org.springframework.aop.support.AopUtils; 29 import org.springframework.jmx.support.JmxUtils; 30 31 46 public abstract class AbstractMBeanInfoAssembler implements MBeanInfoAssembler { 47 48 62 public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException { 63 checkManagedBean(managedBean); 64 ModelMBeanInfo info = new ModelMBeanInfoSupport ( 65 getClassName(managedBean, beanKey), getDescription(managedBean, beanKey), 66 getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey), 67 getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey)); 68 Descriptor desc = info.getMBeanDescriptor(); 69 populateMBeanDescriptor(desc, managedBean, beanKey); 70 info.setMBeanDescriptor(desc); 71 return info; 72 } 73 74 81 protected void checkManagedBean(Object managedBean) throws IllegalArgumentException { 82 } 83 84 93 protected Class getTargetClass(Object managedBean) { 94 return AopUtils.getTargetClass(managedBean); 95 } 96 97 105 protected Class getClassToExpose(Object managedBean) { 106 return JmxUtils.getClassToExpose(managedBean); 107 } 108 109 116 protected Class getClassToExpose(Class beanClass) { 117 return JmxUtils.getClassToExpose(beanClass); 118 } 119 120 130 protected String getClassName(Object managedBean, String beanKey) throws JMException { 131 return getTargetClass(managedBean).getName(); 132 } 133 134 143 protected String getDescription(Object managedBean, String beanKey) throws JMException { 144 String targetClassName = getTargetClass(managedBean).getName(); 145 if (AopUtils.isAopProxy(managedBean)) { 146 return "Proxy for " + targetClassName; 147 } 148 return targetClassName; 149 } 150 151 162 protected void populateMBeanDescriptor(Descriptor descriptor, Object managedBean, String beanKey) 163 throws JMException { 164 } 165 166 177 protected ModelMBeanConstructorInfo [] getConstructorInfo(Object managedBean, String beanKey) 178 throws JMException { 179 return new ModelMBeanConstructorInfo [0]; 180 } 181 182 193 protected ModelMBeanNotificationInfo [] getNotificationInfo(Object managedBean, String beanKey) 194 throws JMException { 195 return new ModelMBeanNotificationInfo [0]; 196 } 197 198 199 209 protected abstract ModelMBeanAttributeInfo [] getAttributeInfo(Object managedBean, String beanKey) 210 throws JMException ; 211 212 222 protected abstract ModelMBeanOperationInfo [] getOperationInfo(Object managedBean, String beanKey) 223 throws JMException ; 224 225 } 226 | Popular Tags |