Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 217   Methods: 17
NCLOC: 86   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultSourceFileExceptionList.java 100% 40,6% 35,3% 43,4%
coverage coverage
 1    /* $Id: DefaultSourceFileExceptionList.java,v 1.2 2008/01/26 12:39: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.xml.parser;
 19   
 20    import java.io.IOException;
 21    import java.util.ArrayList;
 22    import java.util.List;
 23   
 24    import javax.xml.parsers.ParserConfigurationException;
 25   
 26    import org.qedeq.kernel.common.SourceArea;
 27    import org.qedeq.kernel.common.SourceFileException;
 28    import org.qedeq.kernel.common.SourceFileExceptionList;
 29    import org.qedeq.kernel.trace.Trace;
 30    import org.qedeq.kernel.xml.common.XmlSyntaxException;
 31    import org.xml.sax.SAXException;
 32   
 33   
 34    /**
 35    * Type save {@link org.qedeq.kernel.common.SourceFileException} list.
 36    * TODO mime 20080109: shouldn't this list have some informations about the source being parsed?
 37    *
 38    * @version $Revision: 1.2 $
 39    * @author Michael Meyling
 40    */
 41    public class DefaultSourceFileExceptionList extends SourceFileExceptionList {
 42   
 43    /** This class. */
 44    private static final Class CLASS = DefaultSourceFileExceptionList.class;
 45   
 46    /** List with parse exceptions. */
 47    private final List exceptions = new ArrayList();
 48   
 49    /**
 50    * Constructor.
 51    */
 52  1007 public DefaultSourceFileExceptionList() {
 53    }
 54   
 55    /**
 56    * Constructor.
 57    *
 58    * @param e Wrap me.
 59    */
 60  10 public DefaultSourceFileExceptionList(final IOException e) {
 61  10 initCause(e);
 62  10 add(new SourceFileException(e));
 63    }
 64   
 65    /**
 66    * Constructor.
 67    *
 68    * @param e Wrap me.
 69    */
 70  0 public DefaultSourceFileExceptionList(final SAXException e) {
 71  0 initCause(e);
 72  0 add(new SourceFileException(e));
 73    }
 74   
 75    /**
 76    * Constructor.
 77    *
 78    * @param e Wrap me.
 79    */
 80  0 public DefaultSourceFileExceptionList(final RuntimeException e) {
 81  0 initCause(e);
 82  0 add(new SourceFileException(e));
 83    }
 84   
 85    /**
 86    * Constructor.
 87    *
 88    * @param e Wrap me.
 89    */
 90  0 public DefaultSourceFileExceptionList(final Throwable e) {
 91  0 initCause(e);
 92  0 add(new SourceFileException(e));
 93  0 Trace.fatal(CLASS, "Constructor(Throwable)",
 94    "Major unexpected problem", e);
 95    }
 96   
 97    /**
 98    * Constructor.
 99    *
 100    * @param e Wrap me.
 101    */
 102  0 public DefaultSourceFileExceptionList(final Exception e) {
 103  0 initCause(e);
 104  0 Trace.fatal(CLASS, "Constructor(Exception)",
 105    "Unexpected problem", e);
 106  0 add(new SourceFileException(e));
 107    }
 108   
 109    /**
 110    * Constructor.
 111    *
 112    * @param e Wrap me.
 113    */
 114  0 public DefaultSourceFileExceptionList(final SourceFileException e) {
 115  0 initCause(e);
 116  0 add(e);
 117    }
 118   
 119    /**
 120    * Add exception.
 121    *
 122    * @param e Exception to add.
 123    */
 124  66 public void add(final SourceFileException e) {
 125  66 exceptions.add(e);
 126    }
 127   
 128    /**
 129    * Add exception.
 130    *
 131    * @param e Exception to add.
 132    */
 133  0 public final void add(final XmlSyntaxException e) {
 134  0 final SourceFileException sfe = new SourceFileException(e.getErrorCode(), e.getMessage(), e,
 135    new SourceArea(e.getErrorPosition().getAddress(), e.getErrorPosition(), null), null);
 136   
 137  0 exceptions.add(sfe);
 138    }
 139   
 140    /**
 141    * Add exception.
 142    *
 143    * @param e Exception to add.
 144    */
 145  0 public final void add(final SAXException e) {
 146  0 exceptions.add(new SourceFileException(e));
 147    }
 148   
 149    /**
 150    * Add exception.
 151    *
 152    * @param e Exception to add.
 153    */
 154  0 public final void add(final IOException e) {
 155  0 exceptions.add(new SourceFileException(e));
 156    }
 157   
 158    /**
 159    * Add exception.
 160    *
 161    * @param e Exception to add.
 162    */
 163  0 public void add(final ParserConfigurationException e) {
 164  0 exceptions.add(new SourceFileException(e));
 165    }
 166   
 167    /**
 168    * Add exception.
 169    *
 170    * @param e Exception to add.
 171    */
 172  0 public void add(final RuntimeException e) {
 173  0 exceptions.add(new SourceFileException(e));
 174    }
 175   
 176    /**
 177    * Get number of collected exceptions.
 178    *
 179    * @return Number of collected exceptions.
 180    */
 181  1324 public final int size() {
 182  1324 return exceptions.size();
 183    }
 184   
 185    /**
 186    * Get <code>i</code>-th exception.
 187    *
 188    * @param i Starts with 0 and must be smaller than {@link #size()}.
 189    * @return Wanted exception.
 190    */
 191  520 public final SourceFileException get(final int i) {
 192  520 return (SourceFileException) exceptions.get(i);
 193    }
 194   
 195    /**
 196    * Get all exceptions.
 197    *
 198    * @return All exceptions.
 199    */
 200  0 public final SourceFileException[] toArray() {
 201  0 return (SourceFileException[]) exceptions.toArray(new SourceFileException[0]);
 202    }
 203   
 204  204 public String getMessage() {
 205  204 final StringBuffer buffer = new StringBuffer();
 206  204 for (int i = 0; i < size(); i++) {
 207  258 if (i != 0) {
 208  54 buffer.append("\n");
 209    }
 210  258 final SourceFileException e = get(i);
 211  258 buffer.append(i).append(": ");
 212  258 buffer.append(e.toString());
 213    }
 214  204 return buffer.toString();
 215    }
 216   
 217    }