Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Jan 11 2007 09:03:50 CET
file stats: LOC: 110   Methods: 2
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LoadXmlOperatorListUtility.java 16,7% 44,1% 50% 40,5%
coverage coverage
 1    /* $Id: LoadXmlOperatorListUtility.java,v 1.1 2006/10/20 20:23:05 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.handler.parser;
 19   
 20    import java.io.FileNotFoundException;
 21    import java.io.IOException;
 22    import java.net.URL;
 23    import java.util.List;
 24   
 25    import javax.xml.parsers.ParserConfigurationException;
 26   
 27    import org.qedeq.kernel.log.Trace;
 28    import org.qedeq.kernel.xml.mapper.XmlFilePositionException;
 29    import org.qedeq.kernel.xml.parser.SaxDefaultHandler;
 30    import org.qedeq.kernel.xml.parser.SaxParser;
 31    import org.qedeq.kernel.xml.parser.SyntaxException;
 32    import org.xml.sax.SAXException;
 33    import org.xml.sax.SAXParseException;
 34   
 35   
 36    /**
 37    * Load operator list from an XML file.
 38    *
 39    * @version $Revision: 1.1 $
 40    * @author Michael Meyling
 41    */
 42    public final class LoadXmlOperatorListUtility {
 43   
 44    /**
 45    * Constructor.
 46    */
 47  0 private LoadXmlOperatorListUtility() {
 48    // nothing to do
 49    }
 50   
 51    /**
 52    * Get operator list out of XML file.
 53    *
 54    * @param from Read this XML file.
 55    * @return Operator list.
 56    * @throws XmlFilePositionException Loading failed.
 57    */
 58  81 public static List getOperatorList(final String from) throws XmlFilePositionException {
 59  81 final String method = "generate(String, String, String, String)";
 60  81 URL url = null;
 61  81 try {
 62  81 Trace.begin(LoadXmlOperatorListUtility.class, method);
 63  81 Trace.param(LoadXmlOperatorListUtility.class, method, "from", from);
 64  81 url = LoadXmlOperatorListUtility.class.getResource("/" + from);
 65  81 if (url == null) {
 66  0 throw new FileNotFoundException(from);
 67    }
 68  81 SaxDefaultHandler handler = new SaxDefaultHandler();
 69  81 ParserHandler simple = new ParserHandler(handler);
 70  81 handler.setBasisDocumentHandler(simple);
 71  81 SaxParser parser = new SaxParser(handler);
 72  81 try {
 73  81 parser.parse(url);
 74    } catch (SAXException ex) {
 75  0 if (parser.getExceptionList().size() > 0) {
 76  0 final Exception exc = parser.getExceptionList().get(0);
 77  0 if (exc instanceof SyntaxException) { // TODO mime 20050826: give more than one
 78  0 throw new XmlFilePositionException((SyntaxException) exc);
 79    }
 80    }
 81  0 throw ex;
 82    }
 83   
 84  81 return simple.getOperators();
 85    } catch (RuntimeException e) {
 86  0 Trace.trace(LoadXmlOperatorListUtility.class, method, e);
 87  0 throw new XmlFilePositionException(url, e);
 88    } catch (IOException e) {
 89  0 Trace.trace(LoadXmlOperatorListUtility.class, method, e);
 90  0 throw new XmlFilePositionException(url, e);
 91    } catch (ParserConfigurationException e) {
 92  0 Trace.trace(LoadXmlOperatorListUtility.class, method, e);
 93  0 throw new XmlFilePositionException(url, e);
 94    } catch (final SAXParseException e) {
 95  0 Trace.trace(LoadXmlOperatorListUtility.class, method, e);
 96  0 throw new XmlFilePositionException(url, e);
 97    } catch (SAXException e) {
 98  0 Trace.trace(LoadXmlOperatorListUtility.class, method, e);
 99  0 throw new XmlFilePositionException(url, e);
 100    } catch (javax.xml.parsers.FactoryConfigurationError e) {
 101  0 Trace.trace(LoadXmlOperatorListUtility.class, method, e);
 102  0 final String msg = "SAX Parser not in classpath, "
 103    + "add for example \"xercesImpl.jar\" and \"xml-apis.jar\".";
 104  0 throw new XmlFilePositionException(url, new IOException(msg));
 105    } finally {
 106  81 Trace.end(LoadXmlOperatorListUtility.class, method);
 107    }
 108    }
 109   
 110    }