/** * evaluate array access upon a base object. * * <p>foo.bar[2] * * <p>makes me rethink the array operator :) * * @param jc the {@link JexlContext} to evaluate against. * @param obj not used. * @return the value of the array expression. * @throws Exception on any error */ public Object execute(Object obj, JexlContext jc) throws Exception { ASTIdentifier base = (ASTIdentifier) jjtGetChild(0); Object result = base.execute(obj, jc); /* * ignore the first child - it's our identifier */ for (int i = 1; i < jjtGetNumChildren(); i++) { Object loc = ((SimpleNode) jjtGetChild(i)).value(jc); if (loc == null) { return null; } result = evaluateExpr(result, loc); } return result; }
/** {@inheritDoc} */ public Object value(JexlContext jc) throws Exception { /* * get the base ASTIdentifier */ ASTIdentifier base = (ASTIdentifier) jjtGetChild(0); Object o = base.value(jc); /* * ignore the first child - it's our identifier */ for (int i = 1; i < jjtGetNumChildren(); i++) { Object loc = ((SimpleNode) jjtGetChild(i)).value(jc); if (loc == null) { return null; } o = evaluateExpr(o, loc); } return o; }