freemarker.template.instruction
Class FunctionInstruction

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

public final class FunctionInstruction
extends GenericStartInstruction
implements java.io.Serializable

An instruction representing a function definition. Function calls are represented by the CallInstruction class.

Unlike other instructions, FunctionInstruction is not added directly to the TemplateProcessor chain. Instead, instances are added directly to the template using the FunctionTemplateProcessor.addFunction(freemarker.template.instruction.FunctionInstruction) method. At run time, these functions can be added to the data model for speedy lookup.

At compile time, instances of FunctionInstruction are replaced by NOOPInstruction, so that the TemplateProcessor tree doesn't have to deal with null values.

Version:
$Id: FunctionInstruction.java,v 1.25 2003/11/27 11:36:45 run2000 Exp $
See Also:
Serialized Form

Fields inherited from class freemarker.template.instruction.GenericStartInstruction
body
 
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
FunctionInstruction(Identifier name, java.util.List arguments)
          Constructor for a function definition.
 
Method Summary
 TemplateProcessor callBuilder(TemplateBuilder builder)
          Call the TemplateBuilder with this comment instruction.
 java.util.List getArgumentNames()
          Retrieve a list of argument names.
 java.lang.String getName()
          Retrieve the function name.
 void process(TemplateModelRoot modelRoot, java.io.Writer out, TemplateRuntimeHandler eventHandler)
          Processes the contents of this <function ...
 boolean testEndInstruction(Instruction endInstruction)
          Is this the right kind of instruction for the given EndInstruction?
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class freemarker.template.instruction.GenericStartInstruction
getEndType, isEndInstruction, setBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FunctionInstruction

public FunctionInstruction(Identifier name,
                           java.util.List arguments)
Constructor for a function definition.
Parameters:
name - the name of the function
arguments - a List of Identifiers containing the names of each of the arguments
Throws:
NullPointerException - the name or argument list is null
Method Detail

getName

public java.lang.String getName()
Retrieve the function name.
Returns:
the name of the function as a String

getArgumentNames

public java.util.List getArgumentNames()
Retrieve a list of argument names.
Returns:
a List of Identifiers representing the argument names

testEndInstruction

public boolean testEndInstruction(Instruction endInstruction)
Is this the right kind of instruction for the given EndInstruction?
Parameters:
endInstruction - the end instruction we're testing
Returns:
true if the EndInstruction is a function end instruction, otherwise false

callBuilder

public TemplateProcessor callBuilder(TemplateBuilder builder)
                              throws ParseException
Call the TemplateBuilder with this comment instruction.
Overrides:
callBuilder in class GenericStartInstruction
Parameters:
builder - the TemplateBuilder to be called back

process

public void process(TemplateModelRoot modelRoot,
                    java.io.Writer out,
                    TemplateRuntimeHandler eventHandler)
             throws java.io.IOException
Processes the contents of this <function ... > and outputs the resulting text to a Writer.
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