1 18 package org.apache.activemq.filter; 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 25 31 public class AnyChildDestinationNode implements DestinationNode { 32 private DestinationNode node; 33 34 public AnyChildDestinationNode(DestinationNode node) { 35 this.node = node; 36 } 37 38 public void appendMatchingValues(Set answer, String [] paths, int startIndex) { 39 Iterator iter = getChildNodes().iterator(); 40 while (iter.hasNext()) { 41 DestinationNode child = (DestinationNode) iter.next(); 42 child.appendMatchingValues(answer, paths, startIndex); 43 } 44 } 45 46 47 public void appendMatchingWildcards(Set answer, String [] paths, int startIndex) { 48 Iterator iter = getChildNodes().iterator(); 49 while (iter.hasNext()) { 50 DestinationNode child = (DestinationNode) iter.next(); 51 child.appendMatchingWildcards(answer, paths, startIndex); 52 } 53 } 54 55 56 public void appendDescendantValues(Set answer) { 57 Iterator iter = getChildNodes().iterator(); 58 while (iter.hasNext()) { 59 DestinationNode child = (DestinationNode) iter.next(); 60 child.appendDescendantValues(answer); 61 } 62 } 63 64 public DestinationNode getChild(String path) { 65 final Collection list = new ArrayList (); 66 Iterator iter = getChildNodes().iterator(); 67 while (iter.hasNext()) { 68 DestinationNode child = (DestinationNode) iter.next(); 69 DestinationNode answer = child.getChild(path); 70 if (answer != null) { 71 list.add(answer); 72 } 73 } 74 if (!list.isEmpty()) { 75 return new AnyChildDestinationNode(this) { 76 protected Collection getChildNodes() { 77 return list; 78 } 79 }; 80 } 81 return null; 82 } 83 84 public Collection getDesendentValues() { 85 Collection answer = new ArrayList (); 86 Iterator iter = getChildNodes().iterator(); 87 while (iter.hasNext()) { 88 DestinationNode child = (DestinationNode) iter.next(); 89 answer.addAll(child.getDesendentValues()); 90 } 91 return answer; 92 } 93 94 public Collection getValues() { 95 Collection answer = new ArrayList (); 96 Iterator iter = getChildNodes().iterator(); 97 while (iter.hasNext()) { 98 DestinationNode child = (DestinationNode) iter.next(); 99 answer.addAll(child.getValues()); 100 } 101 return answer; 102 } 103 104 105 public Collection getChildren() { 106 Collection answer = new ArrayList (); 107 Iterator iter = getChildNodes().iterator(); 108 while (iter.hasNext()) { 109 DestinationNode child = (DestinationNode) iter.next(); 110 answer.addAll(child.getChildren()); 111 } 112 return answer; 113 } 114 115 public Collection removeDesendentValues() { 116 Collection answer = new ArrayList (); 117 Iterator iter = getChildNodes().iterator(); 118 while (iter.hasNext()) { 119 DestinationNode child = (DestinationNode) iter.next(); 120 answer.addAll(child.removeDesendentValues()); 121 } 122 return answer; 123 } 124 125 public Collection removeValues() { 126 Collection answer = new ArrayList (); 127 Iterator iter = getChildNodes().iterator(); 128 while (iter.hasNext()) { 129 DestinationNode child = (DestinationNode) iter.next(); 130 answer.addAll(child.removeValues()); 131 } 132 return answer; 133 } 134 135 protected Collection getChildNodes() { 136 return node.getChildren(); 137 } 138 } 139 140 141 | Popular Tags |