| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| DefaultNavigator |
|
| 1.9523809523809523;1.952 |
| 1 | /* |
|
| 2 | * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/DefaultNavigator.java,v 1.17 2005/06/28 13:44:44 elharo Exp $ |
|
| 3 | * $Revision: 1.17 $ |
|
| 4 | * $Date: 2005/06/28 13:44:44 $ |
|
| 5 | * |
|
| 6 | * ==================================================================== |
|
| 7 | * |
|
| 8 | * Copyright (C) 2000-2002 bob mcwhirter & James Strachan. |
|
| 9 | * All rights reserved. |
|
| 10 | * |
|
| 11 | * Redistribution and use in source and binary forms, with or without |
|
| 12 | * modification, are permitted provided that the following conditions |
|
| 13 | * are met: |
|
| 14 | * |
|
| 15 | * 1. Redistributions of source code must retain the above copyright |
|
| 16 | * notice, this list of conditions, and the following disclaimer. |
|
| 17 | * |
|
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
|
| 19 | * notice, this list of conditions, and the disclaimer that follows |
|
| 20 | * these conditions in the documentation and/or other materials |
|
| 21 | * provided with the distribution. |
|
| 22 | * |
|
| 23 | * 3. The name "Jaxen" must not be used to endorse or promote products |
|
| 24 | * derived from this software without prior written permission. For |
|
| 25 | * written permission, please contact license@jaxen.org. |
|
| 26 | * |
|
| 27 | * 4. Products derived from this software may not be called "Jaxen", nor |
|
| 28 | * may "Jaxen" appear in their name, without prior written permission |
|
| 29 | * from the Jaxen Project Management (pm@jaxen.org). |
|
| 30 | * |
|
| 31 | * In addition, we request (but do not require) that you include in the |
|
| 32 | * end-user documentation provided with the redistribution and/or in the |
|
| 33 | * software itself an acknowledgement equivalent to the following: |
|
| 34 | * "This product includes software developed by the |
|
| 35 | * Jaxen Project <http://www.jaxen.org/>." |
|
| 36 | * Alternatively, the acknowledgment may be graphical using the logos |
|
| 37 | * available at http://www.jaxen.org/ |
|
| 38 | * |
|
| 39 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
|
| 40 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
| 41 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
| 42 | * DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT |
|
| 43 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
| 45 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
| 46 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
| 47 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
| 48 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
|
| 49 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
| 50 | * SUCH DAMAGE. |
|
| 51 | * |
|
| 52 | * ==================================================================== |
|
| 53 | * This software consists of voluntary contributions made by many |
|
| 54 | * individuals on behalf of the Jaxen Project and was originally |
|
| 55 | * created by bob mcwhirter <bob@werken.com> and |
|
| 56 | * James Strachan <jstrachan@apache.org>. For more information on the |
|
| 57 | * Jaxen Project, please see <http://www.jaxen.org/>. |
|
| 58 | * |
|
| 59 | * $Id: DefaultNavigator.java,v 1.17 2005/06/28 13:44:44 elharo Exp $ |
|
| 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 | 7014 | public abstract class DefaultNavigator implements Navigator |
| 99 | { |
|
| 100 | ||
| 101 | /** Throws <code>UnsupportedAxisException</code> |
|
| 102 | * |
|
| 103 | * @param contextNode |
|
| 104 | * @return never returns |
|
| 105 | * @throws UnsupportedAxisException always |
|
| 106 | */ |
|
| 107 | public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 108 | { |
|
| 109 | 0 | throw new UnsupportedAxisException("child"); |
| 110 | } |
|
| 111 | ||
| 112 | /* (non-Javadoc) |
|
| 113 | * @see org.jaxen.Navigator#getDescendantAxisIterator(java.lang.Object) |
|
| 114 | */ |
|
| 115 | public Iterator getDescendantAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 116 | { |
|
| 117 | 498 | return new DescendantAxisIterator( contextNode, |
| 118 | this ); |
|
| 119 | } |
|
| 120 | ||
| 121 | /** Throws <code>UnsupportedAxisException</code> |
|
| 122 | * |
|
| 123 | * @param contextNode |
|
| 124 | * @return never returns |
|
| 125 | * @throws UnsupportedAxisException |
|
| 126 | */ |
|
| 127 | public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 128 | { |
|
| 129 | 0 | throw new UnsupportedAxisException("parent"); |
| 130 | } |
|
| 131 | ||
| 132 | public Iterator getAncestorAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 133 | { |
|
| 134 | 120 | return new AncestorAxisIterator( contextNode, |
| 135 | this ); |
|
| 136 | } |
|
| 137 | ||
| 138 | ||
| 139 | public Iterator getFollowingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 140 | { |
|
| 141 | 41184 | return new FollowingSiblingAxisIterator( contextNode, |
| 142 | this ); |
|
| 143 | } |
|
| 144 | ||
| 145 | ||
| 146 | public Iterator getPrecedingSiblingAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 147 | { |
|
| 148 | 198 | return new PrecedingSiblingAxisIterator( contextNode, |
| 149 | this ); |
|
| 150 | } |
|
| 151 | ||
| 152 | public Iterator getFollowingAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 153 | { |
|
| 154 | 144 | return new FollowingAxisIterator( contextNode, |
| 155 | this ); |
|
| 156 | ||
| 157 | // throw new UnsupportedAxisException("following"); |
|
| 158 | } |
|
| 159 | ||
| 160 | ||
| 161 | public Iterator getPrecedingAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 162 | { |
|
| 163 | 462 | return new PrecedingAxisIterator( contextNode, |
| 164 | this ); |
|
| 165 | ||
| 166 | // throw new UnsupportedAxisException("preceding"); |
|
| 167 | } |
|
| 168 | ||
| 169 | /** Throws <code>UnsupportedAxisException</code>. Subclasses that |
|
| 170 | * support the attribute axis must override this method. |
|
| 171 | * |
|
| 172 | * @param contextNode |
|
| 173 | * @return never returns |
|
| 174 | * @throws UnsupportedAxisException |
|
| 175 | */ |
|
| 176 | public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 177 | { |
|
| 178 | 0 | throw new UnsupportedAxisException("attribute"); |
| 179 | } |
|
| 180 | ||
| 181 | /** Throws <code>UnsupportedAxisException</code>. Subclasses that |
|
| 182 | * support the namespace axis must override this method. |
|
| 183 | * |
|
| 184 | * @param contextNode |
|
| 185 | * @return never returns |
|
| 186 | * @throws UnsupportedAxisException |
|
| 187 | */ |
|
| 188 | public Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 189 | { |
|
| 190 | 0 | throw new UnsupportedAxisException("namespace"); |
| 191 | } |
|
| 192 | ||
| 193 | public Iterator getSelfAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 194 | { |
|
| 195 | 630 | return new SelfAxisIterator( contextNode ); |
| 196 | } |
|
| 197 | ||
| 198 | public Iterator getDescendantOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 199 | { |
|
| 200 | 1206 | return new DescendantOrSelfAxisIterator( contextNode, |
| 201 | this ); |
|
| 202 | } |
|
| 203 | ||
| 204 | public Iterator getAncestorOrSelfAxisIterator(Object contextNode) throws UnsupportedAxisException |
|
| 205 | { |
|
| 206 | 528 | return new AncestorOrSelfAxisIterator( contextNode, |
| 207 | this ); |
|
| 208 | } |
|
| 209 | ||
| 210 | public Object getDocumentNode(Object contextNode) |
|
| 211 | { |
|
| 212 | 0 | return null; |
| 213 | } |
|
| 214 | ||
| 215 | public String translateNamespacePrefixToUri(String prefix, Object element) |
|
| 216 | { |
|
| 217 | 0 | return null; |
| 218 | } |
|
| 219 | ||
| 220 | public String getProcessingInstructionTarget(Object obj) |
|
| 221 | { |
|
| 222 | 0 | return null; |
| 223 | } |
|
| 224 | ||
| 225 | public String getProcessingInstructionData(Object obj) |
|
| 226 | { |
|
| 227 | 0 | return null; |
| 228 | } |
|
| 229 | ||
| 230 | public short getNodeType(Object node) |
|
| 231 | { |
|
| 232 | 450 | if ( isElement(node) ) |
| 233 | { |
|
| 234 | 0 | return Pattern.ELEMENT_NODE; |
| 235 | } |
|
| 236 | 450 | else if ( isAttribute(node) ) |
| 237 | { |
|
| 238 | 0 | return Pattern.ATTRIBUTE_NODE; |
| 239 | } |
|
| 240 | 450 | else if ( isText(node) ) |
| 241 | { |
|
| 242 | 0 | return Pattern.TEXT_NODE; |
| 243 | } |
|
| 244 | 450 | else if ( isComment(node) ) |
| 245 | { |
|
| 246 | 0 | return Pattern.COMMENT_NODE; |
| 247 | } |
|
| 248 | 450 | else if ( isDocument(node) ) |
| 249 | { |
|
| 250 | 0 | return Pattern.DOCUMENT_NODE; |
| 251 | } |
|
| 252 | 450 | else if ( isProcessingInstruction(node) ) |
| 253 | { |
|
| 254 | 0 | return Pattern.PROCESSING_INSTRUCTION_NODE; |
| 255 | } |
|
| 256 | 450 | else if ( isNamespace(node) ) |
| 257 | { |
|
| 258 | 450 | return Pattern.NAMESPACE_NODE; |
| 259 | } |
|
| 260 | else { |
|
| 261 | 0 | return Pattern.UNKNOWN_NODE; |
| 262 | } |
|
| 263 | } |
|
| 264 | ||
| 265 | /** |
|
| 266 | * Default implementation that cannot find parent. Subclasses for |
|
| 267 | * models with parent should override this method. |
|
| 268 | * |
|
| 269 | * @param contextNode the node whose parent to return |
|
| 270 | * @return null |
|
| 271 | * @throws UnsupportedAxisException if the parent axis is not supported |
|
| 272 | */ |
|
| 273 | public Object getParentNode(Object contextNode) throws UnsupportedAxisException |
|
| 274 | { |
|
| 275 | 150360 | Iterator iter = getParentAxisIterator( contextNode ); |
| 276 | 150360 | if ( iter != null && iter.hasNext() ) |
| 277 | { |
|
| 278 | 121008 | return iter.next(); |
| 279 | } |
|
| 280 | 29352 | return null; |
| 281 | } |
|
| 282 | ||
| 283 | /** |
|
| 284 | * Default implementation that always returns null. Override in subclass |
|
| 285 | * if the subclass can load documents. |
|
| 286 | * |
|
| 287 | * @param url the URL of the document to load |
|
| 288 | * |
|
| 289 | * @return null |
|
| 290 | * @throws FunctionCallException if an error occurs while loading the |
|
| 291 | * URL; e.g. an I/O error or the document is malformed |
|
| 292 | */ |
|
| 293 | public Object getDocument(String url) throws FunctionCallException |
|
| 294 | { |
|
| 295 | 0 | return null; |
| 296 | } |
|
| 297 | ||
| 298 | /** |
|
| 299 | * Default implementation that cannot find elements. Override in subclass |
|
| 300 | * if subclass does know about attribute types. |
|
| 301 | * |
|
| 302 | * @param contextNode a node from the document in which to look for the |
|
| 303 | * id |
|
| 304 | * @param elementId id to look for |
|
| 305 | * |
|
| 306 | * @return null |
|
| 307 | */ |
|
| 308 | public Object getElementById(Object contextNode, String elementId) |
|
| 309 | { |
|
| 310 | 0 | return null; |
| 311 | } |
|
| 312 | ||
| 313 | } |