Java Code Examples for org.springframework.aop.support.ComposablePointcut

The following examples show how to use org.springframework.aop.support.ComposablePointcut. These examples are extracted from open source projects. 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 Project: beihu-boot   Source File: ApiBootDataSourceSwitchAdvisor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * build pointcut instance
 */
private Pointcut buildPointcut() {
    // class
    Pointcut cpc = new AnnotationMatchingPointcut(DataSourceSwitch.class, true);
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(DataSourceSwitch.class);

    //union
    ComposablePointcut pointcut = new ComposablePointcut(cpc);
    return pointcut.union(mpc);
}
 
Example 2
Source Project: spring-analysis-note   Source File: AbstractAspectJAdvice.java    License: MIT License 5 votes vote down vote up
/**
 * Build a 'safe' pointcut that excludes the AspectJ advice method itself.
 * @return a composable pointcut that builds on the original AspectJ expression pointcut
 * @see #getPointcut()
 */
public final Pointcut buildSafePointcut() {
	Pointcut pc = getPointcut();
	MethodMatcher safeMethodMatcher = MethodMatchers.intersection(
			new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher());
	return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher);
}
 
Example 3
Source Project: java-technology-stack   Source File: AbstractAspectJAdvice.java    License: MIT License 5 votes vote down vote up
/**
 * Build a 'safe' pointcut that excludes the AspectJ advice method itself.
 * @return a composable pointcut that builds on the original AspectJ expression pointcut
 * @see #getPointcut()
 */
public final Pointcut buildSafePointcut() {
	Pointcut pc = getPointcut();
	MethodMatcher safeMethodMatcher = MethodMatchers.intersection(
			new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher());
	return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher);
}
 
Example 4
Source Project: api-boot   Source File: ApiBootDataSourceSwitchAdvisor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * build pointcut instance
 * use {@link DataSourceSwitch} as a {@link Pointcut}
 * scope:
 * 1. {@link DataSourceSwitch} on the class
 * 2. {@link DataSourceSwitch} on the method
 */
private Pointcut buildPointcut() {
    // class
    Pointcut cpc = new AnnotationMatchingPointcut(DataSourceSwitch.class, true);
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(DataSourceSwitch.class);

    //union
    ComposablePointcut pointcut = new ComposablePointcut(cpc);
    return pointcut.union(mpc);
}
 
Example 5
Source Project: lams   Source File: AbstractAspectJAdvice.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build a 'safe' pointcut that excludes the AspectJ advice method itself.
 * @return a composable pointcut that builds on the original AspectJ expression pointcut
 * @see #getPointcut()
 */
public final Pointcut buildSafePointcut() {
	Pointcut pc = getPointcut();
	MethodMatcher safeMethodMatcher = MethodMatchers.intersection(
			new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher());
	return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher);
}
 
Example 6
/**
 * Build a 'safe' pointcut that excludes the AspectJ advice method itself.
 * @return a composable pointcut that builds on the original AspectJ expression pointcut
 * @see #getPointcut()
 */
public final Pointcut buildSafePointcut() {
	Pointcut pc = getPointcut();
	MethodMatcher safeMethodMatcher = MethodMatchers.intersection(
			new AdviceExcludingMethodMatcher(this.aspectJAdviceMethod), pc.getMethodMatcher());
	return new ComposablePointcut(pc.getClassFilter(), safeMethodMatcher);
}
 
Example 7
/**
 * Calculate a pointcut for the given async annotation types, if any.
 * @param asyncAnnotationTypes the async annotation types to introspect
 * @return the applicable Pointcut object, or {@code null} if none
 */
protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) {
	ComposablePointcut result = null;
	for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) {
		Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
		Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(asyncAnnotationType);
		if (result == null) {
			result = new ComposablePointcut(cpc).union(mpc);
		}
		else {
			result.union(cpc).union(mpc);
		}
	}
	return result;
}
 
Example 8
ShardingTransactionTypeAdvisor() {
    Pointcut classPointcut = new ComposablePointcut(AnnotationMatchingPointcut.forClassAnnotation(ShardingTransactionType.class));
    Pointcut methodPointcut = new ComposablePointcut(AnnotationMatchingPointcut.forMethodAnnotation(ShardingTransactionType.class));
    transactionTypePointcut = new ComposablePointcut(classPointcut).union(methodPointcut);
    transactionTypeInterceptor = new ShardingTransactionTypeInterceptor();
    setOrder(Ordered.LOWEST_PRECEDENCE - 1);
}
 
Example 9
Source Project: spring-analysis-note   Source File: AspectMetadata.java    License: MIT License 4 votes vote down vote up
/**
 * Create a new AspectMetadata instance for the given aspect class.
 * @param aspectClass the aspect class
 * @param aspectName the name of the aspect
 */
public AspectMetadata(Class<?> aspectClass, String aspectName) {
	this.aspectName = aspectName;

	Class<?> currClass = aspectClass;
	AjType<?> ajType = null;
	while (currClass != Object.class) {
		AjType<?> ajTypeToCheck = AjTypeSystem.getAjType(currClass);
		if (ajTypeToCheck.isAspect()) {
			ajType = ajTypeToCheck;
			break;
		}
		currClass = currClass.getSuperclass();
	}
	if (ajType == null) {
		throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect");
	}
	if (ajType.getDeclarePrecedence().length > 0) {
		throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP");
	}
	this.aspectClass = ajType.getJavaClass();
	this.ajType = ajType;

	switch (this.ajType.getPerClause().getKind()) {
		case SINGLETON:
			this.perClausePointcut = Pointcut.TRUE;
			return;
		case PERTARGET:
		case PERTHIS:
			AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
			ajexp.setLocation(aspectClass.getName());
			ajexp.setExpression(findPerClause(aspectClass));
			ajexp.setPointcutDeclarationScope(aspectClass);
			this.perClausePointcut = ajexp;
			return;
		case PERTYPEWITHIN:
			// Works with a type pattern
			this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass)));
			return;
		default:
			throw new AopConfigException(
					"PerClause " + ajType.getPerClause().getKind() + " not supported by Spring AOP for " + aspectClass);
	}
}
 
