Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 275   Methods: 13
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ValidityException.java - 100% 100% 100%
coverage
 1    /* Copyright 2002-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;
 23   
 24    import java.util.ArrayList;
 25    import java.util.List;
 26   
 27    import org.xml.sax.SAXParseException;
 28   
 29    /**
 30    * <p>
 31    * Signals a validity error in a document being parsed.
 32    * These are not thrown by default, unless you specifically
 33    * request that the builder validate.
 34    * </p>
 35   
 36    * @author Elliotte Rusty Harold
 37    * @version 1.1b3
 38    *
 39    */
 40    public class ValidityException extends ParsingException {
 41   
 42   
 43    private static final long serialVersionUID = 8950434465665278751L;
 44   
 45    private List saxExceptions = new ArrayList();
 46    private transient Document document;
 47   
 48   
 49    /**
 50    * <p>
 51    * Creates a new <code>ValidityException</code>
 52    * with a detail message and an underlying root cause.
 53    * </p>
 54    *
 55    * @param message a string indicating the specific problem
 56    * @param cause the original cause of this exception
 57    */
 58  2 public ValidityException(String message, Throwable cause) {
 59  2 super(message, cause);
 60    }
 61   
 62   
 63    /**
 64    * <p>
 65    * Creates a new <code>ValidityException</code>
 66    * with a detail message and line and column numbers.
 67    * </p>
 68    *
 69    * @param message a string indicating the specific problem
 70    * @param lineNumber the approximate line number
 71    * where the problem occurs
 72    * @param columnNumber the approximate column number
 73    * where the problem occurs
 74    */
 75  1 public ValidityException(
 76    String message,
 77    int lineNumber,
 78    int columnNumber) {
 79  1 super(message, lineNumber, columnNumber);
 80    }
 81   
 82   
 83    /**
 84    * <p>
 85    * Creates a new <code>ValidityException</code>
 86    * with a detail message, line and column numbers,
 87    * and an underlying exception.
 88    * </p>
 89    *
 90    * @param message a string indicating the specific problem
 91    * @param lineNumber the approximate line number
 92    * where the problem occurs
 93    * @param columnNumber the approximate column number
 94    * where the problem occurs
 95    * @param cause the original cause of this exception
 96    */
 97  1 public ValidityException(
 98    String message,
 99    int lineNumber,
 100    int columnNumber,
 101    Throwable cause) {
 102  1 super(message, lineNumber, columnNumber, cause);
 103    }
 104   
 105   
 106    /**
 107    * <p>
 108    * Creates a new <code>ValidityException</code>
 109    * with a detail message, the URI of the document that contained
 110    * the error, and approximate line and column numbers of the
 111    * first validity error.
 112    * </p>
 113    *
 114    * @param message a string indicating the specific problem
 115    * @param lineNumber the approximate line number
 116    * where the problem occurs
 117    * @param columnNumber the approximate column number
 118    * where the problem occurs
 119    */
 120  1 public ValidityException(String message, String uri,
 121    int lineNumber, int columnNumber) {
 122  1 super(message, uri, lineNumber, columnNumber);
 123    }
 124   
 125   
 126    /**
 127    * <p>
 128    * Creates a new <code>ValidityException</code>
 129    * with a detail message, URI of the document containing the
 130    * validity error, line and column numbers of the error,
 131    * and an underlying exception.
 132    * </p>
 133    *
 134    * @param message a string indicating the specific problem
 135    * @param lineNumber the approximate line number
 136    * where the problem occurs
 137    * @param columnNumber the approximate column number
 138    * where the problem occurs
 139    * @param cause the original cause of this exception
 140    */
 141  12 public ValidityException(
 142    String message,
 143    String uri,
 144    int lineNumber,
 145    int columnNumber,
 146    Throwable cause) {
 147  12 super(message, uri, lineNumber, columnNumber, cause);
 148    }
 149   
 150   
 151    /**
 152    * <p>
 153    * Creates a new <code>ValidityException</code>
 154    * with a detail message.
 155    * </p>
 156    *
 157    * @param message a string indicating the specific problem
 158    */
 159  9 public ValidityException(String message) {
 160  9 super(message);
 161    }
 162   
 163   
 164    /**
 165    * <p>
 166    * Returns a <code>Document</code> object for the document that
 167    * caused this exception. This is useful if you want notification
 168    * of validity errors, but nonetheless wish to further process
 169    * the invalid document.
 170    * </p>
 171    *
 172    * @return the invalid document
 173    */
 174  13 public Document getDocument() {
 175  13 return document;
 176    }
 177   
 178   
 179  9 void setDocument(Document doc) {
 180  9 this.document = doc;
 181    }
 182   
 183   
 184  83 void addError(SAXParseException ex) {
 185  83 saxExceptions.add(ex);
 186    }
 187   
 188   
 189    /**
 190    * <p>
 191    * Returns the number of validity errors the parser detected
 192    * in the document. This is likely to not be consistent from one
 193    * parser to another.
 194    * </p>
 195    *
 196    * @return the number of validity errors the parser detected
 197    */
 198  75 public int getErrorCount() {
 199  75 return saxExceptions.size();
 200    }
 201   
 202   
 203    /**
 204    * <p>
 205    * Returns a message indicating a specific validity problem
 206    * in the input document as detected by the parser. Normally,
 207    * these will be in the order they appear in the document.
 208    * For instance, an error in the root element is likely
 209    * to appear before an error in a child element. However, this
 210    * depends on the underlying parser and is not guaranteed.
 211    * </p>
 212    *
 213    * @param n the index of the validity error to report
 214    *
 215    * @return a string describing the n<i>th</i> validity error
 216    *
 217    * @throws IndexOutOfBoundsException if <code>n</code> is greater
 218    * than or equal to the number of errors detected
 219    */
 220  61 public String getValidityError(int n) {
 221  61 Exception ex = (Exception) saxExceptions.get(n);
 222  61 return ex.getMessage();
 223    }
 224   
 225   
 226    /**
 227    * <p>
 228    * Returns the line number of the <i>n</i>th validity
 229    * error. It returns -1 if this is not known. This number
 230    * may be helpful for debugging, but should not be relied on.
 231    * Different parsers may set it differently. For instance
 232    * a problem with an element might be reported using the
 233    * line number of the start-tag or the line number of the
 234    * end-tag.
 235    * </p>
 236    *
 237    * @param n the index of the validity error to report
 238    * @return the approximate line number where the n<i>th</i>
 239    * validity error was detected
 240    *
 241    * @throws IndexOutOfBoundsException if <code>n</code> is greater
 242    * than or equal to the number of errors detected
 243    */
 244  40 public int getLineNumber(int n) {
 245  40 SAXParseException ex = (SAXParseException) saxExceptions.get(n);
 246  40 return ex.getLineNumber();
 247    }
 248   
 249   
 250    /**
 251    * <p>
 252    * Returns the column number of the <i>n</i>th validity
 253    * error. It returns -1 if this is not known. This number
 254    * may be helpful for debugging, but should not be relied on.
 255    * Different parsers may set it differently. For instance
 256    * a problem with an element might be reported using the
 257    * column of the <code>&lt;</code> or the <code>&gt;</code>
 258    * of the start-tag
 259    * </p>
 260    *
 261    * @param n the index of the validity error to report
 262    *
 263    * @return the approximate column where the n<i>th</i>
 264    * validity error was detected
 265    *
 266    * @throws IndexOutOfBoundsException if <code>n</code> is greater
 267    * than or equal to the number of errors detected
 268    */
 269  40 public int getColumnNumber(int n) {
 270  40 SAXParseException ex = (SAXParseException) saxExceptions.get(n);
 271  40 return ex.getColumnNumber();
 272    }
 273   
 274   
 275    }