Author: dion Date: Mon Feb 27 04:57:40 2006 New Revision: 381331 URL: http://svn.apache.org/viewcvs?rev=381331&view=rev Log: Implement while statement
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTWhileStatement.java Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java?rev=381331&r1=381330&r2=381331&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java Mon Feb 27 04:57:40 2006 @@ -21,6 +21,7 @@ import org.apache.commons.jexl.parser.ASTIfStatement; import org.apache.commons.jexl.parser.ASTReferenceExpression; import org.apache.commons.jexl.parser.ASTStatementExpression; +import org.apache.commons.jexl.parser.ASTWhileStatement; import org.apache.commons.jexl.parser.Parser; import org.apache.commons.jexl.parser.SimpleNode; import org.apache.commons.logging.Log; @@ -132,7 +133,8 @@ return e; } - else if (node instanceof ASTIfStatement) + else if (node instanceof ASTIfStatement + || node instanceof ASTWhileStatement) { return new ExpressionImpl(expression, node); } Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTWhileStatement.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTWhileStatement.java?rev=381331&r1=381330&r2=381331&view=diff ============================================================================== --- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTWhileStatement.java (original) +++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTWhileStatement.java Mon Feb 27 04:57:40 2006 @@ -1,19 +1,55 @@ /* Generated By:JJTree: Do not edit this line. ASTWhileStatement.java */ +/* + * Copyright 2002,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.commons.jexl.parser; +import org.apache.commons.jexl.JexlContext; +import org.apache.commons.jexl.util.Coercion; + +/** + * while ( expression ) statement + * + * @author Dion Gillard + * @since 1.0.1 + */ public class ASTWhileStatement extends SimpleNode { - public ASTWhileStatement(int id) { - super(id); - } - - public ASTWhileStatement(Parser p, int id) { - super(p, id); - } + public ASTWhileStatement(int id) { + super(id); + } + + public ASTWhileStatement(Parser p, int id) { + super(p, id); + } + + /** Accept the visitor. * */ + public Object jjtAccept(ParserVisitor visitor, Object data) { + return visitor.visit(this, data); + } + + public Object value(JexlContext jc) throws Exception { + Object result = null; + /* first child is the expression */ + SimpleNode expressionNode = (SimpleNode) jjtGetChild(0); + while (Coercion.coerceBoolean(expressionNode.value(jc)).booleanValue()) { + // execute statement + result = ((SimpleNode) jjtGetChild(1)).value(jc); + } + return result; + } - /** Accept the visitor. **/ - public Object jjtAccept(ParserVisitor visitor, Object data) { - return visitor.visit(this, data); - } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]