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

Martin Kouba (JIRA) issues at jboss.org
Tue Sep 16 04:36:02 EDT 2014


Martin Kouba created CDI-479:
--------------------------------

             Summary: 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.3.1#6329)


More information about the cdi-dev mailing list