How it works

Contents

Overall approach
View layer
Generation flow diagram
Technologies used

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.

Overall approach

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 elements
The 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.

View layer

The View layer is treated differently, as

  1. there is a much greater need to customise this layer for user preferences

  2. multiple logical views may be needed for each object

  3. views may need to be presented in many different forms eg HTML, WML, XML

Views are defined in a simple XML language which defines which object type the view displays, which properties of that object are included, and the manner in which the property is displayed. This language can be learned by developers much more easily than the XMI representation of UML. Gen2J uses the UML model of the Use case model layer to create default view specifications in this language. It then uses XSLT to transform the view specifications into JSP pages. Both the default views and the transformation to a particular output format can be easily overridden by the developer.

Generation flow diagram

This diagram shows how the XMI file exported by the UML case tool is transformed into a J2EE application.

Technologies used

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.