Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 116   Methods: 3
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ModuleDataException2XmlFileException.java 75% 68,2% 66,7% 69%
coverage coverage
 1    /* $Id: ModuleDataException2XmlFileException.java,v 1.4 2008/01/26 12:39:09 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.IOException;
 21   
 22    import javax.xml.parsers.ParserConfigurationException;
 23   
 24    import org.qedeq.kernel.base.module.Qedeq;
 25    import org.qedeq.kernel.bo.module.ModuleContext;
 26    import org.qedeq.kernel.bo.module.ModuleDataException;
 27    import org.qedeq.kernel.common.SourceArea;
 28    import org.qedeq.kernel.common.SourceFileException;
 29    import org.qedeq.kernel.common.SourceFileExceptionList;
 30    import org.qedeq.kernel.context.KernelContext;
 31    import org.qedeq.kernel.trace.Trace;
 32    import org.qedeq.kernel.xml.parser.DefaultSourceFileExceptionList;
 33    import org.qedeq.kernel.xml.tracker.SimpleXPath;
 34    import org.qedeq.kernel.xml.tracker.XPathLocationParser;
 35    import org.xml.sax.SAXException;
 36   
 37   
 38    /**
 39    * Converts a {@link org.qedeq.kernel.bo.module.ModuleDataException} into a
 40    * {@link org.qedeq.kernel.common.SourceFileException}.
 41    *
 42    * @version $Revision: 1.4 $
 43    * @author Michael Meyling
 44    */
 45    public final class ModuleDataException2XmlFileException {
 46   
 47    /** This class. */
 48    private static final Class CLASS = ModuleDataException2XmlFileException.class;
 49   
 50    /**
 51    * Constructor.
 52    */
 53  0 private ModuleDataException2XmlFileException() {
 54    // nothing to do
 55    }
 56   
 57    /**
 58    * Create exception out of {@link ModuleDataException}.
 59    *
 60    * @param exception Take this exception.
 61    * @param qedeq Take this QEDEQ module.
 62    * @return Newly created instance.
 63    */
 64  25 public static final SourceFileExceptionList createXmlFileExceptionList(final ModuleDataException
 65    exception, final Qedeq qedeq) {
 66  25 final DefaultSourceFileExceptionList list = new DefaultSourceFileExceptionList();
 67  25 final SourceFileException e = new SourceFileException(exception, createSourceArea(qedeq,
 68    exception.getContext()), createSourceArea(qedeq, exception.getReferenceContext()));
 69  25 list.add(e);
 70  25 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  50 public static SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {
 81  50 final String method = "createSourceArea(Qedeq, ModuleContext)";
 82  50 if (qedeq == null || context == null) {
 83  21 return null;
 84    }
 85  29 final String xpath;
 86  29 try {
 87  29 xpath = Context2SimpleXPath.getXPath(context, qedeq).toString();
 88    } catch (ModuleDataException e) {
 89  0 Trace.trace(CLASS, method, e);
 90  0 return null;
 91    };
 92   
 93  29 SimpleXPath find = null;
 94  29 try {
 95  29 find = XPathLocationParser.getXPathLocation(
 96    KernelContext.getInstance().getLocalFilePath(context.getModuleLocation()),
 97    xpath,
 98    context.getModuleLocation().getURL());
 99  29 if (find.getStartLocation() == null) {
 100  0 return null;
 101    }
 102  29 return new SourceArea(context.getModuleLocation().getURL(), find.getStartLocation(),
 103    find.getEndLocation());
 104    } catch (ParserConfigurationException e) {
 105  0 Trace.trace(CLASS, method, e);
 106    } catch (SAXException e) {
 107  0 Trace.trace(CLASS, method, e);
 108    } catch (IOException e) {
 109  0 Trace.trace(CLASS, method, e);
 110    }
 111  0 return null;
 112    }
 113   
 114   
 115   
 116    }