You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2016/01/04 20:55:44 UTC
svn commit: r1722953 [3/3] - in /qpid/java/trunk:
broker-core/src/main/java/org/apache/qpid/server/filter/
broker-plugins/management-http/
broker-plugins/management-http/src/main/grammar/
broker-plugins/management-http/src/main/java/org/apache/qpid/ser...
Added: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java?rev=1722953&view=auto
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java (added)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java Mon Jan 4 19:55:44 2016
@@ -0,0 +1,175 @@
+/*
+ *
+ * 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.server.management.plugin.servlet.rest;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.qpid.server.management.plugin.HttpManagementUtil;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Connection;
+import org.apache.qpid.server.model.Model;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.VirtualHostNode;
+
+public class VirtualHostQueryServlet extends QueryServlet<VirtualHost<?>>
+{
+ @Override
+ protected VirtualHost<?> getParent(final HttpServletRequest request)
+ {
+ final String[] path = getPathInfoElements(request);
+ final Broker<?> broker = HttpManagementUtil.getBroker(request.getServletContext());
+ VirtualHostNode<?> vhn = broker.getChildByName(VirtualHostNode.class, path[0]);
+ if(vhn != null)
+ {
+ return vhn.getChildByName(VirtualHost.class, path[1]);
+ }
+ return null;
+ }
+
+ protected Class<? extends ConfiguredObject> getSupportedCategory(final String categoryName,
+ final Model brokerModel)
+ {
+
+ Class<? extends ConfiguredObject> category = null;
+ for(Class<? extends ConfiguredObject> supportedCategory : brokerModel.getSupportedCategories())
+ {
+ if(categoryName.equalsIgnoreCase(supportedCategory.getSimpleName()))
+ {
+ category = supportedCategory;
+ break;
+ }
+ }
+ final Collection<Class<? extends ConfiguredObject>> ancestors = brokerModel.getAncestorCategories(category);
+ if(category == VirtualHost.class
+ || category == Connection.class
+ || ancestors.contains(VirtualHost.class)
+ || ancestors.contains(Connection.class))
+ {
+ return category;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ protected String getRequestedCategory(final HttpServletRequest request)
+ {
+ String[] pathInfoElements = getPathInfoElements(request);
+ if(pathInfoElements.length == 3)
+ {
+ return pathInfoElements[2];
+ }
+ return null;
+ }
+
+ protected List<ConfiguredObject<?>> getAllObjects(final VirtualHost<?> virtualHost,
+ final Class<? extends ConfiguredObject> category,
+ final HttpServletRequest request)
+ {
+ final Model model = virtualHost.getModel();
+ if(category == VirtualHost.class)
+ {
+ return Collections.<ConfiguredObject<?>>singletonList(virtualHost);
+ }
+ else if(model.getAncestorCategories(category).contains(VirtualHost.class))
+ {
+
+ List<Class<? extends ConfiguredObject>> hierarchy = new ArrayList<>();
+
+ Class<? extends ConfiguredObject> element = category;
+ while (element != null && element != VirtualHost.class)
+ {
+ hierarchy.add(element);
+ final Collection<Class<? extends ConfiguredObject>> parentTypes =
+ model.getParentTypes(element);
+ if(parentTypes == null || parentTypes.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ element = parentTypes.iterator().next();
+ }
+ }
+ Collections.reverse(hierarchy);
+ Collection<ConfiguredObject<?>> parents = Collections.<ConfiguredObject<?>>singletonList(virtualHost);
+ return getObjects(hierarchy, parents);
+ }
+ else
+ {
+ List<ConfiguredObject<?>> parents = new ArrayList<>();
+ parents.addAll(virtualHost.getConnections());
+
+ if(category == Connection.class)
+ {
+ return parents;
+ }
+ else
+ {
+ List<Class<? extends ConfiguredObject>> hierarchy = new ArrayList<>();
+
+ Class<? extends ConfiguredObject> element = category;
+ while (element != null && element != Connection.class)
+ {
+ hierarchy.add(element);
+ final Collection<Class<? extends ConfiguredObject>> parentTypes =
+ model.getParentTypes(element);
+ if (parentTypes == null || parentTypes.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ element = parentTypes.iterator().next();
+ }
+ }
+ Collections.reverse(hierarchy);
+
+ return getObjects(hierarchy, parents);
+ }
+ }
+ }
+
+ private List<ConfiguredObject<?>> getObjects(final List<Class<? extends ConfiguredObject>> hierarchy,
+ Collection<ConfiguredObject<?>> parents)
+ {
+ Collection<ConfiguredObject<?>> children = Collections.emptyList();
+ for(Class<? extends ConfiguredObject> childClass : hierarchy)
+ {
+ children = new HashSet<>();
+ for(ConfiguredObject<?> parent : parents)
+ {
+ children.addAll((Collection<? extends ConfiguredObject<?>>) parent.getChildren(childClass)) ;
+ }
+ parents = children;
+ }
+
+ return new ArrayList<>(children);
+ }
+}
Propchange: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostQueryServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: qpid/java/trunk/common/pom.xml
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/pom.xml?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/pom.xml (original)
+++ qpid/java/trunk/common/pom.xml Mon Jan 4 19:55:44 2016
@@ -32,7 +32,7 @@
<!-- used during the antrun-plugin execution -->
<generated-amqp-0-8-dir>${basedir}/src/main/java</generated-amqp-0-8-dir>
<generated-amqp-0-10-dir>${basedir}/src/main/java</generated-amqp-0-10-dir>
- <selector.output.dir>${basedir}/src/main/java/org/apache/qpid/filter/selector</selector.output.dir>
+ <selector.output.dir>${basedir}/src/main/java</selector.output.dir>
<qpid.name>qpid</qpid.name>
<qpid.version>${project.version}</qpid.version>
<qpid.version.suffix />
Modified: qpid/java/trunk/common/src/main/grammar/SelectorParser.jj
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/grammar/SelectorParser.jj?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/grammar/SelectorParser.jj (original)
+++ qpid/java/trunk/common/src/main/grammar/SelectorParser.jj Mon Jan 4 19:55:44 2016
@@ -72,6 +72,7 @@ import org.apache.qpid.filter.ConstantEx
import org.apache.qpid.filter.Expression;
import org.apache.qpid.filter.LogicExpression;
import org.apache.qpid.filter.PropertyExpression;
+import org.apache.qpid.filter.PropertyExpressionFactory;
import org.apache.qpid.filter.UnaryExpression;
/**
@@ -79,15 +80,28 @@ import org.apache.qpid.filter.UnaryExpre
*
* Do not edit this .java file directly - it is autogenerated from SelectorParser.jj
*/
-public class SelectorParser
+public class SelectorParser<E>
{
+ private PropertyExpressionFactory<E> _factory;
+ private boolean _allowNonPropertyInExpressions;
+
public SelectorParser()
{
this(new StringReader(""));
}
- public BooleanExpression parse(String sql) throws ParseException
+ public void setPropertyExpressionFactory(PropertyExpressionFactory<E> factory)
+ {
+ _factory = factory;
+ }
+
+ public void allowNonPropertyInExpressions(boolean allow)
+ {
+ _allowNonPropertyInExpressions = allow;
+ }
+
+ public BooleanExpression<E> parse(String sql) throws ParseException
{
this.ReInit(new StringReader(sql));
@@ -95,15 +109,15 @@ public class SelectorParser
}
- private BooleanExpression asBooleanExpression(Expression value) throws ParseException
+ private BooleanExpression<E> asBooleanExpression(Expression<E> value) throws ParseException
{
if (value instanceof BooleanExpression)
{
- return (BooleanExpression) value;
+ return (BooleanExpression<E>) value;
}
if (value instanceof PropertyExpression)
{
- return UnaryExpression.createBooleanCast( value );
+ return UnaryExpression.createBooleanCast( (Expression<E>) value );
}
throw new ParseException("Expression will not result in a boolean value: " + value);
}
@@ -349,7 +363,7 @@ Expression comparisonExpression() :
)*
")"
{
- left = ComparisonExpression.createInFilter(left, list);
+ left = ComparisonExpression.createInFilter(left, list, _allowNonPropertyInExpressions );
}
|
LOOKAHEAD(2)
@@ -370,7 +384,7 @@ Expression comparisonExpression() :
)*
")"
{
- left = ComparisonExpression.createNotInFilter(left, list);
+ left = ComparisonExpression.createNotInFilter(left, list, _allowNonPropertyInExpressions);
}
)*
@@ -586,7 +600,7 @@ PropertyExpression variable() :
(
t = <ID>
{
- left = new PropertyExpression(t.image);
+ left = _factory.createPropertyExpression(t.image);
}
|
t = <QUOTED_ID>
@@ -601,7 +615,7 @@ PropertyExpression variable() :
}
rc.append(c);
}
- return new PropertyExpression(rc.toString());
+ return _factory.createPropertyExpression(rc.toString());
}
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ArithmeticExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ArithmeticExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ArithmeticExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ArithmeticExpression.java Mon Jan 4 19:55:44 2016
@@ -23,21 +23,21 @@ package org.apache.qpid.filter;
/**
* An expression which performs an operation on two expression values
*/
-public abstract class ArithmeticExpression extends BinaryExpression
+public abstract class ArithmeticExpression<T> extends BinaryExpression<T>
{
protected static final int INTEGER = 1;
protected static final int LONG = 2;
protected static final int DOUBLE = 3;
- public ArithmeticExpression(Expression left, Expression right)
+ public ArithmeticExpression(Expression<T> left, Expression<T> right)
{
super(left, right);
}
- public static Expression createPlus(Expression left, Expression right)
+ public static <E> Expression<E> createPlus(Expression<E> left, Expression<E> right)
{
- return new ArithmeticExpression(left, right)
+ return new ArithmeticExpression<E>(left, right)
{
protected Object evaluate(Object lvalue, Object rvalue)
{
@@ -63,9 +63,9 @@ public abstract class ArithmeticExpressi
};
}
- public static Expression createMinus(Expression left, Expression right)
+ public static <E> Expression<E> createMinus(Expression<E> left, Expression<E> right)
{
- return new ArithmeticExpression(left, right)
+ return new ArithmeticExpression<E>(left, right)
{
protected Object evaluate(Object lvalue, Object rvalue)
{
@@ -84,9 +84,9 @@ public abstract class ArithmeticExpressi
};
}
- public static Expression createMultiply(Expression left, Expression right)
+ public static <E> Expression<E> createMultiply(Expression<E> left, Expression<E> right)
{
- return new ArithmeticExpression(left, right)
+ return new ArithmeticExpression<E>(left, right)
{
protected Object evaluate(Object lvalue, Object rvalue)
@@ -106,9 +106,9 @@ public abstract class ArithmeticExpressi
};
}
- public static Expression createDivide(Expression left, Expression right)
+ public static <E> Expression<E> createDivide(Expression<E> left, Expression<E> right)
{
- return new ArithmeticExpression(left, right)
+ return new ArithmeticExpression<E>(left, right)
{
protected Object evaluate(Object lvalue, Object rvalue)
@@ -128,9 +128,9 @@ public abstract class ArithmeticExpressi
};
}
- public static Expression createMod(Expression left, Expression right)
+ public static <E> Expression<E> createMod(Expression<E> left, Expression<E> right)
{
- return new ArithmeticExpression(left, right)
+ return new ArithmeticExpression<E>(left, right)
{
protected Object evaluate(Object lvalue, Object rvalue)
@@ -241,7 +241,7 @@ public abstract class ArithmeticExpressi
}
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(T message)
{
Object lvalue = getLeft().evaluate(message);
if (lvalue == null)
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BinaryExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BinaryExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BinaryExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BinaryExpression.java Mon Jan 4 19:55:44 2016
@@ -23,23 +23,23 @@ package org.apache.qpid.filter;
/**
* An expression which performs an operation on two expression values.
*/
-public abstract class BinaryExpression implements Expression
+public abstract class BinaryExpression<T> implements Expression<T>
{
- private final Expression left;
- private final Expression right;
+ private final Expression<T> left;
+ private final Expression<T> right;
- public BinaryExpression(Expression left, Expression right)
+ public BinaryExpression(Expression<T> left, Expression<T> right)
{
this.left = left;
this.right = right;
}
- public Expression getLeft()
+ public Expression<T> getLeft()
{
return left;
}
- public Expression getRight()
+ public Expression<T> getRight()
{
return right;
}
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BooleanExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BooleanExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BooleanExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/BooleanExpression.java Mon Jan 4 19:55:44 2016
@@ -24,13 +24,13 @@ package org.apache.qpid.filter;
* A BooleanExpression is an expression that always
* produces a Boolean result.
*/
-public interface BooleanExpression extends Expression
+public interface BooleanExpression<E> extends Expression<E>
{
/**
- * @param message message to match
+ * @param object object to match
* @return true if the expression evaluates to Boolean.TRUE.
*/
- public boolean matches(FilterableMessage message);
+ boolean matches(E object);
}
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ComparisonExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ComparisonExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ComparisonExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ComparisonExpression.java Mon Jan 4 19:55:44 2016
@@ -30,15 +30,15 @@ import java.util.regex.Pattern;
/**
* A filter performing a comparison of two objects
*/
-public abstract class ComparisonExpression extends BinaryExpression implements BooleanExpression
+public abstract class ComparisonExpression<T> extends BinaryExpression<T> implements BooleanExpression<T>
{
- public static BooleanExpression createBetween(Expression value, Expression left, Expression right)
+ public static <E> BooleanExpression<E> createBetween(Expression<E> value, Expression<E> left, Expression<E> right)
{
return LogicExpression.createAND(createGreaterThanEqual(value, left), createLessThanEqual(value, right));
}
- public static BooleanExpression createNotBetween(Expression value, Expression left, Expression right)
+ public static <E> BooleanExpression<E> createNotBetween(Expression<E> value, Expression<E> left, Expression<E> right)
{
return LogicExpression.createOR(createLessThan(value, left), createGreaterThan(value, right));
}
@@ -69,16 +69,16 @@ public abstract class ComparisonExpressi
REGEXP_CONTROL_CHARS.add('!');
}
- static class LikeExpression extends UnaryExpression implements BooleanExpression
+ static class LikeExpression<E> extends UnaryExpression<E> implements BooleanExpression<E>
{
private Pattern likePattern;
- public LikeExpression(Expression right, String like, int escape)
+ public LikeExpression(Expression<E> right, String like, int escape)
{
super(right);
- StringBuffer regexp = new StringBuffer(like.length() * 2);
+ StringBuilder regexp = new StringBuilder(like.length() * 2);
regexp.append("\\A"); // The beginning of the input
for (int i = 0; i < like.length(); i++)
{
@@ -131,7 +131,7 @@ public abstract class ComparisonExpressi
/**
* org.apache.activemq.filter.Expression#evaluate(MessageEvaluationContext)
*/
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Object rv = this.getRight().evaluate(message);
@@ -150,7 +150,7 @@ public abstract class ComparisonExpressi
return likePattern.matcher((String) rv).matches() ? Boolean.TRUE : Boolean.FALSE;
}
- public boolean matches(FilterableMessage message)
+ public boolean matches(E message)
{
Object object = evaluate(message);
@@ -158,7 +158,7 @@ public abstract class ComparisonExpressi
}
}
- public static BooleanExpression createLike(Expression left, String right, String escape)
+ public static <E> BooleanExpression<E> createLike(Expression<E> left, String right, String escape)
{
if ((escape != null) && (escape.length() != 1))
{
@@ -172,54 +172,54 @@ public abstract class ComparisonExpressi
c = 0xFFFF & escape.charAt(0);
}
- return new LikeExpression(left, right, c);
+ return new LikeExpression<>(left, right, c);
}
- public static BooleanExpression createNotLike(Expression left, String right, String escape)
+ public static <E> BooleanExpression<E> createNotLike(Expression<E> left, String right, String escape)
{
return UnaryExpression.createNOT(createLike(left, right, escape));
}
- public static BooleanExpression createInFilter(Expression left, List elements)
+ public static <E> BooleanExpression<E> createInFilter(Expression<E> left, List<?> elements, boolean allowNonProperties)
{
- if (!(left instanceof PropertyExpression))
+ if (!(allowNonProperties || left instanceof PropertyExpression))
{
throw new SelectorParsingException("Expected a property for In expression, got: " + left);
}
- return UnaryExpression.createInExpression((PropertyExpression) left, elements, false);
+ return UnaryExpression.createInExpression(left, elements, false);
}
- public static BooleanExpression createNotInFilter(Expression left, List elements)
+ public static <E> BooleanExpression<E> createNotInFilter(Expression<E> left, List<?> elements, boolean allowNonProperties)
{
- if (!(left instanceof PropertyExpression))
+ if (!(allowNonProperties || left instanceof PropertyExpression))
{
throw new SelectorParsingException("Expected a property for In expression, got: " + left);
}
- return UnaryExpression.createInExpression((PropertyExpression) left, elements, true);
+ return UnaryExpression.createInExpression(left, elements, true);
}
- public static BooleanExpression createIsNull(Expression left)
+ public static <E> BooleanExpression<E> createIsNull(Expression<E> left)
{
- return doCreateEqual(left, ConstantExpression.NULL);
+ return doCreateEqual(left, ConstantExpression.<E>NULL());
}
- public static BooleanExpression createIsNotNull(Expression left)
+ public static <E> BooleanExpression<E> createIsNotNull(Expression<E> left)
{
- return UnaryExpression.createNOT(doCreateEqual(left, ConstantExpression.NULL));
+ return UnaryExpression.createNOT(doCreateEqual(left, ConstantExpression.<E>NULL()));
}
- public static BooleanExpression createNotEqual(Expression left, Expression right)
+ public static <E> BooleanExpression<E> createNotEqual(Expression<E> left, Expression<E> right)
{
return UnaryExpression.createNOT(createEqual(left, right));
}
- public static BooleanExpression createEqual(Expression left, Expression right)
+ public static <E> BooleanExpression<E> createEqual(Expression<E> left, Expression<E> right)
{
checkEqualOperand(left);
checkEqualOperand(right);
@@ -228,17 +228,17 @@ public abstract class ComparisonExpressi
return doCreateEqual(left, right);
}
- private static BooleanExpression doCreateEqual(Expression left, Expression right)
+ private static <E> BooleanExpression<E> doCreateEqual(Expression<E> left, Expression<E> right)
{
- return new EqualExpression(left, right);
+ return new EqualExpression<>(left, right);
}
- public static BooleanExpression createGreaterThan(final Expression left, final Expression right)
+ public static <E> BooleanExpression<E> createGreaterThan(final Expression<E> left, final Expression<E> right)
{
checkLessThanOperand(left);
checkLessThanOperand(right);
- return new ComparisonExpression(left, right)
+ return new ComparisonExpression<E>(left, right)
{
protected boolean asBoolean(int answer)
{
@@ -252,12 +252,12 @@ public abstract class ComparisonExpressi
};
}
- public static BooleanExpression createGreaterThanEqual(final Expression left, final Expression right)
+ public static <E> BooleanExpression<E> createGreaterThanEqual(final Expression<E> left, final Expression<E> right)
{
checkLessThanOperand(left);
checkLessThanOperand(right);
- return new ComparisonExpression(left, right)
+ return new ComparisonExpression<E>(left, right)
{
protected boolean asBoolean(int answer)
{
@@ -271,12 +271,12 @@ public abstract class ComparisonExpressi
};
}
- public static BooleanExpression createLessThan(final Expression left, final Expression right)
+ public static <E> BooleanExpression<E> createLessThan(final Expression<E> left, final Expression<E> right)
{
checkLessThanOperand(left);
checkLessThanOperand(right);
- return new ComparisonExpression(left, right)
+ return new ComparisonExpression<E>(left, right)
{
protected boolean asBoolean(int answer)
@@ -292,12 +292,12 @@ public abstract class ComparisonExpressi
};
}
- public static BooleanExpression createLessThanEqual(final Expression left, final Expression right)
+ public static <E> BooleanExpression<E> createLessThanEqual(final Expression<E> left, final Expression<E> right)
{
checkLessThanOperand(left);
checkLessThanOperand(right);
- return new ComparisonExpression(left, right)
+ return new ComparisonExpression<E>(left, right)
{
protected boolean asBoolean(int answer)
@@ -317,7 +317,7 @@ public abstract class ComparisonExpressi
*
* @param expr expression to check
*/
- public static void checkLessThanOperand(Expression expr)
+ public static <E> void checkLessThanOperand(Expression<E> expr)
{
if (expr instanceof ConstantExpression)
{
@@ -343,7 +343,7 @@ public abstract class ComparisonExpressi
*
* @param expr expression to check
*/
- public static void checkEqualOperand(Expression expr)
+ public static <E> void checkEqualOperand(Expression<E> expr)
{
if (expr instanceof ConstantExpression)
{
@@ -355,12 +355,7 @@ public abstract class ComparisonExpressi
}
}
- /**
- *
- * @param left
- * @param right
- */
- private static void checkEqualOperandCompatability(Expression left, Expression right)
+ private static <E> void checkEqualOperandCompatability(Expression<E> left, Expression<E> right)
{
if ((left instanceof ConstantExpression) && (right instanceof ConstantExpression))
{
@@ -371,12 +366,12 @@ public abstract class ComparisonExpressi
}
}
- public ComparisonExpression(Expression left, Expression right)
+ public ComparisonExpression(Expression<T> left, Expression<T> right)
{
super(left, right);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(T message)
{
Comparable lv = (Comparable) getLeft().evaluate(message);
if (lv == null)
@@ -538,21 +533,21 @@ public abstract class ComparisonExpressi
protected abstract boolean asBoolean(int answer);
- public boolean matches(FilterableMessage message)
+ public boolean matches(T message)
{
Object object = evaluate(message);
return (object != null) && (object == Boolean.TRUE);
}
- private static class EqualExpression extends ComparisonExpression
+ private static class EqualExpression<E> extends ComparisonExpression<E>
{
- public EqualExpression(final Expression left, final Expression right)
+ public EqualExpression(final Expression<E> left, final Expression<E> right)
{
super(left, right);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Object lv = getLeft().evaluate(message);
Object rv = getRight().evaluate(message);
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ConstantExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ConstantExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ConstantExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/ConstantExpression.java Mon Jan 4 19:55:44 2016
@@ -28,17 +28,17 @@ import java.math.BigDecimal;
/**
* Represents a constant expression
*/
-public class ConstantExpression implements Expression
+public class ConstantExpression<T> implements Expression<T>
{
- static class BooleanConstantExpression extends ConstantExpression implements BooleanExpression
+ static class BooleanConstantExpression<E> extends ConstantExpression<E> implements BooleanExpression<E>
{
public BooleanConstantExpression(Object value)
{
super(value);
}
- public boolean matches(FilterableMessage message)
+ public boolean matches(E message)
{
Object object = evaluate(message);
@@ -50,9 +50,26 @@ public class ConstantExpression implemen
public static final BooleanConstantExpression TRUE = new BooleanConstantExpression(Boolean.TRUE);
public static final BooleanConstantExpression FALSE = new BooleanConstantExpression(Boolean.FALSE);
+
+
private Object _value;
- public static ConstantExpression createFromDecimal(String text)
+ public static <E> ConstantExpression<E> NULL()
+ {
+ return NULL;
+ }
+
+ public static <E> ConstantExpression<E> TRUE()
+ {
+ return TRUE;
+ }
+
+ public static <E> ConstantExpression<E> FALSE()
+ {
+ return FALSE;
+ }
+
+ public static <E> ConstantExpression<E> createFromDecimal(String text)
{
// Strip off the 'l' or 'L' if needed.
@@ -78,10 +95,10 @@ public class ConstantExpression implemen
value = value.intValue();
}
- return new ConstantExpression(value);
+ return new ConstantExpression<>(value);
}
- public static ConstantExpression createFromHex(String text)
+ public static <E> ConstantExpression<E> createFromHex(String text)
{
Number value = Long.parseLong(text.substring(2), 16);
long l = value.longValue();
@@ -90,10 +107,10 @@ public class ConstantExpression implemen
value = value.intValue();
}
- return new ConstantExpression(value);
+ return new ConstantExpression<>(value);
}
- public static ConstantExpression createFromOctal(String text)
+ public static <E> ConstantExpression<E> createFromOctal(String text)
{
Number value = Long.parseLong(text, 8);
long l = value.longValue();
@@ -102,14 +119,14 @@ public class ConstantExpression implemen
value = value.intValue();
}
- return new ConstantExpression(value);
+ return new ConstantExpression<>(value);
}
- public static ConstantExpression createFloat(String text)
+ public static <E> ConstantExpression<E> createFloat(String text)
{
Number value = new Double(text);
- return new ConstantExpression(value);
+ return new ConstantExpression<>(value);
}
public ConstantExpression(Object value)
@@ -117,7 +134,7 @@ public class ConstantExpression implemen
this._value = value;
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(T message)
{
return _value;
}
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/Expression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/Expression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/Expression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/Expression.java Mon Jan 4 19:55:44 2016
@@ -23,13 +23,13 @@ package org.apache.qpid.filter;
/**
* Represents an expression
*/
-public interface Expression
+public interface Expression<T>
{
/**
- * @param message message to evaluate
+ * @param object object to evaluate
* @return the value of this expression
*/
- public Object evaluate(FilterableMessage message);
+ public Object evaluate(T object);
}
Copied: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/JMSMessagePropertyExpression.java (from r1722330, qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java)
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/JMSMessagePropertyExpression.java?p2=qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/JMSMessagePropertyExpression.java&p1=qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java&r1=1722330&r2=1722953&rev=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/JMSMessagePropertyExpression.java Mon Jan 4 19:55:44 2016
@@ -24,27 +24,36 @@ package org.apache.qpid.filter;
//
+import java.util.HashMap;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-
/**
* Represents a property expression
*/
-public class PropertyExpression implements Expression
+public class JMSMessagePropertyExpression implements PropertyExpression<FilterableMessage>
{
+ public static final PropertyExpressionFactory<FilterableMessage> FACTORY = new PropertyExpressionFactory<FilterableMessage>()
+ {
+ @Override
+ public PropertyExpression<FilterableMessage> createPropertyExpression(final String value)
+ {
+ return new JMSMessagePropertyExpression(value);
+ }
+ };
+
// Constants - defined the same as JMS
private static enum JMSDeliveryMode { NON_PERSISTENT, PERSISTENT }
private static final int DEFAULT_PRIORITY = 4;
- private static final Logger _logger = LoggerFactory.getLogger(PropertyExpression.class);
+ private static final Logger _logger = LoggerFactory.getLogger(JMSMessagePropertyExpression.class);
private static final HashMap<String, Expression> JMS_PROPERTY_EXPRESSIONS = new HashMap<String, Expression>();
static
{
- JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new Expression()
+ JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new Expression<FilterableMessage>()
{
public Object evaluate(FilterableMessage message)
{
@@ -70,7 +79,7 @@ public class PropertyExpression implemen
JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new ExpirationExpression());
- JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new Expression()
+ JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new Expression<FilterableMessage>()
{
public Object evaluate(FilterableMessage message)
{
@@ -87,12 +96,10 @@ public class PropertyExpression implemen
return false;
}
- public PropertyExpression(String name)
+ private JMSMessagePropertyExpression(String name)
{
this.name = name;
-
-
jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
}
@@ -115,7 +122,7 @@ public class PropertyExpression implemen
}
/**
- * @see java.lang.Object#toString()
+ * @see Object#toString()
*/
public String toString()
{
@@ -123,7 +130,7 @@ public class PropertyExpression implemen
}
/**
- * @see java.lang.Object#hashCode()
+ * @see Object#hashCode()
*/
public int hashCode()
{
@@ -131,7 +138,7 @@ public class PropertyExpression implemen
}
/**
- * @see java.lang.Object#equals(java.lang.Object)
+ * @see Object#equals(Object)
*/
public boolean equals(Object o)
{
@@ -141,11 +148,11 @@ public class PropertyExpression implemen
return false;
}
- return name.equals(((PropertyExpression) o).name);
+ return name.equals(((JMSMessagePropertyExpression) o).name);
}
- private static class ReplyToExpression implements Expression
+ private static class ReplyToExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -155,7 +162,7 @@ public class PropertyExpression implemen
}
- private static class TypeExpression implements Expression
+ private static class TypeExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -166,7 +173,7 @@ public class PropertyExpression implemen
}
}
- private static class DeliveryModeExpression implements Expression
+ private static class DeliveryModeExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -181,7 +188,7 @@ public class PropertyExpression implemen
}
}
- private static class PriorityExpression implements Expression
+ private static class PriorityExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -190,7 +197,7 @@ public class PropertyExpression implemen
}
}
- private static class MessageIDExpression implements Expression
+ private static class MessageIDExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -202,7 +209,7 @@ public class PropertyExpression implemen
}
}
- private static class TimestampExpression implements Expression
+ private static class TimestampExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -211,7 +218,7 @@ public class PropertyExpression implemen
}
}
- private static class CorrelationIdExpression implements Expression
+ private static class CorrelationIdExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
@@ -222,7 +229,7 @@ public class PropertyExpression implemen
}
}
- private static class ExpirationExpression implements Expression
+ private static class ExpirationExpression implements Expression<FilterableMessage>
{
public Object evaluate(FilterableMessage message)
{
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/LogicExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/LogicExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/LogicExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/LogicExpression.java Mon Jan 4 19:55:44 2016
@@ -23,41 +23,41 @@ package org.apache.qpid.filter;
/**
* A filter performing a comparison of two objects
*/
-public abstract class LogicExpression extends BinaryExpression implements BooleanExpression
+public abstract class LogicExpression<T> extends BinaryExpression<T> implements BooleanExpression<T>
{
- public static BooleanExpression createOR(BooleanExpression lvalue, BooleanExpression rvalue)
+ public static <E> BooleanExpression<E> createOR(BooleanExpression<E> lvalue, BooleanExpression<E> rvalue)
{
- return new OrExpression(lvalue, rvalue);
+ return new OrExpression<>(lvalue, rvalue);
}
- public static BooleanExpression createAND(BooleanExpression lvalue, BooleanExpression rvalue)
+ public static <E> BooleanExpression<E> createAND(BooleanExpression<E> lvalue, BooleanExpression<E> rvalue)
{
- return new AndExpression(lvalue, rvalue);
+ return new AndExpression<>(lvalue, rvalue);
}
- public LogicExpression(BooleanExpression left, BooleanExpression right)
+ public LogicExpression(BooleanExpression<T> left, BooleanExpression<T> right)
{
super(left, right);
}
- public abstract Object evaluate(FilterableMessage message);
+ public abstract Object evaluate(T message);
- public boolean matches(FilterableMessage message)
+ public boolean matches(T message)
{
Object object = evaluate(message);
return (object != null) && (object == Boolean.TRUE);
}
- private static class OrExpression extends LogicExpression
+ private static class OrExpression<E> extends LogicExpression<E>
{
- public OrExpression(final BooleanExpression lvalue, final BooleanExpression rvalue)
+ public OrExpression(final BooleanExpression<E> lvalue, final BooleanExpression<E> rvalue)
{
super(lvalue, rvalue);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Boolean lv = (Boolean) getLeft().evaluate(message);
@@ -78,14 +78,14 @@ public abstract class LogicExpression ex
}
}
- private static class AndExpression extends LogicExpression
+ private static class AndExpression<E> extends LogicExpression<E>
{
- public AndExpression(final BooleanExpression lvalue, final BooleanExpression rvalue)
+ public AndExpression(final BooleanExpression<E> lvalue, final BooleanExpression<E> rvalue)
{
super(lvalue, rvalue);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Boolean lv = (Boolean) getLeft().evaluate(message);
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpression.java Mon Jan 4 19:55:44 2016
@@ -19,216 +19,11 @@
*
*/
package org.apache.qpid.filter;
-//
-// Based on like named file from r450141 of the Apache ActiveMQ project <http://www.activemq.org/site/home.html>
-//
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
-
/**
* Represents a property expression
*/
-public class PropertyExpression implements Expression
+public interface PropertyExpression<E> extends Expression<E>
{
- // Constants - defined the same as JMS
- private static enum JMSDeliveryMode { NON_PERSISTENT, PERSISTENT }
-
- private static final int DEFAULT_PRIORITY = 4;
-
- private static final Logger _logger = LoggerFactory.getLogger(PropertyExpression.class);
-
- private static final HashMap<String, Expression> JMS_PROPERTY_EXPRESSIONS = new HashMap<String, Expression>();
- static
- {
- JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new Expression()
- {
- public Object evaluate(FilterableMessage message)
- {
- //TODO
- return null;
- }
- });
- JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new ReplyToExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSType", new TypeExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new DeliveryModeExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new PriorityExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID", new MessageIDExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("AMQMessageID", new MessageIDExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSTimestamp", new TimestampExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSCorrelationID", new CorrelationIdExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSExpiration", new ExpirationExpression());
-
- JMS_PROPERTY_EXPRESSIONS.put("JMSRedelivered", new Expression()
- {
- public Object evaluate(FilterableMessage message)
- {
- return message.isRedelivered();
- }
- });
- }
-
- private final String name;
- private final Expression jmsPropertyExpression;
-
- public boolean outerTest()
- {
- return false;
- }
-
- public PropertyExpression(String name)
- {
- this.name = name;
-
-
-
- jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
- }
-
- public Object evaluate(FilterableMessage message)
- {
-
- if (jmsPropertyExpression != null)
- {
- return jmsPropertyExpression.evaluate(message);
- }
- else
- {
- return message.getHeader(name);
- }
- }
-
- public String getName()
- {
- return name;
- }
-
- /**
- * @see java.lang.Object#toString()
- */
- public String toString()
- {
- return name;
- }
-
- /**
- * @see java.lang.Object#hashCode()
- */
- public int hashCode()
- {
- return name.hashCode();
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object o)
- {
-
- if ((o == null) || !this.getClass().equals(o.getClass()))
- {
- return false;
- }
-
- return name.equals(((PropertyExpression) o).name);
-
- }
-
- private static class ReplyToExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
- String replyTo = message.getReplyTo();
- return replyTo;
- }
-
- }
-
- private static class TypeExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
-
- String type = message.getType();
- return type;
-
- }
- }
-
- private static class DeliveryModeExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
- JMSDeliveryMode mode = message.isPersistent() ? JMSDeliveryMode.PERSISTENT :
- JMSDeliveryMode.NON_PERSISTENT;
- if (_logger.isDebugEnabled())
- {
- _logger.debug("JMSDeliveryMode is :" + mode);
- }
-
- return mode.toString();
- }
- }
-
- private static class PriorityExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
- byte priority = message.getPriority();
- return (int) priority;
- }
- }
-
- private static class MessageIDExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
-
- String messageId = message.getMessageId();
-
- return messageId;
-
- }
- }
-
- private static class TimestampExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
- long timestamp = message.getTimestamp();
- return timestamp;
- }
- }
-
- private static class CorrelationIdExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
-
- String correlationId = message.getCorrelationId();
-
- return correlationId;
- }
- }
-
- private static class ExpirationExpression implements Expression
- {
- public Object evaluate(FilterableMessage message)
- {
- long expiration = message.getExpiration();
- return expiration;
-
- }
- }
}
Added: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpressionFactory.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpressionFactory.java?rev=1722953&view=auto
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpressionFactory.java (added)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpressionFactory.java Mon Jan 4 19:55:44 2016
@@ -0,0 +1,26 @@
+/*
+ *
+ * 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.filter;
+
+public interface PropertyExpressionFactory<E>
+{
+ PropertyExpression<E> createPropertyExpression(String value);
+}
Propchange: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/PropertyExpressionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/UnaryExpression.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/UnaryExpression.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/UnaryExpression.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/UnaryExpression.java Mon Jan 4 19:55:44 2016
@@ -31,22 +31,22 @@ import java.util.List;
/**
* An expression which performs an operation on two expression values
*/
-public abstract class UnaryExpression implements Expression
+public abstract class UnaryExpression<T> implements Expression<T>
{
private static final BigDecimal BD_LONG_MIN_VALUE = BigDecimal.valueOf(Long.MIN_VALUE);
- private Expression right;
+ private Expression<T> right;
- public static Expression createNegate(Expression left)
+ public static <E> Expression<E> createNegate(Expression<E> left)
{
- return new NegativeExpression(left);
+ return new NegativeExpression<>(left);
}
- public static BooleanExpression createInExpression(PropertyExpression right, List elements, final boolean not)
+ public static <E> BooleanExpression<E> createInExpression(Expression<E> right, List<?> elements, final boolean not)
{
// Use a HashSet if there are many elements.
- Collection t;
+ Collection<?> t;
if (elements.size() == 0)
{
t = null;
@@ -57,22 +57,22 @@ public abstract class UnaryExpression im
}
else
{
- t = new HashSet(elements);
+ t = new HashSet<>(elements);
}
- final Collection inList = t;
+ final Collection<?> inList = t;
- return new InExpression(right, inList, not);
+ return new InExpression<>(right, inList, not);
}
- abstract static class BooleanUnaryExpression extends UnaryExpression implements BooleanExpression
+ abstract static class BooleanUnaryExpression<E> extends UnaryExpression<E> implements BooleanExpression<E>
{
- public BooleanUnaryExpression(Expression left)
+ public BooleanUnaryExpression(Expression<E> left)
{
super(left);
}
- public boolean matches(FilterableMessage message)
+ public boolean matches(E message)
{
Object object = evaluate(message);
@@ -80,14 +80,14 @@ public abstract class UnaryExpression im
}
}
- public static BooleanExpression createNOT(BooleanExpression left)
+ public static <E> BooleanExpression<E> createNOT(BooleanExpression<E> left)
{
- return new NotExpression(left);
+ return new NotExpression<>(left);
}
- public static BooleanExpression createBooleanCast(Expression left)
+ public static <E> BooleanExpression<E> createBooleanCast(Expression<E> left)
{
- return new BooleanCastExpression(left);
+ return new BooleanCastExpression<>(left);
}
private static Number negate(Number left)
@@ -131,12 +131,12 @@ public abstract class UnaryExpression im
}
}
- public UnaryExpression(Expression left)
+ public UnaryExpression(Expression<T> left)
{
this.right = left;
}
- public Expression getRight()
+ public Expression<T> getRight()
{
return right;
}
@@ -177,14 +177,14 @@ public abstract class UnaryExpression im
*/
public abstract String getExpressionSymbol();
- private static class NegativeExpression extends UnaryExpression
+ private static class NegativeExpression<E> extends UnaryExpression<E>
{
- public NegativeExpression(final Expression left)
+ public NegativeExpression(final Expression<E> left)
{
super(left);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Object rvalue = getRight().evaluate(message);
if (rvalue == null)
@@ -206,19 +206,19 @@ public abstract class UnaryExpression im
}
}
- private static class InExpression extends BooleanUnaryExpression
+ private static class InExpression<E> extends BooleanUnaryExpression<E>
{
- private final Collection _inList;
+ private final Collection<?> _inList;
private final boolean _not;
- public InExpression(final PropertyExpression right, final Collection inList, final boolean not)
+ public InExpression(final Expression<E> right, final Collection<?> inList, final boolean not)
{
super(right);
_inList = inList;
_not = not;
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Object rvalue = getRight().evaluate(message);
@@ -227,12 +227,7 @@ public abstract class UnaryExpression im
return null;
}
- if (rvalue.getClass() != String.class)
- {
- return null;
- }
-
- if (((_inList != null) && _inList.contains(rvalue)) ^ _not)
+ if (((_inList != null) && isInList(rvalue, message)) ^ _not)
{
return Boolean.TRUE;
}
@@ -243,6 +238,25 @@ public abstract class UnaryExpression im
}
+ private boolean isInList(final Object rvalue, final E message)
+ {
+ for(Object entry : _inList)
+ {
+ Object value = entry instanceof Expression ? ((Expression<E>)entry).evaluate(message) : entry;
+ if((rvalue == null && value == null) || (rvalue != null && rvalue.equals(value)))
+ {
+ return true;
+ }
+ if(rvalue instanceof Number && value instanceof Number)
+ {
+ Number num1 = (Number) rvalue;
+ Number num2 = (Number) value;
+ return num1.doubleValue() == num2.doubleValue() && num1.longValue() == num2.longValue();
+ }
+ }
+ return false;
+ }
+
public String toString()
{
StringBuilder answer = new StringBuilder(String.valueOf(getRight()));
@@ -280,14 +294,14 @@ public abstract class UnaryExpression im
}
}
- private static class NotExpression extends BooleanUnaryExpression
+ private static class NotExpression<E> extends BooleanUnaryExpression<E>
{
- public NotExpression(final BooleanExpression left)
+ public NotExpression(final BooleanExpression<E> left)
{
super(left);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Boolean lvalue = (Boolean) getRight().evaluate(message);
if (lvalue == null)
@@ -304,14 +318,14 @@ public abstract class UnaryExpression im
}
}
- private static class BooleanCastExpression extends BooleanUnaryExpression
+ private static class BooleanCastExpression<E> extends BooleanUnaryExpression<E>
{
- public BooleanCastExpression(final Expression left)
+ public BooleanCastExpression(final Expression<E> left)
{
super(left);
}
- public Object evaluate(FilterableMessage message)
+ public Object evaluate(E message)
{
Object rvalue = getRight().evaluate(message);
if (rvalue == null)
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParser.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParser.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParser.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParser.java Mon Jan 4 19:55:44 2016
@@ -32,6 +32,7 @@ import org.apache.qpid.filter.ConstantEx
import org.apache.qpid.filter.Expression;
import org.apache.qpid.filter.LogicExpression;
import org.apache.qpid.filter.PropertyExpression;
+import org.apache.qpid.filter.PropertyExpressionFactory;
import org.apache.qpid.filter.UnaryExpression;
/**
@@ -39,14 +40,27 @@ import org.apache.qpid.filter.UnaryExpre
*
* Do not edit this .java file directly - it is autogenerated from SelectorParser.jj
*/
-public class SelectorParser implements SelectorParserConstants {
+public class SelectorParser<E> implements SelectorParserConstants {
+ private PropertyExpressionFactory<E> _factory;
+ private boolean _allowNonPropertyInExpressions;
+
public SelectorParser()
{
this(new StringReader(""));
}
- public BooleanExpression parse(String sql) throws ParseException
+ public void setPropertyExpressionFactory(PropertyExpressionFactory<E> factory)
+ {
+ _factory = factory;
+ }
+
+ public void allowNonPropertyInExpressions(boolean allow)
+ {
+ _allowNonPropertyInExpressions = allow;
+ }
+
+ public BooleanExpression<E> parse(String sql) throws ParseException
{
this.ReInit(new StringReader(sql));
@@ -54,15 +68,15 @@ public class SelectorParser implements S
}
- private BooleanExpression asBooleanExpression(Expression value) throws ParseException
+ private BooleanExpression<E> asBooleanExpression(Expression<E> value) throws ParseException
{
if (value instanceof BooleanExpression)
{
- return (BooleanExpression) value;
+ return (BooleanExpression<E>) value;
}
if (value instanceof PropertyExpression)
{
- return UnaryExpression.createBooleanCast( value );
+ return UnaryExpression.createBooleanCast( (Expression<E>) value );
}
throw new ParseException("Expression will not result in a boolean value: " + value);
}
@@ -283,7 +297,7 @@ public class SelectorParser implements S
list.add( t );
}
jj_consume_token(35);
- left = ComparisonExpression.createInFilter(left, list);
+ left = ComparisonExpression.createInFilter(left, list, _allowNonPropertyInExpressions );
break;
default:
if (jj_2_4(2)) {
@@ -307,7 +321,7 @@ public class SelectorParser implements S
list.add( t );
}
jj_consume_token(35);
- left = ComparisonExpression.createNotInFilter(left, list);
+ left = ComparisonExpression.createNotInFilter(left, list, _allowNonPropertyInExpressions);
} else {
jj_consume_token(-1);
throw new ParseException();
@@ -534,7 +548,7 @@ public class SelectorParser implements S
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case ID:
t = jj_consume_token(ID);
- left = new PropertyExpression(t.image);
+ left = _factory.createPropertyExpression(t.image);
break;
case QUOTED_ID:
t = jj_consume_token(QUOTED_ID);
@@ -548,7 +562,7 @@ public class SelectorParser implements S
}
rc.append(c);
}
- {if (true) return new PropertyExpression(rc.toString());}
+ {if (true) return _factory.createPropertyExpression(rc.toString());}
break;
default:
jj_consume_token(-1);
@@ -594,60 +608,6 @@ public class SelectorParser implements S
catch(LookaheadSuccess ls) { return true; }
}
- private boolean jj_3R_59() {
- if (jj_scan_token(ESCAPE)) return true;
- if (jj_3R_38()) return true;
- return false;
- }
-
- private boolean jj_3R_38() {
- if (jj_scan_token(STRING_LITERAL)) return true;
- return false;
- }
-
- private boolean jj_3R_15() {
- if (jj_3R_19()) return true;
- return false;
- }
-
- private boolean jj_3R_14() {
- if (jj_scan_token(NOT)) return true;
- if (jj_3R_10()) return true;
- return false;
- }
-
- private boolean jj_3R_12() {
- if (jj_scan_token(36)) return true;
- if (jj_3R_10()) return true;
- return false;
- }
-
- private boolean jj_3R_55() {
- if (jj_scan_token(IN)) return true;
- if (jj_scan_token(33)) return true;
- if (jj_3R_38()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_60()) { jj_scanpos = xsp; break; }
- }
- if (jj_scan_token(35)) return true;
- return false;
- }
-
- private boolean jj_3R_47() {
- if (jj_scan_token(IS)) return true;
- if (jj_scan_token(NOT)) return true;
- if (jj_scan_token(NULL)) return true;
- return false;
- }
-
- private boolean jj_3R_13() {
- if (jj_scan_token(37)) return true;
- if (jj_3R_10()) return true;
- return false;
- }
-
private boolean jj_3R_33() {
if (jj_scan_token(NULL)) return true;
return false;
@@ -1083,6 +1043,60 @@ public class SelectorParser implements S
if (jj_3R_10()) return true;
return false;
}
+
+ private boolean jj_3R_59() {
+ if (jj_scan_token(ESCAPE)) return true;
+ if (jj_3R_38()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_38() {
+ if (jj_scan_token(STRING_LITERAL)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_15() {
+ if (jj_3R_19()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_14() {
+ if (jj_scan_token(NOT)) return true;
+ if (jj_3R_10()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_12() {
+ if (jj_scan_token(36)) return true;
+ if (jj_3R_10()) return true;
+ return false;
+ }
+
+ private boolean jj_3R_55() {
+ if (jj_scan_token(IN)) return true;
+ if (jj_scan_token(33)) return true;
+ if (jj_3R_38()) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_60()) { jj_scanpos = xsp; break; }
+ }
+ if (jj_scan_token(35)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_47() {
+ if (jj_scan_token(IS)) return true;
+ if (jj_scan_token(NOT)) return true;
+ if (jj_scan_token(NULL)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_13() {
+ if (jj_scan_token(37)) return true;
+ if (jj_3R_10()) return true;
+ return false;
+ }
/** Generated Token Manager. */
public SelectorParserTokenManager token_source;
Modified: qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParserTokenManager.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParserTokenManager.java?rev=1722953&r1=1722952&r2=1722953&view=diff
==============================================================================
--- qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParserTokenManager.java (original)
+++ qpid/java/trunk/common/src/main/java/org/apache/qpid/filter/selector/SelectorParserTokenManager.java Mon Jan 4 19:55:44 2016
@@ -1,26 +1,37 @@
/* Generated By:JavaCC: Do not edit this line. SelectorParserTokenManager.java */
-/*
- *
- * 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.
- *
+/*
+ *
+ * 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.filter.selector;
+import java.io.StringReader;
+import java.util.ArrayList;
+import org.apache.qpid.filter.ArithmeticExpression;
+import org.apache.qpid.filter.BooleanExpression;
+import org.apache.qpid.filter.ComparisonExpression;
+import org.apache.qpid.filter.ConstantExpression;
+import org.apache.qpid.filter.Expression;
+import org.apache.qpid.filter.LogicExpression;
+import org.apache.qpid.filter.PropertyExpression;
+import org.apache.qpid.filter.PropertyExpressionFactory;
+import org.apache.qpid.filter.UnaryExpression;
/** Token Manager. */
public class SelectorParserTokenManager implements SelectorParserConstants
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org