Returns the name of the MBean attribute corresponding to the given method object - chops the given prefix from the method name and returns the result. - Java Reflection

Java examples for Reflection:Method

Description

Returns the name of the MBean attribute corresponding to the given method object - chops the given prefix from the method name and returns the result.

Demo Code

/**//from   www.  j a v  a2 s.c om
 * A utility class that performs various operations using the Java reflection
 * API.
 * 
 * @author Yanick Duchesne
 *         <dl>
 *         <dt><b>Copyright: </b>
 *         <dd>Copyright &#169; 2002-2003 <a
 *         href="http://www.sapia-oss.org">Sapia Open Source Software </a>. All
 *         Rights Reserved.</dd>
 *         </dt>
 *         <dt><b>License: </b>
 *         <dd>Read the license.txt file of the jar or visit the <a
 *         href="http://www.sapia-oss.org/license.html">license page </a> at the
 *         Sapia OSS web site</dd>
 *         </dt>
 *         </dl>
 */
//package com.java2s;
import java.lang.reflect.Method;

public class Main {
    /**
     * Returns the name of the MBean attribute corresponding to the given method
     * object - chops the given prefix from the method name and returns the
     * result.
     * 
     * @param method
     *          a <code>Method</code> object.
     * @param removePrefix
     *          the prefix to remove from the method's name - to result in a MBean
     *          attribute name.
     * @return a MBean attribute name.
     */
    public static String getAttributeName(Method method, String removePrefix) {
        return method.getName().substring(removePrefix.length());
    }
}

Related Tutorials