Home | Docs | Download | SourceForge.net Logo
-> introduction | wizard | actions | ant | templates Rate this resource

Introduction

Simteec is a small Eclipse plugin for easy code generation. It it based upon the velocity template engine.
Code is generated by specifying a template- and a properties-file, which is needed to define the variables for the template . A picture should bring a little light into this mechanism:

Or in detail:

Template File

Template Syntax

To get an overview about the features of the template language, i advise you to have a look at the examples included in the plugin-folder or read the excelent velociy users manual.

Property File

In the properties file you can specify a set of system properties that tell the engine what files to generate and what templates to use. Each properties file can have one output target and one template. The properties file can also specify other properties files that have their output targets and templates. This way one can build a generation hierarchy that can be executed by selecting its root properties file.

Each properties file can also define a set of user properties that are used in the templates. The properties of a parent properties file are passed on to its children (branches). The properties of parent files have precedence over the properties of their children.

Properties Syntax

The syntax is very simple and limited, but powerful. There are three types of variable:
It is also possible to specify comment by using '#'. The syntax is really pretty simple and can be easily understood by having a look at the examples included in the downloadable zip-file or at the sample project simteecExamples.zip . The examples have been extended, to show some of the new functionalities.

Comment handling has been improved and it is now possible to have empty lines without any problems. It is also possible to put comments in all places (e.g. at the end of each line in a map declaration)

A very nice feature is the new possibility to use user defined template variables inside simteec variables. You can use them by surrounding them with ${ and }. Have a look at the file2.prop at the bottom of this page.

Path Properties

The path properties can have a very flexible syntax. The paths can be absolute, relative to the Eclipse Workspace, relative to the project or relative to their properties file. Here are some examples:

C:\projects\simteec\templates\TypesafeEnum.vm
/home/user/projects/templates/template.vm

PROJECT:/spec/person.prop

WORKSPACE:/templates/model/model.vm

override.prop
src/com/company/hr/Person.java

simteec_template

simteec_template = "PROJECT:/template/mybean.vm";
	
The "simteec_template" property specifies the Velocity template (.vm file). This is a path property (see Path Properties).

simteec_output

simteec_output = "${output}/outputfile.txt";
	
The "simteec_output" property specifies the output file path (see Path Properties).

simteec_overwrite

simteec_overwrite = "true";
	
The "simteec_overwrite" property defines what to do if the file specified by "simteec_output" already exists. If the property is not specified the engine will ask the user whether to overwrite the file or not. If the property is defined and its value is "true" it will overwrite the file without asking the user. In any other case it will skip the file without writing. The property is passed on to the branches, so be careful when you specify simteec_overwrite="true" in the base of the generation hierarchy – you may end up deleting modifications that you made to the generated files. One good policy that is used in Apache Torque for class generation is to generate two classes – one called Base${Class}.java and the other ${Class}.java. The Base- class will contain all the generated logic, the second class will inherit the base and you will make modifications only to the second. You should set simteec_overwrite="true" for the Base- class generator and simteec_overwrite="false" for the second class.

simteec_branches

simteec_branch = @(
	"propertyfile1.prop",
	"propertyfile2.prop"
	);
	
The "simteec_branches" property defines what additional property files the current generator must run. The property can be either a one value property, like:
simteec_branches="next.prop";
or it can specify a list of values, like:
simteec_branches=@("next_one.prop", "next_two.prop", "WORKSPACE:/generators/global.prop");
Each value must be a path to a Simteec generator properties file.

simteec_classes

simteec_classes = %(
	"myClass" => "my.package.MyHelper",
	"myEmptyArrayList" => "java.lang.ArrayList",
	);
);
	
This is a new feature, which allows you to put classes from the current project into the velocity context. The property is a map and should be defined in the following way: simteec_utils=%("strUtil"=>"org.apache.lang.StringUtils", "myUtil"=>"com.company.util.MyUtil");
I would like to emphesis this new feature, because it opens up quite a lot of new possibilities! More information will follow! For now, you should know, that all classes, which you want to use in the velocity context, must have an empty constructor!!

simteec_velocity

simteec_velocity = (
	"COUNTER_NAME" => "myCounter",
	"FILE_RESOURCE_LOADER_PATH" => "c:/test" );
	
A map variable, where the user can specify runtime properties, which will be passed to the velocity engine. For a detailed description of all possible keys have a look here: http://jakarta.apache.org/velocity/api/org/apache/velocity/runtime/RuntimeConstants.html

Example

file1.prop :
# ---------------------
# simteec configuration
# ---------------------

# template which will be used for all branches
simteec_template="PROJECT:/templates/simteecWeb.vm";

# overwrite all generated output file if they exist
simteec_overwrite="true";

# other property files , for which the generater will be started
simteec_branches=@(
    "ant.prop");

# ------------------
# template variables
# ------------------

# just a simple string variable which will be available in all property file branches
name = "this is a name";

# another simple variable
output_path = "PROJECT:/simteecWebsite/output";


file2.prop :
# ---------------------
# simteec configuration
# ---------------------

# the name and path of the output file which should be generated
simteec_output="${output_path}/ant.html";

# ------------------
# template variables
# ------------------

# simple string variable
title = "Ant";

# another simple string variable
content = "
 here is some
 text
";

# a array variable
array = @(
	"value1",
	"value2" );

# a map variable
map = %(
	"key"  => "value",
	"key2" => "value2" );

Velocity Context

By default the velocity context will contain all the properties from the specified properties file. But there are also some special objects inside the context These are:

ctx

contains the current velocity context (usefull for the velocity RenderTool).

velocityTools

contains all the generic tools provided by the velocity tools subgroup. The tools can be accessed in the templates using:
  $velocityTools.DateTool,
  $velocityTools.MathTool,
  $velocityTools.IteratorTool or
  $velocityTools.RenderTool.
Details about the provided methods of these tools can be found on the velocity generic tools page: http://jakarta.apache.org/velocity/tools/generic/


This product includes software developed by the Apache Software Foundation (http://www.apache.org).
These page was generated using SIMTEEC on Tue Apr 06 19:39:53 CEST 2004.