You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by James Carman <ja...@carmanconsulting.com> on 2008/12/05 04:58:24 UTC

Re: using annotation @AuthorizeInstantiation

I don't know about this.  It would work (and break existing code, unless you
use something other than value for the annotation).  I don't know if I would
want to have to create a new class for each role in my project.  Yes, it
would be a small price to pay, but it just feels wrong.

On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <br...@gmail.com>wrote:

> 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/<http://www.iam.unibe.ch/%7Eakuhn/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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
Yes Adriano, that's what I said on my last reply. :-)

 >> So, the only way, for now, to have type-safety is using that 
Class-thing. I don't vote for this though. A simple class with String 
constants does de job quite well. :-D

Cheers,
Bruno

Adriano dos Santos Fernandes wrote:
> Bruno Borges escreveu:
>> Note that this is really type-safe, and these classes will never be 
>> instantiated.
> I don't think this has any value in this context. Where will the roles 
> x user will be? On the database, certainly...
>
> So why declare dummy classes for them? If yon don't want to repeat 
> strings, you could create static final constants somewhere...
>
>
> Adriano
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Adriano dos Santos Fernandes <ad...@uol.com.br>.
Bruno Borges escreveu:
> Note that this is really type-safe, and these classes will never be 
> instantiated.
I don't think this has any value in this context. Where will the roles x 
user will be? On the database, certainly...

So why declare dummy classes for them? If yon don't want to repeat 
strings, you could create static final constants somewhere...


Adriano


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
It is not possible to extend enums nor annotations. And as the question 
here is about the use of @AuthorizeInstantiation, there's no way to 
declare MyEnum[], of course :-)

So, the only way, for now, to have type-safety is using that 
Class-thing. I don't vote for this though. A simple class with String 
constants does de job quite well. :-D

James Carman wrote:
> But, you can declare the values "property" to be of type MyEnum[].  Is what
> we're really looking for here the ability to extend an enum (if that even
> makes sense)?  I've often thought it would be nice if I could add stuff to
> an enum from the outside.  But, that kind of goes against the idea of an
> enum, doesn't it?
>
> On Thu, Dec 4, 2008 at 11:51 PM, Bruno Borges <br...@gmail.com>wrote:
>
>   
>> Well... you can't do this:
>>
>> @Foo(values={MyEnum.FOO,  MyEnum.BAR});
>>
>> @interface Foo {
>>  Object[] values() default {};
>>
>> }
>>
>> James Carman wrote:
>>
>>     
>>> What do you mean by "Enums as Objects"?
>>>
>>> On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <bruno.borges@gmail.com
>>>       
>>>> wrote:
>>>>         
>>>
>>>       
>>>> Well... You don't have to create one java file for each class. You can
>>>> put
>>>> all of them on the same file, like:
>>>>
>>>> public final class MyAppRoles {
>>>>  private MyAppRoles() {}
>>>>  public static final class Admin extends Role {
>>>>      private Admin() {}
>>>>  }
>>>>
>>>>  public static final class User extends Role {
>>>>      private User() {}
>>>>  }
>>>> }
>>>>
>>>> Note that this is really type-safe, and these classes will never be
>>>> instantiated.
>>>> But, I'm not defending that we should change that. I'm just showing a
>>>> possibility. :-)
>>>>
>>>> I really did't understand why Sun decided to reject Enums as Objects in
>>>> this context of annotations.
>>>>
>>>> cheers,
>>>> Bruno
>>>>
>>>> James Carman wrote:
>>>>
>>>>
>>>>
>>>>         
>>>>> I don't know about this.  It would work (and break existing code, unless
>>>>> you
>>>>> use something other than value for the annotation).  I don't know if I
>>>>> would
>>>>> want to have to create a new class for each role in my project.  Yes, it
>>>>> would be a small price to pay, but it just feels wrong.
>>>>>
>>>>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>>>>>
>>>>>
>>>>>           
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>             
>>>>>
>>>>>           
>>>>>> 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/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>>>>> <
>>>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>>>               
>>>>>>> <
>>>>>>>
>>>>>>> http://www.iam.unibe.ch/%7Eakuhn/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: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>>
>>>>>           
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>         
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by James Carman <ja...@carmanconsulting.com>.
But, you can declare the values "property" to be of type MyEnum[].  Is what
we're really looking for here the ability to extend an enum (if that even
makes sense)?  I've often thought it would be nice if I could add stuff to
an enum from the outside.  But, that kind of goes against the idea of an
enum, doesn't it?

On Thu, Dec 4, 2008 at 11:51 PM, Bruno Borges <br...@gmail.com>wrote:

