ii. Calling the object properties, for example, $object.name.
Velocity allows you to call the referenced Java object’s method directly like you would in Java. This is very
useful as you can create methods in Java that can help you create a more flexible Velocity template. For
instance, if you need to perform a complex operation, such as sorting a list according to certain variables,
you can create a sorting method in Java, and then call that method from a Java object.
Report Wizard provides a collection of complex statements in standard tool methods. You can find more
information on the standard tool in the Helper Modules section, Report Wizard User Guide. You can also
create your own custom tool, deploy, and use it inside a template. For more information on the custom tool,
see Appendix A: Report Extensions, Report Wizard User Guide.
(ii) Velocity Directives
A Velocity directive is a keyword used by Velocity to perform certain tasks such as looping, controlling the
output of the document based on values from MagicDraw, etc. With directives you can make dynamic
templates and you can do more than just printing out MagicDraw elements and attributes. A Velocity
directive begins with # and followed by the directive name. Some of the frequently used Velocity directives
are as follows:
i) #if, #elseif, and #else: these directives are used to decide whether or not text should be
included in the output based on the conditional statement.
ii) #set: this directive is used to assign a value to a variable.
iii) #foreach: this directive is used to iterate through a list of variables.
iv) #macro: this directive is used as a means to create a reusable script. It is especially useful if you
need to call a certain line of scripts repeatedly.
#set statement
In Velocity, you can declare a variable and set its value by using the #set directive, for example:
##String
#set ($var = "abc")
##Boolean
#set($var2 = true)
##Value
#set($var3 = 10)
The above example shows that $var has a string value, $var2 has a Boolean value, and $var3 has a
numerical value. The #set directive can also set an array to a declared Velocity variable. To assign an array
to a variable type, for example:
#set($var = ["a", "b", "c"])
#if, #elseif, and #else statement
The #if directive allows you to include text when generating a document, on condition that the if-statement is
true, for example:
#if( $condition )
Hello World
#end
Copyright © 1998-2011 No Magic, Inc.