freemarker.template.instruction
Class IfElseInstruction

java.lang.Object
  |
  +--freemarker.template.instruction.IfElseInstruction
All Implemented Interfaces:
Instruction, java.io.Serializable, TemplateProcessor

public final class IfElseInstruction
extends java.lang.Object
implements Instruction, TemplateProcessor, java.io.Serializable

A instruction that handles if-elseif-else functionality. The initial "if" clause is held in a single variable. If any else or elseif clauses are encountered, they are stored in a List of IfInstructions. The List is not constructed until the first else or elseif is encountered.

Version:
$Id: IfElseInstruction.java,v 1.26 2003/11/27 11:36:45 run2000 Exp $
Author:
Jonathan Revusky
See Also:
Serialized Form

Fields inherited from interface freemarker.template.instruction.Instruction
BREAK, CASE, COMMENT_END, COMPRESS_END, DEFAULT, ELSE, ELSEIF, FOREACH_END, FUNCTION_END, IF_END, LIST_END, NONE, NOPARSE_END, SWITCH_END, TRANSFORM_END
 
Constructor Summary
IfElseInstruction(Expression condition)
          Constructs a new if/else instruction without the first block.
 
Method Summary
 void addTest(ElseInstruction instruction)
          Adds a new test to the if/else instruction.
 TemplateProcessor callBuilder(TemplateBuilder builder)
          A TemplateBuilder can call this method to have an Instruction call it back to be built.
 int getEndType()
          Determine what type of end instruction this is, if any.
 boolean isEndInstruction()
          Is this an end instruction?
 void process(TemplateModelRoot modelRoot, java.io.Writer out, TemplateRuntimeHandler eventHandler)
          Evaluate the <if ...
 void setIfBlock(TemplateProcessor block)
          Adds the main block to the first "if" statement.
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfElseInstruction

public IfElseInstruction(Expression condition)
Constructs a new if/else instruction without the first block.
Parameters:
condition - the condition for the first if
Throws:
NullPointerException - condition is null
Method Detail

setIfBlock

public void setIfBlock(TemplateProcessor block)
Adds the main block to the first "if" statement. For if/else, this is a special case.
Parameters:
block - the block to be processed if the first "if" statement is true

addTest

public void addTest(ElseInstruction instruction)
Adds a new test to the if/else instruction. Each test is evaluated in the order they are added using this method.
Parameters:
instruction - the "if" instruction to be evaluated and executed
Throws:
NullPointerException - instruction is null

isEndInstruction

public boolean isEndInstruction()
Is this an end instruction?
Specified by:
isEndInstruction in interface Instruction
Returns:
false, indicating that this is not an end instruction

getEndType

public int getEndType()
Determine what type of end instruction this is, if any.
Specified by:
getEndType in interface Instruction
Returns:
NONE, indicating that this is not an end instruction

callBuilder

public TemplateProcessor callBuilder(TemplateBuilder builder)
                              throws ParseException
A TemplateBuilder can call this method to have an Instruction call it back to be built. This implementation throws an UnsupportedOperationException indicating that this is not yet production code.
Specified by:
callBuilder in interface Instruction
Parameters:
builder - the builder to be called back by this method

process

public void process(TemplateModelRoot modelRoot,
                    java.io.Writer out,
                    TemplateRuntimeHandler eventHandler)
             throws java.io.IOException
Evaluate the <if ... > instruction.
Specified by:
process in interface TemplateProcessor
Parameters:
modelRoot - the root node of the data model.
out - a Writer to send the output to.
eventHandler - a TemplateEventAdapter for handling any events that occur during processing.

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
a String representing this instruction subtree