tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r1650974 - in /tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard: lang/jstl/Evaluator.java lang/support/ExpressionEvaluator.java lang/support/ExpressionEvaluatorManager.java tlv/el/ValidationUtil.java
Date Sun, 11 Jan 2015 21:36:58 GMT
Author: jboynes
Date: Sun Jan 11 21:36:58 2015
New Revision: 1650974

URL: http://svn.apache.org/r1650974
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57433
Use a ConcurrentMap for the cache. However, as our code always uses the same implementation,

use a single instance of that and deprecate public access to the cache. Also includes some
Java5 TLC.

Modified:
    tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java
    tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluator.java
    tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluatorManager.java
    tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/tlv/el/ValidationUtil.java

Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java?rev=1650974&r1=1650973&r2=1650974&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java
(original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/jstl/Evaluator.java
Sun Jan 11 21:36:58 2015
@@ -76,11 +76,9 @@ public class Evaluator
             return
                     MessageFormat.format
                             (Constants.ATTRIBUTE_PARSE_EXCEPTION,
-                                    new Object[]{
-                                            "" + pAttributeName,
-                                            "" + pAttributeValue,
-                                            exc.getMessage()
-                                    });
+                                    "" + pAttributeName,
+                                    "" + pAttributeValue,
+                                    exc.getMessage());
         }
     }
 
@@ -109,12 +107,10 @@ public class Evaluator
             throw new JspException
                     (MessageFormat.format
                             (Constants.ATTRIBUTE_EVALUATION_EXCEPTION,
-                                    new Object[]{
-                                            "" + pAttributeName,
-                                            "" + pAttributeValue,
-                                            exc.getMessage(),
-                                            exc.getRootCause()
-                                    }), exc.getRootCause());
+                                    "" + pAttributeName,
+                                    "" + pAttributeValue,
+                                    exc.getMessage(),
+                                    exc.getRootCause()), exc.getRootCause());
         }
     }
 
