-
1. Re: How to write an errai-style annotation?
jfuerth Apr 26, 2013 11:30 AM (in response to mdhirsch30345)1 of 1 people found this helpfulHi Michael,
There two main approaches that we use within Errai: for adding functionality to IOC/CDI beans, we use Errai IOC Code Decorators. These decorators generate code that's incorporated into BootstrapperImpl.java, and influences the behaviour of IOC beans. Errai UI Templating and Data Binding are implemented this way, for example.
For "standalone" features that can work outside of IOC beans, we use plain old GWT Generators and a cleverly hidden call to GWT.create() somewhere in the library. Starting in Errai 3, we've introduced an annotation-driven system for running these GWT code generators in parallel. You don't have to use this, but you are welcome to if you like! Errai features implemented in this way include Marshalling, JAX-RS Client, JPA, and the IOC container itself.
In all cases, we generate the Java code itself using the errai-codegen module, which includes a reflection API (MetaClass, MetaMethod, MetaType, etc) and a validating code generator (most of the generator's functionality is accessible through the static methods on the Stmt class).
Unfortunately, code generation is one of the underdocumented parts of Errai, so the best way to get a feel for it is to clone the Errai git repo, import the sources into your IDE, and play with some of the existing code generators. For an example IOC extension, you could start with ObservesExtension, which implements the CDI @Observes behaviour:
For an example of a non-IOC generator that works in parallel, have a look at JaxrsProxyLoaderGenerator, which is responsible for generating the client-side call stubs for JAX-RS interfaces:
Hope this helps!
-Jonathan
-
2. Re: How to write an errai-style annotation?
mdhirsch30345 Apr 26, 2013 11:58 AM (in response to jfuerth)Thanks Jonathan,
I've got the errai code and I'm looking at it. It may take a while... That's a lot of interesting stuff going on.
I've found the code for @Observes and @EventHandler. What I'm thinking of is somewhere between those two, so I think I'll start there.
Thanks for the quick response.
--Michael