freemarker.template.expression
Class Constant

java.lang.Object
  extended by freemarker.template.expression.Constant
All Implemented Interfaces:
Expression, java.io.Serializable

public final 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 1101 2013-04-01 04:17:32Z run2000 $
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(TemplateWriteableHashModel modelRoot)
          The TemplateModel value of this constant Expression.
 java.util.Set<ExpressionUtils.ExpressionType> 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?
 boolean isConstant()
          Determine whether result calculated by this expression is a constant value.
 Expression resolveExpression()
          Resolves the current expression, possibly into a different expression object.
 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:
java.lang.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 java.util.Set<ExpressionUtils.ExpressionType> 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

isConstant

public boolean isConstant()
Determine whether result calculated by this expression is a constant value.

Specified by:
isConstant in interface Expression

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateWriteableHashModel 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

resolveExpression

public Expression resolveExpression()
Resolves the current expression, possibly into a different expression object. This is loosely equivalent to the serialization protocol's readResolve method. Situations where this may be used are:

Specified by:
resolveExpression in interface Expression