activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1416612 - in /activemq/activemq-apollo/trunk: apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ apollo-selector/src/main/javacc/ apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/
Date Mon, 03 Dec 2012 18:18:09 GMT
Author: chirino
Date: Mon Dec  3 18:18:06 2012
New Revision: 1416612

URL: http://svn.apache.org/viewvc?rev=1416612&view=rev
Log:
Support relaxed and strict JMS selector evaluation in regard to String conversions.

Modified:
    activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ComparisonExpression.java
    activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
    activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala

Modified: activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ComparisonExpression.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ComparisonExpression.java?rev=1416612&r1=1416611&r2=1416612&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ComparisonExpression.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/java/org/apache/activemq/apollo/filter/ComparisonExpression.java
Mon Dec  3 18:18:06 2012
@@ -29,6 +29,9 @@ import java.util.regex.Pattern;
  */
 public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression
{
 
+    public static final ThreadLocal<Boolean> CONVERT_STRING_EXPRESSIONS = new ThreadLocal<Boolean>();
+
+    boolean convertStringExpressions = false;
     private static final Set<Character> REGEXP_CONTROL_CHARS = new HashSet<Character>();
 
     /**
@@ -37,6 +40,7 @@ public abstract class ComparisonExpressi
      */
     public ComparisonExpression(Expression left, Expression right) {
         super(left, right);
+        convertStringExpressions = CONVERT_STRING_EXPRESSIONS.get()!=null;
     }
 
     public static BooleanExpression createBetween(Expression value, Expression left, Expression
right) {
@@ -75,7 +79,6 @@ public abstract class ComparisonExpressi
         Pattern likePattern;
 
         /**
-         * @param left
          */
         public LikeExpression(Expression right, String like, int escape) {
             super(right);
@@ -352,7 +355,7 @@ public abstract class ComparisonExpressi
         if (lc != rc) {
             try {
                 if (lc == Boolean.class) {
-                    if (rc == String.class) {
+                    if (convertStringExpressions && rc == String.class) {
                         rv = Boolean.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
@@ -368,7 +371,7 @@ public abstract class ComparisonExpressi
                         lv = new Float(((Number)lv).floatValue());
                     } else if (rc == Double.class) {
                         lv = new Double(((Number)lv).doubleValue());
-                    } else if (rc == String.class) {
+                    } else if (convertStringExpressions && rc == String.class) {
                         rv = Byte.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
@@ -382,7 +385,7 @@ public abstract class ComparisonExpressi
                         lv = new Float(((Number)lv).floatValue());
                     } else if (rc == Double.class) {
                         lv = new Double(((Number)lv).doubleValue());
-                    } else if (rc == String.class) {
+                    } else if (convertStringExpressions && rc == String.class) {
                         rv = Short.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
@@ -394,7 +397,7 @@ public abstract class ComparisonExpressi
                         lv = new Float(((Number)lv).floatValue());
                     } else if (rc == Double.class) {
                         lv = new Double(((Number)lv).doubleValue());
-                    } else if (rc == String.class) {
+                    } else if (convertStringExpressions && rc == String.class) {
                         rv = Integer.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
@@ -406,7 +409,7 @@ public abstract class ComparisonExpressi
                         lv = new Float(((Number)lv).floatValue());
                     } else if (rc == Double.class) {
                         lv = new Double(((Number)lv).doubleValue());
-                    } else if (rc == String.class) {
+                    } else if (convertStringExpressions && rc == String.class) {
                         rv = Long.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
@@ -418,7 +421,7 @@ public abstract class ComparisonExpressi
                         rv = new Float(((Number)rv).floatValue());
                     } else if (rc == Double.class) {
                         lv = new Double(((Number)lv).doubleValue());
-                    } else if (rc == String.class) {
+                    } else if (convertStringExpressions && rc == String.class) {
                         rv = Float.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
@@ -430,12 +433,12 @@ public abstract class ComparisonExpressi
                         rv = new Double(((Number)rv).doubleValue());
                     } else if (rc == Float.class) {
                         rv = new Double(((Number)rv).doubleValue());
-                    } else if (rc == String.class) {
+                    } else if (convertStringExpressions && rc == String.class) {
                         rv = Double.valueOf((String)rv);
                     } else {
                         return Boolean.FALSE;
                     }
-                } else if (lc == String.class) {
+                } else if (convertStringExpressions && lc == String.class) {
 
                     if (rc == Boolean.class) {
                         lv = Boolean.valueOf((String)lv);

Modified: activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj?rev=1416612&r1=1416611&r2=1416612&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj (original)
+++ activemq/activemq-apollo/trunk/apollo-selector/src/main/javacc/SelectorParser.jj Mon Dec
 3 18:18:06 2012
@@ -62,6 +62,7 @@ import org.apache.activemq.apollo.filter
 public class SelectorParser {
 
     private static final LRUCache cache = new LRUCache(100);
+    private static final String CONVERT_STRING_EXPRESSIONS_PREFIX = "convert_string_expressions:";
 
     public static BooleanExpression parse(String sql) throws FilterException {
         Object result = cache.get(sql);
@@ -70,6 +71,16 @@ public class SelectorParser {
         } else if (result instanceof BooleanExpression) {
             return (BooleanExpression) result;
         } else {
+
+            boolean convertStringExpressions = false;
+            if( sql.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
+                convertStringExpressions = true;
+                sql = sql.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
+            }
+
+            if( convertStringExpressions ) {
+                ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
+            }
             try {
                 BooleanExpression e = new SelectorParser(sql).parse();
                 cache.put(sql, e);
@@ -77,6 +88,10 @@ public class SelectorParser {
             } catch (FilterException t) {
                 cache.put(sql, t);
                 throw t;
+            } finally {
+                if( convertStringExpressions ) {
+                    ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
+                }
             }
         }
     }

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala?rev=1416612&r1=1416611&r2=1416612&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
Mon Dec  3 18:18:06 2012
@@ -1409,7 +1409,7 @@ class StompProtocolHandler extends Proto
       case Some(x)=>
         try {
           val s = decode_header(x)
-          (s, SelectorParser.parse(s))
+          (s, SelectorParser.parse("convert_string_expressions:"+s))
         } catch {
           case e:FilterException =>
             die("Invalid selector expression: "+e.getMessage)



Mime
View raw message