1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 package org.jaxen;
65
66 import java.util.Iterator;
67
68 import org.jaxen.pattern.Pattern;
69 import org.jaxen.util.AncestorAxisIterator;
70 import org.jaxen.util.AncestorOrSelfAxisIterator;
71 import org.jaxen.util.DescendantAxisIterator;
72 import org.jaxen.util.DescendantOrSelfAxisIterator;
73 import org.jaxen.util.FollowingAxisIterator;
74 import org.jaxen.util.FollowingSiblingAxisIterator;
75 import org.jaxen.util.PrecedingAxisIterator;
76 import org.jaxen.util.PrecedingSiblingAxisIterator;
77 import org.jaxen.util.SelfAxisIterator;
78
79 /*** Default implementation of {@link Navigator}.
80 *
81 * <p>
82 * This implementation is an abstract class, since
83 * some required operations cannot be implemented without
84 * additional knowledge of the object model.
85 * </p>
86 *
87 * <p>
88 * When possible, default method implementations build
89 * upon each other, to reduce the number of methods required
90 * to be implemented for each object model. All methods,
91 * of course, may be overridden, to provide more-efficient
92 * implementations.
93 * </p>
94 *
95 * @author bob mcwhirter (bob@werken.com)
96 * @author Erwin Bolwidt (ejb@klomp.org)
97 */
98 public abstract class DefaultNavigator implements Navigator
99 {
100 /*** Throws <code>UnsupportedAxisException</code>
101 */
102 public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException
103 {
104 throw new UnsupportedAxisException("child");
105 }
106
107 public Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException
108 {
109 return new DescendantAxisIterator( contextNode,
110 this );
111 }
112
113 /*** Throws <code>UnsupportedAxisException</code>
114 */
115 public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException
116 {
117 throw new UnsupportedAxisException("parent");
118 }
119
120 public Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException
121 {
122 return new AncestorAxisIterator( contextNode,
123 this );
124 }
125
126 /*** Throws <code>UnsupportedAxisException</code>
127 */
128 public Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException
129 {
130 return new FollowingSiblingAxisIterator( contextNode,
131 this );
132 }
133
134 /*** Throws <code>UnsupportedAxisException</code>
135 */
136 public Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException
137 {
138 return new PrecedingSiblingAxisIterator( contextNode,
139 this );
140 }
141
142 /*** Throws <code>UnsupportedAxisException</code>
143 */
144 public Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException
145 {
146 return new FollowingAxisIterator( contextNode,
147 this );
148
149
150 }
151
152 /*** Throws <code>UnsupportedAxisException</code>
153 */
154 public Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException
155 {
156 return new PrecedingAxisIterator( contextNode,
157 this );
158
159
160 }
161
162 /*** Throws <code>UnsupportedAxisException</code>
163 */
164 public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException
165 {
166 throw new UnsupportedAxisException("attribute");
167 }
168
169 /*** Throws <code>UnsupportedAxisException</code>
170 */
171 public Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException
172 {
173 throw new UnsupportedAxisException("namespace");
174 }
175
176 public Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException
177 {
178 return new SelfAxisIterator( contextNode );
179 }
180
181 public Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException
182 {
183 return new DescendantOrSelfAxisIterator( contextNode,
184 this );
185 }
186
187 public Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException
188 {
189 return new AncestorOrSelfAxisIterator( contextNode,
190 this );
191 }
192
193 public Object getDocumentNode(Object contextNode)
194 {
195 return null;
196 }
197
198 public String translateNamespacePrefixToUri(String prefix, Object element)
199 {
200 return null;
201 }
202
203 public String getProcessingInstructionTarget(Object obj)
204 {
205 return null;
206 }
207
208 public String getProcessingInstructionData(Object obj)
209 {
210 return null;
211 }
212
213 public short getNodeType(Object node)
214 {
215 if ( isElement(node) )
216 {
217 return Pattern.ELEMENT_NODE;
218 }
219 else if ( isAttribute(node) )
220 {
221 return Pattern.ATTRIBUTE_NODE;
222 }
223 else if ( isText(node) )
224 {
225 return Pattern.TEXT_NODE;
226 }
227 else if ( isComment(node) )
228 {
229 return Pattern.COMMENT_NODE;
230 }
231 else if ( isDocument(node) )
232 {
233 return Pattern.DOCUMENT_NODE;
234 }
235 else if ( isProcessingInstruction(node) )
236 {
237 return Pattern.PROCESSING_INSTRUCTION_NODE;
238 }
239 else {
240 return Pattern.UNKNOWN_NODE;
241 }
242 }
243
244 public Object getParentNode(Object contextNode) throws UnsupportedAxisException
245 {
246 Iterator iter = getParentAxisIterator( contextNode );
247 if ( iter != null && iter.hasNext() )
248 {
249 return iter.next();
250 }
251 return null;
252 }
253
254 public Object getDocument(String url) throws FunctionCallException
255 {
256 return null;
257 }
258
259 /***
260 * Default implementation that cannot find elements. Override in subclass
261 * if subclass does know about attribute types.
262 *
263 * @param contextNode a node from the document in which to look for the
264 * id
265 * @param elementId id to look for
266 *
267 * @return null
268 */
269 public Object getElementById(Object contextNode, String elementId)
270 {
271 return null;
272 }
273 }