You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/02/18 17:38:28 UTC

[6/6] qpid-jms git commit: consolidate the selector parsing bits into the client module

consolidate the selector parsing bits into the client module


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/98a99d3b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/98a99d3b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/98a99d3b

Branch: refs/heads/master
Commit: 98a99d3bcb7e2e51cf9ba251f525fb9d55fb84fa
Parents: 0fc387c
Author: Robert Gemmell <ro...@apache.org>
Authored: Wed Feb 18 16:36:14 2015 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Wed Feb 18 16:36:14 2015 +0000

----------------------------------------------------------------------
 pom.xml                                         |   1 -
 qpid-jms-client/pom.xml                         |  85 ++-
 .../org/apache/qpid/jms/selector/LRUCache.java  |  91 +++
 .../qpid/jms/selector/SelectorParser.java       | 100 ++++
 .../selector/filter/ArithmeticExpression.java   | 212 +++++++
 .../jms/selector/filter/BinaryExpression.java   |  93 +++
 .../jms/selector/filter/BooleanExpression.java  |  32 ++
 .../selector/filter/ComparisonExpression.java   | 489 ++++++++++++++++
 .../jms/selector/filter/ConstantExpression.java | 163 ++++++
 .../qpid/jms/selector/filter/Expression.java    |  29 +
 .../jms/selector/filter/FilterException.java    |  38 ++
 .../qpid/jms/selector/filter/Filterable.java    |  51 ++
 .../jms/selector/filter/LogicExpression.java    |  90 +++
 .../jms/selector/filter/PropertyExpression.java |  65 +++
 .../jms/selector/filter/UnaryExpression.java    | 262 +++++++++
 .../jms/selector/filter/XPathExpression.java    |  78 +++
 .../jms/selector/filter/XQueryExpression.java   |  50 ++
 .../selector/filter/XalanXPathEvaluator.java    | 115 ++++
 .../qpid/jms/selector/filter/package.html       |  27 +
 .../src/main/javacc/HyphenatedParser.jj         | 563 +++++++++++++++++++
 qpid-jms-client/src/main/javacc/StrictParser.jj | 563 +++++++++++++++++++
 .../qpid/jms/selector/SelectorParserTest.java   |  71 +++
 .../apache/qpid/jms/selector/SelectorTest.java  | 477 ++++++++++++++++
 .../qpid-jms-activemq-tests/pom.xml             |   5 -
 qpid-jms-selector/pom.xml                       | 129 -----
 .../org/apache/qpid/jms/selector/LRUCache.java  |  91 ---
 .../qpid/jms/selector/SelectorParser.java       | 100 ----
 .../selector/filter/ArithmeticExpression.java   | 212 -------
 .../jms/selector/filter/BinaryExpression.java   |  93 ---
 .../jms/selector/filter/BooleanExpression.java  |  32 --
 .../selector/filter/ComparisonExpression.java   | 489 ----------------
 .../jms/selector/filter/ConstantExpression.java | 163 ------
 .../qpid/jms/selector/filter/Expression.java    |  29 -
 .../jms/selector/filter/FilterException.java    |  38 --
 .../qpid/jms/selector/filter/Filterable.java    |  51 --
 .../jms/selector/filter/LogicExpression.java    |  90 ---
 .../jms/selector/filter/PropertyExpression.java |  65 ---
 .../jms/selector/filter/UnaryExpression.java    | 262 ---------
 .../jms/selector/filter/XPathExpression.java    |  78 ---
 .../jms/selector/filter/XQueryExpression.java   |  50 --
 .../selector/filter/XalanXPathEvaluator.java    | 115 ----
 .../qpid/jms/selector/filter/package.html       |  27 -
 .../src/main/javacc/HyphenatedParser.jj         | 563 -------------------
 .../src/main/javacc/StrictParser.jj             | 563 -------------------
 .../qpid/jms/selector/SelectorParserTest.java   |  71 ---
 .../apache/qpid/jms/selector/SelectorTest.java  | 477 ----------------
 .../src/test/resources/log4j.properties         |  38 --
 47 files changed, 3739 insertions(+), 3837 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ff384b1..6b57bea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,7 +91,6 @@
     <module>qpid-jms-client</module>
     <module>qpid-jms-discovery</module>
     <module>qpid-jms-interop-tests</module>
-    <module>qpid-jms-selector</module>
     <module>qpid-jms-examples</module>
     <module>qpid-jms-docs</module>
     <module>apache-qpid-jms</module>

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/pom.xml
----------------------------------------------------------------------
diff --git a/qpid-jms-client/pom.xml b/qpid-jms-client/pom.xml
index c22df3e..e8a0749 100644
--- a/qpid-jms-client/pom.xml
+++ b/qpid-jms-client/pom.xml
@@ -30,7 +30,7 @@
 
   <dependencies>
     <!-- =================================== -->
-    <!-- Client Dependencies               -->
+    <!-- Client Dependencies                 -->
     <!-- =================================== -->
     <dependency>
       <groupId>org.slf4j</groupId>
@@ -42,10 +42,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.qpid</groupId>
-      <artifactId>qpid-jms-selector</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.qpid</groupId>
       <artifactId>proton-j</artifactId>
     </dependency>
     <dependency>
@@ -76,6 +72,15 @@
       <artifactId>hamcrest-all</artifactId>
       <scope>test</scope>
     </dependency>
+
+    <!-- =================================== -->
+    <!-- Build Dependencies                  -->
+    <!-- =================================== -->
+    <dependency>
+      <groupId>xalan</groupId>
+      <artifactId>xalan</artifactId>
+      <optional>true</optional>
+    </dependency>
   </dependencies>
 
   <build>
@@ -94,6 +99,76 @@
         </includes>
       </resource>
     </resources>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>javacc-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <configuration>
