HOME
UNTERNEHMEN
LEISTUNGEN
PRODUKTE
PROJEKTE
IQGEN
NEWS
KONTAKT
iQgen News
About iQgen
Whitepaper
Prerequisites
Download
Pricing & Licence
Services
Performance
User's Guide
Getting Started
Roadmap
FAQ
Resources

Getting Started

[Previous] [Overview] [Next]

Hands on Example: Transformation Properties in iQgen

Transformation Properties represent a set of properties which can be accessed in the templates. Therefore they can be used to configure the templates. This means that a set of templates can be applied more flexible. You can change the result of generation without changing the templates.

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

Details on setting Transformation Properties are explain in the usersguide.

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

In order to use Transformation Properties on the commandline set the -transformationProperties option. Example:

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

In ANT use the transformationProperties attribute of the GenerateTask.

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.

Method Description
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:

Method Description
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.

The Example

The example is a set of templates which generate an HTML report of 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

Copyright © 2001-2003 innoQ. Alle Rechte vorbehalten. Rechtliche Hinweise