美文网首页
2018-08-30

2018-08-30

作者: yeathMe | 来源:发表于2018-08-30 20:30 被阅读0次
    /**
     * Implementation of {@code InvocationHandler.invoke}.
     * <p>Callers will see exactly the exception thrown by the target,
     * unless a hook method throws an exception.
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MethodInvocation invocation;
        Object oldProxy = null;
        boolean setProxyContext = false;
// Get the interception chain for this method.
            List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);

            // Check whether we have any advice. If we don't, we can fallback on direct
            // reflective invocation of the target, and avoid creating a MethodInvocation.
            if (chain.isEmpty()) {
                // We can skip creating a MethodInvocation: just invoke the target directly
                // Note that the final invoker must be an InvokerInterceptor so we know it does
                // nothing but a reflective operation on the target, and no hot swapping or fancy proxying.
                Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
                retVal = AopUtils.invokeJoinpointUsingReflection(target, method, argsToUse);
            }
            else {
                // We need to create a method invocation...
                invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
                // Proceed to the joinpoint through the interceptor chain.
                retVal = invocation.proceed();
            }

            // Massage return value if necessary.
            Class<?> returnType = method.getReturnType();
            if (retVal != null && retVal == target && returnType.isInstance(proxy) &&
                    !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
                // Special case: it returned "this" and the return type of the method
                // is type-compatible. Note that we can't help if the target sets
                // a reference to itself in another returned object.
                retVal = proxy;
            }
            else if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) {
                throw new AopInvocationException(
                        "Null return value from advice does not match primitive return type for: " + method);
            }
            return retVal;




相关文章

  • 2018-09-01

    2018-08-30 明小萌 2018-08-30 22:02 · 字数 223 · 阅读 2 · 日记本 201...

  • 2018-09-05

    2018-08-30 c6_李晓红Dorothy 2018-08-30 07:44 · 字数 320 · 阅读 1...

  • hexo博客同时托管到github和coding

    title: 将hexo博客同时托管到github和codingdate: 2018-08-30 00:12:11...

  • 420期六项精进-日精进打卡

    420期六项精进-日精进打卡 雷PetTing 2018-08-30 22:44 · 字数 570 · 阅读 2 ...

  • 2018-08-31

    2018-08-31 万千工品金秀 2018-08-30 21:31 · 字数 542 · 阅读 2 · 日记本 ...

  • 2018-08-30

    2018-08-30 万千工品金秀 2018-08-29 21:16 · 字数 464 · 阅读 2 · 日记本 ...

  • 懂你 L4-U1-3-Vocabulary-Dental Pro

    流利说 D64 2018-08-30 一、复习 Level4-Unit1-Part3*Learning- List...

  • 所谓浪漫

    所谓浪漫 煎蛋品 2018-08-30 23:12 · 字数 355 · 阅读 0 · 失眠 几乎六年没见的小学同...

  • java.lang.IllegalStateException:

    2018-08-30 遇到的一点小问题将项目的targetSdkVersion升级为27,遇到了java.lang...

  • 日精打卡60

    日精打卡60 淡然笑_ce8e 2018-08-30 19:34 · 字数 336 · 阅读 1 · 日记本 淡然...

网友评论

      本文标题:2018-08-30

      本文链接:https://www.haomeiwen.com/subject/skodwftx.html