Example 10
Source Project: java-technology-stack   Source File: AspectMetadata.java    License: MIT License 4 votes vote down vote up
/**
 * Create a new AspectMetadata instance for the given aspect class.
 * @param aspectClass the aspect class
 * @param aspectName the name of the aspect
 */
public AspectMetadata(Class<?> aspectClass, String aspectName) {
	this.aspectName = aspectName;

	Class<?> currClass = aspectClass;
	AjType<?> ajType = null;
	while (currClass != Object.class) {
		AjType<?> ajTypeToCheck = AjTypeSystem.getAjType(currClass);
		if (ajTypeToCheck.isAspect()) {
			ajType = ajTypeToCheck;
			break;
		}
		currClass = currClass.getSuperclass();
	}
	if (ajType == null) {
		throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect");
	}
	if (ajType.getDeclarePrecedence().length > 0) {
		throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP");
	}
	this.aspectClass = ajType.getJavaClass();
	this.ajType = ajType;

	switch (this.ajType.getPerClause().getKind()) {
		case SINGLETON:
			this.perClausePointcut = Pointcut.TRUE;
			return;
		case PERTARGET:
		case PERTHIS:
			AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
			ajexp.setLocation(aspectClass.getName());
			ajexp.setExpression(findPerClause(aspectClass));
			ajexp.setPointcutDeclarationScope(aspectClass);
			this.perClausePointcut = ajexp;
			return;
		case PERTYPEWITHIN:
			// Works with a type pattern
			this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass)));
			return;
		default:
			throw new AopConfigException(
					"PerClause " + ajType.getPerClause().getKind() + " not supported by Spring AOP for " + aspectClass);
	}
}
 
Example 11
Source Project: api-boot   Source File: ApiBootResourceLoadAdvisor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * build pointcut instance
 */
private Pointcut buildPointcut() {
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(ResourceLoad.class);
    return new ComposablePointcut(mpc);
}
 
Example 12
Source Project: lams   Source File: AspectMetadata.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new AspectMetadata instance for the given aspect class.
 * @param aspectClass the aspect class
 * @param aspectName the name of the aspect
 */
public AspectMetadata(Class<?> aspectClass, String aspectName) {
	this.aspectName = aspectName;

	Class<?> currClass = aspectClass;
	AjType<?> ajType = null;
	while (currClass != Object.class) {
		AjType<?> ajTypeToCheck = AjTypeSystem.getAjType(currClass);
		if (ajTypeToCheck.isAspect()) {
			ajType = ajTypeToCheck;
			break;
		}
		currClass = currClass.getSuperclass();
	}
	if (ajType == null) {
		throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect");
	}
	if (ajType.getDeclarePrecedence().length > 0) {
		throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP");
	}
	this.aspectClass = ajType.getJavaClass();
	this.ajType = ajType;

	switch (this.ajType.getPerClause().getKind()) {
		case SINGLETON:
			this.perClausePointcut = Pointcut.TRUE;
			return;
		case PERTARGET:
		case PERTHIS:
			AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
			ajexp.setLocation(aspectClass.getName());
			ajexp.setExpression(findPerClause(aspectClass));
			ajexp.setPointcutDeclarationScope(aspectClass);
			this.perClausePointcut = ajexp;
			return;
		case PERTYPEWITHIN:
			// Works with a type pattern
			this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass)));
			return;
		default:
			throw new AopConfigException(
					"PerClause " + ajType.getPerClause().getKind() + " not supported by Spring AOP for " + aspectClass);
	}
}
 
Example 13
Source Project: spring4-understanding   Source File: AspectMetadata.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Create a new AspectMetadata instance for the given aspect class.
 * @param aspectClass the aspect class
 * @param aspectName the name of the aspect
 */
public AspectMetadata(Class<?> aspectClass, String aspectName) {
	this.aspectName = aspectName;

	Class<?> currClass = aspectClass;
	AjType<?> ajType = null;
	while (currClass != Object.class) {
		AjType<?> ajTypeToCheck = AjTypeSystem.getAjType(currClass);
		if (ajTypeToCheck.isAspect()) {
			ajType = ajTypeToCheck;
			break;
		}
		currClass = currClass.getSuperclass();
	}
	if (ajType == null) {
		throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect");
	}
	this.ajType = ajType;
	if (this.ajType.getDeclarePrecedence().length > 0) {
		throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP");
	}

	switch (this.ajType.getPerClause().getKind()) {
		case SINGLETON :
			this.perClausePointcut = Pointcut.TRUE;
			return;
		case PERTARGET : case PERTHIS :
			AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
			ajexp.setLocation("@Aspect annotation on " + aspectClass.getName());
			ajexp.setExpression(findPerClause(aspectClass));
			this.perClausePointcut = ajexp;
			return;
		case PERTYPEWITHIN :
			// Works with a type pattern
			this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass)));
			return;
		default :
			throw new AopConfigException(
					"PerClause " + ajType.getPerClause().getKind() + " not supported by Spring AOP for " + aspectClass);
	}
}
 
Example 14
Source Project: api-boot   Source File: ApiBootRateLimiterAdvisor.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * build breakthrough point
 * <p>
 * According to {@link RateLimiter} annotation pointcut
 *
 * @return {@link Pointcut}
 */
private Pointcut buildPointcut() {
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(RateLimiter.class);
    return new ComposablePointcut(mpc);
}