[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1117) support enum types in @RaiseEvent or a new @RaiseEventType annotation

Adam Brod (JIRA) jira-events at lists.jboss.org
Tue Mar 27 17:25:18 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBSEAM-1117?page=comments#action_12357542 ] 
            
Adam Brod commented on JBSEAM-1117:
-----------------------------------

Yet another way the Seam team could choose to implement this would be to allow us to define our own Annotations that raise events.  I could define a new annotation like this:

@SeamEvent /* this tells Seam to fire an event on any method with this annotation */
@Target(METHOD)
@Retention(RUNTIME)
@Documented
@interface UserLoginEvent { }

Then I annotate my event raising method like this:

@UserLoginEvent
public void login {
    // do login stuff
}

And I listen to this event like this:

@Observer(UserLoginEvent.class)
public void storeUserLoginRecord {
  // store stuff
}

Again, this may or may not be the better than using Strings.  It does allow for more type-safe event raising/observing.

> support enum types in @RaiseEvent or a new @RaiseEventType annotation
> ---------------------------------------------------------------------
>
>                 Key: JBSEAM-1117
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1117
>             Project: JBoss Seam
>          Issue Type: Feature Request
>          Components: Core
>            Reporter: Bradley Smith
>
> RaiseEvent:
> @Target(METHOD)
> @Retention(RUNTIME)
> @Documented
> public @interface RaiseEvent 
> {
>    
>    /**
>     * The event name, defaults to the name
>     * of the method.
>     * 
>     * @return the event name
>     */
>    String value() default "";
>    
>    //TODO: String[] ifOutcome() default {};
>    
> }
> Is it possible to make the value be based on an enum type?  I currently have all my application event types enumerated in enum called EventType.
> I've tried doing:  
> @RaiseEvent(EventType.ApplicationSaved.name())
> however, this doesn't count as a constant String and is invalid syntax.  It seems more 'elegant' to be able to enumerate the event types of an application in something like an enum than to sprinkle strings throughout the code with the specific event String values.
> Maybe an alternate annotation is called for - say, @RaiseEventType(MyEnum.MyEventType)?
> I'm not sure - I don't have a solid grasp of the syntax used to define an annotation.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list