parent
c406c56d57
commit
d434ef9713
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,9 +19,9 @@ package org.springframework.aop;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized type of MethodMatcher that takes into account introductions when
|
* A specialized type of {@link MethodMatcher} that takes into account introductions
|
||||||
* matching methods. If there are no introductions on the target class, a method
|
* when matching methods. If there are no introductions on the target class,
|
||||||
* matcher may be able to optimize matching more effectively for example.
|
* a method matcher may be able to optimize matching more effectively for example.
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
|
@ -39,6 +39,6 @@ public interface IntroductionAwareMethodMatcher extends MethodMatcher {
|
||||||
* asking is the subject on one or more introductions; {@code false} otherwise
|
* asking is the subject on one or more introductions; {@code false} otherwise
|
||||||
* @return whether or not this method matches statically
|
* @return whether or not this method matches statically
|
||||||
*/
|
*/
|
||||||
boolean matches(Method method, Class targetClass, boolean hasIntroductions);
|
boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,8 +23,7 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static utility methods for composing
|
* Static utility methods for composing {@link ClassFilter ClassFilters}.
|
||||||
* {@link org.springframework.aop.ClassFilter ClassFilters}.
|
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
|
@ -96,9 +95,9 @@ public abstract class ClassFilters {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Class clazz) {
|
public boolean matches(Class<?> clazz) {
|
||||||
for (int i = 0; i < this.filters.length; i++) {
|
for (ClassFilter filter : this.filters) {
|
||||||
if (this.filters[i].matches(clazz)) {
|
if (filter.matches(clazz)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -130,9 +129,9 @@ public abstract class ClassFilters {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Class clazz) {
|
public boolean matches(Class<?> clazz) {
|
||||||
for (int i = 0; i < this.filters.length; i++) {
|
for (ClassFilter filter : this.filters) {
|
||||||
if (!this.filters[i].matches(clazz)) {
|
if (!filter.matches(clazz)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,11 @@ import org.springframework.aop.MethodMatcher;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static utility methods for composing
|
* Static utility methods for composing {@link MethodMatcher MethodMatchers}.
|
||||||
* {@link org.springframework.aop.MethodMatcher MethodMatchers}.
|
|
||||||
*
|
*
|
||||||
* <p>A MethodMatcher may be evaluated statically (based on method
|
* <p>A MethodMatcher may be evaluated statically (based on method and target
|
||||||
* and target class) or need further evaluation dynamically
|
* class) or need further evaluation dynamically (based on arguments at the
|
||||||
* (based on arguments at the time of method invocation).
|
* time of method invocation).
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
|
@ -88,7 +87,7 @@ public abstract class MethodMatchers {
|
||||||
* asking is the subject on one or more introductions; {@code false} otherwise
|
* asking is the subject on one or more introductions; {@code false} otherwise
|
||||||
* @return whether or not this method matches statically
|
* @return whether or not this method matches statically
|
||||||
*/
|
*/
|
||||||
public static boolean matches(MethodMatcher mm, Method method, Class targetClass, boolean hasIntroductions) {
|
public static boolean matches(MethodMatcher mm, Method method, Class<?> targetClass, boolean hasIntroductions) {
|
||||||
Assert.notNull(mm, "MethodMatcher must not be null");
|
Assert.notNull(mm, "MethodMatcher must not be null");
|
||||||
return ((mm instanceof IntroductionAwareMethodMatcher &&
|
return ((mm instanceof IntroductionAwareMethodMatcher &&
|
||||||
((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions)) ||
|
((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions)) ||
|
||||||
|
|
@ -113,21 +112,21 @@ public abstract class MethodMatchers {
|
||||||
this.mm2 = mm2;
|
this.mm2 = mm2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Method method, Class targetClass, boolean hasIntroductions) {
|
public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) {
|
||||||
return (matchesClass1(targetClass) && MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions)) ||
|
return (matchesClass1(targetClass) && MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions)) ||
|
||||||
(matchesClass2(targetClass) && MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions));
|
(matchesClass2(targetClass) && MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Method method, Class targetClass) {
|
public boolean matches(Method method, Class<?> targetClass) {
|
||||||
return (matchesClass1(targetClass) && this.mm1.matches(method, targetClass)) ||
|
return (matchesClass1(targetClass) && this.mm1.matches(method, targetClass)) ||
|
||||||
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
|
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matchesClass1(Class targetClass) {
|
protected boolean matchesClass1(Class<?> targetClass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matchesClass2(Class targetClass) {
|
protected boolean matchesClass2(Class<?> targetClass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +134,7 @@ public abstract class MethodMatchers {
|
||||||
return this.mm1.isRuntime() || this.mm2.isRuntime();
|
return this.mm1.isRuntime() || this.mm2.isRuntime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Method method, Class targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
||||||
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
|
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,12 +178,12 @@ public abstract class MethodMatchers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesClass1(Class targetClass) {
|
protected boolean matchesClass1(Class<?> targetClass) {
|
||||||
return this.cf1.matches(targetClass);
|
return this.cf1.matches(targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesClass2(Class targetClass) {
|
protected boolean matchesClass2(Class<?> targetClass) {
|
||||||
return this.cf2.matches(targetClass);
|
return this.cf2.matches(targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,12 +224,12 @@ public abstract class MethodMatchers {
|
||||||
this.mm2 = mm2;
|
this.mm2 = mm2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Method method, Class targetClass, boolean hasIntroductions) {
|
public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) {
|
||||||
return MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) &&
|
return MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) &&
|
||||||
MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions);
|
MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Method method, Class targetClass) {
|
public boolean matches(Method method, Class<?> targetClass) {
|
||||||
return this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass);
|
return this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,7 +237,7 @@ public abstract class MethodMatchers {
|
||||||
return this.mm1.isRuntime() || this.mm2.isRuntime();
|
return this.mm1.isRuntime() || this.mm2.isRuntime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matches(Method method, Class targetClass, Object[] args) {
|
public boolean matches(Method method, Class<?> targetClass, Object[] args) {
|
||||||
// Because a dynamic intersection may be composed of a static and dynamic part,
|
// Because a dynamic intersection may be composed of a static and dynamic part,
|
||||||
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
|
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
|
||||||
// it will probably be an unsupported operation.
|
// it will probably be an unsupported operation.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -34,16 +34,21 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
public final class TargetPointcutSelectionTests {
|
public final class TargetPointcutSelectionTests {
|
||||||
|
|
||||||
public TestInterface testImpl1;
|
public TestInterface testImpl1;
|
||||||
|
|
||||||
public TestInterface testImpl2;
|
public TestInterface testImpl2;
|
||||||
|
|
||||||
public TestAspect testAspectForTestImpl1;
|
public TestAspect testAspectForTestImpl1;
|
||||||
|
|
||||||
public TestAspect testAspectForAbstractTestImpl;
|
public TestAspect testAspectForAbstractTestImpl;
|
||||||
|
|
||||||
public TestInterceptor testInterceptor;
|
public TestInterceptor testInterceptor;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
ClassPathXmlApplicationContext ctx =
|
ClassPathXmlApplicationContext ctx =
|
||||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||||
|
|
||||||
testImpl1 = (TestInterface) ctx.getBean("testImpl1");
|
testImpl1 = (TestInterface) ctx.getBean("testImpl1");
|
||||||
testImpl2 = (TestInterface) ctx.getBean("testImpl2");
|
testImpl2 = (TestInterface) ctx.getBean("testImpl2");
|
||||||
testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
|
testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
|
||||||
|
|
@ -55,6 +60,7 @@ public final class TargetPointcutSelectionTests {
|
||||||
testInterceptor.count = 0;
|
testInterceptor.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTargetSelectionForMatchedType() {
|
public void testTargetSelectionForMatchedType() {
|
||||||
testImpl1.interfaceMethod();
|
testImpl1.interfaceMethod();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue