Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Jan 11 2007 09:03:50 CET
file stats: LOC: 121   Methods: 6
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ExceptionList.java 0% 8% 33,3% 7,8%
coverage coverage
 1    /* $Id: ExceptionList.java,v 1.8 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.util.ArrayList;
 21    import java.util.List;
 22   
 23    import org.xml.sax.SAXException;
 24    import org.xml.sax.SAXParseException;
 25   
 26   
 27    /**
 28    * Type save Exception list.
 29    *
 30    * @version $Revision: 1.8 $
 31    * @author Michael Meyling
 32    */
 33    public final class ExceptionList {
 34   
 35    /** List with parse exceptions. */
 36    private List exceptions;
 37   
 38    /** Maximum number of exceptions. */
 39    public static final int MAXIMUM = 10;
 40   
 41    /**
 42    * Constructor.
 43    */
 44  356 public ExceptionList() {
 45  356 exceptions = new ArrayList(MAXIMUM);
 46    }
 47   
 48    /**
 49    * Add Exception. This is only done if the number of already collected exceptions is below
 50    * {@link #MAXIMUM}.
 51    *
 52    * @param e Exception to add.
 53    * @throws SAXException Maximum number of exception reached.
 54    */
 55  0 public final void add(final Exception e) throws SAXException {
 56  0 if (e == null) {
 57  0 final NullPointerException ex = new NullPointerException("Exception expected!");
 58  0 exceptions.add(ex);
 59  0 throw ex;
 60    }
 61  0 if (size() < MAXIMUM) {
 62  0 exceptions.add(e);
 63    } else {
 64  0 throw new SAXException("Too much errors already occurred.");
 65    }
 66    }
 67   
 68    /**
 69    * Get number of collected exceptions.
 70    *
 71    * @return Number of collected exceptions.
 72    */
 73  216 public final int size() {
 74  216 return exceptions.size();
 75    }
 76   
 77    /**
 78    * Get <code>i</code>-th exception.
 79    *
 80    * @param i Starts with 0 and must be smaller than {@link #size()}.
 81    * @return Wanted exception.
 82    */
 83  0 public final Exception get(final int i) {
 84  0 return (Exception) exceptions.get(i);
 85    }
 86   
 87    /**
 88    * Get all exceptions.
 89    *
 90    * @return All exceptions.
 91    */
 92  0 public final Exception[] toArray() {
 93  0 return (Exception[]) exceptions.toArray(new Exception[0]);
 94    }
 95   
 96  0 public String toString() {
 97  0 final StringBuffer buffer = new StringBuffer();
 98  0 for (int i = 0; i < size(); i++) {
 99  0 if (i != 0) {
 100  0 buffer.append("\n");
 101    }
 102  0 final Exception e = get(i);
 103  0 if (e instanceof SAXParseException) {
 104  0 final SAXParseException ex = (SAXParseException) e;
 105  0 buffer.append(ex.getSystemId() != null ? ex.getPublicId() + " " : "");
 106  0 buffer.append(ex.getSystemId() != null ? ex.getSystemId() + " " : "");
 107  0 buffer.append(ex.getLineNumber() != -1 ? "Row: " + ex.getLineNumber() + ". " : "");
 108  0 buffer.append(ex.getColumnNumber() != -1
 109    ? "Column: " + ex.getColumnNumber() + ". "
 110    : "");
 111  0 buffer.append((ex.getException() != null
 112    ? ex.getException().getMessage()
 113    : ex.getMessage()));
 114    } else {
 115  0 buffer.append(get(i));
 116    }
 117    }
 118  0 return buffer.toString();
 119    }
 120   
 121    }