调用方法

@param object 对象
@param methodName 方法名
@param parameters 参数

@return 方法返回的结果

@throws NoSuchMethodException 异常
@throws InvocationTargetException 异常
@throws IllegalAccessException 异常
549684
public static Object invokeMethod(Object object, String methodName, Object[] parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        return invokeMethod(object, methodName, getTypes(parameters), parameters);
    }
493633
public static Object executeMethod(Object aObject, String methodName, Object[] aArguments)
   throws Exception
   {
	Class<?>[] parameterTypes = null;
	ArrayList<Object> parameterTypeArrayList = null;
	
	if(aArguments != null && aArguments.length >0)
	{
	   
	   //get array of inputs
	   
	     parameterTypeArrayList = new ArrayList<Object>(aArguments.length);
	         
	     for (int i = 0; i < aArguments.length; i++)
	     {
		  if(aArguments[i] == null)
		  {
		     //TODO: throw new RequiredException("argument["+i+"]");
		     parameterTypeArrayList.add(Object.class);
		  }
		  else
		  {
		     parameterTypeArrayList.add(aArguments[i].getClass());   
		  }
		  
		  
	     }
	     	     
	      parameterTypes = (Class[])parameterTypeArrayList.toArray(new Class[parameterTypeArrayList.size()]);  
	}
      
     
      
      //find method
      Method method = null;
      

      method = aObject.getClass().getDeclaredMethod(methodName, parameterTypes);
     
      try
	{
         return method.invoke(aObject, aArguments);
	} 
      catch (Exception e)
	{          
	   throw new SystemException("methodName="+methodName+" object="+aObject.getClass().getName()+" parameters="+parameterTypeArrayList+" EXCEPTION="+Debugger.stackTrace(e));
	}
      
   }
314513
@SuppressWarnings("unchecked")
    public static <T> T performMethodInvocation(Object tested, Method methodToInvoke, Object... arguments)
            throws Exception {
        final boolean accessible = methodToInvoke.isAccessible();
        if (!accessible) {
            methodToInvoke.setAccessible(true);
        }
        try {
            if (isPotentialVarArgsMethod(methodToInvoke, arguments)) {
                Class<?>[] parameterTypes = methodToInvoke.getParameterTypes();
                final int varArgsIndex = parameterTypes.length - 1;
                Class<?> varArgsType = parameterTypes[varArgsIndex].getComponentType();
                Object varArgsArrayInstance = createAndPopulateVarArgsArray(varArgsType, varArgsIndex, arguments);
                Object[] completeArgumentList = new Object[parameterTypes.length];
                System.arraycopy(arguments, 0, completeArgumentList, 0, varArgsIndex);
                completeArgumentList[completeArgumentList.length - 1] = varArgsArrayInstance;
                return (T) methodToInvoke.invoke(tested, completeArgumentList);
            } else {
                return (T) methodToInvoke.invoke(tested, arguments == null ? new Object[]{arguments} : arguments);
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof Exception) {
                throw (Exception) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            } else {
                throw new MethodInvocationException(cause);
            }
        } finally {
            if (!accessible) {
                methodToInvoke.setAccessible(false);
            }
        }
    }
607336
private Object doInvokeMethod(String methodName, Object name, Object args) {
        Reference explicitResult = new Reference();
        if (checkExplicitMethod(methodName, args, explicitResult)) {
            return explicitResult.get();
        } else {
            try {
                return dispatchNodeCall(name, args);
            } catch(MissingMethodException mme) {
                if(mme.getMethod().equals(methodName) && methodMissingDelegate != null) {
                    return methodMissingDelegate.call(methodName, args);
                }
                throw mme;
            }
        }
    }
669873
protected Object getMethodParam(String methodName, String paramKey) {
        if (CommonUtils.isEmpty(configContext)) {
            return null;
        }
        Object o = configContext.get(buildMethodKey(methodName, paramKey));
        return o == null ? configContext.get(paramKey) : o;
    }
