|
|
|
The Model-Driven System Builder
|
|
JeeWiz Architect's Guide
|
|
|
|
Contents >
2. Overview
|
|
|
2.6 Velocity
Velocity is the templating engine used by JeeWiz to create text artifacts.
Many code generators and UML tools use Velocity for the same purpose.
JeeWiz uses version 1.2 of Velocity.
If you are not familiar with Velocity, see the User's Guide, which is part of an extract of the Velocity documentation included within JeeWiz.
Velocity combines text substitution with the ability to express logic -
set Velocity variables, conditionals, iterate through lists, and reuse code by inclusion or as macros.
The following sections describe additional features built into Velocity renderings to support JeeWiz generation.
2.6.1 The jwVelocity Task
|
To invoke Velocity to create an output file, JeeWiz provides the <jwVelocity> task.
The essentials of this are the two attributes:
- template - the name of the file containing the template script for Velocity
- file - the location of the output file
This is used in the 'build.xml' Ant script to build a model object.
JeeWiz constructs a context for the model object, invokes Velocity passing it the template and then writes the output to the file.
The template is normally a relative path, and as such is looked up using the rendering inheritance techniques - see
Searching For Files
2.6.2 Setting Values Into Model Objects
|
The #set command of Velocity normally sets local variables.
However, in this format
#set( $object.property = "value" )
|
where there is an object with a property available,
Velocity tries to access a setter ('public void setX(...)') method on the object and if present,
uses that to set the value into the object.
JeeWiz extends this to use the extra properties mechanism
if the object is a JeeWiz model object.
The normal setter approach is tried first; if no suitable setter method exists on the class,
then the value is set into the object's properties HashMap.
This makes the value available for later renderings.
2.6.3 Not Updating Files
|
JeeWiz is sometimes used in large builds, where little changes from one build to the next.
To support tools that check whether products need to be built before proceeding,
JeeWiz filters the output of Velocity renderings before they are written to a file.
If there is no change, the file is not written.
Examples of situations where this this speeds up builds are
- compiles - most compilers use dependency checks
- Ant builds, if they use the 'uptodate' mechanism.
2.6.4 Methods
|
JeeWiz supports methods, on a per-object and per-file basis.
For example, a method can be declared by
#method( methodName $param1 $param2 )
|
JeeWiz also introduces a #return() construct to return from a method, with or without a value.
Per-object methods can introduced by higher-level meta-models to add or override functionality of lower-leve meta-models.
2.6.5 Recursive Macros
|
The version of Velocity used by JeeWiz (Velocity 1.2) does not allow recursive macros.
JeeWiz has enhanced Velocity to allow them.
2.6.6 Tracing source files
|
It is sometimes difficult to determine where a particular piece of rendered text.
JeeWiz provides a feature that will add comments to generated XML and Java files
to document the start and end of the Velocity rendering of an input file.
This is invoked by the traceTemplates
or trace build properties.
Copyright (c) 2001-2008 New Technology/enterprise Ltd.
| |