publicobjectinvoke (对象代理,方法方法,对象[ ] args ) throwsThrowable {
Methodinvocationinvocation=空;
对象old proxy=null;
布尔设置代理上下文=false;
targetsourcetargetsource=this.advised.target source;
类目标类=null;
对象目标=null;
try {
//eqauls ()方法,目标对象没有实现此方法
if (! this.equalsdefinedaoputils.isequalsmethod (method ) }
返回(equals (args [0]? Boolean.TRUE : Boolean.FALSE;
}
//hashCode ),目标对象没有实现此方法
if (! this.hashcodedefinedaoputils.ishashcodemethod (method ) }
返回新整数(hashcode ) );
}
//Advised接口或其父接口中定义的方法直接反射调用,不应用通知
if (! this.advised.opaque method.getdeclaringclass ().is接口)。
method.getDeclaringClass ().isassignablefrom ) ) advised.class ) }
//serviceinvocationsonproxyconfigwiththeproxyconfig .
returnaoputils.invokejoinpointusingreflection (this.advised,method,args );
}
对象返回=空值;
if(this.advised.exposeproxy ) {
//makeinvocationavailableifnecessary。
old proxy=AOP context.setcurrentproxy (proxy;
setProxyContext=true;
}
//获取目标对象的类
target=targetSource.getTarget (;
if (目标!=空) {
targetClass=target.getClass (;
}
//获取可应用于此方法的拦截器列表
list chain=this.advised.getinterceptorsanddynamicinterceptionadvice (method,targetClass );
//如果没有可以应用于此方法的通知(Interceptor ),则此直接反射调用method.invoke ) target,args
if(chain.isempty () ) ) ) )。
retval=AOP utils.invokejoinpointusingreflection (target,method,args );
} else {
创建方法调用
invocation=newreflectivemethodinvocation (代理、target、method、args、targetClass、chain );
retVal=invocation.proceed (;
}
//massagereturnvalueifnecessary。
If (回帖!=null retval==target method.get returntype ().isinstance(proxy ) ) ) ) ) )。
! rawtargetaccess.class.isassignablefrom (method.getdeclaringclass (() ) }{
//special case : it returned ' this ' andthereturntypeofthemethod
//istype-compatible.notethatwecan ' thelpifthetargetsets
//areferencetoitselfinanotherreturnedobject。
retVal=proxy;
}
返回恢复;
} finally {
if (目标!=空! targetSource.isStatic (
//Must have come fromTargetSource。
目标源. release target (target;
}
if(setproxycontext ) {
//恢复old proxy。
AOPcontext.setcurrentproxy;
}
}
}