Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 201   Methods: 11
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SyntaxException.java - 33,3% 27,3% 30,4%
coverage coverage
 1    /* $Id: SyntaxException.java,v 1.1 2007/04/12 23:50:10 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.common;
 19   
 20    import java.net.URL;
 21   
 22    import org.xml.sax.SAXParseException;
 23   
 24   
 25    /**
 26    * Exception that occurs during XML parsing. It specifies an syntactical error.
 27    * It can also mark a lack of inner consistence of something.
 28    * Also a programming error can lead to this exception.
 29    *
 30    * @version $Revision: 1.1 $
 31    * @author Michael Meyling
 32    */
 33    public final class SyntaxException extends QedeqException {
 34   
 35    /** Error code for Exceptions thrown by the SAXParser. */
 36    public static final int SAX_PARSER_EXCEPTION = 9001;
 37   
 38    /** Error code for unexpected tag. */
 39    public static final int UNEXPECTED_TAG_CODE = 9002;
 40   
 41    /** Unexpected tag message text. */
 42    public static final String UNEXPECTED_TAG_TEXT = "Unexpected tag: ";
 43   
 44    /** Error code for unexpected character data. */
 45    public static final int UNEXPECTED_DATA_CODE = 9003;
 46   
 47    /** Unexpected tag message text, part one. */
 48    public static final String UNEXPECTED_DATA_TEXT = "Unexpected character data in tag: ";
 49   
 50    /** Error code for missing attribute. */
 51    public static final int MISSING_ATTRIBUTE_CODE = 9004;
 52   
 53    /** Missing attribute text. */
 54    public static final String MISSING_ATTRIBUTE_TEXT_1 = "Missing attribute: ";
 55   
 56    /** Missing attribute, part two. */
 57    public static final String MISSING_ATTRIBUTE_TEXT_2 = " in tag: ";
 58   
 59    /** Error code for empty attribute. */
 60    public static final int EMPTY_ATTRIBUTE_CODE = 9004;
 61   
 62    /** Missing attribute text. */
 63    public static final String EMPTY_ATTRIBUTE_TEXT_1 = "Missing attribute: ";
 64   
 65    /** Missing attribute, part two. */
 66    public static final String EMPTY_ATTRIBUTE_TEXT_2 = " in tag: ";
 67   
 68    /** Error code for a programming error. */
 69    public static final int PROGRAMMING_ERROR_CODE = 9999;
 70   
 71    /** Unexpected tag message text, part one. */
 72    public static final String PROGRAMMING_ERROR_TEXT = "A programming error occurred.";
 73   
 74    /** Error location. */
 75    private SourcePosition position;
 76   
 77   
 78   
 79    /**
 80    * Constructor.
 81    *
 82    * @param code Error code.
 83    * @param message Error message.
 84    */
 85  0 private SyntaxException(final int code, final String message) {
 86  0 super(code, message);
 87    }
 88   
 89    /**
 90    * Constructor.
 91    *
 92    * @param code Error code.
 93    * @param message Error message.
 94    * @param e Error cause.
 95    */
 96  0 private SyntaxException(final int code, final String message, final RuntimeException e) {
 97  0 super(code, message, e);
 98    }
 99   
 100    /**
 101    * Constructor.
 102    *
 103    * @param e Exception thrown by the {@link javax.xml.parsers.SAXParser}.
 104    * @param url Parsed file.
 105    */
 106  10 private SyntaxException(final SAXParseException e, final URL url) {
 107  10 super(SAX_PARSER_EXCEPTION, e.getMessage(), e);
 108  10 position = new SourcePosition(url, e.getLineNumber(),
 109    e.getColumnNumber());
 110    }
 111   
 112    /**
 113    * Get error position.
 114    *
 115    * @return Error position.
 116    */
 117  34 public final SourcePosition getErrorPosition() {
 118  34 return position;
 119    }
 120   
 121   
 122    /**
 123    * Set error position.
 124    *
 125    * @param position Error position.
 126    */
 127  0 public final void setErrorPosition(final SourcePosition position) {
 128  0 this.position = position;
 129    }
 130   
 131    /**
 132    * Create exception for unexpected tag.
 133    *
 134    * @param name Tag name.
 135    * @return Exception.
 136    */
 137  0 public static final SyntaxException createUnexpectedTagException(final String name) {
 138  0 return new SyntaxException(UNEXPECTED_TAG_CODE, UNEXPECTED_TAG_TEXT + name);
 139    }
 140   
 141    /**
 142    * Create exception for unexpected text data within a tag.
 143    *
 144    * @param name Tag name.
 145    * @param value Data found.
 146    * @return Exception.
 147    */
 148  0 public static final SyntaxException createUnexpectedTextDataException(final String name,
 149    final String value) {
 150  0 return new SyntaxException(UNEXPECTED_DATA_CODE, UNEXPECTED_DATA_TEXT + name);
 151    }
 152   
 153    /**
 154    * Create exception for missing attribute within a tag.
 155    *
 156    * @param name Tag name.
 157    * @param attribute Attribute name.
 158    * @return Exception.
 159    */
 160  0 public static final SyntaxException createMissingAttributeException(final String name,
 161    final String attribute) {
 162  0 return new SyntaxException(MISSING_ATTRIBUTE_CODE, MISSING_ATTRIBUTE_TEXT_1 + attribute
 163    + MISSING_ATTRIBUTE_TEXT_2 + name);
 164    }
 165   
 166    /**
 167    * Create exception for empty attribute within a tag.
 168    *
 169    * @param name Tag name.
 170    * @param attribute Attribute name.
 171    * @return Exception.
 172    */
 173  0 public static final SyntaxException createEmptyAttributeException(final String name,
 174    final String attribute) {
 175  0 return new SyntaxException(EMPTY_ATTRIBUTE_CODE, EMPTY_ATTRIBUTE_TEXT_1 + attribute
 176    + EMPTY_ATTRIBUTE_TEXT_2 + name);
 177    }
 178   
 179    /**
 180    * Create exception for {@link org.xml.sax.SAXException}.
 181    *
 182    * @param e Exception thrown by the {@link javax.xml.parsers.SAXParser}.
 183    * @param url Parsed file.
 184    * @return Created exception.
 185    */
 186  10 public static final SyntaxException createBySAXParseException(final SAXParseException e,
 187    final URL url) {
 188  10 return new SyntaxException(e, url);
 189    }
 190   
 191    /**
 192    * Create exception for a programming error.
 193    *
 194    * @param e Exception.
 195    * @return Created exception.
 196    */
 197  0 public static final SyntaxException createByRuntimeException(final RuntimeException e) {
 198  0 return new SyntaxException(PROGRAMMING_ERROR_CODE, PROGRAMMING_ERROR_TEXT, e);
 199    }
 200   
 201    }