Model Driven Code Generation with Wurblets and Templates

The Model Driven Development (MDD) is based on the notion that an abstract platform independent model can be transformed into more specific models and/or directly into platform dependent source code. In this example, collaborating wurblets generate Java code for a data abstraction layer according to a data model.

The Template

Although the wurbelizer is not a template engine, templating can easily be achieved by creating a file that contains a set of wurblet anchors which will describe the generated part of the template. Most IDEs provide at least some rudimentary template support which in combination with the wurbelizer can be upgraded to a full-featured template processor. As an example, the Netbeans-template for a Tentackle Application Database Object, an AppDbObject, looks like this:
AppDbObject Template
(click on the image to view the complete code)

The Netbeans-variable __NAME__ will be replaced by the actual Java classname when the new file is created with Netbeans from a template. The Wurbelizer-variables and the model must be provided by the developer, which is shown in the next step:

From the Model to the Source

The database wurblets expect the model to be specified in two parts: one for the attribute mapping ($mapping) and the other for the relations between the database objects ($relations). It is up to the developer whether to put these specifications either in regular files or to store the model directly within the source file to be wurbelized. Knowing that the code is the truth, we prefer the latter variant.

Below is a sample class from a real project (a node of an xml-document stored in a database):
DocumentNode
(click on the image to view the complete code)

To create a new class, all we have to do is to specify the model ($mapping and $relations), a few properties like $tablename and some application specific anchors for wurblets like AppDbSelectList. All the rest is generated by the wurblets. Isn't that easy?

Notes

to the next example... >