Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mrz 27 2008 21:46:26 CET
file stats: LOC: 185   Methods: 12
NCLOC: 78   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SourceFileException.java 75% 64,9% 66,7% 66,7%
coverage coverage
 1    /* $Id: SourceFileException.java,v 1.3 2008/03/27 05:16:25 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2008, 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.io.File;
 21    import java.io.IOException;
 22    import java.net.URL;
 23   
 24    import org.qedeq.kernel.utility.IoUtility;
 25   
 26   
 27    /**
 28    * Data validation error. Shows an error within a source file.
 29    *
 30    * @version $Revision: 1.3 $
 31    * @author Michael Meyling
 32    */
 33    public class SourceFileException extends QedeqException {
 34   
 35    /** Serialization information. */
 36    private static final long serialVersionUID = -4109767904038020052L;
 37   
 38    /** Start of error location. */
 39    private final SourceArea errorArea;
 40   
 41    /** End of error location. */
 42    private final SourceArea referenceArea;
 43   
 44    /**
 45    * Constructor.
 46    *
 47    * @param errorCode Error code.
 48    * @param errorText Error text.
 49    * @param exception Exception to wrap.
 50    * @param errorArea Error location.
 51    * @param referenceArea Error reference location.
 52    */
 53  132 public SourceFileException(final int errorCode, final String errorText,
 54    final Throwable exception, final SourceArea errorArea, final SourceArea referenceArea) {
 55  132 super(errorCode, errorText, exception);
 56  132 this.errorArea = errorArea;
 57  132 this.referenceArea = referenceArea;
 58    }
 59   
 60   
 61    /**
 62    * Constructor.
 63    *
 64    * @param exception Exception to wrap.
 65    * @param errorArea Error location.
 66    * @param referenceArea Error reference location.
 67    */
 68  79 public SourceFileException(final QedeqException exception, final SourceArea errorArea,
 69    final SourceArea referenceArea) {
 70  79 this(exception.getErrorCode(), exception.getMessage(), exception, errorArea, referenceArea);
 71    }
 72   
 73   
 74    /**
 75    * Constructor.
 76    *
 77    * @param url Parsed file.
 78    * @param exception Exception to wrap.
 79    */
 80  0 public SourceFileException(final URL url, final Exception exception) {
 81  0 super(9997, exception.toString(), exception); // TODO mime 20071116: error code refac
 82  0 errorArea = new SourceArea(url, new SourcePosition(url, 1, 1), null);
 83  0 referenceArea = null;
 84    }
 85   
 86    /**
 87    * Constructor.
 88    *
 89    * @param file Parsed file.
 90    * @param exception Exception to wrap.
 91    */
 92  0 public SourceFileException(final File file, final Exception exception) {
 93  0 super(9998, exception.getMessage(), exception); // TODO mime 20071116: error code refac
 94  0 final URL url = IoUtility.toUrl(file);
 95  0 errorArea = new SourceArea(url, new SourcePosition(url, 1, 1), null);
 96  0 referenceArea = null;
 97    }
 98   
 99    /**
 100    * Constructor.
 101    *
 102    * @param exception Exception to wrap.
 103    */
 104  11 public SourceFileException(final Exception exception) {
 105  11 super(9999, exception.getMessage(), exception); // TODO mime 20071116: error code refac
 106  11 errorArea = null;
 107  11 referenceArea = null;
 108    }
 109   
 110    /**
 111    * Constructor.
 112    *
 113    * @param exception Exception to wrap.
 114    */
 115  0 public SourceFileException(final Throwable exception) {
 116  0 super(1000, exception.toString(), exception); // TODO mime 20071116: error code refac
 117  0 errorArea = null;
 118  0 referenceArea = null;
 119    }
 120   
 121    /**
 122    * Constructor.
 123    *
 124    * @param exception Exception to wrap.
 125    */
 126  3 public SourceFileException(final IOException exception) {
 127  3 super(9997, exception.toString(), exception); // TODO mime 20071116: error code refac
 128  3 errorArea = null;
 129  3 referenceArea = null;
 130    }
 131   
 132    /**
 133    * Get position information about error location.
 134    *
 135    * @return Error location position.
 136    */
 137  463 public SourceArea getSourceArea() {
 138  463 return errorArea;
 139    }
 140   
 141    /**
 142    * Get additional position information about another associated location.
 143    *
 144    * @return Additional error location position.
 145    */
 146  0 public SourceArea getReferenceArea() {
 147  0 return referenceArea;
 148    }
 149   
 150  309 public String getMessage() {
 151  309 if (getCause() != null) {
 152  309 if (getCause() instanceof IOException) {
 153  7 return getCause().toString();
 154    }
 155  302 if (getCause().getCause() != null) {
 156  0 return getCause().getCause().getMessage();
 157    }
 158  302 return getCause().getMessage();
 159    }
 160  0 return "";
 161    }
 162   
 163    /**
 164    * Get detailed error description.
 165    * The first line contains {@link #getErrorCode()} and {@link #getMessage()}.
 166    * The second line contains the local address, the line and column.
 167    *
 168    * @return Error description.
 169    */
 170  273 public String getDescription() {
 171  273 final StringBuffer buffer = new StringBuffer();
 172  273 buffer.append(getErrorCode() + ": " + getMessage());
 173  273 if (errorArea != null && errorArea.getStartPosition() != null) {
 174  256 final SourcePosition start = errorArea.getStartPosition();
 175  256 buffer.append("\n");
 176  256 buffer.append(errorArea.getAddress() + ":" + start.getLine() + ":"
 177    + start.getColumn());
 178    }
 179  273 return buffer.toString();
 180    }
 181   
 182  260 public String toString() {
 183  260 return getDescription();
 184    }
 185    }