freemarker.template.expression
Class Constant

java.lang.Object
  |
  +--freemarker.template.expression.Constant
All Implemented Interfaces:
Expression, ExpressionElement, java.io.Serializable

public class Constant
extends java.lang.Object
implements Expression, java.io.Serializable

Represents a constant value within an expression. This is calculated by the ExpressionBuilder and stored within the parse tree in place of a more complex expression. The value is stored as a TemplateModel, which is returned on demand.

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

Constructor Summary
Constant(TemplateModel constantValue)
          Creates a new constant expression with the given model as its value.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines whether this object is equal to the given object.
 TemplateModel getAsTemplateModel(TemplateModelRoot modelRoot)
          The TemplateModel value of this constant Expression.
 int getType()
          Determine the type of result that can be calculated by this expression.
 int hashCode()
          Returns the hash code for this constant expression.
 boolean isComplete()
          Is the Expression complete?
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constant

public Constant(TemplateModel constantValue)
Creates a new constant expression with the given model as its value.
Parameters:
constantValue - the value to be returned when a template model is requested
Throws:
NullPointerException - the value is null
Method Detail

isComplete

public boolean isComplete()
Is the Expression complete?
Specified by:
isComplete in interface Expression
Returns:
true since the constant Expression is always complete

getType

public int getType()
Determine the type of result that can be calculated by this expression. This is in the form of an integer constant ored together from values in the ExpressionUtils class.
Specified by:
getType in interface Expression

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateModelRoot modelRoot)
                                 throws TemplateException
The TemplateModel value of this constant Expression.
Specified by:
getAsTemplateModel in interface Expression
Parameters:
modelRoot - the template model that will be evaluated by the expression
Throws:
TemplateException - the expression could not be evaluated for some reason

toString

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

equals

public boolean equals(java.lang.Object o)
Determines whether this object is equal to the given object.
Overrides:
equals in class java.lang.Object
Parameters:
o - the object to be compared with
Returns:
true if the objects are equal, otherwise false

hashCode

public int hashCode()
Returns the hash code for this constant expression.
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this object