KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > filter > AnyChildDestinationNode


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.filter;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24
25 /**
26  * An implementation of {@link DestinationNode} which navigates all the children of the given node
27  * ignoring the name of the current path (so for navigating using * in a wildcard).
28  *
29  * @version $Revision: 478324 $
30  */

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 JavaDoc answer, String JavaDoc[] paths, int startIndex) {
39         Iterator JavaDoc 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 JavaDoc answer, String JavaDoc[] paths, int startIndex) {
48         Iterator JavaDoc 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 JavaDoc answer) {
57         Iterator JavaDoc 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 JavaDoc path) {
65         final Collection JavaDoc list = new ArrayList JavaDoc();
66         Iterator JavaDoc 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 JavaDoc getChildNodes() {
77                     return list;
78                 }
79             };
80         }
81         return null;
82     }
83
84     public Collection JavaDoc getDesendentValues() {
85         Collection JavaDoc answer = new ArrayList JavaDoc();
86         Iterator JavaDoc 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 JavaDoc getValues() {
95         Collection JavaDoc answer = new ArrayList JavaDoc();
96         Iterator JavaDoc 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 JavaDoc getChildren() {
106         Collection JavaDoc answer = new ArrayList JavaDoc();
107         Iterator JavaDoc 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 JavaDoc removeDesendentValues() {
116         Collection JavaDoc answer = new ArrayList JavaDoc();
117         Iterator JavaDoc 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 JavaDoc removeValues() {
126         Collection JavaDoc answer = new ArrayList JavaDoc();
127         Iterator JavaDoc 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 JavaDoc getChildNodes() {
136         return node.getChildren();
137     }
138 }
139
140
141
Popular Tags