Java Code Examples for org.springframework.aop.Advisor#getAdvice()

The following examples show how to use org.springframework.aop.Advisor#getAdvice() . 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: DefaultAdvisorAdapterRegistry.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
	List<MethodInterceptor> interceptors = new ArrayList<>(3);
	Advice advice = advisor.getAdvice();
	if (advice instanceof MethodInterceptor) {
		interceptors.add((MethodInterceptor) advice);
	}
	for (AdvisorAdapter adapter : this.adapters) {
		if (adapter.supportsAdvice(advice)) {
			interceptors.add(adapter.getInterceptor(advisor));
		}
	}
	if (interceptors.isEmpty()) {
		throw new UnknownAdviceTypeException(advisor.getAdvice());
	}
	return interceptors.toArray(new MethodInterceptor[0]);
}
 
Example 2
Source File: DefaultAdvisorAdapterRegistry.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {
	List<MethodInterceptor> interceptors = new ArrayList<>(3);
	Advice advice = advisor.getAdvice();
	if (advice instanceof MethodInterceptor) {
		interceptors.add((MethodInterceptor) advice);
	}
	for (AdvisorAdapter adapter : this.adapters) {
		if (adapter.supportsAdvice(advice)) {
			interceptors.add(adapter.getInterceptor(advisor));
		}
	}
	if (interceptors.isEmpty()) {
		throw new UnknownAdviceTypeException(advisor.getAdvice());
	}
	return interceptors.toArray(new MethodInterceptor[0]);
}
 
Example 3
Source File: AdvisedSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Is the given advice included in any advisor within this proxy configuration?
 * @param advice the advice to check inclusion of
 * @return whether this advice instance is included
 */
public boolean adviceIncluded(@Nullable Advice advice) {
	if (advice != null) {
		for (Advisor advisor : this.advisors) {
			if (advisor.getAdvice() == advice) {
				return true;
			}
		}
	}
	return false;
}
 
Example 4
Source File: AdvisedSupport.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Is the given advice included in any advisor within this proxy configuration?
 * @param advice the advice to check inclusion of
 * @return whether this advice instance is included
 */
public boolean adviceIncluded(@Nullable Advice advice) {
	if (advice != null) {
		for (Advisor advisor : this.advisors) {
			if (advisor.getAdvice() == advice) {
				return true;
			}
		}
	}
	return false;
}
 
Example 5
Source File: AspectJAopUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return the AspectJPrecedenceInformation provided by this advisor or its advice.
 * If neither the advisor nor the advice have precedence information, this method
 * will return {@code null}.
 */
@Nullable
public static AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(Advisor anAdvisor) {
	if (anAdvisor instanceof AspectJPrecedenceInformation) {
		return (AspectJPrecedenceInformation) anAdvisor;
	}
	Advice advice = anAdvisor.getAdvice();
	if (advice instanceof AspectJPrecedenceInformation) {
		return (AspectJPrecedenceInformation) advice;
	}
	return null;
}
 
Example 6
Source File: AspectJAopUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Return {@code true} if the advisor is a form of after advice.
 */
public static boolean isAfterAdvice(Advisor anAdvisor) {
	AspectJPrecedenceInformation precedenceInfo = getAspectJPrecedenceInformationFor(anAdvisor);
	if (precedenceInfo != null) {
		return precedenceInfo.isAfterAdvice();
	}
	return (anAdvisor.getAdvice() instanceof AfterAdvice);
}
 
Example 7
Source File: AspectJProxyUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine whether the given Advisor contains an AspectJ advice.
 * @param advisor the Advisor to check
 */
