|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XPointerException.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 1 | /* Copyright 2003-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 | ||
| 22 | package nu.xom.xinclude; | |
| 23 | ||
| 24 | /** | |
| 25 | * <p> | |
| 26 | * Indicates an error as defined by the XPointer specification. | |
| 27 | * </p> | |
| 28 | * | |
| 29 | * @author Elliotte Rusty Harold | |
| 30 | * @version 1.1b3 | |
| 31 | */ | |
| 32 | class XPointerException extends Exception { | |
| 33 | ||
| 34 | ||
| 35 | private static final long serialVersionUID = -533329510409448717L; | |
| 36 | ||
| 37 | private Throwable cause = null; | |
| 38 | ||
| 39 | /** | |
| 40 | * <p> | |
| 41 | * Constructs an <code>XPointerException</code> with the | |
| 42 | * specified detail message. | |
| 43 | * </p> | |
| 44 | * | |
| 45 | * @param message a string indicating the specific problem | |
| 46 | */ | |
| 47 | 19 | XPointerException(String message) { |
| 48 | 19 | super(message); |
| 49 | } | |
| 50 | ||
| 51 | ||
| 52 | /** | |
| 53 | * <p> | |
| 54 | * Constructs an <code>XPointerException</code> with the | |
| 55 | * specified detail message and root cause. | |
| 56 | * </p> | |
| 57 | * | |
| 58 | * @param message a string indicating the specific problem | |
| 59 | * @param cause the initial exception which caused this | |
| 60 | * <code>XPointerException</code> | |
| 61 | */ | |
| 62 | 3 | XPointerException(String message, Throwable cause) { |
| 63 | 3 | super(message); |
| 64 | 3 | initCause(cause); |
| 65 | } | |
| 66 | ||
| 67 | ||
| 68 | /** | |
| 69 | * <p> | |
| 70 | * When an <code>IOException</code>, | |
| 71 | * <code>MalformedURLException</code>, or other generic | |
| 72 | * exception is thrown while processing an XML document | |
| 73 | * for XPointer, it is customarily replaced | |
| 74 | * by some form of <code>XPointerSyntaxException</code>. | |
| 75 | * This method allows you to retrieve the original exception. | |
| 76 | * It returns null if no such exception caused this | |
| 77 | * <code>XPointerSyntaxException</code>. | |
| 78 | *</p> | |
| 79 | * | |
| 80 | * @return the underlying exception which | |
| 81 | * caused this XPointerSyntaxException to be thrown | |
| 82 | */ | |
| 83 | 1 | public Throwable getCause() { |
| 84 | 1 | return this.cause; |
| 85 | } | |
| 86 | ||
| 87 | ||
| 88 | // null is insufficient for detecting an uninitialized cause. | |
| 89 | // The cause may be set to null which may not then be reset. | |
| 90 | private boolean causeSet = false; | |
| 91 | ||
| 92 | ||
| 93 | /** | |
| 94 | * <p> | |
| 95 | * When an <code>IOException</code>, | |
| 96 | * <code>MalformedURLException</code>, or other generic exception | |
| 97 | * is thrown while processing an XML document | |
| 98 | * for XPointers, it is customarily replaced | |
| 99 | * by some form of <code>XPointerException</code>. | |
| 100 | * This method allows you to store the original exception. | |
| 101 | * </p> | |
| 102 | * | |
| 103 | * @param cause the root cause of this exception | |
| 104 | * | |
| 105 | * @return this <code>XPointerException</code> | |
| 106 | * | |
| 107 | * @throws IllegalArgumentException if the cause is this exception | |
| 108 | * (An exception cannot be its own cause.) | |
| 109 | * @throws IllegalStateException if this method is called twice | |
| 110 | */ | |
| 111 | 6 | public Throwable initCause(Throwable cause) { |
| 112 | 6 | if (causeSet) { |
| 113 | 1 | throw new IllegalStateException("Can't overwrite cause"); |
| 114 | } | |
| 115 | 5 | else if (cause == this) { |
| 116 | 1 | throw new IllegalArgumentException("Self-causation not permitted"); |
| 117 | } | |
| 118 | 4 | else this.cause = cause; |
| 119 | 4 | causeSet = true; |
| 120 | 4 | return this; |
| 121 | } | |
| 122 | ||
| 123 | ||
| 124 | } |
|
||||||||||