Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: So Mrz 11 2007 07:05:19 CET
file stats: LOC: 881   Methods: 74
NCLOC: 611   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Context2SimpleXPath.java 85,5% 92,2% 86,5% 90,5%
coverage coverage
 1    /* $Id: Context2SimpleXPath.java,v 1.6 2007/03/11 01:19:33 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.ModuleDataException;
 59    import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor;
 60    import org.qedeq.kernel.bo.visitor.QedeqNotNullTransverser;
 61    import org.qedeq.kernel.context.ModuleContext;
 62    import org.qedeq.kernel.dto.list.Enumerator;
 63    import org.qedeq.kernel.log.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.6 $
 85    * @author Michael Meyling
 86    */
 87    public final class Context2SimpleXPath extends AbstractModuleVisitor {
 88   
 89    /** Transverse QEDEQ module with this transverser. */
 90    private QedeqNotNullTransverser transverser;
 91   
 92    /** QEDEQ object to work on. */
 93    private Qedeq qedeq;
 94   
 95    /** Search for this context. */
 96    private final ModuleContext find;
 97   
 98    /** We are currently at this position. */
 99    private SimpleXPath current;
 100   
 101    /** Element stack. */
 102    private final List elements;
 103   
 104    /** Current stack level. */
 105    private int level;
 106   
 107    /** Is the current context already matching the beginning of the search context? */
 108    private boolean matching;
 109   
 110    /** Last matching begin of search context. See {@link #matching}. */
 111    private String matchingBegin;
 112   
 113    /** Corresponding XPath for the {@link #matchingBegin}. */
 114    private SimpleXPath matchingPath;
 115   
 116    /**
 117    * Constructor.
 118    *
 119    * @param find Find this location.
 120    * @param qedeq Within this QEDEQ object.
 121    */
 122  26681 private Context2SimpleXPath(final ModuleContext find, final Qedeq qedeq) {
 123  26681 this.qedeq = qedeq;
 124  26681 transverser = new QedeqNotNullTransverser(find.getModuleLocation(), this);
 125  26681 this.find = find;
 126  26681 elements = new ArrayList(20);
 127    }
 128   
 129    /**
 130    * This method finds a {@link ModuleContext} something like<br>
 131    * <code>
 132    * getChapterList().get(4).getSectionList().get(0).getSubsectionList().get(4).getLatex().get(0)
 133    * </code><br>
 134    * within a {@link Qedeq} module and returns a kind of XPath location for an associated
 135    * XML document:<br>
 136    * <code>QEDEQ/CHAPTER[5]/SECTION/SUBSECTIONS/SUBSECTION[2]/TEXT/LATEX</code>
 137    *
 138    * <p>
 139    * At this example one can already see that <code>getSubsectionList().get(4)</code> is
 140    * transformed into <code>SUBSECTIONS/SUBSECTION[2]</code>. This is due to the fact that
 141    * <code>SUBSECTION</code> contains a sequence of <code>SUBSECTION</code> or <code>NODE</code>
 142    * elements. The transformation depends not only from the context but also from
 143    * the concrete QEDEQ module.
 144    *
 145    * <p>
 146    * Especially the transformation of formula location information in their XML counterpart
 147    * demands parsing the whole formula.
 148    *
 149    * @param find Find this location.
 150    * @param qedeq Within this QEDEQ object.
 151    * @return XPath for this location in the XML document.
 152    * @throws ModuleDataException
 153    */
 154  26681 public static SimpleXPath getXPath(final ModuleContext find, final Qedeq qedeq)
 155    throws ModuleDataException {
 156  26681 final Context2SimpleXPath converter = new Context2SimpleXPath(find, qedeq);
 157  26681 return converter.find();
 158    }
 159   
 160  26681 private final SimpleXPath find() throws ModuleDataException {
 161  26681 final String method = "find()";
 162  26681 Trace.paramInfo(this, method, "find", find);
 163  26681 elements.clear();
 164  26681 level = 0;
 165  26681 current = new SimpleXPath();
 166  26681 try {
 167  26681 transverser.accept(qedeq);
 168    } catch (LocationFoundException e) {
 169  26681 Trace.paramInfo(this, method, "location found", current);
 170  26681 return current;
 171    }
 172  0 Trace.param(this, method, "level", level); // level should be equal to zero now
 173  0 Trace.info(this, method, "location was not found");
 174  0 throw new LocationNotFoundException(find);
 175    }
 176   
 177  26681 public final void visitEnter(final Qedeq qedeq) throws ModuleDataException {
 178  26681 enter("QEDEQ");
 179  26681 final String method = "visitEnter(Qedeq)";
 180  26681 Trace.param(this, method, "current", current);
 181  26681 checkMatching(method);
 182    }
 183   
 184  0 public final void visitLeave(final Qedeq qedeq) {
 185  0 leave();
 186    }
 187   
 188  26679 public final void visitEnter(final Header header) throws ModuleDataException {
 189  26679 enter("HEADER");
 190  26679 final String method = "visitEnter(Header)";
 191  26679 Trace.param(this, method, "current", current);
 192  26679 final String context = transverser.getCurrentContext().getLocationWithinModule();
 193  26679 checkMatching(method);
 194   
 195  26666 transverser.setLocationWithinModule(context + ".getEmail()");
 196  26666 current.setAttribute("email");
 197  26666 checkIfFound();
 198    }
 199   
 200  26215 public final void visitLeave(final Header header) {
 201  26215 leave();
 202    }
 203   
 204  563 public final void visitEnter(final Specification specification) throws ModuleDataException {
 205  563 enter("SPECIFICATION");
 206  563 final String method = "visitEnter(Specification)";
 207  563 Trace.param(this, method, "current", current);
 208  563 final String context = transverser.getCurrentContext().getLocationWithinModule();
 209  563 checkMatching(method);
 210   
 211  511 transverser.setLocationWithinModule(context + ".getName()");
 212  511 current.setAttribute("name");
 213  511 checkIfFound();
 214   
 215  487 transverser.setLocationWithinModule(context + ".getRuleVersion()");
 216  487 current.setAttribute("ruleVersion");
 217  487 checkIfFound();
 218    }
 219   
 220  335 public final void visitLeave(final Specification specification) {
 221  335 leave();
 222    }
 223   
 224  138451 public final void visitEnter(final LatexList latexList) throws ModuleDataException {
 225  138451 final String method = "visitEnter(LatexList)";
 226  138451 final String context = transverser.getCurrentContext().getLocationWithinModule();
 227  138451 final String name;
 228  138451 if (context.endsWith(".getTitle()")) {
 229  58496 name = "TITLE";
 230  79955 } else if (context.endsWith(".getSummary()")) {
 231  289 name = "ABSTRACT";
 232  79666 } else if (context.endsWith(".getIntroduction()")) {
 233  50266 name = "INTRODUCTION";
 234  29400 } else if (context.endsWith(".getName()")) {
 235  7583 name = "NAME";
 236  21817 } else if (context.endsWith(".getPrecedingText()")) {
 237  21107 name = "PRECEDING";
 238  710 } else if (context.endsWith(".getSucceedingText()")) {
 239  276 name = "SUCCEEDING";
 240  434 } else if (context.endsWith(".getLatex()")) {
 241  150 name = "TEXT";
 242  284 } else if (context.endsWith(".getDescription()")) {
 243  120 name = "DESCRIPTION";
 244  164 } else if (context.endsWith(".getNonFormalProof()")) { // no extra XSD element
 245  66 name = null;
 246  98 } else if (context.endsWith(".getItem()")) { // no extra XSD element
 247  98 name = null;
 248    } else { // programming error
 249  0 throw new IllegalArgumentException("unknown LatexList " + context);
 250    }
 251  138451 Trace.param(this, method, "name", name);
 252  138451 if (name != null) {
 253  138287 enter(name);
 254    }
 255  138451 Trace.param(this, method, "current", current);
 256   
 257  138451 checkMatching(method);
 258    }
 259   
 260  133505 public final void visitLeave(final LatexList latexList) {
 261  133505 final String context = transverser.getCurrentContext().getLocationWithinModule();
 262  133505 if (!context.endsWith(".getNonFormalProof()") // no extra XSD element
 263    && !context.endsWith(".getItem()")) {
 264  133505 leave();
 265    }
 266    }
 267   
 268  3785 public final void visitEnter(final Latex latex) throws ModuleDataException {
 269  3785 final String context = transverser.getCurrentContext().getLocationWithinModule();
 270  3785 if (context.indexOf(".getAuthorList().get(") >= 0) { // TODO mime 20070216: why is the
 271  13 enter("NAME"); // XSD so cruel???
 272    }
 273  3785 enter("LATEX");
 274  3785 final String method = "visitEnter(Latex)";
 275  3785 Trace.param(this, method, "current", current);
 276  3785 checkMatching(method);
 277   
 278  1178 transverser.setLocationWithinModule(context + ".getLanguage()");
 279  1178 current.setAttribute("language");
 280  1178 checkIfFound();
 281   
 282  1178 transverser.setLocationWithinModule(context + ".getLatex()");
 283  1178 current.setAttribute(null); // element character data of LATEX is LaTeX content
 284  1178 checkIfFound();
 285    }
 286   
 287  1178 public final void visitLeave(final Latex latex) {
 288    // because NAME of AUTHOR/NAME/LATEX has no equivalent in interfaces:
 289  1178 final String context = transverser.getCurrentContext().getLocationWithinModule();
 290  1178 if (context.indexOf(".getAuthorList().get(") >= 0) {
 291  0 leave();
 292    }
 293  1178 leave();
 294    }
 295   
 296  128 public final void visitEnter(final LocationList locationList) throws ModuleDataException {
 297  128 enter("LOCATIONS");
 298  128 final String method = "visitEnter(LocationList)";
 299  128 Trace.param(this, method, "current", current);
 300  128 checkMatching(method);
 301   
 302    }
 303   
 304  0 public final void visitLeave(final LocationList locationList) {
 305  0 leave();
 306    }
 307   
 308  76 public final void visitEnter(final Location location) throws ModuleDataException {
 309  76 enter("LOCATION");
 310  76 final String method = "visitEnter(Location)";
 311  76 Trace.param(this, method, "current", current);
 312  76 final String context = transverser.getCurrentContext().getLocationWithinModule();
 313  76 checkMatching(method);
 314   
 315  24 transverser.setLocationWithinModule(context + ".getLocation()");
 316  24 current.setAttribute("value");
 317  24 checkIfFound();
 318    }
 319   
 320  0 public final void visitLeave(final Location location) {
 321  0 leave();
 322    }
 323   
 324  243 public final void visitEnter(final AuthorList authorList) throws ModuleDataException {
 325  243 enter("AUTHORS");
 326  243 final String method = "visitEnter(AuthorList)";
 327  243 Trace.param(this, method, "current", current);
 328  243 checkMatching(method);
 329    }
 330   
 331  171 public final void visitLeave(final AuthorList authorList) {
 332  171 leave();
 333    }
 334   
 335  48 public final void visitEnter(final Author author) throws ModuleDataException {
 336  48 enter("AUTHOR");
 337  48 final String method = "visitEnter(Author)";
 338  48 Trace.param(this, method, "current", current);
 339  48 final String context = transverser.getCurrentContext().getLocationWithinModule();
 340  48 checkMatching(method);
 341   
 342  24 transverser.setLocationWithinModule(context + ".getEmail()");
 343  24 current.setAttribute("email");
 344  24 checkIfFound();
 345    }
 346   
 347  0 public final void visitLeave(final Author author) {
 348  0 leave();
 349    }
 350   
 351  149 public final void visitEnter(final ImportList importList) throws ModuleDataException {
 352  149 enter("IMPORTS");
 353  149 final String method = "visitEnter(ImportList)";
 354  149 Trace.param(this, method, "current", current);
 355  149 checkMatching(method);
 356    }
 357   
 358  33 public final void visitLeave(final ImportList importList) {
 359  33 leave();
 360    }
 361   
 362  140 public final void visitEnter(final Import imp) throws ModuleDataException {
 363  140 enter("IMPORT");
 364  140 final String method = "visitEnter(Import)";
 365  140 Trace.param(this, method, "current", current);
 366  140 final String context = transverser.getCurrentContext().getLocationWithinModule();
 367  140 checkMatching(method);
 368   
 369  122 transverser.setLocationWithinModule(context + ".getLabel()");
 370  122 current.setAttribute("label");
 371  122 checkIfFound();
 372    }
 373   
 374  36 public final void visitLeave(final Import imp) {
 375  36 leave();
 376    }
 377   
 378  55 public final void visitEnter(final UsedByList usedByList) throws ModuleDataException {
 379  55 enter("USEDBY");
 380  55 final String method = "visitEnter(UsedByList)";
 381  55 Trace.param(this, method, "current", current);
 382  55 checkMatching(method);
 383    }
 384   
 385  0 public final void visitLeave(final UsedByList usedByList) {
 386  0 leave();
 387    }
 388   
 389  26215 public final void visitEnter(final ChapterList chapterList) throws ModuleDataException {
 390  26215 final String method = "visitEnter(ChapterList)";
 391    // because no equivalent level of "getChapterList()" exists in the XSD we simply
 392    // point to the current location that must be "QEDEQ"
 393  26215 checkMatching(method);
 394    }
 395   
 396  170 public final void visitLeave(final ChapterList chapterList) {
 397  170 transverser.setBlocked(false); // free sub node search
 398    }
 399   
 400  105943 public final void visitEnter(final Chapter chapter) throws ModuleDataException {
 401  105943 enter("CHAPTER");
 402  105943 final String method = "visitEnter(Chapter)";
 403  105943 Trace.param(this, method, "current", current);
 404  105943 final String context = transverser.getCurrentContext().getLocationWithinModule();
 405  105943 checkMatching(method);
 406   
 407  105818 transverser.setLocationWithinModule(context + ".getNoNumber()");
 408  105818 current.setAttribute("noNumber");
 409  105818 checkIfFound();
 410    }
 411   
 412  79910 public final void visitLeave(final Chapter chapter) {
 413  79910 leave();
 414    }
 415   
 416  25409 public final void visitEnter(final SectionList sectionList) throws ModuleDataException {
 417  25409 final String method = "visitEnter(SectionList)";
 418    // because no equivalent level of "getSectionList()" exists in the XSD we simply
 419    // point to the current location that must be "QEDEQ/CHAPTER[x]"
 420  25409 checkMatching(method);
 421    }
 422   
 423  0 public final void visitLeave(final SectionList sectionList) {
 424  0 transverser.setBlocked(false); // free sub node search
 425    }
 426   
 427  67004 public final void visitEnter(final Section section) throws ModuleDataException {
 428  67004 enter("SECTION");
 429  67004 final String method = "visitEnter(Section)";
 430  67004 Trace.param(this, method, "current", current);
 431  67004 final String context = transverser.getCurrentContext().getLocationWithinModule();
 432  67004 checkMatching(method);
 433   
 434  66771 transverser.setLocationWithinModule(context + ".getNoNumber()");
 435  66771 current.setAttribute("noNumber");
 436  66771 checkIfFound();
 437    }
 438   
 439