Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Annotation class discovery with Vaadin
If I'm right, since v6.2, Vaadin introduced some annotation.
Do you use a mechanism to discover the classes having a specific annotation?
For example, how to I obtain a list of all the classes (in the classpath) that are annotated @ClientWidget ?
If, as an add-on developer, I need to do that kind of thing, how am I supposed to do?
I guess that I should not introduce a dependency to Spring that does it well...
Thanks for the answers.
John Rizzo: For example, how to I obtain a list of all the classes (in the classpath) that are annotated @ClientWidget ?
We've used the scannotation library to scan annotations at runtime, it works quite fast and we liked it for that project we used it in. So you can givi it a try as well.
We've used the scannotation library to scan annotations at runtime
Thank you Dmitri.
Where is it within vaadin-6.3.0.jar ? I cannot find it?
If Vaadin uses it at runtime, I guess the code is in the vaadin jar file? (because Vaadin has no dependencies, as far as I know).
I think vaadin.jar does not have this library. You have to download it from the link I mentioned and add to your classpath of your project.
I do not know what exactly uses Vaadin, we just used the scannotation externally in one of the pre-vaadin projects.
Question: Does anybody know how Vaadin supports (plans to support) annotated classes detection?
Sub question: and how add-on authors are supposed to do it?
Vaadin will have to do that soon or later, it's just a matter of time ;-)
Vaadin already uses annotations for finding the client-side implementation of an ui component.
There is no limitation for using annotations for any purpose - some of the most useful ones that come into mind are marking bean properties for validation constraints, visible names and formatting. Here is an example application that uses Annotation based validation: http://dev.vaadin.com/svn/incubator/SpringApplication/.
Thank you Joonas.
I fear that my question remains.
The code you mention uses Spring. It has a dependency on, let's say, spring.jar.
Vaadin.jar does not have such a dependency (as far as I know). How does the code in Vaadin.jar automatically discover annotations without any dependency to an external framework? (Or it does no annotation discovery yet?)
Vaadin itself does not search for annotations at runtime.
The WidgetMapGenerator (run at the beginning of widgetset compilation) does search for annotations by loading classes in the classpath and checking the Class objects for the annotation. This is far from ideal, but we found it acceptable in this phase (widgetset compilation) and it does not introduce additional dependencies. ClassPathExplorer implements the search for classes with specific annotations.
Thank you Henri, for this very clear answer to my question!