Java Code Examples for org.springframework.aop.MethodMatcher#TRUE

The following examples show how to use org.springframework.aop.MethodMatcher#TRUE . 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: MetaAnnotationMatchingPointcut.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new MetaAnnotationMatchingPointcut for the given annotation type.
 *
 * @param classAnnotationType	the annotation type to look for at the class level
 *                             (can be <code>null</code>)
 * @param methodAnnotationType the annotation type to look for at the method level
 *                             (can be <code>null</code>)
 */
public MetaAnnotationMatchingPointcut(
		Class<? extends Annotation> classAnnotationType, Class<? extends Annotation> methodAnnotationType) {

	Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
			"Either Class annotation type or Method annotation type needs to be specified (or both)");

	if (classAnnotationType != null) {
		this.classFilter = new AnnotationClassFilter(classAnnotationType);
	} else {
		this.classFilter = ClassFilter.TRUE;
	}

	if (methodAnnotationType != null) {
		this.methodMatcher = new MetaAnnotationMethodMatcher(methodAnnotationType);
	} else {
		this.methodMatcher = MethodMatcher.TRUE;
	}
}
 
Example 2
Source File: AnnotationMatchingPointcut.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a new AnnotationMatchingPointcut for the given annotation type.
 * @param classAnnotationType the annotation type to look for at the class level
 * (can be {@code null})
 * @param methodAnnotationType the annotation type to look for at the method level
 * (can be {@code null})
 * @param checkInherited whether to also check the superclasses and interfaces
 * as well as meta-annotations for the annotation type
 * @since 5.0
 * @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
 * @see AnnotationMethodMatcher#AnnotationMethodMatcher(Class, boolean)
 */
public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,
		@Nullable Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {

	Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
			"Either Class annotation type or Method annotation type needs to be specified (or both)");

	if (classAnnotationType != null) {
		this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
	}
	else {
		this.classFilter = ClassFilter.TRUE;
	}

	if (methodAnnotationType != null) {
		this.methodMatcher = new AnnotationMethodMatcher(methodAnnotationType, checkInherited);
	}
	else {
		this.methodMatcher = MethodMatcher.TRUE;
	}
}
 
Example 3
Source File: AnnotationMatchingPointcut.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new AnnotationMatchingPointcut for the given annotation type.
 * @param classAnnotationType the annotation type to look for at the class level
 * (can be {@code null})
 * @param methodAnnotationType the annotation type to look for at the method level
 * (can be {@code null})
 */
public AnnotationMatchingPointcut(
		Class<? extends Annotation> classAnnotationType, Class<? extends Annotation> methodAnnotationType) {

	Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
			"Either Class annotation type or Method annotation type needs to be specified (or both)");

	if (classAnnotationType != null) {
		this.classFilter = new AnnotationClassFilter(classAnnotationType);
	}
	else {
		this.classFilter = ClassFilter.TRUE;
	}

	if (methodAnnotationType != null) {
		this.methodMatcher = new AnnotationMethodMatcher(methodAnnotationType);
	}
	else {
		this.methodMatcher = MethodMatcher.TRUE;
	}
}
 
Example 4
Source File: MethodMatchersTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingle() throws Exception {
	MethodMatcher defaultMm = MethodMatcher.TRUE;
	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
	defaultMm = MethodMatchers.intersection(defaultMm, new StartsWithMatcher("get"));

	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
}
 
Example 5
Source File: MethodMatchersTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSingle() throws Exception {
	MethodMatcher defaultMm = MethodMatcher.TRUE;
	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
	defaultMm = MethodMatchers.intersection(defaultMm, new StartsWithMatcher("get"));

	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
}
 
Example 6
Source File: CglibProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private ITestBean getAdvisedProxy(TestBean target) {
	ProxyFactory pf = new ProxyFactory(new Class<?>[]{ITestBean.class});
	pf.setProxyTargetClass(true);

	MethodInterceptor advice = new NopInterceptor();
	Pointcut pointcut = new Pointcut() {
		@Override
		public ClassFilter getClassFilter() {
			return ClassFilter.TRUE;
		}
		@Override
		public MethodMatcher getMethodMatcher() {
			return MethodMatcher.TRUE;
		}
		@Override
		public boolean equals(Object obj) {
			return true;
		}
		@Override
		public int hashCode() {
			return 0;
		}
	};
	pf.addAdvisor(new DefaultPointcutAdvisor(pointcut, advice));

	pf.setTarget(target);
	pf.setFrozen(true);
	pf.setExposeProxy(false);

	return (ITestBean) pf.getProxy();
}
 
Example 7
Source File: MethodMatchersTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testDynamicAndStaticMethodMatcherIntersection() throws Exception {
	MethodMatcher mm1 = MethodMatcher.TRUE;
	MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
	MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
	assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
	assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
	assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
	// Knock out dynamic part
	intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
	assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
	assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
	assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Object[] { new Integer(5) }));
}
 
