View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.argeo.slc.core.execution.tasks;
17  
18  import java.lang.reflect.Method;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.springframework.util.Assert;
23  import org.springframework.util.ReflectionUtils;
24  
25  public class MethodCall implements Runnable {
26  	private Object target;
27  	private String method;
28  	private List<Object> args = new ArrayList<Object>();
29  
30  	public void run() {
31  		Assert.notNull(target, "target");
32  		Assert.notNull(method, "method");
33  		Method methodRef = ReflectionUtils
34  				.findMethod(target.getClass(), method);
35  		if (args.size() == 0)
36  			ReflectionUtils.invokeMethod(methodRef, target);
37  		else
38  			ReflectionUtils.invokeMethod(methodRef, methodRef, args.toArray());
39  	}
40  
41  	public void setTarget(Object target) {
42  		this.target = target;
43  	}
44  
45  	public void setMethod(String method) {
46  		this.method = method;
47  	}
48  
49  	public void setArgs(List<Object> args) {
50  		this.args = args;
51  	}
52  
53  }