-
1. Re: How to detect Stereotypes from an interceptor
jharting Nov 13, 2013 9:39 AM (in response to mmusgrov)1 of 1 people found this helpfulUnfortunately I am not aware of any easy way of doing this so you will need to implement the spec logic:
The set of interceptor bindings for a method declared at class level includes those declared on stereotypes. An interceptor binding
declared on a bean class replaces an interceptor binding of the same type declared by a stereotype that is applied to the bean class.
Which means you need to check the method, the declaring type and all the stereotypes it declares in order to determine what stereotypes are effective. Note that you can use BeanManager.isStereotype() to check whether an annotation is a stereotype portable.
Btw, this could make for a nice reusable utility for e.g. Apache DeltaSpike.
-
2. Re: How to detect Stereotypes from an interceptor
mmusgrov Nov 15, 2013 10:42 AM (in response to jharting)Thanks for the help.
The main issue I had was that I was looking for the Stereotype annotation via the invocation target class using ic.getTarget().getClass() but this gives me a Weld proxy to the bean and calling getAnnotations() on the proxy does not return stereotypes (which personally I think is wrong - the proxy should give me all the direct annotations on the proxied object). So instead I got the actual (proxied) class using ic.getMethod().getDeclaringClass() which does return the stereotype annotation.
Once I had the stereotype I was able to use your suggestion of using the BeanManager to see if the @Transactional interceptor was in the stereotype.
Btw, this could make for a nice reusable utility for e.g. Apache DeltaSpike.
There is an AnnotationInspector that does something similar in the http://seamframework.org/Seam3/Solder project (org.jboss.solder.reflection)