1 package org.sapia.soto.jmx; 2 3 import java.lang.reflect.Method ; 4 import java.lang.reflect.Modifier ; 5 6 7 17 public class MethodUtils { 18 public static final String SET_PREFIX = "set"; 19 public static final String GET_PREFIX = "get"; 20 21 31 public static String getAttributeName(Method method, String removePrefix) { 32 return method.getName().substring(removePrefix.length()); 33 } 34 35 43 public static boolean isSetter(Method method) { 44 return method.getName().startsWith("set") && 45 Modifier.isPublic(method.getModifiers()) && 46 !Modifier.isStatic(method.getModifiers()) && 47 (method.getParameterTypes().length == 1); 48 } 49 50 58 public static boolean isGetter(Method method) { 59 return method.getName().startsWith("get") && 60 Modifier.isPublic(method.getModifiers()) && 61 !Modifier.isStatic(method.getModifiers()) && 62 (method.getParameterTypes().length == 0) && 63 (method.getReturnType() != null) && 64 !method.getReturnType().equals(void.class); 65 } 66 67 75 public static boolean isBoolean(Method method) { 76 return method.getName().startsWith("is") && 77 Modifier.isPublic(method.getModifiers()) && 78 !Modifier.isStatic(method.getModifiers()) && 79 (method.getParameterTypes().length == 0) && 80 (method.getReturnType() != null) && 81 !method.getReturnType().equals(void.class); 82 } 83 84 92 public static boolean isOperation(Method method) { 93 return Modifier.isPublic(method.getModifiers()) && 94 !Modifier.isStatic(method.getModifiers()) && !isSetter(method) && 95 !isGetter(method) && !isBoolean(method); 96 } 97 98 105 public static String getShortClassName(Class clazz) { 106 int idx = clazz.getName().lastIndexOf('.'); 107 108 if (idx < 0) { 109 return clazz.getName(); 110 } else { 111 return clazz.getName().substring(idx + 1); 112 } 113 } 114 115 121 public static String pretty(String name) { 122 return name; 123 } 124 } 125 | Popular Tags |