Author: dion
Date: Sun Feb 26 16:14:47 2006
New Revision: 381203

URL: http://svn.apache.org/viewcvs?rev=381203&view=rev
Log:
Start work on if 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/ASTIfStatement.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=381203&r1=381202&r2=381203&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
 Sun Feb 26 16:14:47 2006
@@ -18,6 +18,7 @@
 import java.io.StringReader;
 
 import org.apache.commons.jexl.parser.ASTExpressionExpression;
+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.Parser;
@@ -130,6 +131,10 @@
             Expression e = new ExpressionImpl(expression, node);
         
             return e;
+        }
+        else if (node instanceof ASTIfStatement)
+        {
+            return new ExpressionImpl(expression, node);
         }
         log.error( "Invalid Expression, node of type: " + 
node.getClass().getName() );
         throw new Exception("Invalid Expression: neither Reference nor 
Expression");

Modified: 
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIfStatement.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIfStatement.java?rev=381203&r1=381202&r2=381203&view=diff
==============================================================================
--- 
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIfStatement.java
 (original)
+++ 
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTIfStatement.java
 Sun Feb 26 16:14:47 2006
@@ -1,19 +1,60 @@
 /* Generated By:JJTree: Do not edit this line. ASTIfStatement.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;
+
+/**
+ * if ( expression ) statement [else statement]
+ * 
+ * @author Dion Gillard
+ * @since 1.0.1
+ */
 public class ASTIfStatement extends SimpleNode {
-  public ASTIfStatement(int id) {
-    super(id);
-  }
-
-  public ASTIfStatement(Parser p, int id) {
-    super(p, id);
-  }
+    public ASTIfStatement(int id) {
+        super(id);
+    }
+
+    public ASTIfStatement(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 */
+        Object expression = ((SimpleNode) jjtGetChild(0)).value(jc);
+        if (Coercion.coerceBoolean(expression).booleanValue()) {
+            // true statement
+            result = ((SimpleNode) jjtGetChild(1)).value(jc);
+        } else {
+            // if there is a false, execute it
+            if (jjtGetNumChildren() == 3) {
+                result = ((SimpleNode) jjtGetChild(2)).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]

Reply via email to