@Test public void testExecuteOnInstance() throws Exception { Method source = Utils.methodByName(String.class, "equals"); Object obj = new Object(); assertEquals(Boolean.TRUE, Utils.executeOnInstance(obj, source, new Object[]{obj})); assertEquals(Boolean.FALSE, Utils.executeOnInstance(obj, source, new Object[]{this})); }
public static Object executeOnInstance(Object object, Method method, Object[] args) { Method targetMethod = methodByName(object.getClass(), method.getName()); if (targetMethod == null) { throw new IllegalArgumentException(format( "Signature of method %s is not compatible with the object %s", method.getName(), object.getClass().getSimpleName())); } try { return targetMethod.invoke(object, args); } catch (Exception ex) { throw new RibbonProxyException(format( "Failed to execute method %s on object %s", method.getName(), object.getClass().getSimpleName()), ex); } }
Utils { public static Object executeOnInstance(Object object, Method method, Object[] args) { Method targetMethod = methodByName(object.getClass(), method.getName()); if (targetMethod == null) { throw new IllegalArgumentException(format( "Signature of method %s is not compatible with the object %s", method.getName(), object.getClass().getSimpleName())); } try { return targetMethod.invoke(object, args); } catch (Exception ex) { throw new RibbonProxyException(format( "Failed to execute method %s on object %s", method.getName(), object.getClass().getSimpleName()), ex); } } }
Utils { public static Object executeOnInstance(Object object, Method method, Object[] args) { Method targetMethod = methodByName(object.getClass(), method.getName()); if (targetMethod == null) { throw new IllegalArgumentException(format( "Signature of method %s is not compatible with the object %s", method.getName(), object.getClass().getSimpleName())); } try { return targetMethod.invoke(object, args); } catch (Exception ex) { throw new RibbonProxyException(format( "Failed to execute method %s on object %s", method.getName(), object.getClass().getSimpleName()), ex); } } private  Utils(); }
Utils { public static Object executeOnInstance(Object object, Method method, Object[] args) { Method targetMethod = methodByName(object.getClass(), method.getName()); if (targetMethod == null) { throw new IllegalArgumentException(format( "Signature of method %s is not compatible with the object %s", method.getName(), object.getClass().getSimpleName())); } try { return targetMethod.invoke(object, args); } catch (Exception ex) { throw new RibbonProxyException(format( "Failed to execute method %s on object %s", method.getName(), object.getClass().getSimpleName()), ex); } } private  Utils(); static Method methodByName(Class<T> aClass, String name); static Object executeOnInstance(Object object, Method method, Object[] args); static T newInstance(Class<T> aClass); }
Utils { public static Object executeOnInstance(Object object, Method method, Object[] args) { Method targetMethod = methodByName(object.getClass(), method.getName()); if (targetMethod == null) { throw new IllegalArgumentException(format( "Signature of method %s is not compatible with the object %s", method.getName(), object.getClass().getSimpleName())); } try { return targetMethod.invoke(object, args); } catch (Exception ex) { throw new RibbonProxyException(format( "Failed to execute method %s on object %s", method.getName(), object.getClass().getSimpleName()), ex); } } private  Utils(); static Method methodByName(Class<T> aClass, String name); static Object executeOnInstance(Object object, Method method, Object[] args); static T newInstance(Class<T> aClass);  }