+              <sourceDirectory>${basedir}/src/main/javacc</sourceDirectory>
+              <outputDirectory>${basedir}/target/generated-sources/javacc</outputDirectory>
+            </configuration>
+            <goals>
+              <goal>javacc</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>add-source</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>add-source</goal>
+            </goals>
+            <configuration>
+              <sources>
+                <source>${basedir}/target/generated-sources/javacc</source>
+              </sources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence
+          on the Maven build itself. -->
+        <plugin>
+          <groupId>org.eclipse.m2e</groupId>
+          <artifactId>lifecycle-mapping</artifactId>
+          <version>1.0.0</version>
+          <configuration>
+            <lifecycleMappingMetadata>
+              <pluginExecutions>
+                <pluginExecution>
+                  <pluginExecutionFilter>
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>
+                      javacc-maven-plugin
+                    </artifactId>
+                    <versionRange>[2.6,)</versionRange>
+                    <goals>
+                      <goal>javacc</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <execute>
+                      <runOnIncremental>true</runOnIncremental>
+                    </execute>
+                  </action>
+                </pluginExecution>
+              </pluginExecutions>
+            </lifecycleMappingMetadata>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
   </build>
 
   <reporting>

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/LRUCache.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/LRUCache.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/LRUCache.java
new file mode 100755
index 0000000..6e9858d
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/LRUCache.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * A Simple LRU Cache
+ * 
+ * @param <K>
+ * @param <V>
+ */
+
+public class LRUCache<K, V> extends LinkedHashMap<K, V> {
+    private static final long serialVersionUID = -342098639681884413L;
+    protected int maxCacheSize = 10000;
+
+    /**
+     * Default constructor for an LRU Cache The default capacity is 10000
+     */
+    public LRUCache() {
+        this(0,10000, 0.75f, true);
+    }
+
+    /**
+     * Constructs a LRUCache with a maximum capacity
+     * 
+     * @param maximumCacheSize
+     */
+    public LRUCache(int maximumCacheSize) {
+        this(0, maximumCacheSize, 0.75f, true);
+    }
+
+    /**
+     * Constructs an empty <tt>LRUCache</tt> instance with the specified
+     * initial capacity, maximumCacheSize,load factor and ordering mode.
+     * 
+     * @param initialCapacity the initial capacity.
+     * @param maximumCacheSize
+     * @param loadFactor the load factor.
+     * @param accessOrder the ordering mode - <tt>true</tt> for access-order,
+     *                <tt>false</tt> for insertion-order.
+     * @throws IllegalArgumentException if the initial capacity is negative or
+     *                 the load factor is non-positive.
+     */
+
+    public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) {
+        super(initialCapacity, loadFactor, accessOrder);
+        this.maxCacheSize = maximumCacheSize;
+    }
+
+    /**
+     * @return Returns the maxCacheSize.
+     */
+    public int getMaxCacheSize() {
+        return maxCacheSize;
+    }
+
+    /**
+     * @param maxCacheSize The maxCacheSize to set.
+     */
+    public void setMaxCacheSize(int maxCacheSize) {
+        this.maxCacheSize = maxCacheSize;
+    }
+
+    protected boolean removeEldestEntry(Map.Entry<K,V> eldest) {
+        if( size() > maxCacheSize ) {
+            onCacheEviction(eldest);
+            return true;
+        }
+        return false;
+    }
+
+    protected void onCacheEviction(Map.Entry<K,V> eldest) {
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/SelectorParser.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/SelectorParser.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/SelectorParser.java
new file mode 100644
index 0000000..9e68112
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/SelectorParser.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector;
+
+import org.apache.qpid.jms.selector.filter.BooleanExpression;
+import org.apache.qpid.jms.selector.filter.ComparisonExpression;
+import org.apache.qpid.jms.selector.filter.FilterException;
+import org.apache.qpid.jms.selector.hyphenated.HyphenatedParser;
+import org.apache.qpid.jms.selector.strict.StrictParser;
+
+import java.io.StringReader;
+
+/**
+ */
+public class SelectorParser {
+
+    private static final LRUCache cache = new LRUCache(100);
+    private static final String CONVERT_STRING_EXPRESSIONS_PREFIX = "convert_string_expressions:";
+    private static final String HYPHENATED_PROPS_PREFIX = "hyphenated_props:";
+    private static final String NO_CONVERT_STRING_EXPRESSIONS_PREFIX = "no_convert_string_expressions:";
+    private static final String NO_HYPHENATED_PROPS_PREFIX = "no_hyphenated_props:";
+
+    public static BooleanExpression parse(String sql) throws FilterException {
+        Object result = cache.get(sql);
+        if (result instanceof FilterException) {
+            throw (FilterException) result;
+        } else if (result instanceof BooleanExpression) {
+            return (BooleanExpression) result;
+        } else {
+            String actual = sql;
+            boolean convertStringExpressions = false;
+            boolean hyphenatedProps=false;
+            while(true) {
+              if( actual.startsWith(CONVERT_STRING_EXPRESSIONS_PREFIX)) {
+                  convertStringExpressions = true;
+                  actual = actual.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length());
+                  continue;
+              }
+              if( actual.startsWith(HYPHENATED_PROPS_PREFIX)) {
+                  hyphenatedProps = true;
+                  actual = actual.substring(HYPHENATED_PROPS_PREFIX.length());
+                  continue;
+              }
+              if( actual.startsWith(NO_CONVERT_STRING_EXPRESSIONS_PREFIX)) {
+                  convertStringExpressions = false;
+                  actual = actual.substring(NO_CONVERT_STRING_EXPRESSIONS_PREFIX.length());
+                  continue;
+              }
+              if( actual.startsWith(NO_HYPHENATED_PROPS_PREFIX)) {
+                  hyphenatedProps = false;
+                  actual = actual.substring(NO_HYPHENATED_PROPS_PREFIX.length());
+                  continue;
+              }
+              break;
+            }
+
+            if( convertStringExpressions ) {
+                ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true);
+            }
+            try {
+                BooleanExpression e = null;
+                if( hyphenatedProps ) {
+                    HyphenatedParser parser = new HyphenatedParser(new StringReader(actual));
+                    e = parser.JmsSelector();
+                } else {
+                    StrictParser parser = new StrictParser(new StringReader(actual));
+                    e = parser.JmsSelector();
+                }
+                cache.put(sql, e);
+                return e;
+            } catch (Throwable e) {
+                FilterException fe = new FilterException(actual, e);
+                cache.put(sql, fe);
+                throw fe;
+            } finally {
+                if( convertStringExpressions ) {
+                    ComparisonExpression.CONVERT_STRING_EXPRESSIONS.remove();
+                }
+            }
+        }
+    }
+
+    public static void clearCache() {
+        cache.clear();
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ArithmeticExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ArithmeticExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ArithmeticExpression.java
new file mode 100755
index 0000000..8aa0c25
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ArithmeticExpression.java
@@ -0,0 +1,212 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * An expression which performs an operation on two expression values
+ */
+public abstract class ArithmeticExpression extends BinaryExpression {
+
+    protected static final int INTEGER = 1;
+    protected static final int LONG = 2;
+    protected static final int DOUBLE = 3;
+    boolean convertStringExpressions = false;
+
+    /**
+     * @param left
+     * @param right
+     */
+    public ArithmeticExpression(Expression left, Expression right) {
+        super(left, right);
+        convertStringExpressions = ComparisonExpression.CONVERT_STRING_EXPRESSIONS.get()!=null;
+    }
+
+    public static Expression createPlus(Expression left, Expression right) {
+        return new ArithmeticExpression(left, right) {
+            @Override
+            protected Object evaluate(Object lvalue, Object rvalue) {
+                if (lvalue instanceof String) {
+                    String text = (String)lvalue;
+                    String answer = text + rvalue;
+                    return answer;
+                } else {
+                    return plus(asNumber(lvalue), asNumber(rvalue));
+                }
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "+";
+            }
+        };
+    }
+
+    public static Expression createMinus(Expression left, Expression right) {
+        return new ArithmeticExpression(left, right) {
+            @Override
+            protected Object evaluate(Object lvalue, Object rvalue) {
+                return minus(asNumber(lvalue), asNumber(rvalue));
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "-";
+            }
+        };
+    }
+
+    public static Expression createMultiply(Expression left, Expression right) {
+        return new ArithmeticExpression(left, right) {
+
+            @Override
+            protected Object evaluate(Object lvalue, Object rvalue) {
+                return multiply(asNumber(lvalue), asNumber(rvalue));
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "*";
+            }
+        };
+    }
+
+    public static Expression createDivide(Expression left, Expression right) {
+        return new ArithmeticExpression(left, right) {
+
+            @Override
+            protected Object evaluate(Object lvalue, Object rvalue) {
+                return divide(asNumber(lvalue), asNumber(rvalue));
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "/";
+            }
+        };
+    }
+
+    public static Expression createMod(Expression left, Expression right) {
+        return new ArithmeticExpression(left, right) {
+
+            @Override
+            protected Object evaluate(Object lvalue, Object rvalue) {
+                return mod(asNumber(lvalue), asNumber(rvalue));
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "%";
+            }
+        };
+    }
+
+    protected Number plus(Number left, Number right) {
+        switch (numberType(left, right)) {
+        case INTEGER:
+            return Integer.valueOf(left.intValue() + right.intValue());
+        case LONG:
+            return Long.valueOf(left.longValue() + right.longValue());
+        default:
+            return new Double(left.doubleValue() + right.doubleValue());
+        }
+    }
+
+    protected Number minus(Number left, Number right) {
+        switch (numberType(left, right)) {
+        case INTEGER:
+            return Integer.valueOf(left.intValue() - right.intValue());
+        case LONG:
+            return Long.valueOf(left.longValue() - right.longValue());
+        default:
+            return new Double(left.doubleValue() - right.doubleValue());
+        }
+    }
+
+    protected Number multiply(Number left, Number right) {
+        switch (numberType(left, right)) {
+        case INTEGER:
+            return Integer.valueOf(left.intValue() * right.intValue());
+        case LONG:
+            return Long.valueOf(left.longValue() * right.longValue());
+        default:
+            return new Double(left.doubleValue() * right.doubleValue());
+        }
+    }
+
+    protected Number divide(Number left, Number right) {
+        return new Double(left.doubleValue() / right.doubleValue());
+    }
+
+    protected Number mod(Number left, Number right) {
+        return new Double(left.doubleValue() % right.doubleValue());
+    }
+
+    private int numberType(Number left, Number right) {
+        if (isDouble(left) || isDouble(right)) {
+            return DOUBLE;
+        } else if (left instanceof Long || right instanceof Long) {
+            return LONG;
+        } else {
+            return INTEGER;
+        }
+    }
+
+    private boolean isDouble(Number n) {
+        return n instanceof Float || n instanceof Double;
+    }
+
+    protected Number asNumber(Object value) {
+        if (value instanceof Number) {
+            return (Number)value;
+        } else {
+            if( convertStringExpressions && value instanceof String) {
+                String v = (String) value;
+                try {
+                    if( v.contains(".") ) {
+                        return new Double(v);
+                    } else {
+                        return Long.valueOf(v);
+                    }
+                } catch (NumberFormatException e) {
+                    throw new RuntimeException("Cannot convert value: " + value + " into a number");
+                }
+            }
+            throw new RuntimeException("Cannot convert value: " + value + " into a number");
+        }
+    }
+
+    @Override
+    public Object evaluate(Filterable message) throws FilterException {
+        Object lvalue = left.evaluate(message);
+        if (lvalue == null) {
+            return null;
+        }
+        Object rvalue = right.evaluate(message);
+        if (rvalue == null) {
+            return null;
+        }
+        return evaluate(lvalue, rvalue);
+    }
+
+    /**
+     * @param lvalue
+     * @param rvalue
+     * @return
+     */
+    protected abstract Object evaluate(Object lvalue, Object rvalue);
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BinaryExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BinaryExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BinaryExpression.java
new file mode 100755
index 0000000..c36cecb
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BinaryExpression.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * An expression which performs an operation on two expression values.
+ *
+ */
+public abstract class BinaryExpression implements Expression {
+    protected Expression left;
+    protected Expression right;
+
+    public BinaryExpression(Expression left, Expression right) {
+        this.left = left;
+        this.right = right;
+    }
+
+    public Expression getLeft() {
+        return left;
+    }
+
+    public Expression getRight() {
+        return right;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "(" + left.toString() + " " + getExpressionSymbol() + " " + right.toString() + ")";
+    }
+
+    /**
+     * TODO: more efficient hashCode()
+     *
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return toString().hashCode();
+    }
+
+    /**
+     * TODO: more efficient hashCode()
+     *
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object o) {
+
+        if (o == null || !this.getClass().equals(o.getClass())) {
+            return false;
+        }
+        return toString().equals(o.toString());
+    }
+
+    /**
+     * Returns the symbol that represents this binary expression.  For example, addition is
+     * represented by "+"
+     *
+     * @return
+     */
+    public abstract String getExpressionSymbol();
+
+    /**
+     * @param expression
+     */
+    public void setRight(Expression expression) {
+        right = expression;
+    }
+
+    /**
+     * @param expression
+     */
+    public void setLeft(Expression expression) {
+        left = expression;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BooleanExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BooleanExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BooleanExpression.java
new file mode 100755
index 0000000..21a3d4b
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/BooleanExpression.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * A BooleanExpression is an expression that always
+ * produces a Boolean result.
+ */
+public interface BooleanExpression extends Expression {
+
+    /**
+     * @param message
+     * @return true if the expression evaluates to Boolean.TRUE.
+     * @throws FilterException
+     */
+    boolean matches(Filterable message) throws FilterException;
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java
new file mode 100755
index 0000000..04ecaf6
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java
@@ -0,0 +1,489 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/**
+ * A filter performing a comparison of two objects
+ */
+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>();
+
+    /**
+     * @param left
+     * @param right
+     */
+    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) {
+        return LogicExpression.createAND(createGreaterThanEqual(value, left), createLessThanEqual(value, right));
+    }
+
+    public static BooleanExpression createNotBetween(Expression value, Expression left, Expression right) {
+        return LogicExpression.createOR(createLessThan(value, left), createGreaterThan(value, right));
+    }
+
+    static {
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('.'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('\\'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('['));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf(']'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('^'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('$'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('?'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('*'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('+'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('{'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('}'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('|'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('('));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf(')'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf(':'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('&'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('<'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('>'));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('='));
+        REGEXP_CONTROL_CHARS.add(Character.valueOf('!'));
+    }
+
+    static class LikeExpression extends UnaryExpression implements BooleanExpression {
+
+        Pattern likePattern;
+
+        /**
+         */
+        public LikeExpression(Expression right, String like, int escape) {
+            super(right);
+
+            StringBuffer regexp = new StringBuffer(like.length() * 2);
+            regexp.append("\\A"); // The beginning of the input
+            for (int i = 0; i < like.length(); i++) {
+                char c = like.charAt(i);
+                if (escape == (0xFFFF & c)) {
+                    i++;
+                    if (i >= like.length()) {
+                        // nothing left to escape...
+                        break;
+                    }
+
+                    char t = like.charAt(i);
+                    regexp.append("\\x");
+                    regexp.append(Integer.toHexString(0xFFFF & t));
+                } else if (c == '%') {
+                    regexp.append(".*?"); // Do a non-greedy match
+                } else if (c == '_') {
+                    regexp.append("."); // match one
+                } else if (REGEXP_CONTROL_CHARS.contains(Character.valueOf(c))) {
+                    regexp.append("\\x");
+                    regexp.append(Integer.toHexString(0xFFFF & c));
+                } else {
+                    regexp.append(c);
+                }
+            }
+            regexp.append("\\z"); // The end of the input
+
+            likePattern = Pattern.compile(regexp.toString(), Pattern.DOTALL);
+        }
+
+        /**
+         * @see org.apache.activemq.filter.UnaryExpression#getExpressionSymbol()
+         */
+        @Override
+        public String getExpressionSymbol() {
+            return "LIKE";
+        }
+
+        /**
+         * @see org.apache.activemq.filter.Expression#evaluate(Filterable)
+         */
+        @Override
+        public Object evaluate(Filterable message) throws FilterException {
+
+            Object rv = this.getRight().evaluate(message);
+
+            if (rv == null) {
+                return null;
+            }
+
+            if (!(rv instanceof String)) {
+                return Boolean.FALSE;
+                // throw new RuntimeException("LIKE can only operate on String
+                // identifiers. LIKE attempted on: '" + rv.getClass());
+            }
+
+            return likePattern.matcher((String)rv).matches() ? Boolean.TRUE : Boolean.FALSE;
+        }
+
+        @Override
+        public boolean matches(Filterable message) throws FilterException {
+            Object object = evaluate(message);
+            return object != null && object == Boolean.TRUE;
+        }
+    }
+
+    public static BooleanExpression createLike(Expression left, String right, String escape) {
+        if (escape != null && escape.length() != 1) {
+            throw new RuntimeException("The ESCAPE string litteral is invalid.  It can only be one character.  Litteral used: " + escape);
+        }
+        int c = -1;
+        if (escape != null) {
+            c = 0xFFFF & escape.charAt(0);
+        }
+
+        return new LikeExpression(left, right, c);
+    }
+
+    public static BooleanExpression createNotLike(Expression left, String right, String escape) {
+        return UnaryExpression.createNOT(createLike(left, right, escape));
+    }
+
+    public static BooleanExpression createInFilter(Expression left, List elements) {
+
+        if (!(left instanceof PropertyExpression)) {
+            throw new RuntimeException("Expected a property for In expression, got: " + left);
+        }
+        return UnaryExpression.createInExpression((PropertyExpression)left, elements, false);
+    }
+
+    public static BooleanExpression createNotInFilter(Expression left, List elements) {
+
+        if (!(left instanceof PropertyExpression)) {
+            throw new RuntimeException("Expected a property for In expression, got: " + left);
+        }
+        return UnaryExpression.createInExpression((PropertyExpression)left, elements, true);
+    }
+
+    public static BooleanExpression createIsNull(Expression left) {
+        return doCreateEqual(left, ConstantExpression.NULL);
+    }
+
+    public static BooleanExpression createIsNotNull(Expression left) {
+        return UnaryExpression.createNOT(doCreateEqual(left, ConstantExpression.NULL));
+    }
+
+    public static BooleanExpression createNotEqual(Expression left, Expression right) {
+        return UnaryExpression.createNOT(createEqual(left, right));
+    }
+
+    public static BooleanExpression createEqual(Expression left, Expression right) {
+        checkEqualOperand(left);
+        checkEqualOperand(right);
+        checkEqualOperandCompatability(left, right);
+        return doCreateEqual(left, right);
+    }
+
+    private static BooleanExpression doCreateEqual(Expression left, Expression right) {
+        return new ComparisonExpression(left, right) {
+
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+                Object lv = left.evaluate(message);
+                Object rv = right.evaluate(message);
+
+                // Iff one of the values is null
+                if (lv == null ^ rv == null) {
+                    return Boolean.FALSE;
+                }
+                if (lv == rv || lv.equals(rv)) {
+                    return Boolean.TRUE;
+                }
+                if (lv instanceof Comparable && rv instanceof Comparable) {
+                    return compare((Comparable)lv, (Comparable)rv);
+                }
+                return Boolean.FALSE;
+            }
+
+            @Override
+            protected boolean asBoolean(int answer) {
+                return answer == 0;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "=";
+            }
+        };
+    }
+
+    public static BooleanExpression createGreaterThan(final Expression left, final Expression right) {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+        return new ComparisonExpression(left, right) {
+            @Override
+            protected boolean asBoolean(int answer) {
+                return answer > 0;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return ">";
+            }
+        };
+    }
+
+    public static BooleanExpression createGreaterThanEqual(final Expression left, final Expression right) {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+        return new ComparisonExpression(left, right) {
+            @Override
+            protected boolean asBoolean(int answer) {
+                return answer >= 0;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return ">=";
+            }
+        };
+    }
+
+    public static BooleanExpression createLessThan(final Expression left, final Expression right) {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+        return new ComparisonExpression(left, right) {
+
+            @Override
+            protected boolean asBoolean(int answer) {
+                return answer < 0;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "<";
+            }
+
+        };
+    }
+
+    public static BooleanExpression createLessThanEqual(final Expression left, final Expression right) {
+        checkLessThanOperand(left);
+        checkLessThanOperand(right);
+        return new ComparisonExpression(left, right) {
+
+            @Override
+            protected boolean asBoolean(int answer) {
+                return answer <= 0;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "<=";
+            }
+        };
+    }
+
+    /**
+     * Only Numeric expressions can be used in >, >=, < or <= expressions.s
+     *
+     * @param expr
+     */
+    public static void checkLessThanOperand(Expression expr) {
+        if (expr instanceof ConstantExpression) {
+            Object value = ((ConstantExpression)expr).getValue();
+            if (value instanceof Number) {
+                return;
+            }
+
+            // Else it's boolean or a String..
+            throw new RuntimeException("Value '" + expr + "' cannot be compared.");
+        }
+        if (expr instanceof BooleanExpression) {
+            throw new RuntimeException("Value '" + expr + "' cannot be compared.");
+        }
+    }
+
+    /**
+     * Validates that the expression can be used in == or <> expression. Cannot
+     * not be NULL TRUE or FALSE litterals.
+     *
+     * @param expr
+     */
+    public static void checkEqualOperand(Expression expr) {
+        if (expr instanceof ConstantExpression) {
+            Object value = ((ConstantExpression)expr).getValue();
+            if (value == null) {
+                throw new RuntimeException("'" + expr + "' cannot be compared.");
+            }
+        }
+    }
+
+    /**
+     * @param left
+     * @param right
+     */
+    private static void checkEqualOperandCompatability(Expression left, Expression right) {
+        if (left instanceof ConstantExpression && right instanceof ConstantExpression) {
+            if (left instanceof BooleanExpression && !(right instanceof BooleanExpression)) {
+                throw new RuntimeException("'" + left + "' cannot be compared with '" + right + "'");
+            }
+        }
+    }
+
+    @Override
+    public Object evaluate(Filterable message) throws FilterException {
+        Comparable<Comparable> lv = (Comparable)left.evaluate(message);
+        if (lv == null) {
+            return null;
+        }
+        Comparable rv = (Comparable)right.evaluate(message);
+        if (rv == null) {
+            return null;
+        }
+        return compare(lv, rv);
+    }
+
+    protected Boolean compare(Comparable lv, Comparable rv) {
+        Class<? extends Comparable> lc = lv.getClass();
+        Class<? extends Comparable> rc = rv.getClass();
+        // If the the objects are not of the same type,
+        // try to convert up to allow the comparison.
+        if (lc != rc) {
+            try {
+                if (lc == Boolean.class) {
+                    if (convertStringExpressions && rc == String.class) {
+                        rv = Boolean.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (lc == Byte.class) {
+                    if (rc == Short.class) {
+                        lv = Short.valueOf(((Number)lv).shortValue());
+                    } else if (rc == Integer.class) {
+                        lv = Integer.valueOf(((Number)lv).intValue());
+                    } else if (rc == Long.class) {
+                        lv = Long.valueOf(((Number)lv).longValue());
+                    } else if (rc == Float.class) {
+                        lv = new Float(((Number)lv).floatValue());
+                    } else if (rc == Double.class) {
+                        lv = new Double(((Number)lv).doubleValue());
+                    } else if (convertStringExpressions && rc == String.class) {
+                        rv = Byte.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (lc == Short.class) {
+                    if (rc == Integer.class) {
+                        lv = Integer.valueOf(((Number)lv).intValue());
+                    } else if (rc == Long.class) {
+                        lv = Long.valueOf(((Number)lv).longValue());
+                    } else if (rc == Float.class) {
+                        lv = new Float(((Number)lv).floatValue());
+                    } else if (rc == Double.class) {
+                        lv = new Double(((Number)lv).doubleValue());
+                    } else if (convertStringExpressions && rc == String.class) {
+                        rv = Short.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (lc == Integer.class) {
+                    if (rc == Long.class) {
+                        lv = Long.valueOf(((Number)lv).longValue());
+                    } else if (rc == Float.class) {
+                        lv = new Float(((Number)lv).floatValue());
+                    } else if (rc == Double.class) {
+                        lv = new Double(((Number)lv).doubleValue());
+                    } else if (convertStringExpressions && rc == String.class) {
+                        rv = Integer.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (lc == Long.class) {
+                    if (rc == Integer.class) {
+                        rv = Long.valueOf(((Number)rv).longValue());
+                    } else if (rc == Float.class) {
+                        lv = new Float(((Number)lv).floatValue());
+                    } else if (rc == Double.class) {
+                        lv = new Double(((Number)lv).doubleValue());
+                    } else if (convertStringExpressions && rc == String.class) {
+                        rv = Long.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (lc == Float.class) {
+                    if (rc == Integer.class) {
+                        rv = new Float(((Number)rv).floatValue());
+                    } else if (rc == Long.class) {
+                        rv = new Float(((Number)rv).floatValue());
+                    } else if (rc == Double.class) {
+                        lv = new Double(((Number)lv).doubleValue());
+                    } else if (convertStringExpressions && rc == String.class) {
+                        rv = Float.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (lc == Double.class) {
+                    if (rc == Integer.class) {
+                        rv = new Double(((Number)rv).doubleValue());
+                    } else if (rc == Long.class) {
+                        rv = new Double(((Number)rv).doubleValue());
+                    } else if (rc == Float.class) {
+                        rv = new Double(((Number)rv).doubleValue());
+                    } else if (convertStringExpressions && rc == String.class) {
+                        rv = Double.valueOf((String)rv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+                } else if (convertStringExpressions && lc == String.class) {
+
+                    if (rc == Boolean.class) {
+                        lv = Boolean.valueOf((String)lv);
+                    } else if (rc == Byte.class) {
+                        lv = Byte.valueOf((String)lv);
+                    } else if (rc == Short.class) {
+                        lv = Short.valueOf((String)lv);
+                    } else if (rc == Integer.class) {
+                        lv = Integer.valueOf((String)lv);
+                    } else if (rc == Long.class) {
+                        lv = Long.valueOf((String)lv);
+                    } else if (rc == Float.class) {
+                        lv = Float.valueOf((String)lv);
+                    } else if (rc == Double.class) {
+                        lv = Double.valueOf((String)lv);
+                    } else {
+                        return Boolean.FALSE;
+                    }
+
+                } else {
+                    return Boolean.FALSE;
+                }
+            } catch (NumberFormatException e) {
+                return Boolean.FALSE;
+            }
+        }
+
+        return asBoolean(lv.compareTo(rv)) ? Boolean.TRUE : Boolean.FALSE;
+    }
+
+    protected abstract boolean asBoolean(int answer);
+
+    @Override
+    public boolean matches(Filterable message) throws FilterException {
+        Object object = evaluate(message);
+        return object != null && object == Boolean.TRUE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java
new file mode 100755
index 0000000..5fe4756
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java
@@ -0,0 +1,163 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+import java.math.BigDecimal;
+
+/**
+ * Represents a constant expression
+ */
+public class ConstantExpression implements Expression {
+
+    static class BooleanConstantExpression extends ConstantExpression implements BooleanExpression {
+        public BooleanConstantExpression(Object value) {
+            super(value);
+        }
+
+        @Override
+        public boolean matches(Filterable message) throws FilterException {
+            Object object = evaluate(message);
+            return object != null && object == Boolean.TRUE;
+        }
+    }
+
+    public static final BooleanConstantExpression NULL = new BooleanConstantExpression(null);
+    public static final BooleanConstantExpression TRUE = new BooleanConstantExpression(Boolean.TRUE);
+    public static final BooleanConstantExpression FALSE = new BooleanConstantExpression(Boolean.FALSE);
+
+    private final Object value;
+
+    public ConstantExpression(Object value) {
+        this.value = value;
+    }
+
+    public static ConstantExpression createFromDecimal(String text) {
+
+        // Strip off the 'l' or 'L' if needed.
+        if (text.endsWith("l") || text.endsWith("L")) {
+            text = text.substring(0, text.length() - 1);
+        }
+
+        Number value;
+        try {
+            value = Long.valueOf(text);
+        } catch (NumberFormatException e) {
+            // The number may be too big to fit in a long.
+            value = new BigDecimal(text);
+        }
+
+        long l = value.longValue();
+        if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) {
+            value = Integer.valueOf(value.intValue());
+        }
+        return new ConstantExpression(value);
+    }
+
+    public static ConstantExpression createFromHex(String text) {
+        Number value = Long.valueOf(Long.parseLong(text.substring(2), 16));
+        long l = value.longValue();
+        if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) {
+            value = Integer.valueOf(value.intValue());
+        }
+        return new ConstantExpression(value);
+    }
+
+    public static ConstantExpression createFromOctal(String text) {
+        Number value = Long.valueOf(Long.parseLong(text, 8));
+        long l = value.longValue();
+        if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) {
+            value = Integer.valueOf(value.intValue());
+        }
+        return new ConstantExpression(value);
+    }
+
+    public static ConstantExpression createFloat(String text) {
+        Number value = new Double(text);
+        return new ConstantExpression(value);
+    }
+
+    @Override
+    public Object evaluate(Filterable message) throws FilterException {
+        return value;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        if (value == null) {
+            return "NULL";
+        }
+        if (value instanceof Boolean) {
+            return ((Boolean)value).booleanValue() ? "TRUE" : "FALSE";
+        }
+        if (value instanceof String) {
+            return encodeString((String)value);
+        }
+        return value.toString();
+    }
+
+    /**
+     * TODO: more efficient hashCode()
+     *
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return toString().hashCode();
+    }
+
+    /**
+     * TODO: more efficient hashCode()
+     *
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object o) {
+
+        if (o == null || !this.getClass().equals(o.getClass())) {
+            return false;
+        }
+        return toString().equals(o.toString());
+    }
+
+    /**
+     * Encodes the value of string so that it looks like it would look like when
+     * it was provided in a selector.
+     *
+     * @param string
+     * @return
+     */
+    public static String encodeString(String s) {
+        StringBuffer b = new StringBuffer();
+        b.append('\'');
+        for (int i = 0; i < s.length(); i++) {
+            char c = s.charAt(i);
+            if (c == '\'') {
+                b.append(c);
+            }
+            b.append(c);
+        }
+        b.append('\'');
+        return b.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java
new file mode 100755
index 0000000..7b69e42
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * Represents an expression
+ */
+public interface Expression {
+
+    /**
+     * @return the value of this expression
+     */
+    Object evaluate(Filterable message) throws FilterException;
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java
new file mode 100644
index 0000000..3d6aeb6
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+public class FilterException extends Exception {
+
+    private static final long serialVersionUID = -6892363158919485507L;
+
+    public FilterException() {
+        super();
+    }
+
+    public FilterException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public FilterException(String message) {
+        super(message);
+    }
+
+    public FilterException(Throwable cause) {
+        super(cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java
new file mode 100755
index 0000000..f1baf69
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * A Filterable is the object being evaluated by the filters.  It provides
+ * access to filtered properties.
+ */
+public interface Filterable {
+
+    /**
+     * This method is used by message filters which do content based routing (Like the XPath
+     * based selectors).
+     *
+     * @param <T>
+     * @param type
+     * @return
+     * @throws FilterException
+     */
+    <T> T getBodyAs(Class<T> type) throws FilterException;
+
+    /**
+     * Extracts the named message property
+     *
+     * @param name
+     * @return
+     */
+    Object getProperty(String name);
+
+    /**
+     * Used by the NoLocal filter.
+     *
+     * @return a unique id for the connection that produced the message.
+     */
+    Object getLocalConnectionId();
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java
new file mode 100755
index 0000000..1e635e7
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * A filter performing a comparison of two objects
+ */
+public abstract class LogicExpression extends BinaryExpression implements BooleanExpression {
+
+    /**
+     * @param left
+     * @param right
+     */
+    public LogicExpression(BooleanExpression left, BooleanExpression right) {
+        super(left, right);
+    }
+
+    public static BooleanExpression createOR(BooleanExpression lvalue, BooleanExpression rvalue) {
+        return new LogicExpression(lvalue, rvalue) {
+
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+
+                Boolean lv = (Boolean)left.evaluate(message);
+                // Can we do an OR shortcut??
+                if (lv != null && lv.booleanValue()) {
+                    return Boolean.TRUE;
+                }
+
+                Boolean rv = (Boolean)right.evaluate(message);
+                return rv == null ? null : rv;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "OR";
+            }
+        };
+    }
+
+    public static BooleanExpression createAND(BooleanExpression lvalue, BooleanExpression rvalue) {
+        return new LogicExpression(lvalue, rvalue) {
+
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+
+                Boolean lv = (Boolean)left.evaluate(message);
+
+                // Can we do an AND shortcut??
+                if (lv == null) {
+                    return null;
+                }
+                if (!lv.booleanValue()) {
+                    return Boolean.FALSE;
+                }
+
+                Boolean rv = (Boolean)right.evaluate(message);
+                return rv == null ? null : rv;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "AND";
+            }
+        };
+    }
+
+    @Override
+    public abstract Object evaluate(Filterable message) throws FilterException;
+
+    @Override
+    public boolean matches(Filterable message) throws FilterException {
+        Object object = evaluate(message);
+        return object != null && object == Boolean.TRUE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java
new file mode 100755
index 0000000..67d99eb
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * Represents a property expression
+ */
+public class PropertyExpression implements Expression {
+
+    private final String name;
+
+    public PropertyExpression(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public Object evaluate(Filterable message) throws FilterException {
+        return message.getProperty(name);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || !this.getClass().equals(o.getClass())) {
+            return false;
+        }
+        return name.equals(((PropertyExpression)o).name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java
new file mode 100755
index 0000000..2d1b7b0
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java
@@ -0,0 +1,262 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+import java.math.BigDecimal;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * An expression which performs an operation on two expression values
+ */
+public abstract class UnaryExpression implements Expression {
+
+    private static final BigDecimal BD_LONG_MIN_VALUE = BigDecimal.valueOf(Long.MIN_VALUE);
+    protected Expression right;
+
+    public UnaryExpression(Expression left) {
+        this.right = left;
+    }
+
+    public static Expression createNegate(Expression left) {
+        return new UnaryExpression(left) {
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+                Object rvalue = right.evaluate(message);
+                if (rvalue == null) {
+                    return null;
+                }
+                if (rvalue instanceof Number) {
+                    return negate((Number)rvalue);
+                }
+                return null;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "-";
+            }
+        };
+    }
+
+    public static BooleanExpression createInExpression(PropertyExpression right, List<Object> elements, final boolean not) {
+
+        // Use a HashSet if there are many elements.
+        Collection<Object> t;
+        if (elements.size() == 0) {
+            t = null;
+        } else if (elements.size() < 5) {
+            t = elements;
+        } else {
+            t = new HashSet<Object>(elements);
+        }
+
+        final Collection<Object> inList = t;
+
+        return new BooleanUnaryExpression(right) {
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+
+                Object rvalue = right.evaluate(message);
+                if (rvalue == null) {
+                    return null;
+                }
+                if (rvalue.getClass() != String.class) {
+                    return null;
+                }
+
+                if ((inList != null && inList.contains(rvalue)) ^ not) {
+                    return Boolean.TRUE;
+                } else {
+                    return Boolean.FALSE;
+                }
+            }
+
+            @Override
+            public String toString() {
+                StringBuffer answer = new StringBuffer();
+                answer.append(right);
+                answer.append(" ");
+                answer.append(getExpressionSymbol());
+                answer.append(" ( ");
+
+                int count = 0;
+                for (Iterator<Object> i = inList.iterator(); i.hasNext();) {
+                    Object o = i.next();
+                    if (count != 0) {
+                        answer.append(", ");
+                    }
+                    answer.append(o);
+                    count++;
+                }
+
+                answer.append(" )");
+                return answer.toString();
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                if (not) {
+                    return "NOT IN";
+                } else {
+                    return "IN";
+                }
+            }
+        };
+    }
+
+    abstract static class BooleanUnaryExpression extends UnaryExpression implements BooleanExpression {
+        public BooleanUnaryExpression(Expression left) {
+            super(left);
+        }
+
+        @Override
+        public boolean matches(Filterable message) throws FilterException {
+            Object object = evaluate(message);
+            return object != null && object == Boolean.TRUE;
+        }
+    };
+
+    public static BooleanExpression createNOT(BooleanExpression left) {
+        return new BooleanUnaryExpression(left) {
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+                Boolean lvalue = (Boolean)right.evaluate(message);
+                if (lvalue == null) {
+                    return null;
+                }
+                return lvalue.booleanValue() ? Boolean.FALSE : Boolean.TRUE;
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "NOT";
+            }
+        };
+    }
+
+    public static BooleanExpression createXPath(final String xpath) {
+        return new XPathExpression(xpath);
+    }
+
+    public static BooleanExpression createXQuery(final String xpath) {
+        return new XQueryExpression(xpath);
+    }
+
+    public static BooleanExpression createBooleanCast(Expression left) {
+        return new BooleanUnaryExpression(left) {
+            @Override
+            public Object evaluate(Filterable message) throws FilterException {
+                Object rvalue = right.evaluate(message);
+                if (rvalue == null) {
+                    return null;
+                }
+                if (!rvalue.getClass().equals(Boolean.class)) {
+                    return Boolean.FALSE;
+                }
+                return ((Boolean)rvalue).booleanValue() ? Boolean.TRUE : Boolean.FALSE;
+            }
+
+            @Override
+            public String toString() {
+                return right.toString();
+            }
+
+            @Override
+            public String getExpressionSymbol() {
+                return "";
+            }
+        };
+    }
+
+    private static Number negate(Number left) {
+        Class<?> clazz = left.getClass();
+        if (clazz == Integer.class) {
+            return Integer.valueOf(-left.intValue());
+        } else if (clazz == Long.class) {
+            return Long.valueOf(-left.longValue());
+        } else if (clazz == Float.class) {
+            return new Float(-left.floatValue());
+        } else if (clazz == Double.class) {
+            return new Double(-left.doubleValue());
+        } else if (clazz == BigDecimal.class) {
+            // We usually get a big decimal when we have Long.MIN_VALUE constant in
+            // the Selector. Long.MIN_VALUE is too big to store in a Long as a positive
+            // so we store it as a Big decimal. But it gets Negated right away.. to here
+            // we try to covert it back to a Long.
+            BigDecimal bd = (BigDecimal) left;
+            bd = bd.negate();
+
+            if (BD_LONG_MIN_VALUE.compareTo(bd) == 0) {
+                return Long.valueOf(Long.MIN_VALUE);
+            }
+            return bd;
+        } else {
+            throw new RuntimeException("Don't know how to negate: " + left);
+        }
+    }
+
+    public Expression getRight() {
+        return right;
+    }
+
+    public void setRight(Expression expression) {
+        right = expression;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return "(" + getExpressionSymbol() + " " + right.toString() + ")";
+    }
+
+    /**
+     * TODO: more efficient hashCode()
+     *
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return toString().hashCode();
+    }
+
+    /**
+     * TODO: more efficient hashCode()
+     *
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || !this.getClass().equals(o.getClass())) {
+            return false;
+        }
+        return toString().equals(o.toString());
+    }
+
+    /**
+     * Returns the symbol that represents this binary expression. For example,
+     * addition is represented by "+"
+     *
+     * @return
+     */
+    public abstract String getExpressionSymbol();
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java
new file mode 100755
index 0000000..ebfc38f
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * Used to evaluate an XPath Expression in a JMS selector.
+ */
+public final class XPathExpression implements BooleanExpression {
+
+    public static XPathEvaluatorFactory XPATH_EVALUATOR_FACTORY = null;
+    static {
+        // Install the xalan xpath evaluator if it available.
+        new XalanXPathEvaluator("//root").evaluate("<root></root>");
+        try {
+            XPATH_EVALUATOR_FACTORY = new XPathExpression.XPathEvaluatorFactory() {
+                @Override
+                public XPathExpression.XPathEvaluator create(String xpath) {
+                    return new XalanXPathEvaluator(xpath);
+                }
+            };
+        } catch(Throwable e) {
+        }
+    }
+
+    private final String xpath;
+    private final XPathEvaluator evaluator;
+
+    public static interface XPathEvaluatorFactory {
+        XPathEvaluator create(String xpath);
+    }
+
+    public static interface XPathEvaluator {
+        boolean evaluate(Filterable message) throws FilterException;
+    }
+
+    XPathExpression(String xpath) {
+        if( XPATH_EVALUATOR_FACTORY == null ) {
+            throw new IllegalArgumentException("XPATH support not enabled.");
+        }
+        this.xpath = xpath;
+        this.evaluator = XPATH_EVALUATOR_FACTORY.create(xpath);
+    }
+
+    @Override
+    public Object evaluate(Filterable message) throws FilterException {
+        return evaluator.evaluate(message) ? Boolean.TRUE : Boolean.FALSE;
+    }
+
+    @Override
+    public String toString() {
+        return "XPATH " + ConstantExpression.encodeString(xpath);
+    }
+
+    /**
+     * @param message
+     * @return true if the expression evaluates to Boolean.TRUE.
+     * @throws FilterException
+     */
+    @Override
+    public boolean matches(Filterable message) throws FilterException {
+        Object object = evaluate(message);
+        return object != null && object == Boolean.TRUE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java
new file mode 100755
index 0000000..00d091c
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+/**
+ * Used to evaluate an XQuery Expression in a JMS selector.
+ */
+public final class XQueryExpression implements BooleanExpression {
+    private final String xpath;
+
+    XQueryExpression(String xpath) {
+        super();
+        this.xpath = xpath;
+    }
+
+    @Override
+    public Object evaluate(Filterable message) throws FilterException {
+        return Boolean.FALSE;
+    }
+
+    @Override
+    public String toString() {
+        return "XQUERY " + ConstantExpression.encodeString(xpath);
+    }
+
+    /**
+     * @param message
+     * @return true if the expression evaluates to Boolean.TRUE.
+     * @throws FilterException
+     */
+    @Override
+    public boolean matches(Filterable message) throws FilterException {
+        Object object = evaluate(message);
+        return object != null && object == Boolean.TRUE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java
new file mode 100644
index 0000000..13ad667
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.qpid.jms.selector.filter;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.xpath.CachedXPathAPI;
+import org.apache.xpath.objects.XObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.traversal.NodeIterator;
+import org.xml.sax.InputSource;
+
+public class XalanXPathEvaluator implements XPathExpression.XPathEvaluator {
+    public static final String DOCUMENT_BUILDER_FACTORY_FEATURE = "org.apache.activemq.apollo.documentBuilderFactory.feature";
+    private final String xpath;
+
+    public XalanXPathEvaluator(String xpath) {
+        this.xpath = xpath;
+    }
+
+    @Override
+    public boolean evaluate(Filterable m) throws FilterException {
+        String stringBody = m.getBodyAs(String.class);
+        if (stringBody!=null) {
+            return evaluate(stringBody);
+        }
+        return false;
+    }
+
+    protected boolean evaluate(String text) {
+        return evaluate(new InputSource(new StringReader(text)));
+    }
+
+    protected boolean evaluate(InputSource inputSource) {
+        try {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
+            factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+            setupFeatures(factory);
+            factory.setNamespaceAware(true);
+            factory.setIgnoringElementContentWhitespace(true);
+            factory.setIgnoringComments(true);
+            DocumentBuilder dbuilder = factory.newDocumentBuilder();
+            Document doc = dbuilder.parse(inputSource);
+
+            // An XPath expression could return a true or false value instead of a node.
+            // eval() is a better way to determine the boolean value of the exp.
+            // For compliance with legacy behavior where selecting an empty node returns true,
+            // selectNodeIterator is attempted in case of a failure.
+
+            CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+            XObject result = cachedXPathAPI.eval(doc, xpath);
+            if (result.bool()) {
+                return true;
+            } else {
+                NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
+                return (iterator.nextNode() != null);
+            }
+        } catch (Throwable e) {
+            return false;
+        }
+    }
+
+    protected void setupFeatures(DocumentBuilderFactory factory) {
+        Properties properties = System.getProperties();
+        List<String> features = new ArrayList<String>();
+        for (Map.Entry<Object, Object> prop : properties.entrySet()) {
+            String key = (String) prop.getKey();
+            if (key.startsWith(DOCUMENT_BUILDER_FACTORY_FEATURE)) {
+                String uri = key.split(DOCUMENT_BUILDER_FACTORY_FEATURE + ":")[1];
+                Boolean value = Boolean.valueOf((String)prop.getValue());
+                try {
+                    factory.setFeature(uri, value);
+                    features.add("feature " + uri + " value " + value);
+                } catch (ParserConfigurationException e) {
+                    throw new RuntimeException("DocumentBuilderFactory doesn't support the feature " + uri + " with value " + value + ", due to " + e);
+                }
+            }
+        }
+
+        if (features.size() > 0) {
+            StringBuffer featureString = new StringBuffer();
+            // just log the configured feature
+            for (String feature : features) {
+                if (featureString.length() != 0) {
+                    featureString.append(", ");
+                }
+                featureString.append(feature);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/package.html
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/package.html b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/package.html
new file mode 100755
index 0000000..836ddd9
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/selector/filter/package.html
@@ -0,0 +1,27 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+<p>
+	Filter implementations for wildcards & JMS selectors
+</p>
+
+</body>
+</html>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org