From 7d5131eacaf69d85e0f957c8754acdfb7bffdcfc Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Thu, 20 Aug 2009 10:13:38 +0000 Subject: [PATCH] fix for https://issues.apache.org/activemq/browse/AMQ-2360 - destination filters and destination types git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@806105 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/filter/DestinationFilter.java | 4 +- .../filter/PrefixDestinationFilter.java | 5 ++- .../filter/WildcardDestinationFilter.java | 5 ++- .../filter/DestinationFilterTest.java | 44 +++++++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java index 1e7a7933c6..b0dfea7a46 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java @@ -60,12 +60,12 @@ public abstract class DestinationFilter implements BooleanExpression { if (idx >= 0) { String lastPath = paths[idx]; if (lastPath.equals(ANY_DESCENDENT)) { - return new PrefixDestinationFilter(paths); + return new PrefixDestinationFilter(paths, destination.getDestinationType()); } else { while (idx >= 0) { lastPath = paths[idx--]; if (lastPath.equals(ANY_CHILD)) { - return new WildcardDestinationFilter(paths); + return new WildcardDestinationFilter(paths, destination.getDestinationType()); } } } diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java b/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java index 6366b71a57..afc5ad74ba 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java @@ -28,17 +28,20 @@ import org.apache.activemq.command.ActiveMQDestination; public class PrefixDestinationFilter extends DestinationFilter { private String[] prefixes; + private byte destinationType; /** * An array of paths, the last path is '>' * * @param prefixes */ - public PrefixDestinationFilter(String[] prefixes) { + public PrefixDestinationFilter(String[] prefixes, byte destinationType) { this.prefixes = prefixes; + this.destinationType = destinationType; } public boolean matches(ActiveMQDestination destination) { + if (destination.getDestinationType() != destinationType) return false; String[] path = DestinationPath.getDestinationPaths(destination.getPhysicalName()); int length = prefixes.length; if (path.length >= length) { diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java b/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java index 173e8562ac..4840ea71a3 100755 --- a/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java @@ -28,13 +28,14 @@ import org.apache.activemq.command.ActiveMQDestination; public class WildcardDestinationFilter extends DestinationFilter { private String[] prefixes; + private byte destinationType; /** * An array of paths containing * characters * * @param prefixes */ - public WildcardDestinationFilter(String[] prefixes) { + public WildcardDestinationFilter(String[] prefixes, byte destinationType) { this.prefixes = new String[prefixes.length]; for (int i = 0; i < prefixes.length; i++) { String prefix = prefixes[i]; @@ -42,9 +43,11 @@ public class WildcardDestinationFilter extends DestinationFilter { this.prefixes[i] = prefix; } } + this.destinationType = destinationType; } public boolean matches(ActiveMQDestination destination) { + if (destination.getDestinationType() != destinationType) return false; String[] path = DestinationPath.getDestinationPaths(destination); int length = prefixes.length; if (path.length == length) { diff --git a/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java b/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java new file mode 100644 index 0000000000..53ea0e78f7 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java @@ -0,0 +1,44 @@ +/** + * 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.activemq.filter; + +import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.command.ActiveMQTopic; + +import junit.framework.TestCase; + +public class DestinationFilterTest extends TestCase { + + public void testPrefixFilter() throws Exception { + DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue(">")); + assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof PrefixDestinationFilter); + System.out.println(filter); + assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic(">"))); + } + + public void testWildcardFilter() throws Exception { + DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.*")); + assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof WildcardDestinationFilter); + assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B"))); + } + + public void testCompositeFilter() throws Exception { + DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue("A.B,B.C")); + assertTrue("Filter not parsed well: " + filter.getClass(), filter instanceof CompositeDestinationFilter); + assertFalse("Filter matched wrong destination type", filter.matches(new ActiveMQTopic("A.B"))); + } +}