freemarker.template.expression
Class DynamicKeyName

java.lang.Object
  |
  +--freemarker.template.expression.DynamicKeyName
All Implemented Interfaces:
Expression, ExpressionElement, Operator, java.io.Serializable, Unary, Variable

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

A unary operator that uses the string value of an expression as a hash key. It associates with other Variable expressions to its left.

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

Fields inherited from interface freemarker.template.expression.Unary
POSTFIX, PREFIX
 
Constructor Summary
DynamicKeyName(Expression key)
          Constructor that takes an Expression used to evaluate the key name at run time.
 
Method Summary
 boolean equals(java.lang.Object o)
          Determines whether this object is equal to the given object.
 int getAssociationType()
          Retrieve the operator association for this operator.
 TemplateModel getAsTemplateModel(TemplateModelRoot modelRoot)
          Sets the target of this DynamicKeyName operator.
 java.lang.String getName(TemplateModelRoot modelRoot)
          Retrieve the name of this portion of the variable.
 int getOperatorClass()
          Return the type of operator this is to the caller.
 int getType()
          Determine the type of result that can be calculated by this expression.
 int hashCode()
          Returns the hash code for this operator.
 boolean isComplete()
          Are both the key name and target specified?
 void setTarget(Expression target)
          Sets the target of the dynamic key.
 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

DynamicKeyName

public DynamicKeyName(Expression key)
Constructor that takes an Expression used to evaluate the key name at run time.
Parameters:
key - the expression to be used to evaluate the key name
Throws:
NullPointerException - the key expression was null
java.lang.IllegalArgumentException - the key could not be evaluated as a number or a String
Method Detail

setTarget

public void setTarget(Expression target)
Sets the target of the dynamic key.
Specified by:
setTarget in interface Unary
Parameters:
target - the target of the dynamic key
Throws:
java.lang.IllegalArgumentException - the expression was not suitable for a dynamic key name evaluation

isComplete

public boolean isComplete()
Are both the key name and target specified?
Specified by:
isComplete in interface Expression
Returns:
true if both target and key name are specified, otherwise false

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

getAssociationType

public int getAssociationType()
Retrieve the operator association for this operator.
Specified by:
getAssociationType in interface Unary
Returns:
POSTFIX.

getAsTemplateModel

public TemplateModel getAsTemplateModel(TemplateModelRoot modelRoot)
                                 throws TemplateException
Sets the target of this DynamicKeyName operator.
Specified by:
getAsTemplateModel in interface Expression
Throws:
TemplateException - the target is of the wrong type for this operator.

getName

public java.lang.String getName(TemplateModelRoot modelRoot)
                         throws TemplateException
Retrieve the name of this portion of the variable.
Specified by:
getName in interface Variable
Parameters:
modelRoot - the model to be used in cases where the variable is the result of an Expression.
Throws:
TemplateException - the name could not be determined

getOperatorClass

public int getOperatorClass()
Return the type of operator this is to the caller. Used for associating operators according to precedence.
Specified by:
getOperatorClass in interface Operator
Returns:
an integer indicating the type of operator this is

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