This section gives a general overview of how Gen2J works. It describes the approach taken, the structure of the system, and the technologies used to implement it.
The most important aspect of the Gen2J approach to generating code from a UML input model (see the “Creating the UML Model” section) is this:
First generate new elements for the UML model, then generate code from those new elementsThe new classes for each layer of the generated application are added one afer another to the UML model. The classes in each layer are generated from those in the previous layer, as well as from information in the original input model. The final UML model holds a representation of the whole application, as well as the original input model. The code for each layer is generated from the UML representation of that layer. Among the advantages of this approach are:
Code generation is much easier, as the distance between the UML representation of each class and the code is much smaller. UML elements (classes, attributes, operations, etc) can be translated one-for-one into the equivalent Java language features.
It should be possible in the future to use the extended UML model for other purposes, such as generating design documentation or re-importing into a UML case tool.
The View layer is treated differently, as
there is a much greater need to customise this layer for user preferences
multiple logical views may be needed for each object
views may need to be presented in many different forms eg HTML, WML, XML
This diagram shows how the XMI file exported by the UML case tool is transformed into a J2EE application.
All of the processing steps shown above are carried out using XSLT. The Gen2J XSLT uses several extensions specific to the Saxon XSLT processor (these extensions will probably become standard in XSLT 2.0). Gen2J includes some Java framework libraries which are used by the generated code. The Ant build tool is used to tie all the system generation steps together, compile the generated code, and build the final EAR file.