Package org.apache.velocity.runtime.parser.node

# 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[]`
`children`
`protected int`
`column`
Column number for this Node in the vm source file.
`protected Token`
`first`
`protected String`
`firstImage`
String image variable of the first Token element that was parsed and connected to this Node.
`protected int`
`id`
`protected int`
`info`
`protected boolean`
`invalid`
`protected Token`
`last`
`protected String`
`lastImage`
String image variable of the last Token element that was parsed and connected to this Node.
`protected int`
`line`
Line number for this Node in the vm source file.
`protected String`
`literal`
For caching the literal value.
`protected org.slf4j.Logger`
`log`
`protected Node`
`parent`
`protected Parser`
`parser`
`protected RuntimeServices`
`rsvc`
`boolean`
`state`
`protected Template`
`template`

## Constructor Summary

Constructors
Constructor
Description
`SimpleNode(int i)`
`SimpleNode(Parser p, int i)`

## Method Summary

Modifier and Type
Method
Description
`Object`
`childrenAccept(StandardParserVisitor visitor, Object data)`
`void`
`cleanupParserAndTokens()`
Removes references to Parser and Tokens since they are not needed anymore at this point.
`Node`
`clone(Template template)`
Root node deep cloning
`protected Node`
`clone(Template template, Node parent)`
Child node deep cloning
`final void`
`dump(String prefix)`
Dumps nodes tree on System.out.
`final void`
`dump(String prefix, PrintStream out)`
Dumps nodes tree on System.out.
`void`
`dump(String prefix, PrintWriter out)`
Dumps nodes tree on System.out.
`boolean`
`evaluate(InternalContextAdapter context)`
`Object`
`execute(Object o, InternalContextAdapter context)`
`int`
`getColumn()`
`Token`
`getFirstToken()`
`String`
`getFirstTokenImage()`
`int`
`getInfo()`
`Token`
`getLastToken()`
`String`
`getLastTokenImage()`
`int`
`getLine()`
`protected String`
`getLocation(InternalContextAdapter context)`
Return a string that tells the current location of this node.
`Parser`
`getParser()`
`RuntimeServices`
`getRuntimeServices()`
`Template`
`getTemplate()`
`String`
`getTemplateName()`
`int`
`getType()`
`Object`
`init(InternalContextAdapter context, Object data)`
`boolean`
`isInvalid()`
`Object`
`jjtAccept(StandardParserVisitor visitor, Object data)`
`void`
`jjtAddChild(Node n, int i)`
This method tells the node to add its argument to the node's list of children.
`void`
`jjtClose()`
This method is called after all the child nodes have been added.
`Node`
`jjtGetChild(int i)`
This method returns a child node.
`int`
`jjtGetNumChildren()`
Return the number of children the node has.
`Node`
`jjtGetParent()`
`void`
`jjtOpen()`
This method is called after the node has been made the current node.
`void`
`jjtSetParent(Node n)`
This pair of methods are used to inform the node of its parent.
`String`
`literal()`
`boolean`
`render(InternalContextAdapter context, Writer writer)`
`void`
`saveTokenImages()`
Call before calling cleanupParserAndTokens() if you want to store image of the first and last token of this node.
`void`
`setFirstToken(Token t)`
`void`
`setInfo(int info)`
`void`
`setInvalid()`
Mark the node as invalid.
`String`
`toString()`
`String`
`toString(String prefix)`
`Object`
`value(InternalContextAdapter context)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### 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 Details

### SimpleNode

public SimpleNode(int i)

Parameters:
  `i` -

### SimpleNode

public SimpleNode(Parser p, int i)

Parameters:
  `p` -
  `i` -

## Method Details

### getRuntimeServices

public RuntimeServices getRuntimeServices()

### jjtOpen

public void jjtOpen()
Description copied from interface: `Node`
This 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:
  `jjtOpen` in interface `Node`
See Also:
  - `Node.jjtOpen()`

### jjtClose

public void jjtClose()
Description copied from interface: `Node`
This method is called after all the child nodes have been added.

Specified by:
  `jjtClose` in interface `Node`
See Also:
  - `Node.jjtClose()`

### setFirstToken

public void setFirstToken(Token t)

Parameters:
  `t` -

### getFirstToken

public Token getFirstToken()

Specified by:
  `getFirstToken` in interface `Node`
Returns:
  The first token.
See Also:
  - `Node.getFirstToken()`

### getLastToken

public Token getLastToken()

Specified by:
  `getLastToken` in interface `Node`
Returns:
  The last token.
See Also:
  - `Node.getLastToken()`

### jjtSetParent

public void jjtSetParent(Node n)
Description copied from interface: `Node`
This pair of methods are used to inform the node of its parent.

Specified by:
  `jjtSetParent` in interface `Node`
Parameters:
  `n` -
See Also:
  - `Node.jjtSetParent(org.apache.velocity.runtime.parser.node.Node)`

### jjtGetParent

public Node jjtGetParent()

Specified by:
  `jjtGetParent` in interface `Node`
Returns:
  The node parent.
See Also:
  - `Node.jjtGetParent()`

### jjtAddChild

public void jjtAddChild(Node n, int i)
Description copied from interface: `Node`
This method tells the node to add its argument to the node's list of children.

Specified by:
  `jjtAddChild` in interface `Node`
Parameters:
  `n` -
  `i` -
See Also:
  - `Node.jjtAddChild(org.apache.velocity.runtime.parser.node.Node, int)`

### jjtGetChild

public Node jjtGetChild(int i)
Description copied from interface: `Node`
This method returns a child node. The children are numbered from zero, left to right.

Specified by:
  `jjtGetChild` in interface `Node`
Parameters:
  `i` -
Returns:
  A child node.
See Also:
  - `Node.jjtGetChild(int)`

### jjtGetNumChildren

public int jjtGetNumChildren()
Description copied from interface: `Node`
Return the number of children the node has.

Specified by:
  `jjtGetNumChildren` in interface `Node`
Returns:
  The number of children of this node.
See Also:
  - `Node.jjtGetNumChildren()`

### jjtAccept

public Object jjtAccept(StandardParserVisitor visitor, Object data)

Specified by:
  `jjtAccept` in interface `Node`
Parameters:
  `visitor` -
  `data` -
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:
  `childrenAccept` in interface `Node`
Parameters:
  `visitor` -
  `data` -
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 prefix
  `out` - 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 prefix
  `out` - 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:
  `literal` in interface `Node`
Returns:
  A literal.
See Also:
  - `Node.literal()`

### init

public Object init(InternalContextAdapter context, Object data) throws TemplateInitException

Specified by:
  `init` in interface `Node`
Parameters:
  `context` -
  `data` -
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:
  `evaluate` in interface `Node`
Parameters:
  `context` -
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:
  `value` in interface `Node`
Parameters:
  `context` -
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:
  `render` in interface `Node`
Specified by:
  `render` in interface `Renderable`
Parameters:
  `context` -
  `writer` -
Returns:
  True if the node rendered successfully.
Throws:
  `IOException`
  `MethodInvocationException`
  `ParseErrorException`
  `ResourceNotFoundException`
See Also:
  - `Node.render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer)`

### execute

public Object execute(Object o, InternalContextAdapter context) throws MethodInvocationException

Specified by:
  `execute` in interface `Node`
Parameters:
  `o` -
  `context` -
Returns:
  The execution result.
Throws:
  `MethodInvocationException`
See Also:
  - `Node.execute(java.lang.Object, org.apache.velocity.context.InternalContextAdapter)`

### getType

public int getType()

Specified by:
  `getType` in interface `Node`
Returns:
  The NodeType.
See Also:
  - `Node.getType()`

### setInfo

public void setInfo(int info)

Specified by:
  `setInfo` in interface `Node`
Parameters:
  `info` -
See Also:
  - `Node.setInfo(int)`

### getInfo

public int getInfo()

Specified by:
  `getInfo` in interface `Node`
Returns:
  The current node info.
See Also:
  - `Node.getInfo()`

### setInvalid

public void setInvalid()
Description copied from interface: `Node`
Mark the node as invalid.

Specified by:
  `setInvalid` in interface `Node`
See Also:
  - `Node.setInvalid()`

### isInvalid

public boolean isInvalid()

Specified by:
  `isInvalid` in interface `Node`
Returns:
  True if the node is invalid.
See Also:
  - `Node.isInvalid()`

### getLine

public int getLine()

Specified by:
  `getLine` in interface `Node`
Returns:
  The current line position.
See Also:
  - `Node.getLine()`

### getColumn

public int getColumn()

Specified by:
  `getColumn` in interface `Node`
Returns:
  The current column position.
See Also:
  - `Node.getColumn()`

### toString

public String toString()

Overrides:
  `toString` in class `Object`
Since:
  1.5

### getTemplateName

public String getTemplateName()

Specified by:
  `getTemplateName` in interface `Node`
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:
  `getFirstTokenImage` in interface `Node`
Returns:
  String image variable of the first Token element that was parsed and connected to this Node.

### getLastTokenImage

public String getLastTokenImage()

Specified by:
  `getLastTokenImage` in interface `Node`
Returns:
  String image variable of the last Token element that was parsed and connected to this Node.

### getTemplate

public Template getTemplate()

Specified by:
  `getTemplate` in interface `Node`
Returns:
  the template this node belongs to

### getParser

public Parser getParser()

Specified by:
  `getParser` in interface `Node`
Returns:
  the parser which created this node
Since:
  2.2

### 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 template
  `parent` - parent node
Returns:
  cloned node
Throws:
  `CloneNotSupportedException`
Since:
  2.4