[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Overriding pointcuts
|
Savita,
Unfortunately this won't work because
you can only extend abstract aspects so you cannot override the behaviour
of an existing woven concrete aspect. You can override a pointcut but only
in a sub-aspect:
public
abstract
aspect
AbstractPrimitiveFlightRecorder {
protected
pointcut
myMethod() :
PrimitiveFlightRecorderPointcutLibrary.recordedMethod();
}
public
aspect
PrimitiveFlightRecorderAspect extends
AbstractPrimitiveFlightRecorder
{
protected
pointcut
myMethod()
:
execution(!@PrimitiveDataLoggerAnnotation
public
* *.Method*(..));
before
(): myMethod() {
System.out.println(">
PrimitiveFlightRecorderAspect.before() "
+ thisJoinPoint);
}
after
(): myMethod() {
System.out.println("<
PrimitiveFlightRecorderAspect.before() "
+ thisJoinPoint);
}
}
However one solution is to use a separate
pointcut library which is used to weave at compile-time:
public
aspect
PrimitiveFlightRecorderPointcutLibrary {
protected
pointcut
recordedMethod() :
execution(@PrimitiveDataLoggerAnnotation
public
* *.Method*(..));
}
public
aspect
PrimitiveFlightRecorderAspect
{
protected
pointcut
myMethod() :
PrimitiveFlightRecorderPointcutLibrary.recordedMethod();
before
(): myMethod() {
System.out.println(">
PrimitiveFlightRecorderAspect.before() "
+ thisJoinPoint);
}
after
(): myMethod() {
System.out.println("<
PrimitiveFlightRecorderAspect.before() "
+ thisJoinPoint);
}
}
Then for LTW substitute an alternative
implementation of the library. Because _all_ aspects must be woven, including
those woven previously, you will pick up the new pointcut definition. Unfortunately
you cannot define pointcut libraries using XML.
Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester, SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/
"Chandan, Savita"
<Savita.Chandan@xxxxxxxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx
06/09/2006 02:43
Please respond to
aspectj-users@xxxxxxxxxxx |
|
To
| <aspectj-users@xxxxxxxxxxx>
|
cc
|
|
Subject
| [aspectj-users] Overriding pointcuts |
|
Hi,
I want to override pointcuts inserted in the
aspect code during compile, at run time. What would I do to achieve this?
If I created a pointcut in aop.xml that contradicts the pointcut inserted
in the code, what would happen?
For ex.
In my aspect class
public aspect PrimitiveFlightRecorderAspect
{
pointcut myMethod():
execution(@ PrimitiveDataLoggerAnnotation public * *.Method*(..))
);
before
(): myMethod() {
}
after
(): myMethod() {}
}
Now if in the aop.xml if I were to do this.
(pardon me for any mistakes in the aop.xml, this is the first time I creating
one) what would happen?
<aspectj>
<aspects>
<aspect
name="PrimitiveFlightRecorderAspect"/>
pointcut myMethod():
execution(! @ PrimitiveDataLoggerAnnotation public * *.Method*(..))
);
</aspects>
</aspectj>
Thanks,
Savita _______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users