1 16 17 package org.springframework.jmx.export.naming; 18 19 import javax.management.MalformedObjectNameException ; 20 import javax.management.ObjectName ; 21 22 import org.springframework.jmx.export.metadata.JmxAttributeSource; 23 import org.springframework.jmx.export.metadata.ManagedResource; 24 import org.springframework.jmx.support.ObjectNameManager; 25 import org.springframework.jmx.support.JmxUtils; 26 import org.springframework.util.StringUtils; 27 import org.springframework.aop.support.AopUtils; 28 29 37 public class MetadataNamingStrategy implements ObjectNamingStrategy { 38 39 42 private JmxAttributeSource attributeSource; 43 44 45 49 public void setAttributeSource(JmxAttributeSource attributeSource) { 50 this.attributeSource = attributeSource; 51 } 52 53 54 58 public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { 59 if (AopUtils.isJdkDynamicProxy(managedBean)) { 60 throw new IllegalArgumentException ( 61 "MetadataNamingStrategy does not support JDK dynamic proxies - " + 62 "export the target beans directly or use CGLIB proxies instead"); 63 } 64 Class managedClass = JmxUtils.getClassToExpose(managedBean); 65 ManagedResource mr = this.attributeSource.getManagedResource(managedClass); 66 67 if (mr == null) { 69 throw new MalformedObjectNameException ("Your bean class [" + managedBean.getClass().getName() + 70 "] must be marked with a valid ManagedResource attribute when using MetadataNamingStrategy"); 71 } 72 73 String objectName = mr.getObjectName(); 75 76 if (!StringUtils.hasText(objectName)) { 77 throw new MalformedObjectNameException ( 78 "You must specify an ObjectName for class [" + managedBean.getClass().getName() + "]"); 79 } 80 81 return ObjectNameManager.getInstance(objectName); 83 } 84 85 } 86 | Popular Tags |