@@ -154,11 +150,9 @@ public class Evaluator
             throw new JspException
                     (MessageFormat.format
                             (Constants.ATTRIBUTE_PARSE_EXCEPTION,
-                                    new Object[]{
-                                            "test",
-                                            "" + pAttributeValue,
-                                            exc.getMessage()
-                                    }));
+                                    "test",
+                                    "" + pAttributeValue,
+                                    exc.getMessage()));
         }
     }
 

Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluator.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluator.java?rev=1650974&r1=1650973&r2=1650974&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluator.java
(original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluator.java
Sun Jan 11 21:36:58 2015
@@ -43,8 +43,7 @@ public interface ExpressionEvaluator {
 
     /**
      * Translation time validation of an expression.
-     * This method will return a null String if the expression
-     * is valid; otherwise an error message.
+     * This method will return a null String if the expression is valid; otherwise an error
message.
      */
     public String validate(String attributeName,
                            String expression);

Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluatorManager.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluatorManager.java?rev=1650974&r1=1650973&r2=1650974&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluatorManager.java
(original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/lang/support/ExpressionEvaluatorManager.java
Sun Jan 11 21:36:58 2015
@@ -17,7 +17,8 @@
 
 package org.apache.taglibs.standard.lang.support;
 
-import java.util.HashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
@@ -25,6 +26,7 @@ import javax.servlet.jsp.tagext.Tag;
 
 import org.apache.taglibs.standard.lang.jstl.Coercions;
 import org.apache.taglibs.standard.lang.jstl.ELException;
+import org.apache.taglibs.standard.lang.jstl.Evaluator;
 import org.apache.taglibs.standard.lang.jstl.Logger;
 
 /**
@@ -42,23 +44,22 @@ public class ExpressionEvaluatorManager
     //*********************************************************************
     // Constants
 
-    public static final String EVALUATOR_CLASS =
-            "org.apache.taglibs.standard.lang.jstl.Evaluator";
-    // private static final String EVALUATOR_PARAMETER =
-    //    "javax.servlet.jsp.jstl.temp.ExpressionEvaluatorClass";
+    public static final String EVALUATOR_CLASS = "org.apache.taglibs.standard.lang.jstl.Evaluator";
 
     //*********************************************************************
     // Internal, static state
 
-    private static HashMap nameMap = new HashMap();
-    private static Logger logger = new Logger(System.out);
+    private static final ExpressionEvaluator EVALUATOR = new Evaluator();
+    private static final ConcurrentMap<String, ExpressionEvaluator> nameMap =
+            new ConcurrentHashMap<String, ExpressionEvaluator>();
+    static {
+        nameMap.put(EVALUATOR_CLASS, EVALUATOR);
+    }
 
-    //*********************************************************************
-    // Public static methods
+    private static final Logger logger = new Logger(System.out);
 
     /**
-     * Invokes the evaluate() method on the "active" ExpressionEvaluator
-     * for the given pageContext.
+     * Invokes the evaluate() method on the "active" ExpressionEvaluator for the given pageContext.
      */
     public static Object evaluate(String attributeName,
                                   String expression,
@@ -67,17 +68,12 @@ public class ExpressionEvaluatorManager
                                   PageContext pageContext)
             throws JspException {
 
-        // the evaluator we'll use
-        ExpressionEvaluator target = getEvaluatorByName(EVALUATOR_CLASS);
-
         // delegate the call
-        return (target.evaluate(
-                attributeName, expression, expectedType, tag, pageContext));
+        return (EVALUATOR.evaluate(attributeName, expression, expectedType, tag, pageContext));
     }
 
     /**
-     * Invokes the evaluate() method on the "active" ExpressionEvaluator
-     * for the given pageContext.
+     * Invokes the evaluate() method on the "active" ExpressionEvaluator for the given pageContext.
      */
     public static Object evaluate(String attributeName,
                                   String expression,
@@ -85,58 +81,38 @@ public class ExpressionEvaluatorManager
                                   PageContext pageContext)
             throws JspException {
 
-        // the evaluator we'll use
-        ExpressionEvaluator target = getEvaluatorByName(EVALUATOR_CLASS);
-
-        // delegate the call
-        return (target.evaluate(
-                attributeName, expression, expectedType, null, pageContext));
+        return evaluate(attributeName, expression, expectedType, null, pageContext);
     }
 
     /**
      * Gets an ExpressionEvaluator from the cache, or seeds the cache
      * if we haven't seen a particular ExpressionEvaluator before.
      */
-    public static ExpressionEvaluator getEvaluatorByName(String name)
-            throws JspException {
-
-        Object oEvaluator = nameMap.get(name);
-        if (oEvaluator != null) {
-            return ((ExpressionEvaluator) oEvaluator);
-        }
+    @Deprecated
+    public static ExpressionEvaluator getEvaluatorByName(String name) throws JspException
{
         try {
-            synchronized (nameMap) {
-                oEvaluator = nameMap.get(name);
-                if (oEvaluator != null) {
-                    return ((ExpressionEvaluator) oEvaluator);
-                }
-                ExpressionEvaluator e = (ExpressionEvaluator)
-                        Class.forName(name).newInstance();
-                nameMap.put(name, e);
-                return (e);
+            ExpressionEvaluator evaluator = nameMap.get(name);
+            if (evaluator == null) {
+                nameMap.putIfAbsent(name, (ExpressionEvaluator) Class.forName(name).newInstance());
+                evaluator = nameMap.get(name);
             }
+            return evaluator;
         } catch (ClassCastException ex) {
             // just to display a better error message
-            throw new JspException("invalid ExpressionEvaluator: " +
-                    ex.toString(), ex);
+            throw new JspException("invalid ExpressionEvaluator: " + name, ex);
         } catch (ClassNotFoundException ex) {
-            throw new JspException("couldn't find ExpressionEvaluator: " +
-                    ex.toString(), ex);
+            throw new JspException("couldn't find ExpressionEvaluator: " + name, ex);
         } catch (IllegalAccessException ex) {
-            throw new JspException("couldn't access ExpressionEvaluator: " +
-                    ex.toString(), ex);
+            throw new JspException("couldn't access ExpressionEvaluator: " + name, ex);
         } catch (InstantiationException ex) {
-            throw new JspException(
-                    "couldn't instantiate ExpressionEvaluator: " +
-                            ex.toString(), ex);
+            throw new JspException("couldn't instantiate ExpressionEvaluator: " + name, ex);
         }
     }
 
     /**
      * Performs a type conversion according to the EL's rules.
      */
-    public static Object coerce(Object value, Class classe)
-            throws JspException {
+    public static Object coerce(Object value, Class classe) throws JspException {
         try {
             // just delegate the call
             return Coercions.coerce(value, classe, logger);
@@ -145,4 +121,13 @@ public class ExpressionEvaluatorManager
         }
     }
 
+    /**
+     * Validates an expression.
+     * @param attributeName the name of the attribute containing the expression
+     * @param expression the expression to validate
+     * @return null an error message or null of the expression is valid
+     */
+    public static String validate(String attributeName, String expression) {
+        return EVALUATOR.validate(attributeName, expression);
+    }
 } 

Modified: tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/tlv/el/ValidationUtil.java
URL: http://svn.apache.org/viewvc/tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/tlv/el/ValidationUtil.java?rev=1650974&r1=1650973&r2=1650974&view=diff
==============================================================================
--- tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/tlv/el/ValidationUtil.java
(original)
+++ tomcat/taglibs/standard/trunk/jstlel/src/main/java/org/apache/taglibs/standard/tlv/el/ValidationUtil.java
Sun Jan 11 21:36:58 2015
@@ -16,34 +16,17 @@
  */
 package org.apache.taglibs.standard.tlv.el;
 
-import javax.servlet.jsp.JspException;
-
-import org.apache.taglibs.standard.lang.support.ExpressionEvaluator;
 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
 
 /**
  */
 public class ValidationUtil {
-    static String validateExpression(
-            String elem, String att, String expr) {
-
-        // let's just use the cache kept by the ExpressionEvaluatorManager
-        ExpressionEvaluator current;
-        try {
-            current =
-                    ExpressionEvaluatorManager.getEvaluatorByName(
-                            ExpressionEvaluatorManager.EVALUATOR_CLASS);
-        } catch (JspException ex) {
-            // (using JspException here feels ugly, but it's what EEM uses)
-            return ex.getMessage();
-        }
+    static String validateExpression(String elem, String att, String expr) {
 
-        String response = current.validate(att, expr);
-        if (response == null) {
-            return response;
-        } else {
-            return "tag = '" + elem + "' / attribute = '" + att + "': "
-                    + response;
+        String response = ExpressionEvaluatorManager.validate(att, expr);
+        if (response != null) {
+            response = "tag = '" + elem + "' / attribute = '" + att + "': " + response;
         }
+        return response;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message