org.apache.velocity.runtime.parser.node
Class ASTReference

java.lang.Object
  extended by org.apache.velocity.runtime.parser.node.SimpleNode
      extended by org.apache.velocity.runtime.parser.node.ASTReference
All Implemented Interfaces:
Node

public class ASTReference
extends SimpleNode

This class is responsible for handling the references in VTL ($foo). Please look at the Parser.jjt file which is what controls the generation of this class.

Version:
$Id: ASTReference.java 720228 2008-11-24 16:58:33Z nbubna $
Author:
Jason van Zyl, Geir Magnusson Jr., Christoph Reck,
Field Summary
 boolean strictRef
          Indicates if we are running in strict reference mode.
protected  Info uberInfo
           
 
Fields inherited from class org.apache.velocity.runtime.parser.node.SimpleNode
children, first, id, info, invalid, last, log, parent, parser, rsvc, state, templateName
 
Constructor Summary
ASTReference(int id)
           
ASTReference(Parser p, int id)
           
 
Method Summary
 boolean evaluate(InternalContextAdapter context)
          Computes boolean value of this reference Returns the actual value of reference return type boolean, and 'true' if value is not null
 Object execute(Object o, InternalContextAdapter context)
          gets an Object that 'is' the value of the reference
 String getRootString()
          Returns the 'root string', the reference key
 Object getVariableValue(Context context, String variable)
           
 Object init(InternalContextAdapter context, Object data)
           
 Object jjtAccept(ParserVisitor visitor, Object data)
           
 String literal()
          Override of the SimpleNode method literal() Returns the literal representation of the node.
 boolean render(InternalContextAdapter context, Writer writer)
          gets the value of the reference and outputs it to the writer.
 void setLiteral(String literal)
          Routine to allow the literal representation to be externally overridden.
 boolean setValue(InternalContextAdapter context, Object value)
          Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()
 Object value(InternalContextAdapter context)
           
 
Methods inherited from class org.apache.velocity.runtime.parser.node.SimpleNode
childrenAccept, dump, getColumn, getFirstToken, getInfo, getLastToken, getLine, getLocation, getTemplateName, getType, isInvalid, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, setFirstToken, setInfo, setInvalid, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strictRef

public boolean strictRef
Indicates if we are running in strict reference mode.


uberInfo

protected Info uberInfo
Constructor Detail

ASTReference

public ASTReference(int id)
Parameters:
id -

ASTReference

public ASTReference(Parser p,
                    int id)
Parameters:
p -
id -
Method Detail

jjtAccept

public Object jjtAccept(ParserVisitor visitor,
                        Object data)
Specified by:
jjtAccept in interface Node
Overrides:
jjtAccept in class SimpleNode
Returns:
The Node execution result object.
See Also:
SimpleNode.jjtAccept(org.apache.velocity.runtime.parser.node.ParserVisitor, java.lang.Object)

init

public Object init(InternalContextAdapter context,
                   Object data)
            throws TemplateInitException
Specified by:
init in interface Node
Overrides:
init in class SimpleNode
Returns:
The init result.
Throws:
TemplateInitException
See Also:
SimpleNode.init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)

getRootString

public String getRootString()
Returns the 'root string', the reference key

Returns:
the root string.

execute

public Object execute(Object o,
                      InternalContextAdapter context)
               throws MethodInvocationException
gets an Object that 'is' the value of the reference

Specified by:
execute in interface Node
Overrides:
execute in class SimpleNode
Parameters:
o - unused Object parameter
context - context used to generate value
Returns:
The execution result.
Throws:
MethodInvocationException
See Also:
Node.execute(java.lang.Object, org.apache.velocity.context.InternalContextAdapter)

render

public boolean render(InternalContextAdapter context,
                      Writer writer)
               throws IOException,
                      MethodInvocationException
gets the value of the reference and outputs it to the writer.

Specified by:
render in interface Node
Overrides:
render in class SimpleNode
Parameters:
context - context of data to use in getting value
writer - writer to render to
Returns:
True if rendering was successful.
Throws:
IOException
MethodInvocationException
See Also:
Node.render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer)

evaluate

public boolean evaluate(InternalContextAdapter context)
                 throws MethodInvocationException
Computes boolean value of this reference Returns the actual value of reference return type boolean, and 'true' if value is not null

Specified by:
evaluate in interface Node
Overrides:
evaluate in class SimpleNode
Parameters:
context - context to compute value with
Returns:
True if evaluation was ok.
Throws:
MethodInvocationException
See Also:
Node.evaluate(org.apache.velocity.context.InternalContextAdapter)

value

public Object value(InternalContextAdapter context)
             throws MethodInvocationException
Specified by:
value in interface Node
Overrides:
value in class SimpleNode
Returns:
The node value.
Throws:
MethodInvocationException
See Also:
SimpleNode.value(org.apache.velocity.context.InternalContextAdapter)

setValue

public boolean setValue(InternalContextAdapter context,
                        Object value)
                 throws MethodInvocationException
Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()

Parameters:
context - context object containing this reference
value - Object to set as value
Returns:
true if successful, false otherwise
Throws:
MethodInvocationException
See Also:
ASTSetDirective

getVariableValue

public Object getVariableValue(Context context,
                               String variable)
                        throws MethodInvocationException
Parameters:
context -
variable -
Returns:
The evaluated value of the variable.
Throws:
MethodInvocationException

setLiteral

public void setLiteral(String literal)
Routine to allow the literal representation to be externally overridden. Used now in the VM system to override a reference in a VM tree with the literal of the calling arg to make it work nicely when calling arg is null. It seems a bit much, but does keep things consistant. Note, you can only set the literal once...

Parameters:
literal - String to render to when null

literal

public String literal()
Override of the SimpleNode method literal() Returns the literal representation of the node. Should be something like $.

Specified by:
literal in interface Node
Overrides:
literal in class SimpleNode
Returns:
A literal string.
See Also:
Node.literal()


Copyright © 2000-2008 The Apache Software Foundation. All Rights Reserved.