freemarker.template.expression
Class Identifier

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

public final class Identifier
extends java.lang.Object
implements Variable, java.io.Serializable

An identifer in a variable. Can be used stand-alone to represent a variable in the root model, or combined with the Dot operator to represent models contained within hash models.

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

Constructor Summary
Identifier(java.lang.String name)
          Constructs a new Identifier with the given name.
 
Method Summary
 boolean equals(java.lang.Object o)
          Tests the equality of two Identifiers.
 TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
          Gets the identifier's referent in modelRoot.
 java.lang.String getName()
          Retrieve the name of the identifier.
 java.lang.String getName(TemplateWriteableHashModel modelRoot)
          Retrieve the name of this Identifier.
 java.util.Set<ExpressionUtils.ExpressionType> getType()
          Determine the type of result that can be calculated by this expression.
 int hashCode()
          Returns a hash code value for the Identifier.
 boolean isComplete()
          Has the identifier's name been assigned?
 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.
 void setTemplateModel(TemplateWriteableHashModel modelRoot, TemplateModel value)
          Sets the identifier's referent in modelRoot.
 java.lang.String toString()
          Returns the name of the identifier as a String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Identifier

public Identifier(java.lang.String name)
Constructs a new Identifier with the given name.

Parameters:
name - the name of the identifier
Method Detail

getName

public java.lang.String getName()
Retrieve the name of the identifier.

Returns:
the name of the identifier

getName

public java.lang.String getName(TemplateWriteableHashModel modelRoot)
Retrieve the name of this Identifier.

Specified by:
getName in interface Variable
Parameters:
modelRoot - the TemplateModelRoot used to evaluate the name of the identifier
Returns:
the name of the identifier

isComplete

public boolean isComplete()
Has the identifier's name been assigned?

Specified by:
isComplete in interface Expression
Returns:
true if the identifier is named, 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

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateWriteableHashModel modelRoot)
                                 throws TemplateException
Gets the identifier's referent in modelRoot.

Specified by:
getAsTemplateModel in interface Expression
Parameters:
modelRoot - the root node of the data model.
Returns:
the TemplateModel that the variable refers to.
Throws:
TemplateException - the expression could not be evaluated for some reason

setTemplateModel

public void setTemplateModel(TemplateWriteableHashModel modelRoot,
                             TemplateModel value)
                      throws TemplateException
Sets the identifier's referent in modelRoot.

Specified by:
setTemplateModel in interface Variable
Parameters:
modelRoot - the root node of the data model.
value - the TemplateModel that the identifier will be set to
Throws:
TemplateException - the value could not be assigned to the model

toString

public java.lang.String toString()
Returns the name of the identifier as a String.

Overrides:
toString in class java.lang.Object
Returns:
the name of the identifier.

equals

public boolean equals(java.lang.Object o)
Tests the equality of two Identifiers.

Overrides:
equals in class java.lang.Object
Returns:
true if the identifiers are equal, otherwise false

hashCode

public int hashCode()
Returns a hash code value for the Identifier.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this Identifier.

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