Transformer (add-on)

From JRapid

(Redirected from Transformer)
Jump to: navigation, search

JRapid's code generator works by applying a series of XSL transformations over the AML definition that it receives as input. These transformations produce the Java classes, HTML front end, and other parts of the user interface.

Any developer can extend the code generator by defining new transformations to apply on elements of the application's XML definition. The transformations define on which element or elements they should be applied, what the content of the output should be, and where this output should be stored, such as file name and location.

For example, a transformer could be used for generating UML diagrams, JUnit classes, HTML help files among many possibilities.

There are two kinds of transformers: all entities and single entity transformers. A UML diagram transformer would probably create a single file containing a class diagram with all the entities of the application. A JUnit class transformer would create a single JUnit test for each entity, and place them in the java sources folder of the web application.


How to import a Transformer

The process of importing a transformer to your project is very straightforward.

1. Go to Add-ons menu and select the Import Transformer option.

Import transformer

2. A new window displaying the available transformers will be opened. Scroll to the desired transformer. When you drag your mouse over each item, the Learn More and Import options are shown. Make sure you read the Learn More info before importing a transformer as it may describe requirements for it to work. Click Import when you are ready to add the transformer to your project.


How to use a Transformer

As mentioned above, transformers operate on certain elements of your application's definition. Make sure you read the transformer's documentation and learn what elements it expects to find in order to apply a transformation.

Creating Transformers

Create transformer

name of the transformer.
Generation path
location where the output file will be saved. Note the use of the ${module} variable, that holds the value of the current application module, generally "Main".
name of the file where the output of the transformation will be saved. The variable ${name} can be used. This holds the value of the name attribute of the element on which the template is applied.
Run for each entity
if true, this parameters makes the engine run the transformation for every entity in the XML source code.
Regenerate every time
if true, the transformation is run with every full generation (this should remain true during development).
Xpath expression to select the target elements for this transformation.

Transformers are defined through an XSL template and there is a single call for the source XML for single entities. In case of creating a for-each-entity transformer, it will be called N times, receiving the current entity as another parameter.

An easy way of getting started is to have a look at the sample transformers in JRapid community site.

See Also

Personal tools