Reply To: Rewrite Annotations

Splash Forums Rewrite Users Rewrite Annotations Reply To: Rewrite Annotations

#24203

Hey Oleg,

You can do this, but you’d probably need to implement your own Annotation handlers, since at the moment we don’t support REST-style annotations.

However, if you look in our showcase, you can see how I’ve implemented this using the Rewrite Configuration itself:

https://github.com/ocpsoft/rewrite/blob/master/showcase/rest-ws/src/main/java/org/ocpsoft/rewrite/showcase/rest/RestRewriteConfiguration.java#L106

We could probably add a few annotations to make this easier, but I have to ask, why not just use the JAX-RS specification from Java EE? RESTEasy is really quite nice to use!

————–
This is actually very easy to do, even in your own code; all you need to do is create a custom annotation, and implement an AnnotationHandler:

https://github.com/ocpsoft/rewrite/blob/master/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/Join.java#L35

https://github.com/ocpsoft/rewrite/blob/master/config-annotations/src/main/java/org/ocpsoft/rewrite/annotation/handler/JoinHandler.java#L39
————–

Once this is done, you register your annotation handler as a service and you’re done! You now have an annotation that will use Rewrite to add behavior to your classes!

https://github.com/ocpsoft/rewrite/blob/master/config-annotations/src/main/resources/META-INF/services/org.ocpsoft.rewrite.annotation.spi.AnnotationHandler

This is the mechanism we use internally to create all annotations, and it’s also a public SPI that anyone can use for their own needs. The whole philosophy of Rewrite is to use the same APIs internally that users would use to extend the framework.

What do you think?

Does that help? Are your maybe interested in adding REST support to Rewrite?