|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer
public class AspectJAdviceParameterNameDiscoverer
Implementation of ParameterNameDiscover that tries to deduce parameter names for an advice method from the pointcut expression, returning, and throwing clauses. If an unambiguous interpretation is not avaliable, it will return null.
This class interprets arguments in the following way:
a
be the number of annotation-based pointcut expressions (@annotation, @this, @target,
@args, @within, @withincode) that are used in binding form. Usage in binding form
has itself to be deduced: if the expression inside the pointcut is a single string literal that meets
Java variable name conventions it is assumed to be a variable name.
If a
is zero we proceed to the next stage. If a
> 1 then an
AmbiguousBindingCondition is raised. If a
== 1, and there are no unbound arguments of
type Annotation+, then an IllegalArgumentCondition is raised. if there is exactly one such argument,
then the corresponding parameter name is assigned the value from the pointcut expression.
The behaviour on raising an IllegalArgumentCondition or AmbiguousBindingConfiguration is configurable to allow this discoverer to be used as part of a chain-of-responsibility. By default the condition will be logged and the getParameterNames method will simply return null. If the raiseExceptions property is set to true, the conditions will be thrown as IllegalArgumentException and AmbiguousBindingException respectively.
Was that perfectly clear?? ;)
Short version: if an unambiguous binding can be deduced, then it is. If the advice requirements cannot possibly be satisfied null is returned. By setting the raiseExceptions property to true, more descriptive exceptions will be thrown instead of returning null in the case that the parameter names cannot be discovered.
Nested Class Summary | |
---|---|
static class |
AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException
|
Constructor Summary | |
---|---|
AspectJAdviceParameterNameDiscoverer(String pointcutExpression)
Create a new discoverer that attempts to discover parameter names from the given pointcut expression. |
Method Summary | |
---|---|
String[] |
getParameterNames(Constructor ctor)
An advice method can never be a constructor. |
String[] |
getParameterNames(Method method)
Deduce the parameter names for an advice method. |
void |
setRaiseExceptions(boolean shouldRaise)
Set this property to true to indicate the IllegalArgumentException and AmbiguousBindingException should be thrown as appropriate in the case of failing to deduce advice parameter names. |
void |
setReturningName(String returningName)
If afterReturning advice binds the return value, the returning variable name must be specified. |
void |
setThrowingName(String throwingName)
If afterThrowing advice binds the thrown value, the throwing variable name must be specified. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AspectJAdviceParameterNameDiscoverer(String pointcutExpression)
pointcutExpression
- Method Detail |
---|
public void setRaiseExceptions(boolean shouldRaise)
Set this property to true to indicate the IllegalArgumentException and AmbiguousBindingException should be thrown as appropriate in the case of failing to deduce advice parameter names.
shouldRaise
- public void setReturningName(String returningName)
returningName
- public void setThrowingName(String throwingName)
throwingName
- public String[] getParameterNames(Method method)
Deduce the parameter names for an advice method. See the javadoc comment for this class for details of the algorithm used.
getParameterNames
in interface ParameterNameDiscoverer
method
- method to find parameter names for
null
if they cannotpublic String[] getParameterNames(Constructor ctor)
getParameterNames
in interface ParameterNameDiscoverer
ctor
- constructor to find parameter names for
UnsupportedOperationException
- iff raiseExceptions has been set to true
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |