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:26 UTC
[4/6] qpid-jms git commit: consolidate the selector parsing bits into
the client module
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java
deleted file mode 100755
index 04ecaf6..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ComparisonExpression.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java
deleted file mode 100755
index 5fe4756..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/ConstantExpression.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java
deleted file mode 100755
index 7b69e42..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/Expression.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java
deleted file mode 100644
index 3d6aeb6..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/FilterException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java
deleted file mode 100755
index f1baf69..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/Filterable.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java
deleted file mode 100755
index 1e635e7..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/LogicExpression.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java
deleted file mode 100755
index 67d99eb..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/PropertyExpression.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java
deleted file mode 100755
index 2d1b7b0..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/UnaryExpression.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java
deleted file mode 100755
index ebfc38f..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XPathExpression.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java
deleted file mode 100755
index 00d091c..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XQueryExpression.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java
deleted file mode 100644
index 13ad667..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/XalanXPathEvaluator.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * 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-selector/src/main/java/org/apache/qpid/jms/selector/filter/package.html
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/package.html b/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/package.html
deleted file mode 100755
index 836ddd9..0000000
--- a/qpid-jms-selector/src/main/java/org/apache/qpid/jms/selector/filter/package.html
+++ /dev/null
@@ -1,27 +0,0 @@
-<!--
- 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>
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-selector/src/main/javacc/HyphenatedParser.jj
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/javacc/HyphenatedParser.jj b/qpid-jms-selector/src/main/javacc/HyphenatedParser.jj
deleted file mode 100755
index 5966027..0000000
--- a/qpid-jms-selector/src/main/javacc/HyphenatedParser.jj
+++ /dev/null
@@ -1,563 +0,0 @@
-/**
- * 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.
- */
-
-// ----------------------------------------------------------------------------
-// OPTIONS
-// ----------------------------------------------------------------------------
-options {
- STATIC = false;
- UNICODE_INPUT = true;
- // some performance optimizations
- ERROR_REPORTING = false;
-}
-
-// ----------------------------------------------------------------------------
-// PARSER
-// ----------------------------------------------------------------------------
-
-PARSER_BEGIN(HyphenatedParser)
-/**
- * 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.hyphenated;
-
-import java.io.*;
-import java.util.*;
-
-import org.apache.qpid.jms.selector.filter.*;
-
-/**
- * JMS Selector Parser generated by JavaCC
- *
- * Do not edit this .java file directly - it is autogenerated from HyphenatedParser.jj
- */
-public class HyphenatedParser {
- private BooleanExpression asBooleanExpression(Expression value) throws ParseException {
- if (value instanceof BooleanExpression) {
- return (BooleanExpression) value;
- }
- if (value instanceof PropertyExpression) {
- return UnaryExpression.createBooleanCast( value );
- }
- throw new ParseException("Expression will not result in a boolean value: " + value);
- }
-}
-
-PARSER_END(HyphenatedParser)
-
-// ----------------------------------------------------------------------------
-// Tokens
-// ----------------------------------------------------------------------------
-
-/* White Space */
-SPECIAL_TOKEN :
-{
- " " | "\t" | "\n" | "\r" | "\f"
-}
-
-/* Comments */
-SKIP:
-{
- <LINE_COMMENT: "--" (~["\n","\r"])* ("\n"|"\r"|"\r\n") >
-}
-
-SKIP:
-{
- <BLOCK_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
-}
-
-/* Reserved Words */
-TOKEN [IGNORE_CASE] :
-{
- < NOT : "NOT">
- | < AND : "AND">
- | < OR : "OR">
- | < BETWEEN : "BETWEEN">
- | < LIKE : "LIKE">
- | < ESCAPE : "ESCAPE">
- | < IN : "IN">
- | < IS : "IS">
- | < TRUE : "TRUE" >
- | < FALSE : "FALSE" >
- | < NULL : "NULL" >
- | < XPATH : "XPATH" >
- | < XQUERY : "XQUERY" >
-}
-
-/* Literals */
-TOKEN [IGNORE_CASE] :
-{
-
- < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? >
- | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
- | < OCTAL_LITERAL: "0" (["0"-"7"])* >
- | < FLOATING_POINT_LITERAL:
- (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? // matches: 5.5 or 5. or 5.5E10 or 5.E10
- | "." (["0"-"9"])+ (<EXPONENT>)? // matches: .5 or .5E10
- | (["0"-"9"])+ <EXPONENT> // matches: 5E10
- >
- | < #EXPONENT: "E" (["+","-"])? (["0"-"9"])+ >
- | < STRING_LITERAL: "'" ( ("''") | ~["'"] )* "'" >
-}
-
-TOKEN [IGNORE_CASE] :
-{
- < ID : ["a"-"z", "_", "$"] (["a"-"z","0"-"9","_", "$", "-"])* >
-}
-
-// ----------------------------------------------------------------------------
-// Grammer
-// ----------------------------------------------------------------------------
-BooleanExpression JmsSelector() :
-{
- Expression left=null;
-}
-{
- (
- left = orExpression()
- )
- {
- return asBooleanExpression(left);
- }
-
-}
-
-Expression orExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- (
- left = andExpression()
- (
- <OR> right = andExpression()
- {
- left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right));
- }
- )*
- )
- {
- return left;
- }
-
-}
-
-
-Expression andExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- (
- left = equalityExpression()
- (
- <AND> right = equalityExpression()
- {
- left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right));
- }
- )*
- )
- {
- return left;
- }
-}
-
-Expression equalityExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- (
- left = comparisonExpression()
- (
-
- "=" right = comparisonExpression()
- {
- left = ComparisonExpression.createEqual(left, right);
- }
- |
- "<>" right = comparisonExpression()
- {
- left = ComparisonExpression.createNotEqual(left, right);
- }
- |
- LOOKAHEAD(2)
- <IS> <NULL>
- {
- left = ComparisonExpression.createIsNull(left);
- }
- |
- <IS> <NOT> <NULL>
- {
- left = ComparisonExpression.createIsNotNull(left);
- }
- )*
- )
- {
- return left;
- }
-}
-
-Expression comparisonExpression() :
-{
- Expression left;
- Expression right;
- Expression low;
- Expression high;
- String t, u;
- boolean not;
- ArrayList list;
-}
-{
- (
- left = addExpression()
- (
-
- ">" right = addExpression()
- {
- left = ComparisonExpression.createGreaterThan(left, right);
- }
- |
- ">=" right = addExpression()
- {
- left = ComparisonExpression.createGreaterThanEqual(left, right);
- }
- |
- "<" right = addExpression()
- {
- left = ComparisonExpression.createLessThan(left, right);
- }
- |
- "<=" right = addExpression()
- {
- left = ComparisonExpression.createLessThanEqual(left, right);
- }
- |
- {
- u=null;
- }
- <LIKE> t = stringLitteral()
- [ <ESCAPE> u = stringLitteral() ]
- {
- left = ComparisonExpression.createLike(left, t, u);
- }
- |
- LOOKAHEAD(2)
- {
- u=null;
- }
- <NOT> <LIKE> t = stringLitteral() [ <ESCAPE> u = stringLitteral() ]
- {
- left = ComparisonExpression.createNotLike(left, t, u);
- }
- |
- <BETWEEN> low = addExpression() <AND> high = addExpression()
- {
- left = ComparisonExpression.createBetween(left, low, high);
- }
- |
- LOOKAHEAD(2)
- <NOT> <BETWEEN> low = addExpression() <AND> high = addExpression()
- {
- left = ComparisonExpression.createNotBetween(left, low, high);
- }
- |
- <IN>
- "("
- t = stringLitteral()
- {
- list = new ArrayList();
- list.add( t );
- }
- (
- ","
- t = stringLitteral()
- {
- list.add( t );
- }
-
- )*
- ")"
- {
- left = ComparisonExpression.createInFilter(left, list);
- }
- |
- LOOKAHEAD(2)
- <NOT> <IN>
- "("
- t = stringLitteral()
- {
- list = new ArrayList();
- list.add( t );
- }
- (
- ","
- t = stringLitteral()
- {
- list.add( t );
- }
-
- )*
- ")"
- {
- left = ComparisonExpression.createNotInFilter(left, list);
- }
-
- )*
- )
- {
- return left;
- }
-}
-
-Expression addExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- left = multExpr()
- (
- LOOKAHEAD( ("+"|"-") multExpr())
- (
- "+" right = multExpr()
- {
- left = ArithmeticExpression.createPlus(left, right);
- }
- |
- "-" right = multExpr()
- {
- left = ArithmeticExpression.createMinus(left, right);
- }
- )
-
- )*
- {
- return left;
- }
-}
-
-Expression multExpr() :
-{
- Expression left;
- Expression right;
-}
-{
- left = unaryExpr()
- (
- "*" right = unaryExpr()
- {
- left = ArithmeticExpression.createMultiply(left, right);
- }
- |
- "/" right = unaryExpr()
- {
- left = ArithmeticExpression.createDivide(left, right);
- }
- |
- "%" right = unaryExpr()
- {
- left = ArithmeticExpression.createMod(left, right);
- }
-
- )*
- {
- return left;
- }
-}
-
-
-Expression unaryExpr() :
-{
- String s=null;
- Expression left=null;
-}
-{
- (
- LOOKAHEAD( "+" unaryExpr() )
- "+" left=unaryExpr()
- |
- "-" left=unaryExpr()
- {
- left = UnaryExpression.createNegate(left);
- }
- |
- <NOT> left=unaryExpr()
- {
- left = UnaryExpression.createNOT( asBooleanExpression(left) );
- }
- |
- <XPATH> s=stringLitteral()
- {
- left = UnaryExpression.createXPath( s );
- }
- |
- <XQUERY> s=stringLitteral()
- {
- left = UnaryExpression.createXQuery( s );
- }
- |
- left = primaryExpr()
- )
- {
- return left;
- }
-
-}
-
-Expression primaryExpr() :
-{
- Expression left=null;
-}
-{
- (
- left = literal()
- |
- left = variable()
- |
- "(" left = orExpression() ")"
- )
- {
- return left;
- }
-}
-
-
-
-ConstantExpression literal() :
-{
- Token t;
- String s;
- ConstantExpression left=null;
-}
-{
- (
- (
- s = stringLitteral()
- {
- left = new ConstantExpression(s);
- }
- )
- |
- (
- t = <DECIMAL_LITERAL>
- {
- left = ConstantExpression.createFromDecimal(t.image);
- }
- )
- |
- (
- t = <HEX_LITERAL>
- {
- left = ConstantExpression.createFromHex(t.image);
- }
- )
- |
- (
- t = <OCTAL_LITERAL>
- {
- left = ConstantExpression.createFromOctal(t.image);
- }
- )
- |
- (
- t = <FLOATING_POINT_LITERAL>
- {
- left = ConstantExpression.createFloat(t.image);
- }
- )
- |
- (
- <TRUE>
- {
- left = ConstantExpression.TRUE;
- }
- )
- |
- (
- <FALSE>
- {
- left = ConstantExpression.FALSE;
- }
- )
- |
- (
- <NULL>
- {
- left = ConstantExpression.NULL;
- }
- )
- )
- {
- return left;
- }
-}
-
-String stringLitteral() :
-{
- Token t;
- StringBuffer rc = new StringBuffer();
- boolean first=true;
-}
-{
- t = <STRING_LITERAL>
- {
- // Decode the sting value.
- String image = t.image;
- for( int i=1; i < image.length()-1; i++ ) {
- char c = image.charAt(i);
- if( c == '\'' )
- i++;
- rc.append(c);
- }
- return rc.toString();
- }
-}
-
-PropertyExpression variable() :
-{
- Token t;
- PropertyExpression left=null;
-}
-{
- (
- t=<ID>
- {
- left = new PropertyExpression(t.image);
- }
- )
- {
- return left;
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98a99d3b/qpid-jms-selector/src/main/javacc/StrictParser.jj
----------------------------------------------------------------------
diff --git a/qpid-jms-selector/src/main/javacc/StrictParser.jj b/qpid-jms-selector/src/main/javacc/StrictParser.jj
deleted file mode 100755
index dfe8dab..0000000
--- a/qpid-jms-selector/src/main/javacc/StrictParser.jj
+++ /dev/null
@@ -1,563 +0,0 @@
-/**
- * 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.
- */
-
-// ----------------------------------------------------------------------------
-// OPTIONS
-// ----------------------------------------------------------------------------
-options {
- STATIC = false;
- UNICODE_INPUT = true;
- // some performance optimizations
- ERROR_REPORTING = false;
-}
-
-// ----------------------------------------------------------------------------
-// PARSER
-// ----------------------------------------------------------------------------
-
-PARSER_BEGIN(StrictParser)
-/**
- * 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.strict;
-
-import java.io.*;
-import java.util.*;
-
-import org.apache.qpid.jms.selector.filter.*;
-
-/**
- * JMS Selector Parser generated by JavaCC
- *
- * Do not edit this .java file directly - it is autogenerated from StrictParser.jj
- */
-public class StrictParser {
- private BooleanExpression asBooleanExpression(Expression value) throws ParseException {
- if (value instanceof BooleanExpression) {
- return (BooleanExpression) value;
- }
- if (value instanceof PropertyExpression) {
- return UnaryExpression.createBooleanCast( value );
- }
- throw new ParseException("Expression will not result in a boolean value: " + value);
- }
-}
-
-PARSER_END(StrictParser)
-
-// ----------------------------------------------------------------------------
-// Tokens
-// ----------------------------------------------------------------------------
-
-/* White Space */
-SPECIAL_TOKEN :
-{
- " " | "\t" | "\n" | "\r" | "\f"
-}
-
-/* Comments */
-SKIP:
-{
- <LINE_COMMENT: "--" (~["\n","\r"])* ("\n"|"\r"|"\r\n") >
-}
-
-SKIP:
-{
- <BLOCK_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*","/"] (~["*"])* "*"))* "/">
-}
-
-/* Reserved Words */
-TOKEN [IGNORE_CASE] :
-{
- < NOT : "NOT">
- | < AND : "AND">
- | < OR : "OR">
- | < BETWEEN : "BETWEEN">
- | < LIKE : "LIKE">
- | < ESCAPE : "ESCAPE">
- | < IN : "IN">
- | < IS : "IS">
- | < TRUE : "TRUE" >
- | < FALSE : "FALSE" >
- | < NULL : "NULL" >
- | < XPATH : "XPATH" >
- | < XQUERY : "XQUERY" >
-}
-
-/* Literals */
-TOKEN [IGNORE_CASE] :
-{
-
- < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? >
- | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
- | < OCTAL_LITERAL: "0" (["0"-"7"])* >
- | < FLOATING_POINT_LITERAL:
- (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? // matches: 5.5 or 5. or 5.5E10 or 5.E10
- | "." (["0"-"9"])+ (<EXPONENT>)? // matches: .5 or .5E10
- | (["0"-"9"])+ <EXPONENT> // matches: 5E10
- >
- | < #EXPONENT: "E" (["+","-"])? (["0"-"9"])+ >
- | < STRING_LITERAL: "'" ( ("''") | ~["'"] )* "'" >
-}
-
-TOKEN [IGNORE_CASE] :
-{
- < ID : ["a"-"z", "_", "$"] (["a"-"z","0"-"9","_", "$"])* >
-}
-
-// ----------------------------------------------------------------------------
-// Grammer
-// ----------------------------------------------------------------------------
-BooleanExpression JmsSelector() :
-{
- Expression left=null;
-}
-{
- (
- left = orExpression()
- )
- {
- return asBooleanExpression(left);
- }
-
-}
-
-Expression orExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- (
- left = andExpression()
- (
- <OR> right = andExpression()
- {
- left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right));
- }
- )*
- )
- {
- return left;
- }
-
-}
-
-
-Expression andExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- (
- left = equalityExpression()
- (
- <AND> right = equalityExpression()
- {
- left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right));
- }
- )*
- )
- {
- return left;
- }
-}
-
-Expression equalityExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- (
- left = comparisonExpression()
- (
-
- "=" right = comparisonExpression()
- {
- left = ComparisonExpression.createEqual(left, right);
- }
- |
- "<>" right = comparisonExpression()
- {
- left = ComparisonExpression.createNotEqual(left, right);
- }
- |
- LOOKAHEAD(2)
- <IS> <NULL>
- {
- left = ComparisonExpression.createIsNull(left);
- }
- |
- <IS> <NOT> <NULL>
- {
- left = ComparisonExpression.createIsNotNull(left);
- }
- )*
- )
- {
- return left;
- }
-}
-
-Expression comparisonExpression() :
-{
- Expression left;
- Expression right;
- Expression low;
- Expression high;
- String t, u;
- boolean not;
- ArrayList list;
-}
-{
- (
- left = addExpression()
- (
-
- ">" right = addExpression()
- {
- left = ComparisonExpression.createGreaterThan(left, right);
- }
- |
- ">=" right = addExpression()
- {
- left = ComparisonExpression.createGreaterThanEqual(left, right);
- }
- |
- "<" right = addExpression()
- {
- left = ComparisonExpression.createLessThan(left, right);
- }
- |
- "<=" right = addExpression()
- {
- left = ComparisonExpression.createLessThanEqual(left, right);
- }
- |
- {
- u=null;
- }
- <LIKE> t = stringLitteral()
- [ <ESCAPE> u = stringLitteral() ]
- {
- left = ComparisonExpression.createLike(left, t, u);
- }
- |
- LOOKAHEAD(2)
- {
- u=null;
- }
- <NOT> <LIKE> t = stringLitteral() [ <ESCAPE> u = stringLitteral() ]
- {
- left = ComparisonExpression.createNotLike(left, t, u);
- }
- |
- <BETWEEN> low = addExpression() <AND> high = addExpression()
- {
- left = ComparisonExpression.createBetween(left, low, high);
- }
- |
- LOOKAHEAD(2)
- <NOT> <BETWEEN> low = addExpression() <AND> high = addExpression()
- {
- left = ComparisonExpression.createNotBetween(left, low, high);
- }
- |
- <IN>
- "("
- t = stringLitteral()
- {
- list = new ArrayList();
- list.add( t );
- }
- (
- ","
- t = stringLitteral()
- {
- list.add( t );
- }
-
- )*
- ")"
- {
- left = ComparisonExpression.createInFilter(left, list);
- }
- |
- LOOKAHEAD(2)
- <NOT> <IN>
- "("
- t = stringLitteral()
- {
- list = new ArrayList();
- list.add( t );
- }
- (
- ","
- t = stringLitteral()
- {
- list.add( t );
- }
-
- )*
- ")"
- {
- left = ComparisonExpression.createNotInFilter(left, list);
- }
-
- )*
- )
- {
- return left;
- }
-}
-
-Expression addExpression() :
-{
- Expression left;
- Expression right;
-}
-{
- left = multExpr()
- (
- LOOKAHEAD( ("+"|"-") multExpr())
- (
- "+" right = multExpr()
- {
- left = ArithmeticExpression.createPlus(left, right);
- }
- |
- "-" right = multExpr()
- {
- left = ArithmeticExpression.createMinus(left, right);
- }
- )
-
- )*
- {
- return left;
- }
-}
-
-Expression multExpr() :
-{
- Expression left;
- Expression right;
-}
-{
- left = unaryExpr()
- (
- "*" right = unaryExpr()
- {
- left = ArithmeticExpression.createMultiply(left, right);
- }
- |
- "/" right = unaryExpr()
- {
- left = ArithmeticExpression.createDivide(left, right);
- }
- |
- "%" right = unaryExpr()
- {
- left = ArithmeticExpression.createMod(left, right);
- }
-
- )*
- {
- return left;
- }
-}
-
-
-Expression unaryExpr() :
-{
- String s=null;
- Expression left=null;
-}
-{
- (
- LOOKAHEAD( "+" unaryExpr() )
- "+" left=unaryExpr()
- |
- "-" left=unaryExpr()
- {
- left = UnaryExpression.createNegate(left);
- }
- |
- <NOT> left=unaryExpr()
- {
- left = UnaryExpression.createNOT( asBooleanExpression(left) );
- }
- |
- <XPATH> s=stringLitteral()
- {
- left = UnaryExpression.createXPath( s );
- }
- |
- <XQUERY> s=stringLitteral()
- {
- left = UnaryExpression.createXQuery( s );
- }
- |
- left = primaryExpr()
- )
- {
- return left;
- }
-
-}
-
-Expression primaryExpr() :
-{
- Expression left=null;
-}
-{
- (
- left = literal()
- |
- left = variable()
- |
- "(" left = orExpression() ")"
- )
- {
- return left;
- }
-}
-
-
-
-ConstantExpression literal() :
-{
- Token t;
- String s;
- ConstantExpression left=null;
-}
-{
- (
- (
- s = stringLitteral()
- {
- left = new ConstantExpression(s);
- }
- )
- |
- (
- t = <DECIMAL_LITERAL>
- {
- left = ConstantExpression.createFromDecimal(t.image);
- }
- )
- |
- (
- t = <HEX_LITERAL>
- {
- left = ConstantExpression.createFromHex(t.image);
- }
- )
- |
- (
- t = <OCTAL_LITERAL>
- {
- left = ConstantExpression.createFromOctal(t.image);
- }
- )
- |
- (
- t = <FLOATING_POINT_LITERAL>
- {
- left = ConstantExpression.createFloat(t.image);
- }
- )
- |
- (
- <TRUE>
- {
- left = ConstantExpression.TRUE;
- }
- )
- |
- (
- <FALSE>
- {
- left = ConstantExpression.FALSE;
- }
- )
- |
- (
- <NULL>
- {
- left = ConstantExpression.NULL;
- }
- )
- )
- {
- return left;
- }
-}
-
-String stringLitteral() :
-{
- Token t;
- StringBuffer rc = new StringBuffer();
- boolean first=true;
-}
-{
- t = <STRING_LITERAL>
- {
- // Decode the sting value.
- String image = t.image;
- for( int i=1; i < image.length()-1; i++ ) {
- char c = image.charAt(i);
- if( c == '\'' )
- i++;
- rc.append(c);
- }
- return rc.toString();
- }
-}
-
-PropertyExpression variable() :
-{
- Token t;
- PropertyExpression left=null;
-}
-{
- (
- t=<ID>
- {
- left = new PropertyExpression(t.image);
- }
- )
- {
- return left;
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org