freemarker.template.expression
Class ListLiteral

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

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

Represents a literal List model in a FM-Classic template. The list model is not evaluated until run time, since the model may contain variables or other more complex expressions that can't be determined at compile time.

Version:
$Id: ListLiteral.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
Serialized Form

Constructor Summary
ListLiteral(java.util.List<Expression> values)
          Constructor that takes a list of Expression elements to be evaluated as a list model at run time.
 
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 Expression.
 java.util.List<TemplateModel> getModelList(TemplateWriteableHashModel modelRoot)
          For the benefit of method calls, return the list of arguments as a list of TemplateModel values.
 java.util.Set<ExpressionUtils.ExpressionType> getType()
          Determine the type of result that can be calculated by this expression.
 java.util.List<java.lang.String> getValueList(TemplateWriteableHashModel modelRoot)
          For the benefit of method calls, return the list of arguments as a list of String values.
 int hashCode()
          Returns the hash code for this operator.
 boolean isComplete()
          Has the ListLiteral been populated?
 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

ListLiteral

public ListLiteral(java.util.List<Expression> values)
Constructor that takes a list of Expression elements to be evaluated as a list model at run time.

Parameters:
values - the values to be added to the ListLiteral
Throws:
java.lang.NullPointerException - the value list is null
Method Detail

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
                                 throws TemplateException
The TemplateModel value of this Expression.

Specified by:
getAsTemplateModel in interface Expression
Parameters:
modelRoot - the template model that will be evaluated by the expression
Returns:
a FastList containing the values in the list model
Throws:
TemplateException - the expression could not be evaluated for some reason

getModelList

public java.util.List<TemplateModel> getModelList(TemplateWriteableHashModel modelRoot)
                                           throws TemplateException
For the benefit of method calls, return the list of arguments as a list of TemplateModel values.

Parameters:
modelRoot - the template model that will be evaluated by the expression
Returns:
a List of TemplateModels contained in the ListLiteral
Throws:
TemplateException - the literal list could not be returned

getValueList

public java.util.List<java.lang.String> getValueList(TemplateWriteableHashModel modelRoot)
                                              throws TemplateException
For the benefit of method calls, return the list of arguments as a list of String values.

Parameters:
modelRoot - the template model that will be evaluated by the expression
Returns:
a List of Strings contained in the ListLiteral
Throws:
TemplateException - the literal list could not be returned

isComplete

public boolean isComplete()
Has the ListLiteral been populated?

Specified by:
isComplete in interface Expression
Returns:
true if the ListLiteral is populated, otherwise false

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

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 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 operator.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of this object

resolveExpression

public Expression resolveExpression()
                             throws TemplateException
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
Throws:
TemplateException