本文整理汇总了Java中org.springframework.aop.ClassFilter类的典型用法代码示例。如果您正苦于以下问题:Java ClassFilter类的具体用法?Java ClassFilter怎么用?Java ClassFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassFilter类属于org.springframework.aop包,在下文中一共展示了ClassFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DeclareParentsAdvisor
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
/**
* Private constructor to share common code between impl-based delegate and reference-based delegate
* (cannot use method such as init() to share common code, due the the use of final fields)
* @param interfaceType static field defining the introduction
* @param typePattern type pattern the introduction is restricted to
* @param implementationClass implementation class
* @param advice delegation advice
*/
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> implementationClass, Advice advice) {
this.introducedInterface = interfaceType;
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
// Excludes methods implemented.
ClassFilter exclusion = new ClassFilter() {
@Override
public boolean matches(Class<?> clazz) {
return !(introducedInterface.isAssignableFrom(clazz));
}
};
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion);
this.advice = advice;
}
示例2: AnnotationMatchingPointcut
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
/**
* 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;
}
}
示例3: equals
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!super.equals(other)) {
return false;
}
ClassFilter otherCf1 = ClassFilter.TRUE;
ClassFilter otherCf2 = ClassFilter.TRUE;
if (other instanceof ClassFilterAwareUnionMethodMatcher) {
ClassFilterAwareUnionMethodMatcher cfa = (ClassFilterAwareUnionMethodMatcher) other;
otherCf1 = cfa.cf1;
otherCf2 = cfa.cf2;
}
return (this.cf1.equals(otherCf1) && this.cf2.equals(otherCf2));
}
示例4: getClassFilter
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Override
public ClassFilter getClassFilter() {
return new ClassFilter() {
@Override public boolean matches(Class<?> targetClass) {
if (targetClass.isInterface()) return false;
val targetClassName = targetClass.getName();
if (targetClassName.startsWith("com.sun.proxy.$Proxy")) return false;
if (targetClassName.startsWith("java.lang.")) return false;
if (existsEqler) {
if (Anns.hasAnnotationInHierarchy(Eqler.class, targetClass)) return false;
if (Anns.hasAnnotationInHierarchy(EqlerConfig.class, targetClass)) return false;
}
return true;
}
};
}
示例5: testMatchExplicit
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void testMatchExplicit() {
String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";
Pointcut pointcut = getPointcut(expression);
ClassFilter classFilter = pointcut.getClassFilter();
MethodMatcher methodMatcher = pointcut.getMethodMatcher();
assertMatchesTestBeanClass(classFilter);
// not currently testable in a reliable fashion
//assertDoesNotMatchStringClass(classFilter);
assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
assertMatchesGetAge(methodMatcher);
assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
}
示例6: testMatchWithTypePattern
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void testMatchWithTypePattern() throws Exception {
String expression = "execution(* *..TestBean.*Age(..))";
Pointcut pointcut = getPointcut(expression);
ClassFilter classFilter = pointcut.getClassFilter();
MethodMatcher methodMatcher = pointcut.getMethodMatcher();
assertMatchesTestBeanClass(classFilter);
// not currently testable in a reliable fashion
//assertDoesNotMatchStringClass(classFilter);
assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
assertMatchesGetAge(methodMatcher);
assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
}
示例7: testMatchWithArgs
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void testMatchWithArgs() throws Exception {
String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";
Pointcut pointcut = getPointcut(expression);
ClassFilter classFilter = pointcut.getClassFilter();
MethodMatcher methodMatcher = pointcut.getMethodMatcher();
assertMatchesTestBeanClass(classFilter);
// not currently testable in a reliable fashion
//assertDoesNotMatchStringClass(classFilter);
assertTrue("Should match with setSomeNumber with Double input",
methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)}));
assertFalse("Should not match setSomeNumber with Integer input",
methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)}));
assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null));
assertTrue("Should be a runtime match", methodMatcher.isRuntime());
}
示例8: testFilterByClass
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void testFilterByClass() throws NoSuchMethodException {
ComposablePointcut pc = new ComposablePointcut();
assertTrue(pc.getClassFilter().matches(Object.class));
ClassFilter cf = new RootClassFilter(Exception.class);
pc.intersection(cf);
assertFalse(pc.getClassFilter().matches(Object.class));
assertTrue(pc.getClassFilter().matches(Exception.class));
pc.intersection(new RootClassFilter(NestedRuntimeException.class));
assertFalse(pc.getClassFilter().matches(Exception.class));
assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
assertFalse(pc.getClassFilter().matches(String.class));
pc.union(new RootClassFilter(String.class));
assertFalse(pc.getClassFilter().matches(Exception.class));
assertTrue(pc.getClassFilter().matches(String.class));
assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
}
示例9: testUnionMethodMatcher
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void testUnionMethodMatcher() {
// Matches the getAge() method in any class
ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER);
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
pc.union(GETTER_METHOD_MATCHER);
// Should now match all getter methods
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
pc.union(ABSQUATULATE_METHOD_MATCHER);
// Should now match absquatulate() as well
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class, null));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class, null));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class, null));
// But it doesn't match everything
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class, null));
}
示例10: DeclareParentsAdvisor
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
/**
* Private constructor to share common code between impl-based delegate and reference-based delegate
* (cannot use method such as init() to share common code, due the use of final fields)
* @param interfaceType static field defining the introduction
* @param typePattern type pattern the introduction is restricted to
* @param implementationClass implementation class
* @param advice delegation advice
*/
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> implementationClass, Advice advice) {
this.introducedInterface = interfaceType;
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
// Excludes methods implemented.
ClassFilter exclusion = new ClassFilter() {
@Override
public boolean matches(Class<?> clazz) {
return !(introducedInterface.isAssignableFrom(clazz));
}
};
this.typePatternClassFilter = ClassFilters.intersection(typePatternFilter, exclusion);
this.advice = advice;
}
示例11: classNamePointcutAdvisor
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void classNamePointcutAdvisor() {
NameMatchMethodPointcut classMethodPointcut = new NameMatchMethodPointcut() {
public ClassFilter getClassFilter() {
return new ClassFilter() {
public boolean matches(Class<?> clazz) {
return clazz.getSimpleName().startsWith("HelloT");
}
};
}
};
classMethodPointcut.setMappedName("sayH*");
checkAdvice(new HelloTarget(), classMethodPointcut, true);
class HelloWorld extends HelloTarget {};
checkAdvice(new HelloWorld(), classMethodPointcut, false);
class HelloToby extends HelloTarget {};
checkAdvice(new HelloToby(), classMethodPointcut, true);
}
示例12: MetaAnnotationMatchingPointcut
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
/**
* 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;
}
}
示例13: matches
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Override
public boolean matches(Class<?> clazz) {
for (ClassFilter filter : this.filters) {
if (filter.matches(clazz)) {
return true;
}
}
return false;
}
示例14: ComposablePointcut
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
/**
* Create a ComposablePointcut for the given ClassFilter and MethodMatcher.
* @param classFilter the ClassFilter to use
* @param methodMatcher the MethodMatcher to use
*/
public ComposablePointcut(ClassFilter classFilter, MethodMatcher methodMatcher) {
Assert.notNull(classFilter, "ClassFilter must not be null");
Assert.notNull(methodMatcher, "MethodMatcher must not be null");
this.classFilter = classFilter;
this.methodMatcher = methodMatcher;
}
示例15: testUnion
import org.springframework.aop.ClassFilter; //导入依赖的package包/类
@Test
public void testUnion() {
assertTrue(exceptionFilter.matches(RuntimeException.class));
assertFalse(exceptionFilter.matches(TestBean.class));
assertFalse(itbFilter.matches(Exception.class));
assertTrue(itbFilter.matches(TestBean.class));
ClassFilter union = ClassFilters.union(exceptionFilter, itbFilter);
assertTrue(union.matches(RuntimeException.class));
assertTrue(union.matches(TestBean.class));
}