Browse Source

jfinal 3.8

James 6 years ago
parent
commit
01d277ac24

+ 9 - 38
src/main/java/com/jfinal/aop/Callback.java

@@ -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() {

+ 2 - 5
src/main/java/com/jfinal/aop/Invocation.java

@@ -31,7 +31,6 @@ public class Invocation {
 	private Action action;
 	// private static final Object[] NULL_ARGS = new Object[0];	// Prevent new Object[0] by jvm for paras of action invocation.
 	
-	boolean useInjectTarget;
 	private Object target;
 	private Method method;
 	private Object[] args;
@@ -78,10 +77,8 @@ public class Invocation {
 				else {
 					// if (!Modifier.isAbstract(method.getModifiers()))
 						// returnValue = methodProxy.invokeSuper(target, args);
-					if (useInjectTarget)
-						returnValue = methodProxy.invoke(target, args);
-					else
-						returnValue = methodProxy.invokeSuper(target, args);
+					
+					returnValue = methodProxy.invokeSuper(target, args);
 				}
 			}
 			catch (InvocationTargetException e) {