确定属于特定属性的get方法的方法。
// 来 自 时 代 J a v a 公 众 号 - N o w J a v a . c o m // Licensed under the Apache License, Version 2.0 (the "License"); //package com.nowjava; import java.lang.reflect.Method; import javax.management.Descriptor; import javax.management.MBeanException; import javax.management.modelmbean.ModelMBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanInfo; public class Main { /** * Method for determining the get method belonging to a particular * attribute. * * @param aModelMBeanInfo * @param aManagedBean * @param aAttribute * @return Method * @throws MBeanException */ public static Method findGetMethod(ModelMBeanInfo aModelMBeanInfo, Object aManagedBean, String aAttribute) throws MBeanException { try { ModelMBeanAttributeInfo lInfo = aModelMBeanInfo .getAttribute(aAttribute); Descriptor lDescriptor = lInfo.getDescriptor(); String lMethodName = (String) (lDescriptor .getFieldValue("getMethod")); /* 来自 *N o w J a v a . c o m - 时 代 Java*/ if (lMethodName == null) { lMethodName = toMethodName("get", aAttribute); } return aManagedBean.getClass().getMethod(lMethodName, new Class[] {}); } catch (NoSuchMethodException e) { throw new MBeanException(e); } }