package org.theonefx.wcframework.aop;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import org.theonefx.aopaloance.intercept.MethodInterceptor;
import org.theonefx.aopaloance.intercept.MethodInvocation;
/**
* @Package org.fx.wcframework.aop
* @ClassName: MethodInvocation
* @author 陈曦
* @date 2011-1-24 20:01:09
* @Description: 拦截器链的调用器
*/
public class ProxyedObjectMethodInvocation implements MethodInvocation {
// 当前拦截器在拦截器链中的索引号
private int index = -1;
private InterceptorChain chain;
private TargetMethodInvoker targetMethodInvoker;
public ProxyedObjectMethodInvocation(TargetMethodInvoker targetMethodInvoker, InterceptorChain chain) {
this.chain = chain;
this.targetMethodInvoker = targetMethodInvoker;
}
public Object proceed() throws Throwable {
index++;
if (index >= chain.getSize()) {
return targetMethodInvoker.invoke();
}
MethodInterceptor interceptor = chain.get(index);
if (interceptor != null) {
return interceptor.invoke(this);
} else {
return proceed();
}
}
public Method getMethod() {
return targetMethodInvoker.getMethod();
}
public Object[] getArguments() {
return (targetMethodInvoker.getArgs() != null ? targetMethodInvoker.getArgs() : new Object[0]);
}
public AccessibleObject getStaticPart() {
return targetMethodInvoker.getMethod();
}
public Object getThis() {
return targetMethodInvoker.getTarget();
}
public int getIndex() {
return index;
}
}