A code generator is critical in producing factory quality software components that provide the base on which business processes are implemented. It is used to generate repetitive program and script source code. The generated code is produced in a independent accessible form that can be used with most development approaches including those that exploit integrated development environments and other code generators.
The code generator has been used with Eclipse , XDoclet , Ant and JUnit .
The code generator reduces the time needed for development. It reduces the risk of typographical errors. For example producing Java source code for JavaBeans (POJO) can be resource intensive especially if the data requirement is subject to change. The normal iterative cycle of change, generate test, change, generate test etc will be more productive if the time taken to generate is reduced to a few seconds from the hours a manual task might take.
Content management systems can require extensive numbers of templates each of which requires simple repetitive code. The cost of development, maintenance and enhancement is significantly increased without the use of a code generator.
The code generator has been used with the OpenCms content management system.
Standard XML dialects as defined by XML Schema are very important in developing industry standard applications. At the points of data entry and data storage generated code provides a cost effective approach of dealing with the elements and attributes of request and response XML instances.
The code generator has been used with the Docbook XML schema , the Open Travel Alliance XML schema and other XML schema.
The code generator is a simple entry level tool. It provides a good introduction to a subject that can appear complex. It is a reasonable introduction to the more sophisticated set of tools that are XDoclet .
In the supplied JavaBean Java source code example the code generator generates Java classes and interfaces. These include not just getter and setter methods but also the validation status, validation messages and validate methods.
The code generator does not enforce mandatory naming conventions but it is recommended that the conventions used in the examples for classes, interfaces, methods, fields and field attributes are followed.
Though the avoidance of code duplication is advisable in most circumstances the code generator can be used to produce multiple versions of duplicate code. Sometimes extension of Java classes may not be the optimum approach.
The code generator is simple in implementation in that all that is required is Java and Ant core tasks together with user editable templates and code fragments. The code generator can be run directly within Ant or within an Ant aware development environment such as Eclipse . No additional Java jars or run time libraries are required. No registry changes are required on Windows operating systems.
Over the years there have been many code generators. Most have passed into history. Many long term survivors are "preprocessors" for programming languages such as PL/1 and COBOL. There are few if any general purpose code generators that continue to generate code in the same way they did even five years ago. The current generation of sophisticated code generators is best represented by XDoclet . History suggests it is a better to use the best general purpose tools of the time to implement code generation.
An ideal code generator needs to allow the editing of simple property files and simple code fragment templates. It needs to process these editable files to generate output code files using general purpose copy and string replacement utilities.
The approach is not new. Anyone involved in serious amounts of programming built their own tool set to reduce development effort and reduce costs.
The approach is the important factor. The tools are less important.
An optimum approach must avoid "lock-in". It must allow for easy migration to better and more capable tools. The key editable elements should be held as text files. These are the easiest to transform into the format for the current generation of tools.