|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XPathException.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 | /* Copyright 2005 Elliotte Rusty Harold | |
| 2 | ||
| 3 | This library is free software; you can redistribute it and/or modify | |
| 4 | it under the terms of version 2.1 of the GNU Lesser General Public | |
| 5 | License as published by the Free Software Foundation. | |
| 6 | ||
| 7 | This library is distributed in the hope that it will be useful, | |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 | GNU Lesser General Public License for more details. | |
| 11 | ||
| 12 | You should have received a copy of the GNU Lesser General Public | |
| 13 | License along with this library; if not, write to the | |
| 14 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
| 15 | Boston, MA 02111-1307 USA | |
| 16 | ||
| 17 | You can contact Elliotte Rusty Harold by sending e-mail to | |
| 18 | elharo@metalab.unc.edu. Please include the word "XOM" in the | |
| 19 | subject line. The XOM home page is located at http://www.xom.nu/ | |
| 20 | */ | |
| 21 | package nu.xom; | |
| 22 | ||
| 23 | /** | |
| 24 | * <p> | |
| 25 | * Indicates problems with XPath syntax or evaluation. | |
| 26 | * </p> | |
| 27 | * | |
| 28 | * @author Elliotte Rusty Harold | |
| 29 | * @version 1.1b3 | |
| 30 | * | |
| 31 | */ | |
| 32 | public class XPathException extends RuntimeException { | |
| 33 | ||
| 34 | ||
| 35 | private static final long serialVersionUID = 6362087755031657439L; | |
| 36 | ||
| 37 | private String expression; | |
| 38 | private Throwable cause; | |
| 39 | ||
| 40 | ||
| 41 | /** | |
| 42 | * <p> | |
| 43 | * Creates a new <code>XPathException</code> | |
| 44 | * with a detail message. | |
| 45 | * </p> | |
| 46 | * | |
| 47 | * @param message a string indicating the specific problem | |
| 48 | */ | |
| 49 | 123 | public XPathException(String message) { |
| 50 | 123 | super(message); |
| 51 | } | |
| 52 | ||
| 53 | ||
| 54 | /** | |
| 55 | * <p> | |
| 56 | * Creates a new <code>IllegalNameException</code> | |
| 57 | * with a detail message and an underlying root cause. | |
| 58 | * </p> | |
| 59 | * | |
| 60 | * @param message a string indicating the specific problem | |
| 61 | * @param cause the original cause of this exception | |
| 62 | */ | |
| 63 | 42 | public XPathException(String message, Throwable cause) { |
| 64 | 42 | super(message); |
| 65 | 42 | this.initCause(cause); |
| 66 | } | |
| 67 | ||
| 68 | ||
| 69 | /** | |
| 70 | * <p> | |
| 71 | * Return the original cause that led to this exception, | |
| 72 | * or null if there was no original exception. | |
| 73 | * </p> | |
| 74 | * | |
| 75 | * @return the root cause of this exception | |
| 76 | */ | |
| 77 | 8 | public Throwable getCause() { |
| 78 | 8 | return this.cause; |
| 79 | } | |
| 80 | ||
| 81 | ||
| 82 | // null is insufficient for detecting an uninitialized cause. | |
| 83 | // The cause may be set to null which may not then be reset. | |
| 84 | private boolean causeSet = false; | |
| 85 | ||
| 86 | ||
| 87 | /** | |
| 88 | * <p> | |
| 89 | * Sets the root cause of this exception. This may | |
| 90 | * only be called once. Subsequent calls throw an | |
| 91 | * <code>IllegalStateException</code>. | |
| 92 | * </p> | |
| 93 | * | |
| 94 | * <p> | |
| 95 | * This method is unnecessary in Java 1.4 where it could easily be | |
| 96 | * inherited from the superclass. However, including it here | |
| 97 | * allows this method to be used in Java 1.3 and earlier. | |
| 98 | * </p> | |
| 99 | * | |
| 100 | * @param cause the root cause of this exception | |
| 101 | * | |
| 102 | * @return this <code>XMLException</code> | |
| 103 | * | |
| 104 | * @throws IllegalArgumentException if the cause is this exception | |
| 105 | * (An exception cannot be its own cause.) | |
| 106 | * @throws IllegalStateException if this method is called twice | |
| 107 | */ | |
| 108 | 48 | public Throwable initCause(Throwable cause) { |
| 109 | ||
| 110 | 48 | if (causeSet) { |
| 111 | 4 | throw new IllegalStateException("Can't overwrite cause"); |
| 112 | } | |
| 113 | 44 | else if (cause == this) { |
| 114 | 1 | throw new IllegalArgumentException("Self-causation not permitted"); |
| 115 | } | |
| 116 | 43 | else this.cause = cause; |
| 117 | 43 | causeSet = true; |
| 118 | 43 | return this; |
| 119 | ||
| 120 | } | |
| 121 | ||
| 122 | ||
| 123 | /** | |
| 124 | * <p> | |
| 125 | * Sets the specific XPath expression that caused this exception. | |
| 126 | * </p> | |
| 127 | * | |
| 128 | * @param expression the XPath expression that caused the exception | |
| 129 | */ | |
| 130 | 267 | void setXPath(String expression) { |
| 131 | 267 | this.expression = expression; |
| 132 | } | |
| 133 | ||
| 134 | ||
| 135 | /** | |
| 136 | * <p> | |
| 137 | * Returns the specific XPath expression being evaluated when this | |
| 138 | * excepiton was thrown. | |
| 139 | * </p> | |
| 140 | * | |
| 141 | * @return the XPath expression that caused the exception | |
| 142 | */ | |
| 143 | 2 | public String getXPath() { |
| 144 | 2 | return this.expression; |
| 145 | } | |
| 146 | ||
| 147 | ||
| 148 | } |
|
||||||||||