fixed edge cases in DestinationMap

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@365882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-01-04 10:30:40 +00:00
parent 6cbd6d2e8d
commit 664b534be5
3 changed files with 48 additions and 14 deletions

View File

@ -27,10 +27,24 @@ import org.springframework.beans.factory.InitializingBean;
* *
* @version $Revision: 1.1 $ * @version $Revision: 1.1 $
*/ */
public abstract class DestinationMapEntry implements InitializingBean { public abstract class DestinationMapEntry implements InitializingBean, Comparable {
private ActiveMQDestination destination; private ActiveMQDestination destination;
public int compareTo(Object that) {
if (that instanceof DestinationMapEntry) {
DestinationMapEntry thatEntry = (DestinationMapEntry) that;
return ActiveMQDestination.compare(destination, thatEntry.destination);
}
else if (that == null) {
return 1;
}
else {
return getClass().getName().compareTo(that.getClass().getName());
}
}
/** /**
* A helper method to set the destination from a configuration file * A helper method to set the destination from a configuration file
*/ */

View File

@ -38,14 +38,13 @@ public class DestinationMapNode {
protected static final String ANY_CHILD = DestinationMap.ANY_CHILD; protected static final String ANY_CHILD = DestinationMap.ANY_CHILD;
protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT; protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
public DestinationMapNode(DestinationMapNode parent) { public DestinationMapNode(DestinationMapNode parent) {
this.parent = parent; this.parent = parent;
} }
/** /**
* Returns the child node for the given named path or null if it does not exist * Returns the child node for the given named path or null if it does not
* exist
*/ */
public DestinationMapNode getChild(String path) { public DestinationMapNode getChild(String path) {
return (DestinationMapNode) childNodes.get(path); return (DestinationMapNode) childNodes.get(path);
@ -56,8 +55,8 @@ public class DestinationMapNode {
} }
/** /**
* Returns the child node for the given named path, lazily creating one if it does * Returns the child node for the given named path, lazily creating one if
* not yet exist * it does not yet exist
*/ */
public DestinationMapNode getChildOrCreate(String path) { public DestinationMapNode getChildOrCreate(String path) {
DestinationMapNode answer = (DestinationMapNode) childNodes.get(path); DestinationMapNode answer = (DestinationMapNode) childNodes.get(path);
@ -169,10 +168,12 @@ public class DestinationMapNode {
public void appendMatchingValues(Set answer, String[] paths, int startIndex) { public void appendMatchingValues(Set answer, String[] paths, int startIndex) {
DestinationMapNode node = this; DestinationMapNode node = this;
boolean couldMatchAny = true;
for (int i = startIndex, size = paths.length; i < size && node != null; i++) { for (int i = startIndex, size = paths.length; i < size && node != null; i++) {
String path = paths[i]; String path = paths[i];
if (path.equals(ANY_DESCENDENT)) { if (path.equals(ANY_DESCENDENT)) {
answer.addAll(node.getDesendentValues()); answer.addAll(node.getDesendentValues());
couldMatchAny = false;
break; break;
} }
@ -186,9 +187,15 @@ public class DestinationMapNode {
} }
if (node != null) { if (node != null) {
answer.addAll(node.getValues()); answer.addAll(node.getValues());
if (couldMatchAny) {
// lets allow FOO.BAR to match the FOO.BAR.> entry in the map
DestinationMapNode child = node.getChild(ANY_DESCENDENT);
if (child != null) {
answer.addAll(child.getValues());
}
}
} }
} }
public String getPath() { public String getPath() {
return path; return path;
@ -200,7 +207,6 @@ public class DestinationMapNode {
} }
} }
protected void removeChild(DestinationMapNode node) { protected void removeChild(DestinationMapNode node) {
childNodes.remove(node.getPath()); childNodes.remove(node.getPath());
pruneIfEmpty(); pruneIfEmpty();

View File

@ -180,6 +180,20 @@ public class DestinationMapTest extends TestCase {
assertMapValue("TEST.BAR.*", v2, v5, v6); assertMapValue("TEST.BAR.*", v2, v5, v6);
} }
public void testAnyPathWildcardInMap() throws Exception {
put("TEST.FOO.>", v1);
assertMapValue("TEST.FOO.BAR.WHANOT.A.B.C", v1);
assertMapValue("TEST.FOO.BAR.WHANOT", v1);
assertMapValue("TEST.FOO.BAR", v1);
assertMapValue("TEST.*.*", v1);
assertMapValue("TEST.BAR", null);
assertMapValue("TEST.FOO", v1);
}
public void testSimpleAddRemove() throws Exception { public void testSimpleAddRemove() throws Exception {
put("TEST.D1", v2); put("TEST.D1", v2);