public class AspectJExpressionPointcut extends AbstractExpressionPointcut implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware
Pointcut
implementation
that uses the AspectJ weaver to evaluate a pointcut expression.
The pointcut expression value is an AspectJ expression. This can reference other pointcuts and use composition and other operations.
Naturally, as this is to be processed by Spring AOP's proxy-based model, only method execution pointcuts are supported.
Modifier and Type | Class and Description |
---|---|
private class |
AspectJExpressionPointcut.BeanContextMatcher
Matcher class for the BeanNamePointcutDesignatorHandler.
|
private class |
AspectJExpressionPointcut.BeanPointcutDesignatorHandler
Handler for the Spring-specific
bean() pointcut designator
extension to AspectJ. |
private static class |
AspectJExpressionPointcut.DefensiveShadowMatch |
Modifier and Type | Field and Description |
---|---|
private BeanFactory |
beanFactory |
private static Log |
logger |
private java.lang.ClassLoader |
pointcutClassLoader |
private java.lang.Class<?> |
pointcutDeclarationScope |
private PointcutExpression |
pointcutExpression |
private java.lang.String[] |
pointcutParameterNames |
private java.lang.Class<?>[] |
pointcutParameterTypes |
private java.util.Map<java.lang.reflect.Method,ShadowMatch> |
shadowMatchCache |
private static java.util.Set<PointcutPrimitive> |
SUPPORTED_PRIMITIVES |
TRUE
Constructor and Description |
---|
AspectJExpressionPointcut()
Create a new default AspectJExpressionPointcut.
|
AspectJExpressionPointcut(java.lang.Class<?> declarationScope,
java.lang.String[] paramNames,
java.lang.Class<?>[] paramTypes)
Create a new AspectJExpressionPointcut with the given settings.
|
Modifier and Type | Method and Description |
---|---|
private void |
bindParameters(ProxyMethodInvocation invocation,
JoinPointMatch jpm) |
private PointcutExpression |
buildPointcutExpression(java.lang.ClassLoader classLoader)
Build the underlying AspectJ pointcut expression.
|
private java.lang.ClassLoader |
determinePointcutClassLoader()
Determine the ClassLoader to use for pointcut evaluation.
|
boolean |
equals(java.lang.Object other) |
ClassFilter |
getClassFilter()
Return the ClassFilter for this pointcut.
|
protected java.lang.String |
getCurrentProxiedBeanName() |
private PointcutExpression |
getFallbackPointcutExpression(java.lang.Class<?> targetClass)
Get a new pointcut expression based on a target class's loader rather than the default.
|
MethodMatcher |
getMethodMatcher()
Return the MethodMatcher for this pointcut.
|
PointcutExpression |
getPointcutExpression()
Return the underlying AspectJ pointcut expression.
|
private RuntimeTestWalker |
getRuntimeTestWalker(ShadowMatch shadowMatch) |
private ShadowMatch |
getShadowMatch(java.lang.reflect.Method targetMethod,
java.lang.reflect.Method originalMethod) |
private ShadowMatch |
getTargetShadowMatch(java.lang.reflect.Method method,
java.lang.Class<?> targetClass) |
int |
hashCode() |
private PointcutParser |
initializePointcutParser(java.lang.ClassLoader classLoader)
Initialize the underlying AspectJ pointcut parser.
|
boolean |
isRuntime()
Is this MethodMatcher dynamic, that is, must a final call be made on the
MethodMatcher.matches(java.lang.reflect.Method, Class, Object[]) method at
runtime even if the 2-arg matches method returns true ? |
boolean |
matches(java.lang.Class<?> targetClass)
Should the pointcut apply to the given interface or target class?
|
boolean |
matches(java.lang.reflect.Method method,
java.lang.Class<?> targetClass)
Perform static checking whether the given method matches.
|
boolean |
matches(java.lang.reflect.Method method,
java.lang.Class<?> targetClass,
boolean hasIntroductions)
Perform static checking whether the given method matches.
|
boolean |
matches(java.lang.reflect.Method method,
java.lang.Class<?> targetClass,
java.lang.Object... args)
Check whether there a runtime (dynamic) match for this method,
which must have matched statically.
|
private PointcutExpression |
obtainPointcutExpression()
Check whether this pointcut is ready to match,
lazily building the underlying AspectJ pointcut expression.
|
private void |
readObject(java.io.ObjectInputStream ois) |
private java.lang.String |
replaceBooleanOperators(java.lang.String pcExpr)
If a pointcut expression has been specified in XML, the user cannot
write
and as "&&" (though && will work). |
private java.lang.String |
resolveExpression() |
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
|
void |
setParameterNames(java.lang.String... names)
Set the parameter names for the pointcut.
|
void |
setParameterTypes(java.lang.Class<?>... types)
Set the parameter types for the pointcut.
|
void |
setPointcutDeclarationScope(java.lang.Class<?> pointcutDeclarationScope)
Set the declaration scope for the pointcut.
|
java.lang.String |
toString() |
getExpression, getLocation, onSetExpression, setExpression, setLocation
private static final java.util.Set<PointcutPrimitive> SUPPORTED_PRIMITIVES
private static final Log logger
@Nullable private java.lang.Class<?> pointcutDeclarationScope
private java.lang.String[] pointcutParameterNames
private java.lang.Class<?>[] pointcutParameterTypes
@Nullable private BeanFactory beanFactory
@Nullable private transient java.lang.ClassLoader pointcutClassLoader
@Nullable private transient PointcutExpression pointcutExpression
private transient java.util.Map<java.lang.reflect.Method,ShadowMatch> shadowMatchCache
public AspectJExpressionPointcut()
public AspectJExpressionPointcut(java.lang.Class<?> declarationScope, java.lang.String[] paramNames, java.lang.Class<?>[] paramTypes)
declarationScope
- the declaration scope for the pointcutparamNames
- the parameter names for the pointcutparamTypes
- the parameter types for the pointcutpublic void setPointcutDeclarationScope(java.lang.Class<?> pointcutDeclarationScope)
public void setParameterNames(java.lang.String... names)
public void setParameterTypes(java.lang.Class<?>... types)
public void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAware
Invoked after the population of normal bean properties
but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.BeanInitializationException
public ClassFilter getClassFilter()
Pointcut
getClassFilter
in interface Pointcut
null
)public MethodMatcher getMethodMatcher()
Pointcut
getMethodMatcher
in interface Pointcut
null
)private PointcutExpression obtainPointcutExpression()
@Nullable private java.lang.ClassLoader determinePointcutClassLoader()
private PointcutExpression buildPointcutExpression(@Nullable java.lang.ClassLoader classLoader)
private java.lang.String resolveExpression()
private PointcutParser initializePointcutParser(@Nullable java.lang.ClassLoader classLoader)
private java.lang.String replaceBooleanOperators(java.lang.String pcExpr)
and
as "&&" (though && will work).
We also allow and
between two pointcut sub-expressions.
This method converts back to &&
for the AspectJ pointcut parser.
public PointcutExpression getPointcutExpression()
public boolean matches(java.lang.Class<?> targetClass)
ClassFilter
matches
in interface ClassFilter
targetClass
- the candidate target classpublic boolean matches(java.lang.reflect.Method method, java.lang.Class<?> targetClass, boolean hasIntroductions)
IntroductionAwareMethodMatcher
MethodMatcher.matches(java.lang.reflect.Method, Class)
method
if the caller supports the extended IntroductionAwareMethodMatcher interface.matches
in interface IntroductionAwareMethodMatcher
method
- the candidate methodtargetClass
- the target classhasIntroductions
- true
if the object on whose behalf we are
asking is the subject on one or more introductions; false
otherwisepublic boolean matches(java.lang.reflect.Method method, java.lang.Class<?> targetClass)
MethodMatcher
If this returns false
or if the MethodMatcher.isRuntime()
method returns false
, no runtime check (i.e. no
MethodMatcher.matches(java.lang.reflect.Method, Class, Object[])
call)
will be made.
matches
in interface MethodMatcher
method
- the candidate methodtargetClass
- the target classpublic boolean isRuntime()
MethodMatcher
MethodMatcher.matches(java.lang.reflect.Method, Class, Object[])
method at
runtime even if the 2-arg matches method returns true
?
Can be invoked when an AOP proxy is created, and need not be invoked again before each method invocation,
isRuntime
in interface MethodMatcher
MethodMatcher.matches(java.lang.reflect.Method, Class, Object[])
method
is required if static matching passedpublic boolean matches(java.lang.reflect.Method method, java.lang.Class<?> targetClass, java.lang.Object... args)
MethodMatcher
This method is invoked only if the 2-arg matches method returns
true
for the given method and target class, and if the
MethodMatcher.isRuntime()
method returns true
. Invoked
immediately before potential running of the advice, after any
advice earlier in the advice chain has run.
matches
in interface MethodMatcher
method
- the candidate methodtargetClass
- the target classargs
- arguments to the methodMethodMatcher.matches(Method, Class)
@Nullable protected java.lang.String getCurrentProxiedBeanName()
@Nullable private PointcutExpression getFallbackPointcutExpression(java.lang.Class<?> targetClass)
private RuntimeTestWalker getRuntimeTestWalker(ShadowMatch shadowMatch)
private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm)
private ShadowMatch getTargetShadowMatch(java.lang.reflect.Method method, java.lang.Class<?> targetClass)
private ShadowMatch getShadowMatch(java.lang.reflect.Method targetMethod, java.lang.reflect.Method originalMethod)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException