org.apache.velocity.runtime.parser.node

Class ASTReference

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,v 1.49.4.1 2004/03/03 23:22:59 geirm Exp $
Authors:
Jason van Zyl
Geir Magnusson Jr.
Christoph Reck

Field Summary

private static int
FORMAL_REFERENCE
private static int
NORMAL_REFERENCE
private static int
QUIET_REFERENCE
private static int
RUNT
private boolean
computableReference
private String
escPrefix
private boolean
escaped
private String
identifier
private String
literal
private String
morePrefix
private String
nullString
private int
numChildren
private int
referenceType
private String
rootString
protected Info
uberInfo

Fields inherited from class org.apache.velocity.runtime.parser.node.SimpleNode

children, first, id, info, invalid, last, parent, parser, rsvc, state

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
private String
getRoot()
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)
Accept the visitor.
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, evaluate, execute, getColumn, getFirstToken, getInfo, getLastToken, getLine, getType, init, isInvalid, jjtAccept, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, literal, render, setFirstToken, setInfo, setInvalid, toString, value

Field Details

FORMAL_REFERENCE

private static final int FORMAL_REFERENCE
Field Value:
2

NORMAL_REFERENCE

private static final int NORMAL_REFERENCE
Field Value:
1

QUIET_REFERENCE

private static final int QUIET_REFERENCE
Field Value:
3

RUNT

private static final int RUNT
Field Value:
4

computableReference

private boolean computableReference

escPrefix

private String escPrefix

escaped

private boolean escaped

identifier

private String identifier

literal

private String literal

morePrefix

private String morePrefix

nullString

private String nullString

numChildren

private int numChildren

referenceType

private int referenceType

rootString

private String rootString

uberInfo

protected Info uberInfo

Constructor Details

ASTReference

public ASTReference(int id)

ASTReference

public ASTReference(Parser p,
                    int id)

Method Details

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 interface SimpleNode
Parameters:
context - context to compute value with

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 interface SimpleNode
Parameters:
o - unused Object parameter
context - context used to generate value

getRoot

private String getRoot()

getRootString

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

getVariableValue

public Object getVariableValue(Context context,
                               String variable)

init

public Object init(InternalContextAdapter context,
                   Object data)
            throws Exception
Specified by:
init in interface Node
Overrides:
init in interface SimpleNode

jjtAccept

public Object jjtAccept(ParserVisitor visitor,
                        Object data)
Accept the visitor. *
Specified by:
jjtAccept in interface Node
Overrides:
jjtAccept in interface SimpleNode

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 interface SimpleNode

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 interface SimpleNode
Parameters:
context - context of data to use in getting value
writer - writer to render to

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

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

value

public Object value(InternalContextAdapter context)
            throws MethodInvocationException
Specified by:
value in interface Node
Overrides:
value in interface SimpleNode

Copyright B) 2002 Apache Software Foundation. All Rights Reserved.