CyLog Software Homepage BeanMaker v2.10
Copyright ©2000-2006 CyLog Software
Introduction
Quick Guide
How the engine works
Writing Templates
   Standard Tags
   Property Loop Tags
   Switch Tags
   Include File Tag
   Regular Expression Tag
   String Function Tags
   Numeric Function Tags
   
Tutorials
Registration
License Agreement

Writing Templates - Property Loop Tags

To add property values (types, names, etc.) you have to do a "property loop". Code enclosed in the property loop is going to be generated for as many times as the number of properties defined in the Properties Edit box. There are two versions of a property loop. A multi-line version ($doproperty) and an inline version ($ploop)

Multi-line loops

$doproperty$start the loop (this line is removed)
    ......the body of the loop (indentation is kept)
$loop$end the loop (this line is removed)

Since version 1.90, an extension to the property loop, allows you to start and end the loop at your preferred point. The syntax of the loop tag is:

$doproperty(a,b)$start the loop (this line is removed),
iterate from property a to b-1
    ......the body of the loop (indentation is kept)
$loop$end the loop (this line is removed)

If the starting point of the loop is 0 and the ending point of the loop is $propertycount$, the loop is equivalent to the original form. To iterate through the first 3 properties you should use a $doproperty(0,3) loop (i.e. property indexes: 0, 1, 2).

Inline loops

An inline loop is a functional expression that iterates through a number of properties and produces a string. It's syntax is as follows:

$ploop(a, b, 'separator')$ ...content... $ploop$ or
$ploop(a, b, 'separator', step, 'step_separator')$ ...content... $ploop$

The inline loop renders the content for all properties from a to b-1 and produces a concatenated string. For example, to iterate through the first 2 properties use $ploop(0, 2, '....')$ ... $ploop$. The separator parameter is appended to the content after each iteration except the last one. The $ploop$ tag content can contain inner-loop tags (like $property$), while the separator parameter cannot contain inner-loop tags.
An extended version of the $ploop$ tag accepts a step numeric parameter and a step_separator string parameter which allows you to append something to the string every step iterations. In conjuction with the %EOL% constant, this feature can produce some clever indented output. BeanMaker will indent the output of the $ploop$ tag with spaces to match the beginning of the tag on the previous line!. See examples.

Inner-loop tags (tags that work inside loops)

As mentioned in the Standard Tags page, inside the property loops you can use the following tags:

$index$, $count$, $pre$,
$propertytype$, $propertytype_rpad$
$property$, $Property$, $property_rpad$, $Property_rpad$
$fieldname$, $fieldname_rpad$, $fieldtype$, $fieldtype_rpad$,
$fieldisnull$

Hungarian notation is sometimes used to denote arguments and member variables. Some coders prefix member variables or arguments in methods with special prefixes. The following tags serve this purpose and although they can be used anywhere in the template, they are normally used inside a property loop:

$arg$prefix of method arguments (e.g., a_)
$var$prefix of member variables (e.g., m_)

Examples 1. Multi-line loop
Using a property loop to create Injectors and Selectors for Java Bean properties:

    // ---- Injectors & Selectors ---------------------------------------------
$doproperty$
    public void set$Property$ ( $propertytype$ $property$ )
    {
        this.$property$ = $property$;
    }

    public $propertytype$ get$Property$ ()
    {
        return this.$property$;
    }

$loop$

Examples 2. Multi-line loop
Using the following Bean Properties definition...

int     productId       product_id      
String  productName     product_name     
int     productTypeId   product_type_id  

...and this template...

$doproperty$
   ($index$) DB field "$fieldname$" is named "$property$" in the code
$loop$

...produces this output:

   (0) DB field "product_id" is named "productId" in the code
   (1) DB field "product_name" is named "productName" in the code
   (2) DB field "product_type_id" is named "productTypeId" in the code

Examples 3. Inline loop
Using the Bean Properties definition from example 2 and the following template...

$ploop(0, 2, '; ')$$property$="$fieldname$"$ploop$
( $ploop(0, $propertycount$, ', ')$$propertytype$ $property$$ploop$ )

...produces this output:

productId="product_id"; productName="product_name"
( int productId, String productName, int productTypeId )

Examples 3. Inline loop with step and indentation
Using the Bean Properties definition from example 2 and the following template...

final String CONSTANT = "$ploop(0, $propertycount$, ', ', 3, '"+%EOL%"')$$fieldname$$ploop$";

...produces this output:

final String CONSTANT = "product_id, product_name, product_type_id, "+
                        "parent_product_id, stitle_id, title_id, "+
                        "swsku_id, hardware_id, hwgroup_id, "+
                        "hwsku_id, sbundle_id, bundle_id";
Copyright ©2000-2006 CyLog Software    www.cylog.org