208780
private static <T> T bean2Another(Object object, Class<?> clazz, T another) throws InvocationTargetException,
            IllegalAccessException {
        Method[] methods = object.getClass().getMethods();
        Map<String, Method> clazzMethods = ReflectUtils.getMethodMap(clazz, "set");
        for (Method method : methods) {
            String name = method.getName();
            if (name.startsWith("get") && !"getClass".equals(name)) {
                String clazzMethod = "s" + name.substring(1);
                if (clazzMethods.containsKey(clazzMethod)) {
                    Object value = method.invoke(object);
                    if (Checker.isNotNull(value)) {
                        clazzMethods.get(clazzMethod).invoke(another, value);
                    }
                }
            }
        }
        return another;

    }
857414
public static <T> T invokeAndUnwrap(final Object instance, final Method method, final Object... parameters) throws Throwable {
        try {
            return cast(method.invoke(instance, parameters));
        } catch (IllegalArgumentException e) {
            throw ReflectionLogger.LOG.illegalArgumentExceptionOnReflectionInvocation(instance.getClass(), instance, method, Arrays.toString(parameters), e);
        } catch (IllegalAccessException e) {
            throw new WeldException(e);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }
818186
public Object invoke (Object object, String methodName, Object... args) {
		return invoke(object, getIndex(methodName, args == null ? 0 : args.length), args);
	}
673537
public Object beforeInvoke(Object object, String methodName, Object[] arguments) {
        if (!calls.containsKey(methodName)) calls.put(methodName, new LinkedList());
        ((List) calls.get(methodName)).add(System.currentTimeMillis());

        return null;
    }
321160
public static Object invokeMethod(Object target, String method, Object... args) {
    try {
      return InvokerHelper.invokeMethod(target, method, args);
    } catch (InvokerInvocationException e) {
      ExceptionUtil.sneakyThrow(e.getCause());
      return null; // never reached
    }
  }
409120
public Object invokeMethod(Object object, String methodName, Object arguments) {
        return delegate.invokeMethod(object, methodName, arguments);
    }
48054
public void executeMethod(final Class<?> targetClass, final Method targetMethod, final Object[] methodArgs)
            throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {

        addImplementationClasses(targetClass);

        if (methodArgs != null) {
            targetMethod.invoke(instanceMap.get(targetClass), methodArgs);
        } else {
            targetMethod.invoke(instanceMap.get(targetClass));
        }
    }
424185
public static Object callGetter(View view, String methodName) {
        try {
            Method method = view.getClass().getMethod(methodName);
            return method.invoke(view);
        } catch (SecurityException ex) {
            throw new AttributeAccessException(ex);
        } catch (NoSuchMethodException ex) {
            throw new AttributeAccessException("No such attribute", ex);
        } catch (IllegalAccessException ex) {
            throw new AttributeAccessException(ex);
        } catch (InvocationTargetException ex) {
            throw new AttributeAccessException(ex);
        }
    }
1292133
public static Object invokeMethod(Object bean, Method method, Object... args) throws Exception {
        Class<?>[] types    = method.getParameterTypes();
        int        argCount = args == null ? 0 : args.length;
        // 参数个数对不上
        if (argCount != types.length) {
            throw new IllegalStateException(String.format("%s in %s", method.getName(), bean));
        }

        // 转参数类型
        for (int i = 0; i < argCount; i++) {
            args[i] = cast(args[i], types[i]);
        }
        return method.invoke(bean, args);
    }
1369234
public static <T> T invokeMethodByName(final Object target, final String name, final Object[] parameterValues) {
		Method method = getAccessibleMethodByName(target, name);
		if (method == null) {
			throw new IllegalArgumentException("Could not find method [" + name + "] on target [" + target + ']');
		}

		try {
			return (T) method.invoke(target, parameterValues);
		} catch (ReflectiveOperationException e) {
			throw new ReflectionRuntimeException(e);
		}
	}
395184
public <T> T execute(final String methodName, final Class<T> clazz, final Object... args) {
        return execute(methodName, clazz, true, args);
    }
985354
public static Object invokeMethod(Object obj, String methodName, Object... params) {
        Method method = findMethod(obj, methodName, params);
        return invokeMethod(obj, method, params);
    }