1 16 17 package org.springframework.jmx.export.assembler; 18 19 import java.lang.reflect.Method ; 20 import java.util.Arrays ; 21 import java.util.Enumeration ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.Map ; 25 import java.util.Properties ; 26 import java.util.Set ; 27 28 import org.springframework.util.StringUtils; 29 30 55 public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBeanInfoAssembler { 56 57 60 private Set managedMethods; 61 62 65 private Map methodMappings; 66 67 68 75 public void setManagedMethods(String [] methodNames) { 76 this.managedMethods = new HashSet (Arrays.asList(methodNames)); 77 } 78 79 86 public void setMethodMappings(Properties mappings) { 87 this.methodMappings = new HashMap (); 88 for (Enumeration en = mappings.keys(); en.hasMoreElements();) { 89 String beanKey = (String ) en.nextElement(); 90 String [] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey)); 91 this.methodMappings.put(beanKey, new HashSet (Arrays.asList(methodNames))); 92 } 93 } 94 95 96 protected boolean includeReadAttribute(Method method, String beanKey) { 97 return isMatch(method, beanKey); 98 } 99 100 protected boolean includeWriteAttribute(Method method, String beanKey) { 101 return isMatch(method, beanKey); 102 } 103 104 protected boolean includeOperation(Method method, String beanKey) { 105 return isMatch(method, beanKey); 106 } 107 108 protected boolean isMatch(Method method, String beanKey) { 109 if (this.methodMappings != null) { 110 Set methodNames = (Set ) this.methodMappings.get(beanKey); 111 if (methodNames != null) { 112 return methodNames.contains(method.getName()); 113 } 114 } 115 return (this.managedMethods != null && this.managedMethods.contains(method.getName())); 116 } 117 118 } 119 | Popular Tags |