|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Substitution
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"
}
| Method Summary | |
|---|---|
Substitution |
detach()
Returns a detached substitution that can be saved and re-used. |
Object |
getIdentifier()
Returns an object that uniquely identifies this substitution block. |
void |
substitute()
Causes the code substitution block to execute against its current output receiver. |
void |
substitute(Context context)
Causes the code substitution block to execute against any context. |
| Method Detail |
|---|
void substitute()
throws Exception
UnsupportedOperationException - if this Substitution was detached.
Exception
void substitute(Context context)
throws Exception
ClassCastException - if context is incompatible with this
substitution.
ExceptionObject getIdentifier()
Substitution detach()
When calling substitute, a context must be provided or else an UnsupportedOperationException is thrown. In order for multiple threads to safely execute this substitution, each must have its own detached instance.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||