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
This commit is contained in:
Bosanac Dejan 2009-08-20 10:13:38 +00:00
parent 490dcf9bd2
commit 7d5131eaca
4 changed files with 54 additions and 4 deletions

View File

@ -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());
}
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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")));
}
}