How to write Templates
The template defines how the source file will look like. It always helps if you have a complete example to start with.
Load your class in the template editor, then try to figure out how many things you can define before the source
file is created.
Templates use tags. All the tags work beautifully together to generate code for you.
There are three types of tags:
Project-scoped tags defined in the project configuration file and saved in the Project configuration file,
Bean Type specific tags defined in the Bean Type configuration screens and saved in the Bean Type XML descriptors,
Class-scoped tags defined in the Bean Properties tab.
There is no real distinction between the above types of tags; you can use all tags anywhere
in templates, in bean type definitions as part of file names etc. The only
tags that are somehow restricted are the obvious
$Property$ tags which have to be used
$doproperty$...$loop$ loop in order to be within
the context of a property.
BeanMaker's code generation engine is simple, yet powerfull. It uses a set of "standard" tags and a set of
user-defined "additional" tags. BeanMaker supports custom defined tags too; with the help of string functions
and regular expressions you can write really powerful tags, for example a tag that replaces the dots ('.') of a
Java package's name to forward slashes ('/')
One of BeanMaker's most useful features is that you can specify a list of properties in the main Bean Definition page,
and then build repetitive template that iterate through the list of properties and generate code for each property.
The properties are defined in single lines (one line for each) and must comply with the following syntax:
property_type property_name [field_name [field_type [NOT_NULL]]]
need to be specified. Accepted property definitions are:
int intNumber // simple type-name property
String sName // simple type-name property
String productName product_name // nullable field, no field type
String productCode product_code varchar2(11) // nullable field
String customerName customer_name varchar2(40) NOT_NULL // mandatory field
As seen above, you can associate any language's code generation with database field names, types and NULLability and write
really powerful templates that can generate very useful code. For example, by using the following template definition
you can generate JDBC code for all your properties in the form:
In any case, the better your templates, the more useful code you can generate with them!
More info on the available tags can be found in these pages:
- Standard Tags
- Property Loop Tags
- Switch Tag
- Include File Tag
- Regular Expression Tag
- String Function Tags
- Numeric Function Tags