KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > reporting > JUnitXMLParserErrorHandler


1 /*
2  * Cobertura - http://cobertura.sourceforge.net/
3  *
4  * Copyright (C) 2005 Mark Doliner
5  * Copyright (C) 2005 Grzegorz Lukasik
6  *
7  * Cobertura is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2 of the License,
10  * or (at your option) any later version.
11  *
12  * Cobertura is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Cobertura; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA
21  */

22
23 package net.sourceforge.cobertura.reporting;
24
25 import junit.framework.Assert;
26
27 import org.xml.sax.ErrorHandler JavaDoc;
28 import org.xml.sax.SAXParseException JavaDoc;
29
30 /**
31  * This is a very simple SAX XML parser ErrorHandler. If
32  * you are parsing an XML document using a DocumentBuilder,
33  * and you set the DocumentBuilder's ErrorHandler to an
34  * instance of this class, and the XML document contains
35  * any suspect XML, then this class will throw a JUnit
36  * assertion failure.
37  */

38 public class JUnitXMLParserErrorHandler implements ErrorHandler JavaDoc
39 {
40     
41     private void createErrorMessage(SAXParseException JavaDoc exception)
42     {
43         Assert.fail("Line number: " + exception.getLineNumber()
44                 + " column: " + exception.getColumnNumber()
45                 + "\n"
46                 + exception.toString());
47     }
48
49     public void error(SAXParseException JavaDoc exception)
50     {
51         createErrorMessage(exception);
52     }
53
54     public void fatalError(SAXParseException JavaDoc exception)
55     {
56         createErrorMessage(exception);
57     }
58
59     public void warning(SAXParseException JavaDoc exception)
60     {
61         createErrorMessage(exception);
62     }
63
64 }
Popular Tags