Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] aspectj help : pointcut annotation binding not work


Hi there,

In your pointcut:

public pointcut checkSecurityCallAdd(Security securityAnnotation) :
 execution(@Security public * *(..)) && @this(securityAnnotation)

@this(securityAnnotation)

will attempt to bind on the annotation associated with the *type* containing your secure method,
rather than the method - so it won't match (as the type isn't annotated).  To bind against the
annotation for the method you need to use @annotation:

public pointcut checkSecurityCallAdd(Security securityAnnotation) :
 execution(@Security public * *(..)) && @annotation(securityAnnotation)

Adrian has a blog entry with a real example in:

        http://www.aspectprogrammer.org/blogs/adrian/2005/03/event_driven_ar.html

cheers,
Andy.



Mac <mac@xxxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

10/03/2005 21:31

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] aspectj help : pointcut annotation binding not work





Hi,

I'm beginner on aspectj.
My aspect want to catch method scoped annotation of type Security using
MyFirstWeaveAspect aspect on MyClass class

The AJDT detect the poincut matching but during runtime, the advise is never
executing.

Please help me.
Thanks
MAC

Aspect code :
public aspect MyFirstWeaveAspect {
public pointcut checkSecurityCallAdd(Security securityAnnotation) :
execution(@Security public * *(..)) && @this(securityAnnotation)

before(Security annotation) : checkSecurityCallAdd(annotation){
if (annotation.style().equals(SecurityType.NORMAL)) {
System.out.println("NORMAL SECURITY");
}
if (annotation.style().equals(SecurityType.PARANOIAC)) {
System.out.println("PARANOIAC SECURITY");
}
if (annotation.style().equals(SecurityType.SIMPLE)) {
System.out.println("SIMPLE SECURITY");
} else
{
System.out.println("BIZARRE");
}
}
}

Class to weave :

public class MyClass extends MyBaseClass{

@Security (style=SecurityType.NORMAL)
public void doGoodThing () {
System.out.println("doGoodthing");
}
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top