1 16 17 package org.apache.commons.jexl.parser; 18 19 import java.util.Iterator ; 20 21 import org.apache.commons.jexl.JexlContext; 22 import org.apache.commons.jexl.util.Introspector; 23 import org.apache.commons.jexl.util.introspection.Info; 24 25 31 public class ASTForeachStatement extends SimpleNode { 32 33 private static final Info DUMMY = new Info("", 1, 1); 34 35 private static final int VAR_INDEX = 0; 36 37 private static final int ITEMS_INDEX = 1; 38 39 private static final int STATEMENT_INDEX = 2; 40 41 42 47 public ASTForeachStatement(int id) { 48 super(id); 49 } 50 51 57 public ASTForeachStatement(Parser p, int id) { 58 super(p, id); 59 } 60 61 62 public Object jjtAccept(ParserVisitor visitor, Object data) { 63 return visitor.visit(this, data); 64 } 65 66 67 public Object value(JexlContext jc) throws Exception { 68 Object result = null; 69 70 ASTReference loopVariable = (ASTReference) jjtGetChild(VAR_INDEX); 71 72 SimpleNode iterable = (SimpleNode) jjtGetChild(ITEMS_INDEX); 73 Object iterableValue = iterable.value(jc); 74 if (iterableValue != null && jjtGetNumChildren() >= (STATEMENT_INDEX + 1)) { 76 77 SimpleNode statement = (SimpleNode) jjtGetChild(2); 78 Iterator itemsIterator = Introspector.getUberspect().getIterator( 81 iterableValue, DUMMY); 82 while (itemsIterator.hasNext()) { 83 Object value = itemsIterator.next(); 85 jc.getVars().put(loopVariable.getRootString(), value); 86 result = statement.value(jc); 88 } 89 } 90 return result; 91 } 92 } 93 | Popular Tags |