Dealing with Changes

One of the toughest aspects of code generation is how you deal with regenerating existing classes. The BeanMaker program takes the easy way out and just rewrites the class file. Obviously, the BeanMaker is meant to be a quick start program just to get a bean going. After that, it's up to you to add additional functionality.

Other code generators take different approaches. Some generators recognize special comment tags that mark off preserved areas of code. For example, you might preserve a method in your generated class with the following:

//@PRESERVE
    public String generateUniqueID()
    {
// some code usually goes here
    }
//@END PRESERVE

When you run the code generator, it looks for the preserved blocks in the old file and ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.