Monday, April 16, 2012

Annotation accepting n parameters

I'd like to be able to call an annotation with as many parameter as I want, something like this :



@Authorize("Admin", "Moderator", "User")
public static void read() {
// ...
}


So far, here's my annotation :



@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Authorize {
String[] value() default {};
}


But as you may know, this only works with :



@Authorize
@Authorize("Admin")
@Authorize({"Admin", "Moderator", "User"})


In fact, the first two are fine to me, it's the last one that bothers me.



The reason is simple.



For rights, I want a method to be available for many profile, and {} means "WITH", I'm looking for a "OR" ;)



Thanks!





No comments:

Post a Comment