/** * Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor * has been included in the interceptor chain. * @param mi the MethodInvocation that should contain the bean name as an attribute * @return the bean name (never {@code null}) * @throws IllegalStateException if the bean name has not been exposed */ public static String getBeanName(MethodInvocation mi) throws IllegalStateException { if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE); if (beanName == null) { throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi); } return beanName; }
@Nullable protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) { String expression = this.pointcut.getExpression(); return (expression != null ? (JoinPointMatch) pmi.getUserAttribute(expression) : null); }
/** * Lazily instantiate joinpoint for the current invocation. * Requires MethodInvocation to be bound with ExposeInvocationInterceptor. * <p>Do not use if access is available to the current ReflectiveMethodInvocation * (in an around advice). * @return current AspectJ joinpoint, or through an exception if we're not in a * Spring AOP invocation. */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); pmi.setUserAttribute(JOIN_POINT_KEY, jp); } return jp; }
/** * Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor * has been included in the interceptor chain. * @param mi the MethodInvocation that should contain the bean name as an attribute * @return the bean name (never {@code null}) * @throws IllegalStateException if the bean name has not been exposed */ public static String getBeanName(MethodInvocation mi) throws IllegalStateException { if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE); if (beanName == null) { throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi); } return beanName; }
/** * Find the bean name for the given invocation. Assumes that an ExposeBeanNameAdvisor * has been included in the interceptor chain. * @param mi MethodInvocation that should contain the bean name as an attribute * @return the bean name (never {@code null}) * @throws IllegalStateException if the bean name has not been exposed */ public static String getBeanName(MethodInvocation mi) throws IllegalStateException { if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalArgumentException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; String beanName = (String) pmi.getUserAttribute(BEAN_NAME_ATTRIBUTE); if (beanName == null) { throw new IllegalStateException("Cannot get bean name; not set on MethodInvocation: " + mi); } return beanName; }
@Nullable protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) { String expression = this.pointcut.getExpression(); return (expression != null ? (JoinPointMatch) pmi.getUserAttribute(expression) : null); }
/** * Lazily instantiate joinpoint for the current invocation. * Requires MethodInvocation to be bound with ExposeInvocationInterceptor. * <p>Do not use if access is available to the current ReflectiveMethodInvocation * (in an around advice). * @return current AspectJ joinpoint, or through an exception if we're not in a * Spring AOP invocation. */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); pmi.setUserAttribute(JOIN_POINT_KEY, jp); } return jp; }
/** * Lazily instantiate joinpoint for the current invocation. * Requires MethodInvocation to be bound with ExposeInvocationInterceptor. * <p>Do not use if access is available to the current ReflectiveMethodInvocation * (in an around advice). * @return current AspectJ joinpoint, or through an exception if we're not in a * Spring AOP invocation. */ public static JoinPoint currentJoinPoint() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY); if (jp == null) { jp = new MethodInvocationProceedingJoinPoint(pmi); pmi.setUserAttribute(JOIN_POINT_KEY, jp); } return jp; }