-
1. Re: Getting a List of all the Web Beans that have been deployed
nickarls Apr 29, 2009 2:07 PM (in response to niravshah)In Web Beans there is the implicit getBeans(). Generally, you could try resolve on the Object class since it's a superclass in the API Types of all beans
-
2. Re: Getting a List of all the Web Beans that have been deployed
nickarls Apr 29, 2009 2:08 PM (in response to niravshah)s/implicit/internal
-
3. Re: Getting a List of all the Web Beans that have been deployed
gavin.king May 12, 2009 9:52 AM (in response to niravshah)In the next rev of the spec, you will be able to do:
@Any Instance<Object> objects; public void printEverything() { for(Object object: objects) print(object); }
Or, if you only want objects of a certain type:
@Any Instance<Foo> foos; public void printFoos() { for(Object foo: foos) print(foo); }
The new design of Instance is super-cool :-)
-
4. Re: Getting a List of all the Web Beans that have been deployed
mikewse May 18, 2009 2:47 PM (in response to niravshah)
Nicklas Karlsson wrote on Apr 29, 2009 14:07:
Generally, you could try resolve on the Object class since it's a superclass in the API Types of all beansI tried this out:
Set<Bean<Object>> beanset = manager.resolveByType(Object.class); for(Bean<Object> bean : beanset) { ... bean.getTypes() ...
I would like to look up the class that implements this webbean, but the closest thing I can get is the getTypes() collection, where both interfaces/superclasses and the class itself are included. How can I find out which is the implementing webbean class without having to apply heuristics to the types collection?
I can see that internally there is both a types collection and a type member (pointing to the implementing class), but the latter doesn't seem to be exposed in the API?
-
5. Re: Getting a List of all the Web Beans that have been deployed
nickarls May 18, 2009 9:15 PM (in response to niravshah)Hmm, I most beans will be descendants of RIBean so you might want to try to cast and do getType to see if that gets you anywhere. I don't think there is a way to do it directly from Bean.
-
6. Re: Getting a List of all the Web Beans that have been deployed
gavin.king May 18, 2009 9:39 PM (in response to niravshah)Why, precisely, are you wanting to do this?
-
7. Re: Getting a List of all the Web Beans that have been deployed
alexanderbell May 19, 2009 6:42 AM (in response to niravshah)That looks pretty cool.
So I get with @Any all beans from one type and it doesn't matter what binding type and scope do they have?Alex
-
8. Re: Getting a List of all the Web Beans that have been deployed
gavin.king May 19, 2009 6:59 AM (in response to niravshah)Exactly, except it's defined a bit more elegantly than that: @Any is actually just a binding, but it's a binding that all beans have.
-
9. Re: Getting a List of all the Web Beans that have been deployed
mikewse May 21, 2009 2:52 PM (in response to niravshah)(Sorry, I wasn't getting any notifications from the forum so didn't know about your replies)
Gavin King wrote on May 18, 2009 21:39:
Why, precisely, are you wanting to do this?We use the webbeans in a service layer that can be dynamically bound to actions in run-time. An administrator person can get a list of services (using resolveByType and a binding annotation) and bind actions to methods of the backing class. The admin interface also examines some (non-webbeans) annotations on the concrete service classes to make decisions.
So, in short, we need to look up methods and annotations on the concrete bean class. We could solve this ourselves by building our own classpath scanning mechanism, but that would waste both developer and cpu resources when the job is already done by webbeans :-).
-
10. Re: Getting a List of all the Web Beans that have been deployed
gavin.king May 21, 2009 4:55 PM (in response to niravshah)OK, so actually what you really need is the new SPI.
-
11. Re: Getting a List of all the Web Beans that have been deployed
mikewse May 21, 2009 7:59 PM (in response to niravshah)
Gavin King wrote on May 21, 2009 16:55:
OK, so actually what you really need is the new SPI.Interesting. How would I do this with the new SPI? (I guess you are saying the right way is not to add a getType() method on Bean in the spec ;-)
When will the new SPI be available in public spec and/or RI?
-
12. Re: Getting a List of all the Web Beans that have been deployed
gavin.king May 22, 2009 12:03 AM (in response to niravshah)The SPI is in chapter 11.
-
13. Re: Getting a List of all the Web Beans that have been deployed
mikewse May 22, 2009 1:27 AM (in response to niravshah)
Gavin King wrote on May 22, 2009 00:03:
The SPI is in chapter 11.Thanks for the link. I guess I would use it along these lines:
void discoverBeans(@Observes ProcessAnnotatedType<?> event) { AnnotatedType<?> at = event.getAnnotatedType(); at.getJavaClass() ... }
This certainly seems to solve my use case. But I need to hook into the startup sequence and run my code during bean registration, as I cannot demand this metadata afterwards.
It would be more flexible if the metadata was available (but not modifiable of course) anytime during the container's lifetime?
-
14. Re: Getting a List of all the Web Beans that have been deployed
gavin.king May 23, 2009 3:44 AM (in response to niravshah)
But I need to hook into the startup sequence and run my code during bean registration, as I cannot demand this metadata afterwards.But surely you want to build and cache your metamodel upfront, and validate that there are no errors in the user code.
At least that is what I would want to do...