File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Code Regneration in Spring Roo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Code Regneration in Spring Roo" Watch "Code Regneration in Spring Roo" New topic
Author

Code Regneration in Spring Roo

Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
One of the reasons that I am a bit reluctant to use Spring Roo is the fact that it depends on code generation, non-Java code generation at that. Do you address this in your book? What can you tell me to assure me that this is not a liability in adopting Spring Roo.

Thanks,
Joshua Smith


Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 432
    
    5
Hi Joshua,

The following is a FlightService_Roo_ToString.aj AspectJ ITD file:



The above code says that FlightService_Roo_ToString.aj file adds a method named toString to FlightService Java class. You can move this toString method into the corresponding FlightService.java source file with just a few clicks in your IDE.

If you look at the above AspectJ ITD file, you can see that it is Java code with slightly different syntax for introducing members to the corresponding Java class. I don't see this can be considered as an impediment in adoption of Spring Roo.

regards
ashish


Author of
Getting started with Spring Framework
Portlets in Action
Spring Roo 1.1 Cookbook
Portlets blogSpring Roo blog
Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Thank you Ashish.

If I move that code into the .java file, does that mean that I can delete the .aj file and not use it any longer?

Why does Roo generate the code in a .aj file instead of generating .java files or modifying existing Java files?

Thanks,
Josh
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 432
    
    5
Hi Joshua,

Let's say you have an AspectJ ITD file which contains a single method toString. When you move this method from AspectJ ITD file to the corresponding Java source file, Roo will automatically delete the ITD file because it is no longer required. You don't need to manually delete the .aj files.

Imagine you have a code generation tool that keeps all the information in Java source files. Now, everytime you do something using such a code generator, it'd result in overwriting the Java source file. It also means that you may lose all the customization that you made. In Spring Roo, the code that is managed by Spring Roo is kept in AspectJ ITD files, which you must not modify. This results in clear separation of what code is owned by developer (the code in .java files) and what is owned by Spring Roo (the code in .aj files).

I have added a blog entry that can give you some idea about what typically forms part of .aj files.

regards
ashish
 
 
subject: Code Regneration in Spring Roo