Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Okt 21 2006 08:24:31 CEST
file stats: LOC: 156   Methods: 8
NCLOC: 48   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.qedeq.kernel.xml.tracker.SourcePosition;
 23    import org.xml.sax.SAXParseException;
 24   
 25   
 26    /**
 27    * Exception that occurs during XML parsing. It specifies an syntactical error.
 28    * It can also mark a lack of inner consistence of something.
 29    *
 30    * @version $Revision: 1.6 $
 31    * @author Michael Meyling
 32    */
 33    public final class SyntaxException extends Exception {
 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 unexpected character data. */
 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    /** For serialization. */
 60    private static final long serialVersionUID = -1356389036916097293L;
 61   
 62    /** Error location. */
 63    private SourcePosition position;
 64   
 65    /** Error code of this Exception. */
 66    private final int errorCode;
 67   
 68   
 69    /**
 70    * Constructor.
 71    *
 72    * @param e Exception thrown by the {@link javax.xml.parsers.SAXParser}.
 73    * @param url Parsed file.
 74    */
 75  0 public SyntaxException(final SAXParseException e, final URL url) {
 76  0 super(e);
 77  0 position = new SourcePosition(url, e.getLineNumber(),
 78    e.getColumnNumber());
 79  0 errorCode = SAX_PARSER_EXCEPTION;
 80    }
 81   
 82    /**
 83    * Constructor.
 84    *
 85    * @param code Error code.
 86    * @param message Error message.
 87    */
 88  0 public SyntaxException(final int code, final String message) {
 89  0 super(message);
 90  0 errorCode = code;
 91    }
 92   
 93    /**
 94    * Get error code.
 95    *
 96    * @return Error code.
 97    */
 98  0 public final int getErrorCode() {
 99  0 return errorCode;
 100    }
 101   
 102    /**
 103    * Get error position.
 104    *
 105    * @return Error position.
 106    */
 107  0 public final SourcePosition getErrorPosition() {
 108  0 return position;
 109    }
 110   
 111   
 112    /**
 113    * Set error position.
 114    *
 115    * @param position Error position.
 116    */
 117  0 public final void setErrorPosition(final SourcePosition position) {
 118  0 this.position = position;
 119    }
 120   
 121    /**
 122    * Create exception for unexpected tag.
 123    *
 124    * @param name Tag name.
 125    * @return Exception.
 126    */
 127  0 public static final SyntaxException createUnexpectedTagException(final String name) {
 128  0 return new SyntaxException(UNEXPECTED_TAG_CODE, UNEXPECTED_TAG_TEXT + name);
 129    }
 130   
 131    /**
 132    * Create exception for unexpected text data within a tag.
 133    *
 134    * @param name Tag name.
 135    * @param value Data found.
 136    * @return Exception.
 137    */
 138  0 public static final SyntaxException createUnexpectedTextDataException(final String name,
 139    final String value) {
 140  0 return new SyntaxException(UNEXPECTED_DATA_CODE, UNEXPECTED_DATA_TEXT + name);
 141    }
 142   
 143    /**
 144    * Create exception for missing attribute within a tag.
 145    *
 146    * @param name Tag name.
 147    * @param attribute Attribute name.
 148    * @return Exception.
 149    */
 150  0 public static final SyntaxException createMissingAttributeException(final String name,
 151    final String attribute) {
 152  0 return new SyntaxException(MISSING_ATTRIBUTE_CODE, MISSING_ATTRIBUTE_TEXT_1 + attribute
 153    + MISSING_ATTRIBUTE_TEXT_2 + name);
 154    }
 155   
 156    }