commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r564701 - /commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java
Date Fri, 10 Aug 2007 18:14:05 GMT
Author: mbenson
Date: Fri Aug 10 11:14:04 2007
New Revision: 564701

URL: http://svn.apache.org/viewvc?view=rev&rev=564701
Log:
[EL-5] (b) save parsed expressions in JSTLExpression instances

Modified:
    commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java

Modified: commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java?view=diff&rev=564701&r1=564700&r2=564701
==============================================================================
--- commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java (original)
+++ commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java Fri
Aug 10 11:14:04 2007
@@ -83,7 +83,6 @@
  * @author Shawn Bayern
  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
  **/
-
 public class ExpressionEvaluatorImpl extends ExpressionEvaluator {
     // -------------------------------------
     // Statics
@@ -150,10 +149,10 @@
     public javax.servlet.jsp.el.Expression parseExpression(String expression,
             Class expectedType, FunctionMapper fMapper) throws ELException {
         // Validate and then create an Expression object.
-        parseExpressionString(expression);
+        Object parsedExpression = parseExpressionString(expression);
 
         // Create an Expression object that knows how to evaluate this.
-        return new JSTLExpression(expression, expectedType, fMapper);
+        return new JSTLExpression(parsedExpression, expectedType, fMapper);
     }
 
     // -------------------------------------
@@ -168,8 +167,7 @@
      * @param functions A FunctionMapper to resolve functions found in 
      *     the expression.  It can be null, in which case no functions 
      *     are supported for this invocation.
-     * @return the expression String evaluated to the given expected
-     * type
+     * @return the expression String evaluated to the given expected type
      **/
     public Object evaluate(String pExpressionString, Class pExpectedType,
             VariableResolver pResolver, FunctionMapper functions)
@@ -181,24 +179,43 @@
 
         // Get the parsed version of the expression string
         Object parsedValue = parseExpressionString(pExpressionString);
+        return evaluate(parsedValue, pExpectedType, pResolver, functions);
+    }
 
+    // -------------------------------------
+    /**
+     *
+     * Evaluates the given parsed expression.
+     *
+     * @param parsedExpression The expression to be evaluated.
+     * @param pExpectedType The expected type of the result of the evaluation
+     * @param pResolver A VariableResolver instance that can be used at 
+     *     runtime to resolve the name of implicit objects into Objects.
+     * @param functions A FunctionMapper to resolve functions found in 
+     *     the expression.  It can be null, in which case no functions 
+     *     are supported for this invocation.
+     * @return the expression evaluated to the given expected type
+     **/
+    public Object evaluate(Object parsedExpression, Class pExpectedType,
+            VariableResolver pResolver, FunctionMapper functions)
+            throws ELException {
         // Evaluate differently based on the parsed type
-        if (parsedValue instanceof String) {
+        if (parsedExpression instanceof String) {
             // Convert the String, and cache the conversion
-            String strValue = (String) parsedValue;
+            String strValue = (String) parsedExpression;
             return convertStaticValueToExpectedType(strValue, pExpectedType);
         }
 
-        if (parsedValue instanceof Expression) {
+        if (parsedExpression instanceof Expression) {
             // Evaluate the expression and convert
-            Object value = ((Expression) parsedValue).evaluate(pResolver,
+            Object value = ((Expression) parsedExpression).evaluate(pResolver,
                     functions);
             return convertToExpectedType(value, pExpectedType);
         }
 
-        if (parsedValue instanceof ExpressionString) {
+        if (parsedExpression instanceof ExpressionString) {
             // Evaluate the expression/string list and convert
-            String strValue = ((ExpressionString) parsedValue).evaluate(
+            String strValue = ((ExpressionString) parsedExpression).evaluate(
                     pResolver, functions);
             return convertToExpectedType(strValue, pExpectedType);
         }
@@ -418,19 +435,19 @@
      * the JSTL evaluator.
      */
     private class JSTLExpression extends javax.servlet.jsp.el.Expression {
-        private String expression;
+        private Object parsedExpression;
         private Class expectedType;
         private FunctionMapper fMapper;
 
-        private JSTLExpression(String expression, Class expectedType,
+        private JSTLExpression(Object parsedExpression, Class expectedType,
                 FunctionMapper fMapper) {
-            this.expression = expression;
+            this.parsedExpression = parsedExpression;
             this.expectedType = expectedType;
             this.fMapper = fMapper;
         }
 
         public Object evaluate(VariableResolver vResolver) throws ELException {
-            return ExpressionEvaluatorImpl.this.evaluate(expression,
+            return ExpressionEvaluatorImpl.this.evaluate(parsedExpression,
                     expectedType, vResolver, fMapper);
         }
     }



Mime
View raw message