[cdi-dev] [JBoss JIRA] (CDI-271) Provide a way to inject Event metadata into an observer method

Jozef Hartinger (JIRA) jira-events at lists.jboss.org
Mon Oct 15 03:59:03 EDT 2012


    [ https://issues.jboss.org/browse/CDI-271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12726339#comment-12726339 ] 

Jozef Hartinger commented on CDI-271:
-------------------------------------

I don't think Annotated is the appropriate level of abstraction for this. Annotated* serves as a low-level abstraction over information obtained from the reflection API whereas InjectionPoint is the abstraction level that recognized qualifiers, etc. Furthermore, you would probably want to obtain all the qualifiers of an event (including those set using Event.select()) which are not reflected within InjectionPoint nor Annotated.

Note that you could implement the ObserverMethod interface yourself that allows you to obtain qualifiers of a received event (see CDI-36).
                
> Provide a way to inject Event metadata into an observer method
> --------------------------------------------------------------
>
>                 Key: CDI-271
>                 URL: https://issues.jboss.org/browse/CDI-271
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Events
>            Reporter: Arne Limburg
>
> Currently there is no way for observer methods to access the qualifiers of the fired event (i.e. to access @Nonbinding members).
> Consider the following example:
> {code}
> @Inject @MyQualifier
> Event<MyObject> event;
> public void fireEvent(MyObject object, MyTypeValue type) {
>     event.select(new MyTypeAnnotationLiteral(type)).fire(object);
> }
> {code}
> Currently no observer can receive the value of MyTypeValue. I suggest to introduce an interface AnnotatedEvent that extends Annotated and contains this information. It then could be injected via the InjectionPoint like this:
> {code}
> public void observeEvent(@Observes @MyType MyObject object, InjectionPoint ip) {
>     MyType annotation = ip.getAnnotated().getAnnotation(MyType.class);
>     MyTypeValue value = annotation.value();
>     ...
> }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the cdi-dev mailing list