A block of code in a template that can be passed as a substitution to
another template or to a function, must implement this interface. A
function that defines its last parameter as a Substitution can receive
a block of code from a template. To execute it, call substitute.
Substitution blocks can contain internal state information which may change
when the called function returns. Therefore, Substitution objects should
never be saved unless explicitly detached.
Functions that accept a Substitution appear to extend the template language
itself. Condsider the following example, which implements a simple looping
function:
public void loop(int count, Substitution s) throws Exception {
while (--count >= 0) {
s.substitute();
}
}
The template might invoke this function as:
loop (100) {
"This message is printed 100 times\n"
}
author: Brian S O'Neill version: 15 , 01/05/03 |