Java Code Examples for org.springframework.aop.MethodMatcher
The following examples show how to use
org.springframework.aop.MethodMatcher. 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: lams Source File: Pointcuts.java License: GNU General Public License v2.0 | 6 votes |
/** * Perform the least expensive check for a pointcut match. * @param pointcut the pointcut to match * @param method the candidate method * @param targetClass the target class * @param args arguments to the method * @return whether there's a runtime match */ public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) { Assert.notNull(pointcut, "Pointcut must not be null"); if (pointcut == Pointcut.TRUE) { return true; } if (pointcut.getClassFilter().matches(targetClass)) { // Only check if it gets past first hurdle. MethodMatcher mm = pointcut.getMethodMatcher(); if (mm.matches(method, targetClass)) { // We may need additional runtime (argument) check. return (!mm.isRuntime() || mm.matches(method, targetClass, args)); } } return false; }
Example 2
Source Project: spring-analysis-note Source File: AnnotationMatchingPointcut.java License: MIT License | 6 votes |
/** * 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 = new AnnotationCandidateClassFilter(methodAnnotationType); } if (methodAnnotationType != null) { this.methodMatcher = new AnnotationMethodMatcher(methodAnnotationType, checkInherited); } else { this.methodMatcher = MethodMatcher.TRUE; } }
Example 3
Source Project: spring-analysis-note Source File: Pointcuts.java License: MIT License | 6 votes |
/** * Perform the least expensive check for a pointcut match. * @param pointcut the pointcut to match * @param method the candidate method * @param targetClass the target class * @param args arguments to the method * @return whether there's a runtime match */ public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) { Assert.notNull(pointcut, "Pointcut must not be null"); if (pointcut == Pointcut.TRUE) { return true; } if (pointcut.getClassFilter().matches(targetClass)) { // Only check if it gets past first hurdle. MethodMatcher mm = pointcut.getMethodMatcher(); if (mm.matches(method, targetClass)) { // We may need additional runtime (argument) check. return (!mm.isRuntime() || mm.matches(method, targetClass, args)); } } return false; }
Example 4
Source Project: spring-analysis-note Source File: AspectJExpressionPointcutTests.java License: MIT License | 6 votes |
@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)); }
Example 5
Source Project: spring-analysis-note Source File: AspectJExpressionPointcutTests.java License: MIT License | 6 votes |
@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 Double(12))); assertFalse("Should not match setSomeNumber with Integer input", methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11))); assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class)); assertTrue("Should be a runtime match", methodMatcher.isRuntime()); }
Example 6
Source Project: camunda-bpm-platform Source File: MetaAnnotationMatchingPointcut.java License: Apache License 2.0 | 6 votes |
/** * 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 7
Source Project: spring4-understanding Source File: AspectJExpressionPointcutTests.java License: Apache License 2.0 | 6 votes |
@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)); }
Example 8
Source Project: lams Source File: AnnotationMatchingPointcut.java License: GNU General Public License v2.0 | 6 votes |
/** * 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 9
Source Project: java-technology-stack Source File: Pointcuts.java License: MIT License | 6 votes |
/** * Perform the least expensive check for a pointcut match. * @param pointcut the pointcut to match * @param method the candidate method * @param targetClass the target class * @param args arguments to the method * @return whether there's a runtime match */ public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) { Assert.notNull(pointcut, "Pointcut must not be null"); if (pointcut == Pointcut.TRUE) { return true; } if (pointcut.getClassFilter().matches(targetClass)) { // Only check if it gets past first hurdle. MethodMatcher mm = pointcut.getMethodMatcher(); if (mm.matches(method, targetClass)) { // We may need additional runtime (argument) check. return (!mm.isRuntime() || mm.matches(method, targetClass, args)); } } return false; }
Example 10
Source Project: java-technology-stack Source File: AspectJExpressionPointcutTests.java License: MIT License | 6 votes |
@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)); }
Example 11
Source Project: java-technology-stack Source File: AspectJExpressionPointcutTests.java License: MIT License | 6 votes |
@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)); }
Example 12
Source Project: spring-analysis-note Source File: AbstractAspectJAdvice.java License: MIT License | 5 votes |
/** * 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 13
Source Project: spring4-understanding Source File: ComposablePointcut.java License: Apache License 2.0 | 5 votes |
/** * 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; }
Example 14
Source Project: spring4-understanding Source File: MethodMatchersTests.java License: Apache License 2.0 | 5 votes |
@Test public void testStaticMethodMatcherUnion() throws Exception { MethodMatcher getterMatcher = new StartsWithMatcher("get"); MethodMatcher setterMatcher = new StartsWithMatcher("set"); MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher); assertFalse("Union is a static matcher", union.isRuntime()); assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class)); assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class)); assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class)); }
Example 15
Source Project: spring4-understanding Source File: AbstractAspectJAdvice.java License: Apache License 2.0 | 5 votes |
/** * 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 16
Source Project: spring4-understanding Source File: CglibProxyTests.java License: Apache License 2.0 | 5 votes |
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 17
Source Project: spring4-understanding Source File: MethodMatchersTests.java License: Apache License 2.0 | 5 votes |
@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 18
Source Project: spring-analysis-note Source File: MethodMatchersTests.java License: MIT License | 5 votes |
@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 19
Source Project: spring-analysis-note Source File: MethodMatchersTests.java License: MIT License | 5 votes |
@Test public void testUnionEquals() { MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE); MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher(); assertTrue(first.equals(second)); assertTrue(second.equals(first)); }
Example 20
Source Project: spring-analysis-note Source File: AopUtilsTests.java License: MIT License | 5 votes |
/** * Test that when we serialize and deserialize various canonical instances * of AOP classes, they return the same instance, not a new instance * that's subverted the singleton construction limitation. */ @Test public void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception { assertSame(MethodMatcher.TRUE, SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)); assertSame(ClassFilter.TRUE, SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE)); assertSame(Pointcut.TRUE, SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE)); assertSame(EmptyTargetSource.INSTANCE, SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE)); assertSame(Pointcuts.SETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS)); assertSame(Pointcuts.GETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS)); assertSame(ExposeInvocationInterceptor.INSTANCE, SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE)); }
Example 21
Source Project: spring-analysis-note Source File: CglibProxyTests.java License: MIT License | 5 votes |
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 22
Source Project: java-technology-stack Source File: AbstractAspectJAdvice.java License: MIT License | 5 votes |
/** * 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 23
Source Project: java-technology-stack Source File: ComposablePointcut.java License: MIT License | 5 votes |
/** * 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; }
Example 24
Source Project: ignite Source File: GridifySpringPointcut.java License: Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public MethodMatcher getMethodMatcher() { switch (type) { case DFLT: return dfltMatcher; case SET_TO_VALUE: return setToValueMatcher; case SET_TO_SET: return setToSetMatcher; default: assert false : "Unknown pointcut type: " + type; } return null; }
Example 25
Source Project: lams Source File: AbstractAspectJAdvice.java License: GNU General Public License v2.0 | 5 votes |
/** * 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 26
Source Project: java-technology-stack Source File: MethodMatchersTests.java License: MIT License | 5 votes |
@Test public void testStaticMethodMatcherUnion() throws Exception { MethodMatcher getterMatcher = new StartsWithMatcher("get"); MethodMatcher setterMatcher = new StartsWithMatcher("set"); MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher); assertFalse("Union is a static matcher", union.isRuntime()); assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class)); assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class)); assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class)); }
Example 27
Source Project: java-technology-stack Source File: MethodMatchersTests.java License: MIT License | 5 votes |
@Test public void testUnionEquals() { MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE); MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher(); assertTrue(first.equals(second)); assertTrue(second.equals(first)); }
Example 28
Source Project: java-technology-stack Source File: AopUtilsTests.java License: MIT License | 5 votes |
/** * Test that when we serialize and deserialize various canonical instances * of AOP classes, they return the same instance, not a new instance * that's subverted the singleton construction limitation. */ @Test public void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception { assertSame(MethodMatcher.TRUE, SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)); assertSame(ClassFilter.TRUE, SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE)); assertSame(Pointcut.TRUE, SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE)); assertSame(EmptyTargetSource.INSTANCE, SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE)); assertSame(Pointcuts.SETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS)); assertSame(Pointcuts.GETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS)); assertSame(ExposeInvocationInterceptor.INSTANCE, SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE)); }
Example 29
Source Project: java-technology-stack Source File: CglibProxyTests.java License: MIT License | 5 votes |
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 30
Source Project: lams Source File: AnnotationMatchingPointcut.java License: GNU General Public License v2.0 | 4 votes |
@Override public MethodMatcher getMethodMatcher() { return this.methodMatcher; }