You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2007/08/20 19:59:11 UTC

svn commit: r567772 - /commons/proper/el/trunk/src/java/org/apache/commons/el/ExpressionEvaluatorImpl.java

Author: mbenson
Date: Mon Aug 20 10:59:10 2007
New Revision: 567772

URL: http://svn.apache.org/viewvc?rev=567772&view=rev
Log:
revert as many revs as practical

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?rev=567772&r1=567771&r2=567772&view=diff
==============================================================================
--- 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 Mon Aug 20 10:59:10 2007
@@ -82,32 +82,32 @@
  * @author Nathan Abramson - Art Technology Group
  * @author Shawn Bayern
  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author$
- */
+ **/
 public class ExpressionEvaluatorImpl extends ExpressionEvaluator {
     // -------------------------------------
     // Statics
     // -------------------------------------
     /** The mapping from expression String to its parsed form (String,
-        Expression, or ExpressionString) */
+        Expression, or ExpressionString) **/
     static Map sCachedExpressionStrings = Collections
             .synchronizedMap(new HashMap());
 
     /** The mapping from ExpectedType to Maps mapping literal String to
-        parsed value */
+        parsed value **/
     static Map sCachedExpectedTypes = new HashMap();
 
     // -------------------------------------
     // Member variables
     // -------------------------------------
 
-    /** Flag if the cache should be bypassed */
+    /** Flag if the cache should be bypassed **/
     boolean mBypassCache;
 
     // -------------------------------------
     /**
      *
      * Constructor
-     */
+     **/
     public ExpressionEvaluatorImpl() {
     }
 
@@ -117,7 +117,7 @@
      *
      * @param pBypassCache flag indicating if the cache should be
      * bypassed
-     */
+     **/
     public ExpressionEvaluatorImpl(boolean pBypassCache) {
         mBypassCache = pBypassCache;
     }
@@ -145,7 +145,7 @@
      * @return The Expression object encapsulating the arguments.
      *
      * @exception ELException Thrown if parsing errors were found.
-     */
+     **/
     public javax.servlet.jsp.el.Expression parseExpression(String expression,
             Class expectedType, FunctionMapper fMapper) throws ELException {
         // Validate and then create an Expression object.
@@ -168,7 +168,7 @@
      *     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
-     */
+     **/
     public Object evaluate(String pExpressionString, Class pExpectedType,
             VariableResolver pResolver, FunctionMapper functions)
             throws ELException {
@@ -195,7 +195,7 @@
      *     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 {
@@ -231,7 +231,7 @@
      * parsed form is cached (and caching is not bypassed), return the
      * cached form, otherwise parse and cache the value.  Returns either
      * a String, Expression, or ExpressionString.
-     */
+     **/
     public Object parseExpressionString(String pExpressionString)
             throws ELException {
         // See if it's an empty String
@@ -240,36 +240,35 @@
         }
 
         // See if it's in the cache
-        if (!mBypassCache
-                && sCachedExpressionStrings.containsKey(pExpressionString)) {
-            return sCachedExpressionStrings.get(pExpressionString);
-        }
+        Object ret = mBypassCache ? null : sCachedExpressionStrings
+                .get(pExpressionString);
 
-        // Parse the expression
-        Reader r = new StringReader(pExpressionString);
-        ELParser parser = new ELParser(r);
-        try {
-            Object result = parser.ExpressionString();
-            if (!mBypassCache) {
-                sCachedExpressionStrings.put(pExpressionString, result);
+        if (ret == null) {
+            // Parse the expression
+            Reader r = new StringReader(pExpressionString);
+            ELParser parser = new ELParser(r);
+            try {
+                ret = parser.ExpressionString();
+                sCachedExpressionStrings.put(pExpressionString, ret);
+            } catch (ParseException exc) {
+                throw new ELException(formatParseException(pExpressionString,
+                        exc));
+            } catch (TokenMgrError exc) {
+                // Note - this should never be reached, since the parser is
+                // constructed to tokenize any input (illegal inputs get
+                // parsed to <BADLY_ESCAPED_STRING_LITERAL> or
+                // <ILLEGAL_CHARACTER>
+                throw new ELException(exc.getMessage());
             }
-            return result;
-        } catch (ParseException exc) {
-            throw new ELException(formatParseException(pExpressionString, exc));
-        } catch (TokenMgrError exc) {
-            // Note - this should never be reached, since the parser is
-            // constructed to tokenize any input (illegal inputs get
-            // parsed to <BADLY_ESCAPED_STRING_LITERAL> or
-            // <ILLEGAL_CHARACTER>
-            throw new ELException(exc.getMessage());
         }
+        return ret;
     }
 
     // -------------------------------------
     /**
      *
      * Converts the given value to the specified expected type.
-     */
+     **/
     Object convertToExpectedType(Object pValue, Class pExpectedType)
             throws ELException {
         return Coercions.coerce(pValue, pExpectedType);
@@ -280,7 +279,7 @@
      *
      * Converts the given String, specified as a static expression
      * string, to the given expected type.  The conversion is cached.
-     */
+     **/
     Object convertStaticValueToExpectedType(String pValue, Class pExpectedType)
             throws ELException {
         // See if the value is already of the expected type
@@ -304,7 +303,7 @@
      *
      * Creates or returns the Map that maps string literals to parsed
      * values for the specified expected type.
-     */
+     **/
     static Map getOrCreateExpectedTypeMap(Class pExpectedType) {
         synchronized (sCachedExpectedTypes) {
             Map ret = (Map) sCachedExpectedTypes.get(pExpectedType);
@@ -323,7 +322,7 @@
      *
      * Formats a ParseException into an error message suitable for
      * displaying on a web page
-     */
+     **/
     static String formatParseException(String pExpressionString,
             ParseException pExc) {
         // Generate the String of expected tokens
@@ -375,7 +374,7 @@
      * Used to convert raw characters to their escaped version when
      * these raw version cannot be used as part of an ASCII string
      * literal.
-     */
+     **/
     static String addEscapes(String str) {
         StringBuffer retval = new StringBuffer();
         char ch;
@@ -419,7 +418,7 @@
      *
      * Parses the given expression string, then converts it back to a
      * String in its canonical form.  This is used to test parsing.
-     */
+     **/
     public String parseAndRender(String pExpressionString) throws ELException {
         Object val = parseExpressionString(pExpressionString);
         if (val instanceof Expression) {