Java Code Examples for org.springframework.aop.ProxyMethodInvocation#setUserAttribute()

The following examples show how to use org.springframework.aop.ProxyMethodInvocation#setUserAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AspectJExpressionPointcut.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm) {
	// Note: Can't use JoinPointMatch.getClass().getName() as the key, since
	// Spring AOP does all the matching at a join point, and then all the invocations
	// under this scenario, if we just use JoinPointMatch as the key, then
	// 'last man wins' which is not what we want at all.
	// Using the expression is guaranteed to be safe, since 2 identical expressions
	// are guaranteed to bind in exactly the same way.
	invocation.setUserAttribute(resolveExpression(), jpm);
}
 
Example 2
Source File: AbstractAspectJAdvice.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: ExposeBeanNameAdvisors.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return mi.proceed();
}
 
Example 4
Source File: ExposeBeanNameAdvisors.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return super.invoke(mi);
}
 
Example 5
Source File: AspectJExpressionPointcut.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm) {
	// Note: Can't use JoinPointMatch.getClass().getName() as the key, since
	// Spring AOP does all the matching at a join point, and then all the invocations
	// under this scenario, if we just use JoinPointMatch as the key, then
	// 'last man wins' which is not what we want at all.
	// Using the expression is guaranteed to be safe, since 2 identical expressions
	// are guaranteed to bind in exactly the same way.
	invocation.setUserAttribute(resolveExpression(), jpm);
}
 
Example 6
Source File: AbstractAspectJAdvice.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: ExposeBeanNameAdvisors.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return mi.proceed();
}
 
Example 8
Source File: ExposeBeanNameAdvisors.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return super.invoke(mi);
}
 
Example 9
Source File: AspectJExpressionPointcut.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm) {
	// Note: Can't use JoinPointMatch.getClass().getName() as the key, since
	// Spring AOP does all the matching at a join point, and then all the invocations
	// under this scenario, if we just use JoinPointMatch as the key, then
	// 'last man wins' which is not what we want at all.
	// Using the expression is guaranteed to be safe, since 2 identical expressions
	// are guaranteed to bind in exactly the same way.
	invocation.setUserAttribute(getExpression(), jpm);
}
 
Example 10
Source File: AbstractAspectJAdvice.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: ExposeBeanNameAdvisors.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return mi.proceed();
}
 
Example 12
Source File: ExposeBeanNameAdvisors.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return super.invoke(mi);
}
 
Example 13
Source File: AspectJExpressionPointcut.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm) {
	// Note: Can't use JoinPointMatch.getClass().getName() as the key, since
	// Spring AOP does all the matching at a join point, and then all the invocations
	// under this scenario, if we just use JoinPointMatch as the key, then
	// 'last man wins' which is not what we want at all.
	// Using the expression is guaranteed to be safe, since 2 identical expressions
	// are guaranteed to bind in exactly the same way.
	invocation.setUserAttribute(getExpression(), jpm);
}
 
Example 14
Source File: AbstractAspectJAdvice.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: ExposeBeanNameAdvisors.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return mi.proceed();
}
 
Example 16
Source File: ExposeBeanNameAdvisors.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {
	if (!(mi instanceof ProxyMethodInvocation)) {
		throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
	}
	ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
	pmi.setUserAttribute(BEAN_NAME_ATTRIBUTE, this.beanName);
	return super.invoke(mi);
}