Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Dez 22 2007 01:35:21 CET
file stats: LOC: 119   Methods: 3
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ModuleDataException2XmlFileException.java 75% 68,2% 66,7% 69%
coverage coverage
 1    /* $Id: ModuleDataException2XmlFileException.java,v 1.3 2007/12/21 23:33:47 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.mapper;
 19   
 20    import java.io.File;
 21    import java.io.IOException;
 22   
 23    import javax.xml.parsers.ParserConfigurationException;
 24   
 25    import org.qedeq.kernel.base.module.Qedeq;
 26    import org.qedeq.kernel.bo.load.DefaultModuleAddress;
 27    import org.qedeq.kernel.bo.module.ModuleContext;
 28    import org.qedeq.kernel.bo.module.ModuleDataException;
 29    import org.qedeq.kernel.common.SourceArea;
 30    import org.qedeq.kernel.common.SourceFileException;
 31    import org.qedeq.kernel.common.SourceFileExceptionList;
 32    import org.qedeq.kernel.context.KernelContext;
 33    import org.qedeq.kernel.trace.Trace;
 34    import org.qedeq.kernel.xml.parser.DefaultSourceFileExceptionList;
 35    import org.qedeq.kernel.xml.tracker.SimpleXPath;
 36    import org.qedeq.kernel.xml.tracker.XPathLocationFinder;
 37    import org.xml.sax.SAXException;
 38   
 39   
 40    /**
 41    * Converts a {@link org.qedeq.kernel.bo.module.ModuleDataException} into a
 42    * {@link org.qedeq.kernel.common.SourceFileException}.
 43    *
 44    * @version $Revision: 1.3 $
 45    * @author Michael Meyling
 46    */
 47    public final class ModuleDataException2XmlFileException {
 48   
 49    /**
 50    * Constructor.
 51    */
 52  0 private ModuleDataException2XmlFileException() {
 53    // nothing to do
 54    }
 55   
 56    /**
 57    * Create exception out of {@link ModuleDataException}.
 58    *
 59    * @param exception Take this exception.
 60    * @param qedeq Take this QEDEQ module.
 61    * @return Newly created instance.
 62    */
 63  2370 public static final SourceFileExceptionList createXmlFileExceptionList(final ModuleDataException
 64    exception, final Qedeq qedeq) {
 65  2370 final DefaultSourceFileExceptionList list = new DefaultSourceFileExceptionList();
 66  2370 final SourceFileException e = new SourceFileException(exception, createSourceArea(qedeq,
 67    exception.getContext()),
 68    createSourceArea(qedeq, exception.getReferenceContext()));
 69  2360 list.add(e);
 70  2360 return list;
 71    }
 72   
 73    /**
 74    * Get area in XML source file for QEDEQ module context.
 75    *
 76    * @param qedeq Look at this QEDEQ module.
 77    * @param context Search for this context.
 78    * @return Created file area. Maybe <code>null</code>.
 79    */
 80  4730 public static SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {
 81  4730 final String method = "createSourceArea(Qedeq, ModuleContext)";
 82  4730 if (qedeq == null || context == null) {
 83  2355 return null;
 84    }
 85  2375 final String xpath;
 86  2375 try {
 87  2375 xpath = Context2SimpleXPath.getXPath(context, qedeq).toString();
 88    } catch (ModuleDataException e) {
 89  0 Trace.trace(SourceFileException.class, method, e);
 90  0 return null;
 91    };
 92   
 93  2369 SimpleXPath find = null;
 94  2369 try {
 95  2369 find = XPathLocationFinder.getXPathLocation(
 96    new File(KernelContext.getInstance().getLocalFilePath(
 97    // FIXME mime 20071218: getLocalFilePath(URL) is missing
 98    // FIXME mime 20071218: getLocalFilePath(URL) should return String
 99    new DefaultModuleAddress(context.getModuleLocation()))),
 100    xpath,
 101    context.getModuleLocation());
 102  2365 if (find.getStartLocation() == null) {
 103  0 return null;
 104    }
 105  2365 return new SourceArea(context.getModuleLocation(), find.getStartLocation(),
 106    find.getEndLocation());
 107    } catch (ParserConfigurationException e) {
 108  0 Trace.trace(SourceFileException.class, method, e);
 109    } catch (SAXException e) {
 110  0 Trace.trace(SourceFileException.class, method, e);
 111    } catch (IOException e) {
 112  0 Trace.trace(SourceFileException.class, method, e);
 113    }
 114  0 return null;
 115    }
 116   
 117   
 118   
 119    }