Example 8
Source File: CglibProxyTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private ITestBean getAdvisedProxy(TestBean target) {
	ProxyFactory pf = new ProxyFactory(new Class<?>[]{ITestBean.class});
	pf.setProxyTargetClass(true);

	MethodInterceptor advice = new NopInterceptor();
	Pointcut pointcut = new Pointcut() {
		@Override
		public ClassFilter getClassFilter() {
			return ClassFilter.TRUE;
		}
		@Override
		public MethodMatcher getMethodMatcher() {
			return MethodMatcher.TRUE;
		}
		@Override
		public boolean equals(Object obj) {
			return true;
		}
		@Override
		public int hashCode() {
			return 0;
		}
	};
	pf.addAdvisor(new DefaultPointcutAdvisor(pointcut, advice));

	pf.setTarget(target);
	pf.setFrozen(true);
	pf.setExposeProxy(false);

	return (ITestBean) pf.getProxy();
}
 
Example 9
Source File: ComposablePointcut.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Create a default ComposablePointcut, with {@code ClassFilter.TRUE}
 * and {@code MethodMatcher.TRUE}.
 */
public ComposablePointcut() {
	this.classFilter = ClassFilter.TRUE;
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 10
Source File: MethodMatchersTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultMatchesAll() throws Exception {
	MethodMatcher defaultMm = MethodMatcher.TRUE;
	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
}
 
Example 11
Source File: ComposablePointcut.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a default ComposablePointcut, with {@code ClassFilter.TRUE}
 * and {@code MethodMatcher.TRUE}.
 */
public ComposablePointcut() {
	this.classFilter = ClassFilter.TRUE;
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 12
Source File: ComposablePointcut.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a ComposablePointcut for the given ClassFilter,
 * with {@code MethodMatcher.TRUE}.
 * @param classFilter the ClassFilter to use
 */
public ComposablePointcut(ClassFilter classFilter) {
	Assert.notNull(classFilter, "ClassFilter must not be null");
	this.classFilter = classFilter;
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 13
Source File: MethodMatchersTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testDefaultMatchesAll() throws Exception {
	MethodMatcher defaultMm = MethodMatcher.TRUE;
	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
}
 
Example 14
Source File: ComposablePointcut.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Create a ComposablePointcut for the given ClassFilter,
 * with {@code MethodMatcher.TRUE}.
 * @param classFilter the ClassFilter to use
 */
public ComposablePointcut(ClassFilter classFilter) {
	Assert.notNull(classFilter, "ClassFilter must not be null");
	this.classFilter = classFilter;
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 15
Source File: MonitoredSpringControllerAndServicePointcut.java    From javamelody with Apache License 2.0 4 votes vote down vote up
/**
 * @return a method matcher that matches any method.
 */
@Override
public MethodMatcher getMethodMatcher() {
	return MethodMatcher.TRUE;
}
 
Example 16
Source File: MethodMatchersTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testDefaultMatchesAll() throws Exception {
	MethodMatcher defaultMm = MethodMatcher.TRUE;
	assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
	assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
}
 
Example 17
Source File: AnnotationMatchingPointcut.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new AnnotationMatchingPointcut for the given annotation type.
 * @param classAnnotationType the annotation type to look for at the class level
 */
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType) {
	this.classFilter = new AnnotationClassFilter(classAnnotationType);
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 18
Source File: AnnotationMatchingPointcut.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a new AnnotationMatchingPointcut for the given annotation type.
 * @param classAnnotationType the annotation type to look for at the class level
 * @param checkInherited whether to also check the superclasses and interfaces
 * as well as meta-annotations for the annotation type
 * @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
 */
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType, boolean checkInherited) {
	this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 19
Source File: AnnotationMatchingPointcut.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new AnnotationMatchingPointcut for the given annotation type.
 * @param classAnnotationType the annotation type to look for at the class level
 * @param checkInherited whether to also check the superclasses and interfaces
 * as well as meta-annotations for the annotation type
 * @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
 */
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType, boolean checkInherited) {
	this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
	this.methodMatcher = MethodMatcher.TRUE;
}
 
Example 20
Source File: MetaAnnotationMatchingPointcut.java    From camunda-bpm-platform with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new MetaAnnotationMatchingPointcut for the given annotation type.
 *
 * @param classAnnotationType the annotation type to look for at the class level
 * @param checkInherited			whether to explicitly check the superclasses and
 *                            interfaces for the annotation type as well (even if the annotation type
 *                            is not marked as inherited itself)
 */
public MetaAnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType, boolean checkInherited) {
	this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
	this.methodMatcher = MethodMatcher.TRUE;
}