Spring Framework MethodInvoker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MethodInvoker class.

This code example shows how to use the following methods:invoke, prepare, setArguments, setTargetMethod, setTargetObject
	 * @see #getListenerMethodName 
	 * @see #buildListenerArguments 
	 */ 
	protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException {
		try { 
			MethodInvoker methodInvoker = new MethodInvoker();
			methodInvoker.setTargetObject(getDelegate());
			methodInvoker.setTargetMethod(methodName);
			methodInvoker.setArguments(arguments);
			methodInvoker.prepare();
			return methodInvoker.invoke();
		} 
		catch (InvocationTargetException ex) {
			Throwable targetEx = ex.getTargetException();
			if (targetEx instanceof JMSException) {
				throw (JMSException) targetEx;
			} 
			else { 
				throw new ListenerExecutionFailedException( 
						"Listener method '" + methodName + "' threw exception", targetEx);
7
CodeRank
This code example shows how to use the following methods:getTargetMethod, invoke, getTargetClass
 
 
	@Override 
	public void run() { 
		try { 
			invoke();
		} 
		catch (InvocationTargetException ex) {
			logger.error(getInvocationFailureMessage(), ex.getTargetException());
			// Do not throw exception, else the main loop of the scheduler might stop! 
		} 
		catch (Throwable ex) {
			logger.error(getInvocationFailureMessage(), ex);
			// Do not throw exception, else the main loop of the scheduler might stop! 
		} 
	} 
 
	/** 
	 * Build a message for an invocation failure exception. 
	 * @return the error message, including the target method name etc 

7
CodeRank
This code example shows how to use the following methods:getTargetClass, getTargetMethod
	 * Constructor for JobMethodInvocationFailedException. 
	 * @param methodInvoker the MethodInvoker used for reflective invocation 
	 * @param cause the root cause (as thrown from the target method) 
	 */ 
	public JobMethodInvocationFailedException(MethodInvoker methodInvoker, Throwable cause) {
		super("Invocation of method '" + methodInvoker.getTargetMethod() +
				"' on target class [" + methodInvoker.getTargetClass() + "] failed", cause);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:setTargetMethod, setTargetObject
This code example shows how to use the following methods:invoke, prepare, setTargetMethod, setTargetObject
This code example shows how to use the following methods:invoke, prepare, setArguments, setTargetMethod, setTargetObject
	 */ 
	public static Object invokeBeanMethod(String beanName, String methodName,
			Object[] arguments) {
		try { 
			// 初始化 
			MethodInvoker methodInvoker = new MethodInvoker();
			methodInvoker.setTargetObject(SpringUtils.getBean(beanName));
			methodInvoker.setTargetMethod(methodName);
 
			// 设置参数 
			if (arguments != null && arguments.length > 0) {
				methodInvoker.setArguments(arguments);
			} 
 
			// 准备方法 
			methodInvoker.prepare();
 
			// 执行方法 
			return methodInvoker.invoke();
		} catch (ClassNotFoundException e) {

6
CodeRank
This code example shows how to use the following methods:invoke, prepare
	public void setArgument(Object argument) {
		setArguments(new Object[] {argument});
	} 
	 
	public void afterPropertiesSet() throws Exception {
		prepare();
		invoke();
	}	 
 
} 
6
CodeRank
This code example shows how to use the following methods:
 *  
 * @author Dave Syer 
 *  
 * @since 2.1 
 */ 
public class HippyMethodInvoker extends MethodInvoker {
 
	@Override 
	protected Method findMatchingMethod() {
		String targetMethod = getTargetMethod();
		Object[] arguments = getArguments();
		int argCount = arguments.length;
 
		Method[] candidates = ReflectionUtils.getAllDeclaredMethods(getTargetClass());
		int minTypeDiffWeight = Integer.MAX_VALUE;
		Method matchingMethod = null;
 
		Object[] transformedArguments = null;
		int transformedArgumentCount = 0;
 
5
CodeRank
This code example shows how to use the following methods:invoke
		 * Invoke the method via the MethodInvoker. 
		 */ 
		@Override 
		protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
			try { 
				context.setResult(this.methodInvoker.invoke());
			} 
			catch (InvocationTargetException ex) {
				if (ex.getTargetException() instanceof JobExecutionException) {
					// -> JobExecutionException, to be logged at info level by Quartz 
					throw (JobExecutionException) ex.getTargetException();
				} 
				else { 
					// -> "unhandled exception", to be logged at error level by Quartz 
					throw new JobMethodInvocationFailedException(this.methodInvoker, ex.getTargetException());
				} 
			} 
			catch (Exception ex) {
				// -> "unhandled exception", to be logged at error level by Quartz 
				throw new JobMethodInvocationFailedException(this.methodInvoker, ex);
5
CodeRank
This code example shows how to use the following methods:prepare
	public void setOrder(int order) {
		this.order = order;
	} 
	 
	public void afterPropertiesSet() throws Exception {
		prepare();
	} 
	 
	public void execute() throws Exception {
		invoke();
	} 
} 
5
CodeRank
See Code Examples for Spring Framework MethodInvoker Methods: