Transformation Properties

Transformation Properties represent a set of properties which can be accessed from within your templates. This enables you to add some flexibility to your templates, as you can change the result of the generation without changing the templates themselves.

This text refers to a sample which is included in the iQgen installation. The templates are in the directory samples/getting_started/properties_sample/templates. It will generate a HTML report on any model. You can use for instance the model of Tutorial 1.

Setting Transformation Properties

To use Transformation Properties from the GUI just create a properties file and place it into the project directory of the transformation you want to use. When the transformation is opened this file will appear in the Transformation Properties combo box in the GUI. Just select it and the properties are available in the templates.

In order to use Transformation Properties on the command line set the -transformationProperties option.

Example:

iqgen.bat "-transform=tutorial_1 -nobackup -transformationProperties=transformation.properties"

In Ant use the transformationProperties attribute of the Generate Task.

Retrieving Transformation Properties

If Transformation Properties are set they will be loaded when generation has started. They can be accessed in the templates via methods of the iQgen JSP base class, i.e. any iQgen JSP.

Table 2.3. Methods for accessing Transformation Properties

MethodDescription
public final String getProperty(String pKey)Returns a property with the given key pKey
public final String getProperty(String pKey, String pDefault)Returns a property with the given key pKey if defined, default pDefault otherwise
public final Properties getProperties()Returns the whole set of Transformation Properties
For more detail please see the Javadoc of iQgen.

Manipulating Transformation Properties

It is also possible to add new properties to the Transformation Properties or to change the value of an existing property. The following methods can be used:

Table 2.4. Methods for manipulating Transformation Properties

MethodDescription
public final void setProperty(String pKey, String pValue)Sets a property with given key and value
public final void setProperties(Properties pProps)Replaces Transformation Properties with pProps
public final void addProperties(Properties pProps)Adds the given properties to the Transformation Properties

Transformation Properties in Action

The following example is a set of templates which generate an HTML report for a model. A Transformation Property (sort) is used to decide whether the lists of classes, attributes or methods will be sorted:

[...]
<TABLE cellpadding="3" cellspacing="3" border="1">
   <TR bgcolor="#98AEB7" align="center">
      <TD>Class Name</TD>
   </TR>
<% List list = new ArrayList(getAttributeList("CLASS_KEY")); %>
<iqgen:if expr="<%=\"true\".equals(getProperty(\"sort\"))%>">
   <% Collections.sort(list, myComparatorInstance); %>
</iqgen:if>
<iqgen:foreach group="<%=list%>" item="item" type="ru.novosoft.uml.MBase">
   <TR bgcolor="#FFFFFF" align="right">
      <TD>
         <a href="<%=getMetaModel().getPath(item)%>/<%=getMetaModel().getName(item)%>.html">
            <%=getMetaModel().getName(item)%>
         </a>
      </TD>
   </TR>
</iqgen:foreach>
</TABLE>
[...] 
To sort the lists all you need is the following property file:
 sort=true