Community
Participate
Working Groups
am using the AspectJ5 style annotations and in addition I also want to create a point-cut based on a custom Annotation (PermissionRequired), my Annotation looks like this - @Retention(RetentionPolicy.RUNTIME) @Target(value = ElementType.METHOD) public @interface PermissionRequired { int mode() default -1; int user() default -1; int group() default -1; public final static int IS_DBA = 04; public final static int IS_OWNER = 02; public final static int IS_MEMBER = 40; } And an example use of this is - @PermissionRequired(user = IS_DBA) private void setOwnerId(int ownerId) { ... } I need to be able to access the values of mode, user and group from the PermissionRequired annotation in my aspect advice. My aspect looks like this - @Aspect public class PermissionRequiredAspect { @Pointcut("execution(@org.exist.security.PermissionRequired * *(..)) && this(permission) && @annotation(permissionRequired)") public void methodWithPermissionRequired(Permission permission, PermissionRequired permissionRequired) { } @Before("methodWithPermissionRequired(permission, permissionRequired)") public void enforcePermissions(JoinPoint joinPoint, Permission permission, PermissionRequired permissionRequired) { System.out.println("POINTCUT"); } Now the above works quite nicely, however after reading the following articles, http://andrewclement.blogspot.com/2009/02/aspectj-optimized-annotation-value.html http://www.eclipse.org/aspectj/doc/released/README-167.html https://bugs.eclipse.org/bugs/show_bug.cgi?id=234943 I feel that it would be nicer, and perhaps more performant to directly bind the values from the PermissionRequired annotation rather than the annotation itself. So I tried to modify my aspect appropriately - @Aspect public class PermissionRequiredAspect { @Pointcut("execution(@org.exist.security.PermissionRequired * *(..)) && this(permission) && @annotation(org.exist.security.PermissionRequired(mode,user,group))") public void methodWithPermissionRequired(Permission permission, int mode, int user, int group) { } @Before("methodWithPermissionRequired(permission, mode, user, group)") public void enforcePermissions(JoinPoint joinPoint, Permission permission, int mode, int user, int group) { System.out.println("POINTCUT"); } } However, when I compile (I am using iajc from Ant), I get the following error messages - [iajc] /Users/aretter/NetBeansProjects/eXist-acl/src/org/exist/security/PermissionRequiredAspect.java:14 [error] Syntax error on token "execution(@org.exist.security.PermissionRequired * *(..)) && this(permission) && @annotation(org.exist.security.PermissionRequired(mode,user,group))", ")" expected [iajc] @Pointcut("execution(@org.exist.security.PermissionRequired * *(..)) && this(permission) && @annotation(org.exist.security.PermissionRequired(mode,user,group))") [iajc] [iajc] /Users/aretter/NetBeansProjects/eXist-acl/src/org/exist/security/PermissionRequiredAspect.java:15 [error] Method annotated with @Pointcut() for abstract pointcut must be abstract [iajc] public void methodWithPermissionRequired(Permission permission, int mode, int user, int group) { [iajc] [iajc] [iajc] 2 errors BUILD FAILED possible for int values? The values themselves are final and static, so should be able to be optimised by the compiler I guess. It would be good if the current support for single Enum or String values in annotation value bindings could be expanded to cover int values and also multiple values of these types. Thanks Adam.
I've expanded it support int values. However, supporting multiple values is a bigger piece of work than I want to tackle right now. I did a bit more work though and this workaround should behave for you. Change from: @Pointcut("execution(@org.exist.security.PermissionRequired * *(..)) && this(permission) && @annotation(org.exist.security.PermissionRequired(mode,user,group))") to @Pointcut("execution(@org.exist.security.PermissionRequired * *(..)) && this(permission) && @annotation(org.exist.security.PermissionRequired(mode)) && @annotation(org.exist.security.PermissionRequired(user)) && @annotation(org.exist.security.PermissionRequired(group))") that should give you the performance boost.
int value binding is done and I want to close this to cover that work. Opened bug 348617 to cover the multiple value case.