[cdi-dev] [JBoss JIRA] (CDI-479) How to identify the bean a static observer method belongs to

Tomas Remes (JIRA) issues at jboss.org
Thu Mar 10 10:00:05 EST 2016


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

Tomas Remes edited comment on CDI-479 at 3/10/16 10:00 AM:
-----------------------------------------------------------

I am not sure but isn't the answer for the first question in {{4.2. Inheritance of member-level metadata}}:
{quote}
If X declares an initializer, non-static observer, @PostConstruct or @PreDestroy method x()
then Y inherits x() if and only if neither Y nor any intermediate class that is a subclass of X
and a superclass of Y overrides the method x()
{quote}
>From this I would say the observer shouldn't be detected (because is static) in the first case. 


was (Author: tremes):
I am not sure but isn't the answer for the first question in `4.2. Inheritance of member-level metadata`:
{quote}
If X declares an initializer, non-static observer, @PostConstruct or @PreDestroy method x()
then Y inherits x() if and only if neither Y nor any intermediate class that is a subclass of X
and a superclass of Y overrides the method x()
{quote}
>From this I would say the observer shouldn't be detected (because is static) in the first case. 

> How to identify the bean a static observer method belongs to
> ------------------------------------------------------------
>
>                 Key: CDI-479
>                 URL: https://issues.jboss.org/browse/CDI-479
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>            Reporter: Martin Kouba
>
> Let's sum up some parts of the spec which are relevant to static observer methods:
> "10.4. Observer methods":
> {quote}
> An observer method is a non-abstract method of a managed bean class or session bean class...
> An observer method may be either static or non-static.
> {quote}
> "10.3. Observer resolution":
> {quote}
> An event is delivered to an observer method if:
> * The observer method belongs to an enabled bean.
> * ...
> {quote}
> "12.4.3. Bean discovery":
> {quote}
> For each observer method of every enabled bean, the container registers an instance of the ObserverMethod interface defined in The ObserverMethod interface.
> {quote}
> Now what is the algorithm to *identify the bean a static observer method belongs to*? Is is bound to all beans whose Bean.getBeanClass() declares the method? There are two special scenarios I have in mind:
> h3. Static observer method on an abstract class
> {code:java}
> public abstract class Foo {
>   public static observe1(@Observes Event1 event1) {
>   }
> }
> public class Bar extends Foo {
> }
> {code}
> Foo is not a bean. Foo.observe1() is not a method of managed bean class Bar (if we strictly follow the JSL). Is the observer method detected? Does it belong to Bar? What if there are several subclasses of Foo?
> h3. Specialization
> {code:java}
> public class Foo {
>   public static observe1(@Observes Event2 event2) {
>   }
> }
> @Specializes
> public class Bar extends Foo {
> }
> {code}
> Foo is specialized by Bar and thus it's disabled. Is the observer method detected? Does it belong to Bar? 



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list