Code Generation Tutorial

Code Generation Tutorial

To run through this tutorial, you are expected to be familiar with XML and have some java. A passing acquaintance with ant and/or velocity would also be helpful.

If you haven't already, download JeeWizCE from here, otherwise you won't be able to do the tutorial exercises.

The tutorial takes you through many of the techniques of writing transforms using the JeeWiz engine. More information is available from the Architect's Guide.

The first four parts build up the nuts and bolts of a JeeWiz transform and are what you need if you are building to a single target architecture. Parts five and six look at larger scale output variations, and are what you need if you are building software factories, generating for multiple platforms or are skinning. The final part looks at integrating visual models.

The whole tutorial is quite extensive and is likely to take you several days to work through properly including the exercises.

Tutorial Contents

  • Code Generation Tutorial Part 1 - Scripting Project
    Jeewiz code generation is run as an ant project, ant being a common application assembly tool. The special ant tasks available to JeeWiz include the availability of a scripting language evolved from Velocity scripting. The first part of the tutorial, The Scripting Project, takes you through the set up of a simple JeeWiz project and the scripting language.

  • Code Generation Tutorial Part 2 - Model-driven Transformation
    The technique used in the scripting project was applied to a single specific instance, just one output file from one template, but for wider application there's a need to model which instances apply and to give details. For example we might want to produce some web pages, and we might have a template to do so, but we need to tell the generator how many pages, what is the title of each one and what the content. In part two we look at how to create and use an XML model that describes the system - the system specification.

  • Code Generation Tutorial Part 3 - Transforms using Meta-Models
    Part three introduces meta-models. JeeWiz can make use of an unknown semantic element by making certain assumptions, but it is often useful for the generator to have access to extra information and methods pertaining to, for example, screen or menu elements in general. This extra information is stored in a meta-model description of the element that might be found in the model and lets the architect provide extra facilities and validation routines.

  • Code Generation Tutorial Part 4 - Patterns
    When a specification model is read by JeeWiz it creates a java object tree in memory, the types of objects being related to the meta-model objects we saw in part three. This tree is what is used to drive the template build, creating the output artefact. Part four of the tutorial looks at patterns, which are JeeWiz's way of embellishing the object tree, adding new elements and changing others, so that the tree better reflects the required output and simplifies the templates.

  • Code Generation Tutorial Part 5 - The Stack
    To be able to vary the output for different platforms or architectures, something needed when creating software factories, or just to add a layer of superficial changes, it is possible to create a stack of code generation levels, each capable of handling all the elements we have in the previous parts of the tutorial. By including different stack levels in the build, the output generated can be tailored for particular architectures. This part of the tutorial explains how to set up such a stack and how the parts interact to generate a single system.

  • Code Generation Tutorial Part 6 - Controls
    It is possible to use extra helper objects at generate time that don't function as part of the object tree, even when they are referenced from it. This can be as simple as requesting a particular java class instance, such as a HashMap or a SAXParser; however, JeeWiz makes a special type of helper object available called a control, which lets you define properties and JeeWiz scripting methods. This tutorial shows you how and when to use controls.

  • Code Generation Tutorial Part 7 - UML and Eclipse
    Although we have written all specification in the tutorial so far as xml, and that works perfectly well, there can be good reason to model specification diagrammatically. In large companies business modellers diagram the specification anyway, as it's easier to show these to the people who have requested and will use the system for validation. So if we want to connect as directly as possible what the business wants with what we generate, it's very useful to be able to generate from the diagrams. This final part of the tutorials discusses some of the issues that follows, using the Eclipse-based Rational Software Modeller tool as an example. There is also a troubleshooting and debugging help section.