|
|
@@ -28,7 +28,6 @@ import static com.jfinal.aop.InterceptorManager.NULL_INTERS;
|
|
|
*/
|
|
|
class Callback implements MethodInterceptor {
|
|
|
|
|
|
- private Object injectTarget = null;
|
|
|
private final Interceptor[] injectInters;
|
|
|
|
|
|
private static final Set<String> excludedMethodName = buildExcludedMethodName();
|
|
|
@@ -43,15 +42,6 @@ class Callback implements MethodInterceptor {
|
|
|
this.injectInters = injectInters;
|
|
|
}
|
|
|
|
|
|
- public Callback(Object injectTarget, Interceptor... injectInters) {
|
|
|
- if (injectTarget == null) {
|
|
|
- throw new IllegalArgumentException("injectTarget can not be null.");
|
|
|
- }
|
|
|
- checkInjectInterceptors(injectInters);
|
|
|
- this.injectTarget = injectTarget;
|
|
|
- this.injectInters = injectInters;
|
|
|
- }
|
|
|
-
|
|
|
private void checkInjectInterceptors(Interceptor... injectInters) {
|
|
|
if (injectInters == null) {
|
|
|
throw new IllegalArgumentException("injectInters can not be null.");
|
|
|
@@ -65,37 +55,18 @@ class Callback implements MethodInterceptor {
|
|
|
|
|
|
public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
|
|
if (excludedMethodName.contains(method.getName())) {
|
|
|
- // if (method.getName().equals("finalize"))
|
|
|
- // return methodProxy.invokeSuper(target, args);
|
|
|
- // return this.injectTarget != null ? methodProxy.invoke(this.injectTarget, args) : methodProxy.invokeSuper(target, args);
|
|
|
-
|
|
|
- // 保留上面注释部分,此处为优化
|
|
|
- if (this.injectTarget == null || method.getName().equals("finalize")) {
|
|
|
- return methodProxy.invokeSuper(target, args);
|
|
|
- } else {
|
|
|
- return methodProxy.invoke(this.injectTarget, args);
|
|
|
- }
|
|
|
+ return methodProxy.invokeSuper(target, args);
|
|
|
}
|
|
|
|
|
|
- if (this.injectTarget != null) {
|
|
|
- target = this.injectTarget;
|
|
|
- Interceptor[] finalInters = interMan.buildServiceMethodInterceptor(injectInters, target.getClass(), method);
|
|
|
- Invocation invocation = new Invocation(target, method, args, methodProxy, finalInters);
|
|
|
- invocation.useInjectTarget = true;
|
|
|
- invocation.invoke();
|
|
|
- return invocation.getReturnValue();
|
|
|
- }
|
|
|
- else {
|
|
|
- Class<?> targetClass = target.getClass();
|
|
|
- if (targetClass.getName().indexOf("$$EnhancerBy") != -1) {
|
|
|
- targetClass = targetClass.getSuperclass();
|
|
|
- }
|
|
|
- Interceptor[] finalInters = interMan.buildServiceMethodInterceptor(injectInters, targetClass, method);
|
|
|
- Invocation invocation = new Invocation(target, method, args, methodProxy, finalInters);
|
|
|
- invocation.useInjectTarget = false;
|
|
|
- invocation.invoke();
|
|
|
- return invocation.getReturnValue();
|
|
|
+ Class<?> targetClass = target.getClass();
|
|
|
+ if (targetClass.getName().indexOf("$$EnhancerBy") != -1) {
|
|
|
+ targetClass = targetClass.getSuperclass();
|
|
|
}
|
|
|
+
|
|
|
+ Interceptor[] finalInters = interMan.buildServiceMethodInterceptor(injectInters, targetClass, method);
|
|
|
+ Invocation invocation = new Invocation(target, method, args, methodProxy, finalInters);
|
|
|
+ invocation.invoke();
|
|
|
+ return invocation.getReturnValue();
|
|
|
}
|
|
|
|
|
|
private static final Set<String> buildExcludedMethodName() {
|