Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Jan 11 2007 09:03:50 CET
file stats: LOC: 155   Methods: 8
NCLOC: 47   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SyntaxException.java - 0% 0% 0%
coverage
 1    /* $Id: SyntaxException.java,v 1.6 2006/10/20 20:23:04 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2006, 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.xml.parser;
 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    *
 29    * @version $Revision: 1.6 $
 30    * @author Michael Meyling
 31    */
 32    public final class SyntaxException extends Exception {
 33   
 34    /** Error code for Exceptions thrown by the SAXParser. */
 35    public static final int SAX_PARSER_EXCEPTION = 9001;
 36   
 37    /** Error code for unexpected tag. */
 38    public static final int UNEXPECTED_TAG_CODE = 9002;
 39   
 40    /** Unexpected tag message text. */
 41    public static final String UNEXPECTED_TAG_TEXT = "Unexpected tag: ";
 42   
 43    /** Error code for unexpected character data. */
 44    public static final int UNEXPECTED_DATA_CODE = 9003;
 45   
 46    /** Unexpected tag message text, part one. */
 47    public static final String UNEXPECTED_DATA_TEXT = "Unexpected character data in tag: ";
 48   
 49    /** Error code for unexpected character data. */
 50    public static final int MISSING_ATTRIBUTE_CODE = 9004;
 51   
 52    /** Missing attribute text. */
 53    public static final String MISSING_ATTRIBUTE_TEXT_1 = "Missing attribute: ";
 54   
 55    /** Missing attribute, part two. */
 56    public static final String MISSING_ATTRIBUTE_TEXT_2 = " in tag: ";
 57   
 58    /** For serialization. */
 59    private static final long serialVersionUID = -1356389036916097293L;
 60   
 61    /** Error location. */
 62    private SourcePosition position;
 63   
 64    /** Error code of this Exception. */
 65    private final int errorCode;
 66   
 67   
 68    /**
 69    * Constructor.
 70    *
 71    * @param e Exception thrown by the {@link javax.xml.parsers.SAXParser}.
 72    * @param url Parsed file.
 73    */
 74  0 public SyntaxException(final SAXParseException e, final URL url) {
 75  0 super(e);
 76  0 position = new SourcePosition(url, e.getLineNumber(),
 77    e.getColumnNumber());
 78  0 errorCode = SAX_PARSER_EXCEPTION;
 79    }
 80   
 81    /**
 82    * Constructor.
 83    *
 84    * @param code Error code.
 85    * @param message Error message.
 86    */
 87  0 public SyntaxException(final int code, final String message) {
 88  0 super(message);
 89  0 errorCode = code;
 90    }
 91   
 92    /**
 93    * Get error code.
 94    *
 95    * @return Error code.
 96    */
 97  0 public final int getErrorCode() {
 98  0 return errorCode;
 99    }
 100   
 101    /**
 102    * Get error position.
 103    *
 104    * @return Error position.
 105    */
 106  0 public final SourcePosition getErrorPosition() {
 107  0 return position;
 108    }
 109   
 110   
 111    /**
 112    * Set error position.
 113    *
 114    * @param position Error position.
 115    */
 116  0 public final void setErrorPosition(final SourcePosition position) {
 117  0 this.position = position;
 118    }
 119   
 120    /**
 121    * Create exception for unexpected tag.
 122    *
 123    * @param name Tag name.
 124    * @return Exception.
 125    */
 126  0 public static final SyntaxException createUnexpectedTagException(final String name) {
 127  0 return new SyntaxException(UNEXPECTED_TAG_CODE, UNEXPECTED_TAG_TEXT + name);
 128    }
 129   
 130    /**
 131    * Create exception for unexpected text data within a tag.
 132    *
 133    * @param name Tag name.
 134    * @param value Data found.
 135    * @return Exception.
 136    */
 137  0 public static final SyntaxException createUnexpectedTextDataException(final String name,
 138    final String value) {
 139  0 return new SyntaxException(UNEXPECTED_DATA_CODE, UNEXPECTED_DATA_TEXT + name);
 140    }
 141   
 142    /**
 143    * Create exception for missing attribute within a tag.
 144    *
 145    * @param name Tag name.
 146    * @param attribute Attribute name.
 147    * @return Exception.
 148    */
 149  0 public static final SyntaxException createMissingAttributeException(final String name,
 150    final String attribute) {
 151  0 return new SyntaxException(MISSING_ATTRIBUTE_CODE, MISSING_ATTRIBUTE_TEXT_1 + attribute
 152    + MISSING_ATTRIBUTE_TEXT_2 + name);
 153    }
 154   
 155    }