org.apache.commons.jexl.parser
Class ASTArrayAccess

java.lang.Object
  |
  +--org.apache.commons.jexl.parser.SimpleNode
        |
        +--org.apache.commons.jexl.parser.ASTArrayAccess
All Implemented Interfaces:
Node

public class ASTArrayAccess
extends SimpleNode

Like an ASTIdentifier, but with array access allowed. $foo[2]

Version:
$Id: ASTArrayAccess.java 398180 2006-04-29 15:40:35Z dion $

Field Summary
 
Fields inherited from class org.apache.commons.jexl.parser.SimpleNode
children, id, parent, parser
 
Constructor Summary
ASTArrayAccess(int id)
          Create the node given an id.
ASTArrayAccess(Parser p, int id)
          Create a node with the given parser and id.
 
Method Summary
static Object evaluateExpr(Object o, Object loc)
          Evaluate the Array expression 'loc' on the given object, o.
 Object execute(Object obj, JexlContext jc)
          evaluate array access upon a base object.
 String getIdentifierString()
          Gets the variable name piece of the expression.
 Object jjtAccept(ParserVisitor visitor, Object data)
          Accept the visitor.
 Object value(JexlContext jc)
          Gets the value of this node.
 
Methods inherited from class org.apache.commons.jexl.parser.SimpleNode
childrenAccept, dump, interpret, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, setValue, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ASTArrayAccess

public ASTArrayAccess(int id)
Create the node given an id.

Parameters:
id - node id.

ASTArrayAccess

public ASTArrayAccess(Parser p,
                      int id)
Create a node with the given parser and id.

Parameters:
p - a parser.
id - node id.
Method Detail

jjtAccept

public Object jjtAccept(ParserVisitor visitor,
                        Object data)
Accept the visitor.

Specified by:
jjtAccept in interface Node
Overrides:
jjtAccept in class SimpleNode
Parameters:
visitor - a ParserVisitor.
data - data to be passed along to the visitor.
Returns:
the value from visiting.
See Also:
ParserVisitor.visit(org.apache.commons.jexl.parser.SimpleNode, java.lang.Object)

execute

public Object execute(Object obj,
                      JexlContext jc)
               throws Exception
evaluate array access upon a base object. foo.bar[2] makes me rethink the array operator :)

Overrides:
execute in class SimpleNode
Parameters:
jc - the JexlContext to evaluate against.
obj - not used.
Returns:
the value of the array expression.
Throws:
Exception - on any error

value

public Object value(JexlContext jc)
             throws Exception
Gets the value of this node.

Overrides:
value in class SimpleNode
Parameters:
jc - the context to retrieve values from.
Returns:
the value of the node.
Throws:
Exception - when evaluating the operands fails.

evaluateExpr

public static Object evaluateExpr(Object o,
                                  Object loc)
                           throws Exception
Evaluate the Array expression 'loc' on the given object, o. e.g. in 'a[2]', 2 is 'loc' and a is 'o'. If o or loc are null, null is returned. If o is a Map, o.get(loc) is returned. If o is a List, o.get(loc) is returned. loc must resolve to an int value. If o is an Array, o[loc] is returned. loc must resolve to an int value. Otherwise loc is treated as a bean property of o.

Parameters:
o - an object to be accessed using the array operator or '.' operator.
loc - the index of the object to be returned.
Returns:
the resulting value.
Throws:
Exception - on any error.

getIdentifierString

public String getIdentifierString()
Gets the variable name piece of the expression.

Returns:
a String of the identifer.
See Also:
ASTIdentifier.getIdentifierString().


Copyright © 2003-2006 The Apache Software Foundation. All Rights Reserved.