private static boolean isAspectJAdvice(Advisor advisor) {
	return (advisor instanceof InstantiationModelAwarePointcutAdvisor ||
			advisor.getAdvice() instanceof AbstractAspectJAdvice ||
			(advisor instanceof PointcutAdvisor &&
					((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut));
}
 
Example 8
Source File: AspectJProxyUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine whether the given Advisor contains an AspectJ advice.
 * @param advisor the Advisor to check
 */
private static boolean isAspectJAdvice(Advisor advisor) {
	return (advisor instanceof InstantiationModelAwarePointcutAdvisor ||
			advisor.getAdvice() instanceof AbstractAspectJAdvice ||
			(advisor instanceof PointcutAdvisor &&
					((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut));
}
 
Example 9
Source File: AdvisedSupport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public int indexOf(Advice advice) {
	Assert.notNull(advice, "Advice must not be null");
	for (int i = 0; i < this.advisors.size(); i++) {
		Advisor advisor = this.advisors.get(i);
		if (advisor.getAdvice() == advice) {
			return i;
		}
	}
	return -1;
}
 
Example 10
Source File: AspectJAopUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the AspectJPrecedenceInformation provided by this advisor or its advice.
 * If neither the advisor nor the advice have precedence information, this method
 * will return {@code null}.
 */
@Nullable
public static AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(Advisor anAdvisor) {
	if (anAdvisor instanceof AspectJPrecedenceInformation) {
		return (AspectJPrecedenceInformation) anAdvisor;
	}
	Advice advice = anAdvisor.getAdvice();
	if (advice instanceof AspectJPrecedenceInformation) {
		return (AspectJPrecedenceInformation) advice;
	}
	return null;
}
 
Example 11
Source File: AspectJAopUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return {@code true} if the advisor is a form of after advice.
 */
public static boolean isAfterAdvice(Advisor anAdvisor) {
	AspectJPrecedenceInformation precedenceInfo = getAspectJPrecedenceInformationFor(anAdvisor);
	if (precedenceInfo != null) {
		return precedenceInfo.isAfterAdvice();
	}
	return (anAdvisor.getAdvice() instanceof AfterAdvice);
}
 
Example 12
Source File: ThrowsAdviceAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	return new ThrowsAdviceInterceptor(advisor.getAdvice());
}
 
Example 13
Source File: MethodBeforeAdviceAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	MethodBeforeAdvice advice = (MethodBeforeAdvice) advisor.getAdvice();
	return new MethodBeforeAdviceInterceptor(advice);
}
 
Example 14
Source File: AdvisorAdapterRegistrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) {
	Advised advised = (Advised) tb;
	Advisor advisor = advised.getAdvisors()[0];
	return (SimpleBeforeAdviceImpl) advisor.getAdvice();
}
 
Example 15
Source File: AdvisorAdapterRegistrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	SimpleBeforeAdvice advice = (SimpleBeforeAdvice) advisor.getAdvice();
	return new SimpleBeforeAdviceInterceptor(advice) ;
}
 
Example 16
Source File: AfterReturningAdviceAdapter.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	AfterReturningAdvice advice = (AfterReturningAdvice) advisor.getAdvice();
	return new AfterReturningAdviceInterceptor(advice);
}
 
Example 17
Source File: AspectJPrecedenceComparator.java    From java-technology-stack with MIT License 4 votes vote down vote up
private boolean hasAspectName(Advisor anAdvisor) {
	return (anAdvisor instanceof AspectJPrecedenceInformation ||
			anAdvisor.getAdvice() instanceof AspectJPrecedenceInformation);
}
 
Example 18
Source File: ThrowsAdviceAdapter.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	return new ThrowsAdviceInterceptor(advisor.getAdvice());
}
 
Example 19
Source File: AdvisorAdapterRegistrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	SimpleBeforeAdvice advice = (SimpleBeforeAdvice) advisor.getAdvice();
	return new SimpleBeforeAdviceInterceptor(advice) ;
}
 
Example 20
Source File: AspectJPrecedenceComparator.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private boolean hasAspectName(Advisor anAdvisor) {
	return (anAdvisor instanceof AspectJPrecedenceInformation ||
			anAdvisor.getAdvice() instanceof AspectJPrecedenceInformation);
}