1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.plugin;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.lang.reflect.Method;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.apache.ibatis.executor.Executor;
24 import org.apache.ibatis.executor.parameter.ParameterHandler;
25 import org.apache.ibatis.executor.resultset.ResultSetHandler;
26 import org.apache.ibatis.executor.statement.StatementHandler;
27
28
29
30
31 public class Invocation {
32
33 private static final List<Class<?>> targetClasses = Arrays.asList(Executor.class, ParameterHandler.class,
34 ResultSetHandler.class, StatementHandler.class);
35 private final Object target;
36 private final Method method;
37 private final Object[] args;
38
39 public Invocation(Object target, Method method, Object[] args) {
40 if (!targetClasses.contains(method.getDeclaringClass())) {
41 throw new IllegalArgumentException("Method '" + method + "' is not supported as a plugin target.");
42 }
43 this.target = target;
44 this.method = method;
45 this.args = args;
46 }
47
48 public Object getTarget() {
49 return target;
50 }
51
52 public Method getMethod() {
53 return method;
54 }
55
56 public Object[] getArgs() {
57 return args;
58 }
59
60 public Object proceed() throws InvocationTargetException, IllegalAccessException {
61 return method.invoke(target, args);
62 }
63
64 }