Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 884   Methods: 74
NCLOC: 612   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Context2SimpleXPath.java 85,5% 92,5% 87,8% 90,9%
coverage coverage
 1    /* $Id: Context2SimpleXPath.java,v 1.8 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.util.ArrayList;
 21    import java.util.HashMap;
 22    import java.util.List;
 23    import java.util.Map;
 24   
 25    import org.qedeq.kernel.base.list.ElementList;
 26    import org.qedeq.kernel.base.module.Author;
 27    import org.qedeq.kernel.base.module.AuthorList;
 28    import org.qedeq.kernel.base.module.Axiom;
 29    import org.qedeq.kernel.base.module.Chapter;
 30    import org.qedeq.kernel.base.module.ChapterList;
 31    import org.qedeq.kernel.base.module.Formula;
 32    import org.qedeq.kernel.base.module.FunctionDefinition;
 33    import org.qedeq.kernel.base.module.Header;
 34    import org.qedeq.kernel.base.module.Import;
 35    import org.qedeq.kernel.base.module.ImportList;
 36    import org.qedeq.kernel.base.module.Latex;
 37    import org.qedeq.kernel.base.module.LatexList;
 38    import org.qedeq.kernel.base.module.LinkList;
 39    import org.qedeq.kernel.base.module.LiteratureItem;
 40    import org.qedeq.kernel.base.module.LiteratureItemList;
 41    import org.qedeq.kernel.base.module.Location;
 42    import org.qedeq.kernel.base.module.LocationList;
 43    import org.qedeq.kernel.base.module.Node;
 44    import org.qedeq.kernel.base.module.PredicateDefinition;
 45    import org.qedeq.kernel.base.module.Proof;
 46    import org.qedeq.kernel.base.module.ProofList;
 47    import org.qedeq.kernel.base.module.Proposition;
 48    import org.qedeq.kernel.base.module.Qedeq;
 49    import org.qedeq.kernel.base.module.Rule;
 50    import org.qedeq.kernel.base.module.Section;
 51    import org.qedeq.kernel.base.module.SectionList;
 52    import org.qedeq.kernel.base.module.Specification;
 53    import org.qedeq.kernel.base.module.Subsection;
 54    import org.qedeq.kernel.base.module.SubsectionList;
 55    import org.qedeq.kernel.base.module.Term;
 56    import org.qedeq.kernel.base.module.UsedByList;
 57    import org.qedeq.kernel.base.module.VariableList;
 58    import org.qedeq.kernel.bo.module.ModuleContext;
 59    import org.qedeq.kernel.bo.module.ModuleDataException;
 60    import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor;
 61    import org.qedeq.kernel.bo.visitor.QedeqNotNullTraverser;
 62    import org.qedeq.kernel.dto.list.Enumerator;
 63    import org.qedeq.kernel.trace.Trace;
 64    import org.qedeq.kernel.xml.tracker.SimpleXPath;
 65   
 66   
 67    /**
 68    * Map content string to SimpleXPath string. This class makes it possible to transfer an location
 69    * of an {@link org.qedeq.kernel.base.module.Qedeq} object into an XPath like position description
 70    * for an XML file representation of that object.
 71    *
 72    * <p>
 73    * See {@link #getXPath(ModuleContext, Qedeq)} for further details.
 74    *
 75    * <p>
 76    * TODO mime 20070217: It seems to work this way but: this class assumes that we can find
 77    * QEDEQ/CHAPTER[2]/SECTION[4]/SUBSECTIONS/SUBSECTION[2]
 78    * even if we have some ../NODE s inbetween.
 79    * (Example: NODE, NODE, SUBSECTION, NODE, SUBSECTION, NODE..)
 80    *
 81    * Is this still a correct XPath? (Old solution was usage of "*")
 82    * Seems ok for official XPath specification, but does it work for our SimpleXPathFinder?
 83    *
 84    * @version $Revision: 1.8 $
 85    * @author Michael Meyling
 86    */
 87    public final class Context2SimpleXPath extends AbstractModuleVisitor {
 88   
 89    /** This class. */
 90    private static final Class CLASS = Context2SimpleXPath.class;
 91   
 92    /** Traverse QEDEQ module with this traverser. */
 93    private QedeqNotNullTraverser traverser;
 94   
 95    /** QEDEQ object to work on. */
 96    private Qedeq qedeq;
 97   
 98    /** Search for this context. */
 99    private final ModuleContext find;
 100   
 101    /** We are currently at this position. */
 102    private SimpleXPath current;
 103   
 104    /** Element stack. */
 105    private final List elements;
 106   
 107    /** Current stack level. */
 108    private int level;
 109   
 110    /** Is the current context already matching the beginning of the search context? */
 111    private boolean matching;
 112   
 113    /** Last matching begin of search context. See {@link #matching}. */
 114    private String matchingBegin;
 115   
 116    /** Corresponding XPath for the {@link #matchingBegin}. */
 117    private SimpleXPath matchingPath;
 118   
 119    /**
 120    * Constructor.
 121    *
 122    * @param find Find this location.
 123    * @param qedeq Within this QEDEQ object.
 124    */
 125  32025 private Context2SimpleXPath(final ModuleContext find, final Qedeq qedeq) {
 126  32025 this.qedeq = qedeq;
 127  32025 traverser = new QedeqNotNullTraverser(find.getModuleLocation(), this);
 128  32025 this.find = find;
 129  32025 elements = new ArrayList(20);
 130    }
 131   
 132    /**
 133    * This method finds a {@link ModuleContext} something like<br>
 134    * <code>
 135    * getChapterList().get(4).getSectionList().get(0).getSubsectionList().get(4).getLatex().get(0)
 136    * </code><br>
 137    * within a {@link Qedeq} module and returns a kind of XPath location for an associated
 138    * XML document:<br>
 139    * <code>QEDEQ/CHAPTER[5]/SECTION/SUBSECTIONS/SUBSECTION[2]/TEXT/LATEX</code>
 140    *
 141    * <p>
 142    * At this example one can already see that <code>getSubsectionList().get(4)</code> is
 143    * transformed into <code>SUBSECTIONS/SUBSECTION[2]</code>. This is due to the fact that
 144    * <code>SUBSECTION</code> contains a sequence of <code>SUBSECTION</code> or <code>NODE</code>
 145    * elements. The transformation depends not only from the context but also from
 146    * the concrete QEDEQ module.
 147    *
 148    * <p>
 149    * Especially the transformation of formula location information in their XML counterpart
 150    * demands parsing the whole formula.
 151    *
 152    * @param find Find this location.
 153    * @param qedeq Within this QEDEQ object.
 154    * @return XPath for this location in the XML document.
 155    * @throws ModuleDataException
 156    */
 157  32025 public static SimpleXPath getXPath(final ModuleContext find, final Qedeq qedeq)
 158    throws ModuleDataException {
 159  32025 final Context2SimpleXPath converter = new Context2SimpleXPath(find, qedeq);
 160  32025 return converter.find();
 161    }
 162   
 163  32025 private final SimpleXPath find() throws ModuleDataException {
 164  32025 final String method = "find()";
 165  32025 Trace.paramInfo(CLASS, this, method, "find", find);
 166  32025 elements.clear();
 167  32025 level = 0;
 168  32025 current = new SimpleXPath();
 169  32025 try {
 170  32025 traverser.accept(qedeq);
 171    } catch (LocationFoundException e) {
 172  32025 Trace.paramInfo(CLASS, this, method, "location found", current);
 173  32025 return current;
 174    }
 175  0 Trace.param(CLASS, this, method, "level", level); // level should be equal to zero now
 176  0 Trace.info(CLASS, this, method, "location was not found");
 177  0 throw new LocationNotFoundException(find);
 178    }
 179   
 180  32025 public final void visitEnter(final Qedeq qedeq) throws ModuleDataException {
 181  32025 enter("QEDEQ");
 182  32025 final String method = "visitEnter(Qedeq)";
 183  32025 Trace.param(CLASS, this, method, "current", current);
 184  32025 checkMatching(method);
 185    }
 186   
 187  0 public final void visitLeave(final Qedeq qedeq) {
 188  0 leave();
 189    }
 190   
 191  32023 public final void visitEnter(final Header header) throws ModuleDataException {
 192  32023 enter("HEADER");
 193  32023 final String method = "visitEnter(Header)";
 194  32023 Trace.param(CLASS, this, method, "current", current);
 195  32023 final String context = traverser.getCurrentContext().getLocationWithinModule();
 196  32023 checkMatching(method);
 197   
 198  32010 traverser.setLocationWithinModule(context + ".getEmail()");
 199  32010 current.setAttribute("email");
 200  32010 checkIfFound();
 201    }
 202   
 203  31569 public final void visitLeave(final Header header) {
 204  31569 leave();
 205    }
 206   
 207  549 public final void visitEnter(final Specification specification) throws ModuleDataException {
 208  549 enter("SPECIFICATION");
 209  549 final String method = "visitEnter(Specification)";
 210  549 Trace.param(CLASS, this, method, "current", current);
 211  549 final String context = traverser.getCurrentContext().getLocationWithinModule();
 212  549 checkMatching(method);
 213   
 214  501 traverser.setLocationWithinModule(context + ".getName()");
 215  501 current.setAttribute("name");
 216  501 checkIfFound();
 217   
 218  479 traverser.setLocationWithinModule(context + ".getRuleVersion()");
 219  479 current.setAttribute("ruleVersion");
 220  479 checkIfFound();
 221    }
 222   
 223  325 public final void visitLeave(final Specification specification) {
 224  325 leave();
 225    }
 226   
 227  174060 public final void visitEnter(final LatexList latexList) throws ModuleDataException {
 228  174060 final String method = "visitEnter(LatexList)";
 229  174060 final String context = traverser.getCurrentContext().getLocationWithinModule();
 230  174060 final String name;
 231  174060 if (context.endsWith(".getTitle()")) {
 232  74004 name = "TITLE";
 233  100056 } else if (context.endsWith(".getSummary()")) {
 234  279 name = "ABSTRACT";
 235  99777 } else if (context.endsWith(".getIntroduction()")) {
 236  60954 name = "INTRODUCTION";
 237  38823 } else if (context.endsWith(".getName()")) {
 238  12539 name = "NAME";
 239  26284 } else if (context.endsWith(".getPrecedingText()")) {
 240  25510 name = "PRECEDING";
 241  774 } else if (context.endsWith(".getSucceedingText()")) {
 242  284 name = "SUCCEEDING";
 243  490 } else if (context.endsWith(".getLatex()")) {
 244  166 name = "TEXT";
 245  324 } else if (context.endsWith(".getDescription()")) {
 246  160 name = "DESCRIPTION";
 247  164 } else if (context.endsWith(".getNonFormalProof()")) { // no extra XSD element
 248  66 name = null;
 249  98 } else if (context.endsWith(".getItem()")) { // no extra XSD element
 250  98 name = null;
 251    } else { // programming error
 252  0 throw new IllegalArgumentException("unknown LatexList " + context);
 253    }
 254  174060 Trace.param(CLASS, this, method, "name", name);
 255  174060 if (name != null) {
 256  173896 enter(name);
 257    }
 258  174060 Trace.param(CLASS, this, method, "current", current);
 259   
 260  174060 checkMatching(method);
 261    }
 262   
 263  168670 public final void visitLeave(final LatexList latexList) {
 264  168670 final String context = traverser.getCurrentContext().getLocationWithinModule();
 265  168670 if (!context.endsWith(".getNonFormalProof()") // no extra XSD element
 266    && !context.endsWith(".getItem()")) {
 267  168670 leave();
 268    }
 269    }
 270   
 271  4133 public final void visitEnter(final Latex latex) throws ModuleDataException {
 272  4133 final String context = traverser.getCurrentContext().getLocationWithinModule();
 273  4133 if (context.indexOf(".getAuthorList().get(") >= 0) { // TODO mime 20070216: why is the
 274  13 enter("NAME"); // XSD so cruel???
 275    }
 276  4133 enter("LATEX");
 277  4133 final String method = "visitEnter(Latex)";
 278  4133 Trace.param(CLASS, this, method, "current", current);
 279  4133 checkMatching(method);
 280   
 281  1298 traverser.setLocationWithinModule(context + ".getLanguage()");
 282  1298 current.setAttribute("language");
 283  1298 checkIfFound();
 284   
 285  1298 traverser.setLocationWithinModule(context + ".getLatex()");
 286  1298 current.setAttribute(null); // element character data of LATEX is LaTeX content
 287  1298 checkIfFound();
 288    }
 289   
 290  1298 public final void visitLeave(final Latex latex) {
 291    // because NAME of AUTHOR/NAME/LATEX has no equivalent in interfaces:
 292  1298 final String context = traverser.getCurrentContext().getLocationWithinModule();
 293  1298 if (context.indexOf(".getAuthorList().get(") >= 0) {
 294  0 leave();
 295    }
 296  1298 leave();
 297    }
 298   
 299  132 public final void visitEnter(final LocationList locationList) throws ModuleDataException {
 300  132 enter("LOCATIONS");
 301  132 final String method = "visitEnter(LocationList)";
 302  132 Trace.param(CLASS, this, method, "current", current);
 303  132 checkMatching(method);
 304   
 305    }
 306   
 307  0 public final void visitLeave(final LocationList locationList) {
 308  0 leave();
 309    }
 310   
 311  98 public final void visitEnter(final Location location) throws ModuleDataException {
 312  98 enter("LOCATION");
 313  98 final String method = "visitEnter(Location)";
 314  98 Trace.param(CLASS, this, method, "current", current);
 315  98 final String context = traverser.getCurrentContext().getLocationWithinModule();
 316  98 checkMatching(method);
 317   
 318  40 traverser.setLocationWithinModule(context + ".getLocation()");
 319  40 current.setAttribute("value");
 320  40 checkIfFound();
 321    }
 322   
 323  14 public final void visitLeave(final Location location) {
 324  14 leave();
 325    }
 326   
 327  233 public final void visitEnter(final AuthorList authorList) throws ModuleDataException {
 328  233 enter("AUTHORS");
 329  233 final String method = "visitEnter(AuthorList)";
 330  233 Trace.param(CLASS, this, method, "current", current);
 331  233 checkMatching(method);
 332    }
 333   
 334  161 public final void visitLeave(final AuthorList authorList) {
 335  161 leave();
 336    }
 337   
 338  48 public final void visitEnter(final Author author) throws ModuleDataException {
 339  48 enter("AUTHOR");
 340  48 final String method = "visitEnter(Author)";
 341  48 Trace.param(CLASS, this, method, "current", current);
 342  48 final String context = traverser.getCurrentContext().getLocationWithinModule();
 343  48 checkMatching(method);
 344   
 345  24 traverser.setLocationWithinModule(context + ".getEmail()");
 346  24 current.setAttribute("email");
 347  24 checkIfFound();
 348    }
 349   
 350  0 public final void visitLeave(final Author author) {
 351  0 leave();
 352    }
 353   
 354  139 public final void visitEnter(final ImportList importList) throws ModuleDataException {
 355  139 enter("IMPORTS");
 356  139 final String method = "visitEnter(ImportList)";
 357  139 Trace.param(CLASS, this, method, "current", current);
 358  139 checkMatching(method);
 359    }
 360   
 361  33 public final void visitLeave(final ImportList importList) {
 362  33 leave();
 363    }
 364   
 365  106 public final void visitEnter(final Import imp) throws ModuleDataException {
 366  106 enter("IMPORT");
 367  106 final String method = "visitEnter(Import)";
 368  106 Trace.param(CLASS, this, method, "current", current);
 369  106 final String context = traverser.getCurrentContext().getLocationWithinModule();
 370  106 checkMatching(method);
 371   
 372  92 traverser.setLocationWithinModule(context + ".getLabel()");
 373  92 current.setAttribute("label");
 374  92 checkIfFound();
 375    }
 376   
 377  12 public final void visitLeave(final Import imp) {
 378  12 leave();
 379    }
 380   
 381  55 public final void visitEnter(final UsedByList usedByList) throws ModuleDataException {
 382  55 enter("USEDBY");
 383  55 final String method = "visitEnter(UsedByList)";
 384  55 Trace.param(CLASS, this, method, "current", current);
 385  55 checkMatching(method);
 386    }
 387   
 388  0 public final void visitLeave(final UsedByList usedByList) {
 389  0 leave();
 390    }
 391   
 392  31569 public final void visitEnter(final ChapterList chapterList) throws ModuleDataException {
 393  31569 final String method = "visitEnter(ChapterList)";
 394    // because no equivalent level of "getChapterList()" exists in the XSD we simply
 395    // point to the current location that must be "QEDEQ"
 396  31569 checkMatching(method);
 397    }
 398   
 399  170 public final void visitLeave(final ChapterList chapterList) {
 400  170 traverser.setBlocked(false); // free sub node search
 401    }
 402   
 403  139181 public final void visitEnter(final Chapter chapter) throws ModuleDataException {
 404  139181 enter("CHAPTER");
 405  139181 final String method = "visitEnter(Chapter)";
 406  139181 Trace.param(CLASS, this, method, "current", current);
 407  139181 final String context = traverser.getCurrentContext().getLocationWithinModule();
 408  139181 checkMatching(method);
 409   
 410  139056 traverser.setLocationWithinModule(context + ".getNoNumber()");
 411  139056 current.setAttribute("noNumber");
 412  139056 checkIfFound();
 413    }
 414   
 415  107794 public final void visitLeave(final Chapter chapter) {
 416  107794 leave();
 417    }
 418   
 419  30761 public final void visitEnter(final SectionList sectionList) throws ModuleDataException {
 420  30761 final String method = "visitEnter(SectionList)";
 421    // because no equivalent level of "getSectionList()" exists in the XSD we simply
 422    // point to the current location that must be "QEDEQ/CHAPTER[x]"
 423  30761 checkMatching(method);
 424    }
 425   
 426  0 public final void visitLeave(final SectionList sectionList) {
 427  0 traverser.setBlocked(false); // free sub node search
 428    }
 429   
 430  74894 public final void visitEnter(final Section section) throws ModuleDataException {
 431  74894 enter("SECTION");
 432  74894 final String method = "visitEnter(Section)";
 433  74894 Trace.param(CLASS, this, method, "current", current);
 434  74894 final String context = traverser.getCurrentContext().getLocationWithinModule();
 435  74894 checkMatching(method);
 436   
 437  74661 traverser.setLocationWithinModule(context + ".getNoNumber()");
 438  74661 current.setAttribute("noNumber");