Can I use XDoclet to modify source code?
1 posts in topic
Flat View  Flat View

Posted By:   Pallavi_Rao
Posted On:   Thursday, January 31, 2008 03:46 AM

Lets say, I want to add entry and exit logging to my existing Java source code. If I use annotation with class scope, can I use XDoclet to generate source code from the given source code, with the additional logging bit added?

Re: Can I use XDoclet to modify source code?

Posted By:   Robert_Lybarger  
Posted On:   Thursday, January 31, 2008 08:58 AM

I'm actually not sure about xdoclet, but the java toolset does provide the ability for you to write an "annotation processing tool" (google for that term) which is directly designed for letting you do things programmatically in response to it reading source code. This includes writing modified versions of the source code. I've done something similar once to write a completely new Factory class based on presence of field methods once. Not *easy* necessarily, but quite doable. The other alternative is that you are asking for exactly what "aspect oriented programming" (google for that) addresses. It takes a little extra understanding of new terminology, but an AOP solution (I've played with AspectJ in the eclipse environment, and with Spring AOP otherise) does exactly that: add common pieces of code that runs on specified methods in specified classes... either before or after the code in the original method executes.
About | Sitemap | Contact