I've found a way to implement a type-safe check for this. Here it goes:
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@AuthorizeInstantiation(value = { User.class, Admin.class })
public class EnumAnnotation {
}
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.PACKAGE, ElementType.TYPE })
@Documented
@Inherited
@interface AuthorizeInstantiation {
Class<? extends Role>[] value() default {};
}
class Role {
}
class User extends Role {
}
class Admin extends Role {
}
So, the only thing that must change is the annotation
@AuthorizeInstantiation, to accept classes that extends roles.
Thoughts anyone?
cheers,
Bruno
Bruno Borges wrote:
You simply can't do that because the nature of Annotations.
Even if AuthorizeInstantiation's values were of type Object[] you
wouldn't be able to do that with Enums.
You will have to use Strings.
Although there's some hack you can make using Java 6 to accomplish
what you want. If you are interested, take a look at this link:
http://www.iam.unibe.ch/~akuhn/blog/2008/roman-numerals-in-your-java/
Good luck!!
Cheers,
Bruno
miro wrote:
I am using this @AuthorizeInstantiation (wicket authetication
annotation)
in my pages , the code for this annotation
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.PACKAGE, ElementType.TYPE })
@Documented
@Inherited
public @interface AuthorizeInstantiation {
/**
* Gets the roles that are allowed to take the action.
* * @return the roles that are allowed. Returns a zero
length array by
default
*/
String[] value() default {};
}
I created my enum with representing authorities
public enum Authorities {
LIASION_OFFICER,
GRANTS_OFFICER,
PROGRAM_ANALYST,
ADMIN;
}
I am trying to use AuthorizeInstantiation in my page here an example
@AuthorizeInstantiation(value={Authorities.LIASION_OFFICER.name()})
public class HomePage extends BasePage {
this line does not compile, I get the error
The value of annotation attribute AuthorizeInstantiation .value must
be a
constant expression .please help me resolve this .
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]