code generation is a key new trend in engineering, one that you need to understand well. the reason is simple: todays modern frameworks are extremely code-intensive. using a code generator to build the code for you can save you a lot of time, both in writing the code and fixing the inevitable bugs that spring from swathes of hand-written code.
building a custom generator is an easy, fun, and cheap (free) way to understand how generation works. with a new understanding about code generation in hand, you will be able to evaluate off-the-shelf tools as well as have the ability to write something yourself. 【程序编程相关:Is Linux Ready for U】
there are a number of code generation options for java development. these range from canned solutions that generate whole applications (e.g. compuwares optimalj), to open source generators (e.g. xdoclet), to custom-built solutions. this article focuses on using xslt to build custom generators. more information about xslt is presented below. 【推荐阅读:Keep Changes Small: 】
the basics 【扩展信息:Migrating the Deskto】lets start with the basics of code generation.
code generation is using one application to build code for another application. in this case, xslt will be our generator application. input for a code generator can come in many forms (source code, database schemas, xml models, etc.). regardless of the source, we call the input the model because it represents (models) what is to be built. on the other side are the templates. the templates render the model into code, or other artifacts such as documentation. figure 1 illustrates this process.
figure 1. flow chart for basic xslt-based code generation
... 下一页