public static Method findMethod(Class<?> clazz, String methodName) { return findMethod(clazz, methodName, null); }
public static Object invokeGetter(Object object, String propertyName) { String getterName = "get"+propertyName.substring(0, 1).toUpperCase()+propertyName.substring(1); try { Method method = Reflection.findMethod(object.getClass(), getterName); return method.invoke(object); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Couldn't invoke "+getterName+": "+e.getMessage(), e); } }
public static void invokeSetter(Object object, String propertyName, Object value) { String setterName = "set"+propertyName.substring(0, 1).toUpperCase()+propertyName.substring(1); try { Method method = Reflection.findMethod(object.getClass(), setterName); method.invoke(object, new Object[]{value}); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Couldn't invoke "+setterName+": "+e.getMessage(), e); } } }
/** @Param args null means don't match args */ public static Method findMethod(Class<?> clazz, String methodName, Object[] args) { if (clazz==null || methodName==null) { return null; } for (Method method: clazz.getDeclaredMethods()) { if (method.getName().equals(methodName)) { if (argsMatch(method, args)) { return method; } } } if (clazz.getSuperclass()!=null) { return findMethod(clazz.getSuperclass(), methodName, args); } return null; }
@Override public void parse(ActivityImpl activityImpl, JavaServiceTask activity, WorkflowParser parser) { super.parse(activityImpl, activity, parser); List<BindingImpl<?>> argBindingsList = parser.parseBindings((List)activity.getArgBindings(), "argBindings"); if (argBindingsList!=null) { this.argBindings = argBindingsList.toArray(new BindingImpl[argBindingsList.size()]); } // TODO add parse warnings if not exactly 1 is specified of : beanName or clazz // TODO add parse warnings if no methodName is specified String methodName = activity.getMethodName(); if (activity.getJavaClass()!=null && methodName!=null) { staticMethod = Reflection.findMethod(activity.getJavaClass(), methodName); if (!Modifier.isStatic(staticMethod.getModifiers())) { parser.addWarning("Method '"+methodName+"' is not static"); } staticMethod.setAccessible(true); } }
if (beanName!=null) { bean = activityInstance.getConfiguration().get(beanName); method = Reflection.findMethod(bean.getClass(), activity.getMethodName(), args);