freemarker.template.instruction
Class FunctionModel

java.lang.Object
  extended by freemarker.template.instruction.FunctionModel
All Implemented Interfaces:
TemplateFunctionModel, TemplateModel, java.io.Serializable

public final class FunctionModel
extends java.lang.Object
implements TemplateFunctionModel, java.io.Serializable

An immutable TemplateModel wrapper for a FunctionInstructions. This approach allows us to add functions to the data model, while still enforcing the restriction that every element of the data model should implement the TemplateModel interface.

Notably, this class is a direct subclass of TemplateModel, rather than going through an intermediate interface.

Version:
$Id: FunctionModel.java 1107 2013-04-12 02:00:10Z run2000 $
See Also:
Serialized Form

Constructor Summary
FunctionModel(FunctionInstruction function)
          Constructor for the function model.
 
Method Summary
 void callFunction(TemplateWriteableHashModel modelRoot, java.io.Writer out, TemplateRuntimeHandler eventHandler, java.util.List<TemplateModel> argValues)
          Calls the specified FunctionInstruction.
 boolean isEmpty()
          Is the function model populated?
 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

FunctionModel

public FunctionModel(FunctionInstruction function)
Constructor for the function model.

Parameters:
function - the function to be stored in the model
Throws:
java.lang.NullPointerException - the function is null
Method Detail

isEmpty

public boolean isEmpty()
Is the function model populated?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if there is no function instruction associated with the model, otherwise false

callFunction

public void callFunction(TemplateWriteableHashModel modelRoot,
                         java.io.Writer out,
                         TemplateRuntimeHandler eventHandler,
                         java.util.List<TemplateModel> argValues)
                  throws java.io.IOException
Calls the specified FunctionInstruction.

Specified by:
callFunction in interface TemplateFunctionModel
Parameters:
modelRoot - the root of the template model
out - the output stream to send the results
eventHandler - handler for any events fired
argValues - the arguments passed to the function
Throws:
java.io.IOException - there was an IO error writing the results

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