public static Method findMethod(Class<?> c, String name, Class<?> params[]) { Method methods[] = findMethods(c); if (methods == null) return null; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { Class<?> methodParams[] = methods[i].getParameterTypes(); if (methodParams == null) if (params == null || params.length == 0) return methods[i]; if (params == null) if (methodParams == null || methodParams.length == 0) return methods[i]; if (params.length != methodParams.length) continue; boolean found = true; for (int j = 0; j < params.length; j++) { if (params[j] != methodParams[j]) { found = false; break; } } if (found) return methods[i]; } } return null; }
public static Method findMethod(Class c, String name, Class params[]) { Method methods[] = findMethods(c); if (methods == null) return null; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { Class methodParams[] = methods[i].getParameterTypes(); if (methodParams == null) if (params == null || params.length == 0) return methods[i]; if (params == null) if (methodParams == null || methodParams.length == 0) return methods[i]; if (params.length != methodParams.length) continue; boolean found = true; for (int j = 0; j < params.length; j++) { if (params[j] != methodParams[j]) { found = false; break; } } if (found) return methods[i]; } } return null; }
public static Method findMethod(Class c, String name, Class params[]) { Method methods[] = findMethods(c); if (methods == null) return null; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(name)) { Class methodParams[] = methods[i].getParameterTypes(); if (methodParams == null) if (params == null || params.length == 0) return methods[i]; if (params == null) if (methodParams == null || methodParams.length == 0) return methods[i]; if (params.length != methodParams.length) continue; boolean found = true; for (int j = 0; j < params.length; j++) { if (params[j] != methodParams[j]) { found = false; break; } } if (found) return methods[i]; } } return null; }
/** Test if the object implements a particular * method */ public static boolean hasHook(Object obj, String methodN) { try { Method myMethods[] = findMethods(obj.getClass()); for (int i = 0; i < myMethods.length; i++) { if (methodN.equals(myMethods[i].getName())) { // check if it's overriden Class<?> declaring = myMethods[i].getDeclaringClass(); Class<?> parentOfDeclaring = declaring.getSuperclass(); // this works only if the base class doesn't extend // another class. // if the method is declared in a top level class // like BaseInterceptor parent is Object, otherwise // parent is BaseInterceptor or an intermediate class if (!"java.lang.Object".equals(parentOfDeclaring.getName())) { return true; } } } } catch (Exception ex) { ex.printStackTrace(); } return false; }
/** Test if the object implements a particular * method */ public static boolean hasHook(Object obj, String methodN) { try { Method myMethods[] = findMethods(obj.getClass()); for (int i = 0; i < myMethods.length; i++) { if (methodN.equals(myMethods[i].getName())) { // check if it's overriden Class declaring = myMethods[i].getDeclaringClass(); Class parentOfDeclaring = declaring.getSuperclass(); // this works only if the base class doesn't extend // another class. // if the method is declared in a top level class // like BaseInterceptor parent is Object, otherwise // parent is BaseInterceptor or an intermediate class if (!"java.lang.Object".equals(parentOfDeclaring.getName())) { return true; } } } } catch (Exception ex) { ex.printStackTrace(); } return false; }
@SuppressWarnings("unchecked") public static String[] findVoidSetters(Class c) { Method m[] = findMethods(c); if (m == null) return null; Vector v = new Vector(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 0) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
@SuppressWarnings("unchecked") public static String[] findVoidSetters(Class<?> c) { Method m[] = findMethods(c); if (m == null) return null; Vector<String> v = new Vector<String>(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 0) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
/** */ public static void setProperty(Object o, String name) { String setter = "set" + capitalize(name); try { Method methods[] = findMethods(o.getClass()); Method setPropertyMethod = null; // find setFoo() method for (int i = 0; i < methods.length; i++) { Class<?> paramT[] = methods[i].getParameterTypes(); if (setter.equals(methods[i].getName()) && paramT.length == 0) { methods[i].invoke(o, new Object[] {}); return; } } } catch (Exception ex1) { if (dbg > 0) d("Exception for " + o.getClass() + " " + name); if (dbg > 1) ex1.printStackTrace(); } }
@SuppressWarnings("unchecked") public static String[] findBooleanSetters(Class c) { Method m[] = findMethods(c); if (m == null) return null; Vector v = new Vector(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 1 && "boolean".equalsIgnoreCase(m[i].getParameterTypes()[0] .getName())) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
@SuppressWarnings("unchecked") public static String[] findVoidSetters(Class c) { Method m[] = findMethods(c); if (m == null) return null; Vector v = new Vector(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 0) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
/** Test if the object implements a particular * method */ public static boolean hasHook(Object obj, String methodN) { try { Method myMethods[] = findMethods(obj.getClass()); for (int i = 0; i < myMethods.length; i++) { if (methodN.equals(myMethods[i].getName())) { // check if it's overriden Class declaring = myMethods[i].getDeclaringClass(); Class parentOfDeclaring = declaring.getSuperclass(); // this works only if the base class doesn't extend // another class. // if the method is declared in a top level class // like BaseInterceptor parent is Object, otherwise // parent is BaseInterceptor or an intermediate class if (!"java.lang.Object".equals(parentOfDeclaring.getName())) { return true; } } } } catch (Exception ex) { ex.printStackTrace(); } return false; }
/** */ public static void setProperty(Object o, String name) { String setter = "set" + capitalize(name); try { Method methods[] = findMethods(o.getClass()); Method setPropertyMethod = null; // find setFoo() method for (int i = 0; i < methods.length; i++) { Class paramT[] = methods[i].getParameterTypes(); if (setter.equals(methods[i].getName()) && paramT.length == 0) { methods[i].invoke(o, new Object[] {}); return; } } } catch (Exception ex1) { if (dbg > 0) d("Exception for " + o.getClass() + " " + name); if (dbg > 1) ex1.printStackTrace(); } }
@SuppressWarnings("unchecked") public static String[] findBooleanSetters(Class c) { Method m[] = findMethods(c); if (m == null) return null; Vector v = new Vector(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 1 && "boolean".equalsIgnoreCase(m[i].getParameterTypes()[0] .getName())) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = (String) v.elementAt(i); } return s; }
@SuppressWarnings("unchecked") public static String[] findBooleanSetters(Class<?> c) { Method m[] = findMethods(c); if (m == null) return null; Vector<String> v = new Vector<String>(); for (int i = 0; i < m.length; i++) { if (m[i].getName().startsWith("set") && m[i].getParameterTypes().length == 1 && "boolean".equalsIgnoreCase(m[i].getParameterTypes()[0] .getName())) { String arg = m[i].getName().substring(3); v.addElement(unCapitalize(arg)); } } String s[] = new String[v.size()]; for (int i = 0; i < s.length; i++) { s[i] = v.elementAt(i); } return s; }
/** */ public static void setProperty(Object o, String name) { String setter = "set" + capitalize(name); try { Method methods[] = findMethods(o.getClass()); Method setPropertyMethod = null; // find setFoo() method for (int i = 0; i < methods.length; i++) { Class paramT[] = methods[i].getParameterTypes(); if (setter.equals(methods[i].getName()) && paramT.length == 0) { methods[i].invoke(o, new Object[] {}); return; } } } catch (Exception ex1) { if (dbg > 0) d("Exception for " + o.getClass() + " " + name); if (dbg > 1) ex1.printStackTrace(); } }
Method methods[] = findMethods(o.getClass()); Method getPropertyMethod = null;
Method methods[] = findMethods(o.getClass()); Method getPropertyMethod = null;
Method methods[] = findMethods(o.getClass()); Method getPropertyMethod = null;
Method methods[] = findMethods(o.getClass()); Method setPropertyMethodVoid = null; Method setPropertyMethodBool = null;
Method methods[] = findMethods(o.getClass()); Method setPropertyMethodVoid = null; Method setPropertyMethodBool = null;