Class SimpleNode
- java.lang.Object
-
- org.apache.velocity.runtime.parser.node.SimpleNode
-
- All Implemented Interfaces:
Cloneable,Node,Renderable
- Direct Known Subclasses:
ASTAssignment,ASTBinaryOperator,ASTBlock,ASTComment,ASTDirective,ASTDirectiveAssign,ASTElseIfStatement,ASTElseStatement,ASTEscape,ASTEscapedDirective,ASTExpression,ASTFalse,ASTFloatingPointLiteral,ASTIdentifier,ASTIfStatement,ASTIncludeStatement,ASTIndex,ASTIntegerLiteral,ASTIntegerRange,ASTMap,ASTMethod,ASTNegateNode,ASTNotNode,ASTObjectArray,ASTParameters,ASTprocess,ASTReference,ASTSetDirective,ASTStringLiteral,ASTText,ASTTextblock,ASTTrue,ASTVariable,ASTWord
public class SimpleNode extends Object implements Node, Cloneable
-
-
Field Summary
Fields Modifier and Type Field Description protected Node[]childrenprotected intcolumnColumn number for this Node in the vm source file.protected Tokenfirstprotected StringfirstImageString image variable of the first Token element that was parsed and connected to this Node.protected intidprotected intinfoprotected booleaninvalidprotected Tokenlastprotected StringlastImageString image variable of the last Token element that was parsed and connected to this Node.protected intlineLine number for this Node in the vm source file.protected StringliteralFor caching the literal value.protected org.slf4j.Loggerlogprotected Nodeparentprotected Parserparserprotected RuntimeServicesrsvcbooleanstateprotected Templatetemplate
-
Constructor Summary
Constructors Constructor Description SimpleNode(int i)SimpleNode(Parser p, int i)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectchildrenAccept(StandardParserVisitor visitor, Object data)voidcleanupParserAndTokens()Removes references to Parser and Tokens since they are not needed anymore at this point.Nodeclone(Template template)Root node deep cloningprotected Nodeclone(Template template, Node parent)Child node deep cloningvoiddump(String prefix)Dumps nodes tree on System.out.voiddump(String prefix, PrintStream out)Dumps nodes tree on System.out.voiddump(String prefix, PrintWriter out)Dumps nodes tree on System.out.booleanevaluate(InternalContextAdapter context)Objectexecute(Object o, InternalContextAdapter context)intgetColumn()TokengetFirstToken()StringgetFirstTokenImage()intgetInfo()TokengetLastToken()StringgetLastTokenImage()intgetLine()protected StringgetLocation(InternalContextAdapter context)Return a string that tells the current location of this node.ParsergetParser()RuntimeServicesgetRuntimeServices()TemplategetTemplate()StringgetTemplateName()intgetType()Objectinit(InternalContextAdapter context, Object data)booleanisInvalid()ObjectjjtAccept(StandardParserVisitor visitor, Object data)voidjjtAddChild(Node n, int i)This method tells the node to add its argument to the node's list of children.voidjjtClose()This method is called after all the child nodes have been added.NodejjtGetChild(int i)This method returns a child node.intjjtGetNumChildren()Return the number of children the node has.NodejjtGetParent()voidjjtOpen()This method is called after the node has been made the current node.voidjjtSetParent(Node n)This pair of methods are used to inform the node of its parent.Stringliteral()booleanrender(InternalContextAdapter context, Writer writer)voidsaveTokenImages()Call before calling cleanupParserAndTokens() if you want to store image of the first and last token of this node.voidsetFirstToken(Token t)voidsetInfo(int info)voidsetInvalid()Mark the node as invalid.StringtoString()StringtoString(String prefix)Objectvalue(InternalContextAdapter context)
-
-
-
Field Detail
-
rsvc
protected RuntimeServices rsvc
-
log
protected org.slf4j.Logger log
-
parent
protected Node parent
-
children
protected Node[] children
-
id
protected int id
-
parser
protected Parser parser
-
info
protected int info
-
state
public boolean state
-
invalid
protected boolean invalid
-
first
protected Token first
-
last
protected Token last
-
template
protected Template template
-
literal
protected String literal
For caching the literal value.
-
line
protected int line
Line number for this Node in the vm source file.
-
column
protected int column
Column number for this Node in the vm source file.
-
firstImage
protected String firstImage
String image variable of the first Token element that was parsed and connected to this Node.
-
lastImage
protected String lastImage
String image variable of the last Token element that was parsed and connected to this Node.
-
-
Constructor Detail
-
SimpleNode
public SimpleNode(int i)
- Parameters:
i-
-
SimpleNode
public SimpleNode(Parser p, int i)
- Parameters:
p-i-
-
-
Method Detail
-
getRuntimeServices
public RuntimeServices getRuntimeServices()
-
jjtOpen
public void jjtOpen()
Description copied from interface:NodeThis method is called after the node has been made the current node. It indicates that child nodes can now be added to it.- Specified by:
jjtOpenin interfaceNode- See Also:
Node.jjtOpen()
-
jjtClose
public void jjtClose()
Description copied from interface:NodeThis method is called after all the child nodes have been added.- Specified by:
jjtClosein interfaceNode- See Also:
Node.jjtClose()
-
setFirstToken
public void setFirstToken(Token t)
- Parameters:
t-
-
getFirstToken
public Token getFirstToken()
- Specified by:
getFirstTokenin interfaceNode- Returns:
- The first token.
- See Also:
Node.getFirstToken()
-
getLastToken
public Token getLastToken()
- Specified by:
getLastTokenin interfaceNode- Returns:
- The last token.
- See Also:
Node.getLastToken()
-
jjtSetParent
public void jjtSetParent(Node n)
Description copied from interface:NodeThis pair of methods are used to inform the node of its parent.- Specified by:
jjtSetParentin interfaceNode- See Also:
Node.jjtSetParent(org.apache.velocity.runtime.parser.node.Node)
-
jjtGetParent
public Node jjtGetParent()
- Specified by:
jjtGetParentin interfaceNode- Returns:
- The node parent.
- See Also:
Node.jjtGetParent()
-
jjtAddChild
public void jjtAddChild(Node n, int i)
Description copied from interface:NodeThis method tells the node to add its argument to the node's list of children.- Specified by:
jjtAddChildin interfaceNode- See Also:
Node.jjtAddChild(org.apache.velocity.runtime.parser.node.Node, int)
-
jjtGetChild
public Node jjtGetChild(int i)
Description copied from interface:NodeThis method returns a child node. The children are numbered from zero, left to right.- Specified by:
jjtGetChildin interfaceNode- Returns:
- A child node.
- See Also:
Node.jjtGetChild(int)
-
jjtGetNumChildren
public int jjtGetNumChildren()
Description copied from interface:NodeReturn the number of children the node has.- Specified by:
jjtGetNumChildrenin interfaceNode- Returns:
- The number of children of this node.
- See Also:
Node.jjtGetNumChildren()
-
jjtAccept
public Object jjtAccept(StandardParserVisitor visitor, Object data)
- Specified by:
jjtAcceptin interfaceNode- Returns:
- The Node execution result object.
- See Also:
Node.jjtAccept(org.apache.velocity.runtime.parser.node.StandardParserVisitor, java.lang.Object)
-
childrenAccept
public Object childrenAccept(StandardParserVisitor visitor, Object data)
- Specified by:
childrenAcceptin interfaceNode- Returns:
- The node execution result.
- See Also:
Node.childrenAccept(org.apache.velocity.runtime.parser.node.StandardParserVisitor, java.lang.Object)
-
toString
public String toString(String prefix)
- Parameters:
prefix- display prefix- Returns:
- String representation of this node.
-
dump
public final void dump(String prefix)
Dumps nodes tree on System.out.
Override
dump(String, PrintWriter)if you want to customize how the node dumps out its children.- Parameters:
prefix-
-
dump
public final void dump(String prefix, PrintStream out)
Dumps nodes tree on System.out.
Override
dump(String, PrintWriter)if you want to customize how the node dumps out its children.- Parameters:
prefix- display prefixout- output print stream
-
dump
public void dump(String prefix, PrintWriter out)
Dumps nodes tree on System.out.
Override this method if you want to customize how the node dumps out its children.
- Parameters:
prefix- display prefixout- output print writer
-
getLocation
protected String getLocation(InternalContextAdapter context)
Return a string that tells the current location of this node.- Parameters:
context-- Returns:
- location
-
literal
public String literal()
- Specified by:
literalin interfaceNode- Returns:
- A literal.
- See Also:
Node.literal()
-
init
public Object init(InternalContextAdapter context, Object data) throws TemplateInitException
- Specified by:
initin interfaceNode- Returns:
- The init result.
- Throws:
TemplateInitException- See Also:
Node.init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
-
evaluate
public boolean evaluate(InternalContextAdapter context) throws MethodInvocationException
- Specified by:
evaluatein interfaceNode- Returns:
- The evaluation result.
- Throws:
MethodInvocationException- See Also:
Node.evaluate(org.apache.velocity.context.InternalContextAdapter)
-
value
public Object value(InternalContextAdapter context) throws MethodInvocationException
- Specified by:
valuein interfaceNode- Returns:
- The node value.
- Throws:
MethodInvocationException- See Also:
Node.value(org.apache.velocity.context.InternalContextAdapter)
-
render
public boolean render(InternalContextAdapter context, Writer writer) throws IOException, MethodInvocationException, ParseErrorException, ResourceNotFoundException
- Specified by:
renderin interfaceNode- Specified by:
renderin interfaceRenderable- Returns:
- True if the node rendered successfully.
- Throws:
IOExceptionMethodInvocationExceptionParseErrorExceptionResourceNotFoundException- See Also:
Node.render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer)
-
execute
public Object execute(Object o, InternalContextAdapter context) throws MethodInvocationException
- Specified by:
executein interfaceNode- Returns:
- The execution result.
- Throws:
MethodInvocationException- See Also:
Node.execute(java.lang.Object, org.apache.velocity.context.InternalContextAdapter)
-
getType
public int getType()
- Specified by:
getTypein interfaceNode- Returns:
- The NodeType.
- See Also:
Node.getType()
-
setInfo
public void setInfo(int info)
- Specified by:
setInfoin interfaceNode- See Also:
Node.setInfo(int)
-
getInfo
public int getInfo()
- Specified by:
getInfoin interfaceNode- Returns:
- The current node info.
- See Also:
Node.getInfo()
-
setInvalid
public void setInvalid()
Description copied from interface:NodeMark the node as invalid.- Specified by:
setInvalidin interfaceNode- See Also:
Node.setInvalid()
-
isInvalid
public boolean isInvalid()
- Specified by:
isInvalidin interfaceNode- Returns:
- True if the node is invalid.
- See Also:
Node.isInvalid()
-
getLine
public int getLine()
- Specified by:
getLinein interfaceNode- Returns:
- The current line position.
- See Also:
Node.getLine()
-
getColumn
public int getColumn()
- Specified by:
getColumnin interfaceNode- Returns:
- The current column position.
- See Also:
Node.getColumn()
-
getTemplateName
public String getTemplateName()
- Specified by:
getTemplateNamein interfaceNode- Returns:
- the file name of the template
-
saveTokenImages
public void saveTokenImages()
Call before calling cleanupParserAndTokens() if you want to store image of the first and last token of this node.
-
cleanupParserAndTokens
public void cleanupParserAndTokens()
Removes references to Parser and Tokens since they are not needed anymore at this point. This allows us to save memory quite a bit.
-
getFirstTokenImage
public String getFirstTokenImage()
- Specified by:
getFirstTokenImagein interfaceNode- Returns:
- String image variable of the first Token element that was parsed and connected to this Node.
-
getLastTokenImage
public String getLastTokenImage()
- Specified by:
getLastTokenImagein interfaceNode- Returns:
- String image variable of the last Token element that was parsed and connected to this Node.
-
getTemplate
public Template getTemplate()
- Specified by:
getTemplatein interfaceNode- Returns:
- the template this node belongs to
-
getParser
public Parser getParser()
-
clone
public Node clone(Template template) throws CloneNotSupportedException
Root node deep cloning- Parameters:
template- owner template- Returns:
- cloned node
- Throws:
CloneNotSupportedException- Since:
- 2.4
-
clone
protected Node clone(Template template, Node parent) throws CloneNotSupportedException
Child node deep cloning- Parameters:
template- owner templateparent- parent node- Returns:
- cloned node
- Throws:
CloneNotSupportedException- Since:
- 2.4
-
-