> Well... you can't do this:
>
> @Foo(values={MyEnum.FOO,  MyEnum.BAR});
>
> @interface Foo {
>  Object[] values() default {};
>
> }
>
> James Carman wrote:
>
>> What do you mean by "Enums as Objects"?
>>
>> On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <bruno.borges@gmail.com
>> >wrote:
>>
>>
>>
>>> Well... You don't have to create one java file for each class. You can
>>> put
>>> all of them on the same file, like:
>>>
>>> public final class MyAppRoles {
>>>  private MyAppRoles() {}
>>>  public static final class Admin extends Role {
>>>      private Admin() {}
>>>  }
>>>
>>>  public static final class User extends Role {
>>>      private User() {}
>>>  }
>>> }
>>>
>>> Note that this is really type-safe, and these classes will never be
>>> instantiated.
>>> But, I'm not defending that we should change that. I'm just showing a
>>> possibility. :-)
>>>
>>> I really did't understand why Sun decided to reject Enums as Objects in
>>> this context of annotations.
>>>
>>> cheers,
>>> Bruno
>>>
>>> James Carman wrote:
>>>
>>>
>>>
>>>> I don't know about this.  It would work (and break existing code, unless
>>>> you
>>>> use something other than value for the annotation).  I don't know if I
>>>> would
>>>> want to have to create a new class for each role in my project.  Yes, it
>>>> would be a small price to pay, but it just feels wrong.
>>>>
>>>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>>>>
>>>>
>>>>> wrote:
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>> 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/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>>>> <
>>>>>> http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/
>>>>>> >
>>>>>> <
>>>>>>
>>>>>> http://www.iam.unibe.ch/%7Eakuhn/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: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
Well... you can't do this:

@Foo(values={MyEnum.FOO,  MyEnum.BAR});

@interface Foo {
  Object[] values() default {};
}

James Carman wrote:
> What do you mean by "Enums as Objects"?
>
> On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <br...@gmail.com>wrote:
>
>   
>> Well... You don't have to create one java file for each class. You can put
>> all of them on the same file, like:
>>
>> public final class MyAppRoles {
>>   private MyAppRoles() {}
>>   public static final class Admin extends Role {
>>       private Admin() {}
>>   }
>>
>>   public static final class User extends Role {
>>       private User() {}
>>   }
>> }
>>
>> Note that this is really type-safe, and these classes will never be
>> instantiated.
>> But, I'm not defending that we should change that. I'm just showing a
>> possibility. :-)
>>
>> I really did't understand why Sun decided to reject Enums as Objects in
>> this context of annotations.
>>
>> cheers,
>> Bruno
>>
>> James Carman wrote:
>>
>>     
>>> I don't know about this.  It would work (and break existing code, unless
>>> you
>>> use something other than value for the annotation).  I don't know if I
>>> would
>>> want to have to create a new class for each role in my project.  Yes, it
>>> would be a small price to pay, but it just feels wrong.
>>>
>>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>>>       
>>>> wrote:
>>>>         
>>>
>>>       
>>>> 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/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>>> <
>>>>> http://www.iam.unibe.ch/%7Eakuhn/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: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>         
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: using annotation @AuthorizeInstantiation

Posted by James Carman <ja...@carmanconsulting.com>.
What do you mean by "Enums as Objects"?

On Thu, Dec 4, 2008 at 11:11 PM, Bruno Borges <br...@gmail.com>wrote:

> Well... You don't have to create one java file for each class. You can put
> all of them on the same file, like:
>
> public final class MyAppRoles {
>   private MyAppRoles() {}
>   public static final class Admin extends Role {
>       private Admin() {}
>   }
>
>   public static final class User extends Role {
>       private User() {}
>   }
> }
>
> Note that this is really type-safe, and these classes will never be
> instantiated.
> But, I'm not defending that we should change that. I'm just showing a
> possibility. :-)
>
> I really did't understand why Sun decided to reject Enums as Objects in
> this context of annotations.
>
> cheers,
> Bruno
>
> James Carman wrote:
>
>> I don't know about this.  It would work (and break existing code, unless
>> you
>> use something other than value for the annotation).  I don't know if I
>> would
>> want to have to create a new class for each role in my project.  Yes, it
>> would be a small price to pay, but it just feels wrong.
>>
>> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <bruno.borges@gmail.com
>> >wrote:
>>
>>
>>
>>> 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/<http://www.iam.unibe.ch/%7Eakuhn/blog/2008/roman-numerals-in-your-java/>
>>>> <
>>>> http://www.iam.unibe.ch/%7Eakuhn/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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: using annotation @AuthorizeInstantiation

Posted by Bruno Borges <br...@gmail.com>.
Well... You don't have to create one java file for each class. You can 
put all of them on the same file, like:

public final class MyAppRoles {
    private MyAppRoles() {}
    public static final class Admin extends Role {
        private Admin() {}
    }

    public static final class User extends Role {
        private User() {}
    }
}

Note that this is really type-safe, and these classes will never be 
instantiated.
But, I'm not defending that we should change that. I'm just showing a 
possibility. :-)

I really did't understand why Sun decided to reject Enums as Objects in 
this context of annotations.

cheers,
Bruno

James Carman wrote:
> I don't know about this.  It would work (and break existing code, unless you
> use something other than value for the annotation).  I don't know if I would
> want to have to create a new class for each role in my project.  Yes, it
> would be a small price to pay, but it just feels wrong.
>
> On Thu, Dec 4, 2008 at 10:33 PM, Bruno Borges <br...@gmail.com>wrote:
>
>   
>> 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/<http://www.iam.unibe.ch/%7Eakuhn/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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org