001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.activemq.filter;
018
019 import java.util.ArrayList;
020 import java.util.Collection;
021 import java.util.Iterator;
022 import java.util.Set;
023
024 /**
025 * An implementation of {@link DestinationNode} which navigates all the children of the given node
026 * ignoring the name of the current path (so for navigating using * in a wildcard).
027 *
028 *
029 */
030 public class AnyChildDestinationNode implements DestinationNode {
031 private DestinationNode node;
032
033 public AnyChildDestinationNode(DestinationNode node) {
034 this.node = node;
035 }
036
037 public void appendMatchingValues(Set answer, String[] paths, int startIndex) {
038 Iterator iter = getChildNodes().iterator();
039 while (iter.hasNext()) {
040 DestinationNode child = (DestinationNode) iter.next();
041 child.appendMatchingValues(answer, paths, startIndex);
042 }
043 }
044
045
046 public void appendMatchingWildcards(Set answer, String[] paths, int startIndex) {
047 Iterator iter = getChildNodes().iterator();
048 while (iter.hasNext()) {
049 DestinationNode child = (DestinationNode) iter.next();
050 child.appendMatchingWildcards(answer, paths, startIndex);
051 }
052 }
053
054
055 public void appendDescendantValues(Set answer) {
056 Iterator iter = getChildNodes().iterator();
057 while (iter.hasNext()) {
058 DestinationNode child = (DestinationNode) iter.next();
059 child.appendDescendantValues(answer);
060 }
061 }
062
063 public DestinationNode getChild(String path) {
064 final Collection list = new ArrayList();
065 Iterator iter = getChildNodes().iterator();
066 while (iter.hasNext()) {
067 DestinationNode child = (DestinationNode) iter.next();
068 DestinationNode answer = child.getChild(path);
069 if (answer != null) {
070 list.add(answer);
071 }
072 }
073 if (!list.isEmpty()) {
074 return new AnyChildDestinationNode(this) {
075 protected Collection getChildNodes() {
076 return list;
077 }
078 };
079 }
080 return null;
081 }
082
083 public Collection getDesendentValues() {
084 Collection answer = new ArrayList();
085 Iterator iter = getChildNodes().iterator();
086 while (iter.hasNext()) {
087 DestinationNode child = (DestinationNode) iter.next();
088 answer.addAll(child.getDesendentValues());
089 }
090 return answer;
091 }
092
093 public Collection getValues() {
094 Collection answer = new ArrayList();
095 Iterator iter = getChildNodes().iterator();
096 while (iter.hasNext()) {
097 DestinationNode child = (DestinationNode) iter.next();
098 answer.addAll(child.getValues());
099 }
100 return answer;
101 }
102
103
104 public Collection getChildren() {
105 Collection answer = new ArrayList();
106 Iterator iter = getChildNodes().iterator();
107 while (iter.hasNext()) {
108 DestinationNode child = (DestinationNode) iter.next();
109 answer.addAll(child.getChildren());
110 }
111 return answer;
112 }
113
114 public Collection removeDesendentValues() {
115 Collection answer = new ArrayList();
116 Iterator iter = getChildNodes().iterator();
117 while (iter.hasNext()) {
118 DestinationNode child = (DestinationNode) iter.next();
119 answer.addAll(child.removeDesendentValues());
120 }
121 return answer;
122 }
123
124 public Collection removeValues() {
125 Collection answer = new ArrayList();
126 Iterator iter = getChildNodes().iterator();
127 while (iter.hasNext()) {
128 DestinationNode child = (DestinationNode) iter.next();
129 answer.addAll(child.removeValues());
130 }
131 return answer;
132 }
133
134 protected Collection getChildNodes() {
135 return node.getChildren();
136 }
137 }
138
139