Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
562   1,244   156   5.11
78   909   0.28   110
110     1.42  
1    
 
  Context2SimpleXPath       Line # 103 562 156 92.1% 0.9213333
 
  (74)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.xml.mapper;
17   
18    import java.util.ArrayList;
19    import java.util.HashMap;
20    import java.util.List;
21    import java.util.Map;
22   
23    import org.qedeq.base.trace.Trace;
24    import org.qedeq.base.utility.Enumerator;
25    import org.qedeq.kernel.se.base.list.ElementList;
26    import org.qedeq.kernel.se.base.module.Add;
27    import org.qedeq.kernel.se.base.module.Author;
28    import org.qedeq.kernel.se.base.module.AuthorList;
29    import org.qedeq.kernel.se.base.module.Axiom;
30    import org.qedeq.kernel.se.base.module.ChangedRule;
31    import org.qedeq.kernel.se.base.module.ChangedRuleList;
32    import org.qedeq.kernel.se.base.module.Chapter;
33    import org.qedeq.kernel.se.base.module.ChapterList;
34    import org.qedeq.kernel.se.base.module.Conclusion;
35    import org.qedeq.kernel.se.base.module.ConditionalProof;
36    import org.qedeq.kernel.se.base.module.Existential;
37    import org.qedeq.kernel.se.base.module.FormalProof;
38    import org.qedeq.kernel.se.base.module.FormalProofLine;
39    import org.qedeq.kernel.se.base.module.FormalProofLineList;
40    import org.qedeq.kernel.se.base.module.FormalProofList;
41    import org.qedeq.kernel.se.base.module.Formula;
42    import org.qedeq.kernel.se.base.module.FunctionDefinition;
43    import org.qedeq.kernel.se.base.module.Header;
44    import org.qedeq.kernel.se.base.module.Hypothesis;
45    import org.qedeq.kernel.se.base.module.Import;
46    import org.qedeq.kernel.se.base.module.ImportList;
47    import org.qedeq.kernel.se.base.module.InitialFunctionDefinition;
48    import org.qedeq.kernel.se.base.module.InitialPredicateDefinition;
49    import org.qedeq.kernel.se.base.module.Latex;
50    import org.qedeq.kernel.se.base.module.LatexList;
51    import org.qedeq.kernel.se.base.module.LinkList;
52    import org.qedeq.kernel.se.base.module.LiteratureItem;
53    import org.qedeq.kernel.se.base.module.LiteratureItemList;
54    import org.qedeq.kernel.se.base.module.Location;
55    import org.qedeq.kernel.se.base.module.LocationList;
56    import org.qedeq.kernel.se.base.module.ModusPonens;
57    import org.qedeq.kernel.se.base.module.Node;
58    import org.qedeq.kernel.se.base.module.PredicateDefinition;
59    import org.qedeq.kernel.se.base.module.Proof;
60    import org.qedeq.kernel.se.base.module.ProofList;
61    import org.qedeq.kernel.se.base.module.Proposition;
62    import org.qedeq.kernel.se.base.module.Qedeq;
63    import org.qedeq.kernel.se.base.module.Reason;
64    import org.qedeq.kernel.se.base.module.Rename;
65    import org.qedeq.kernel.se.base.module.Rule;
66    import org.qedeq.kernel.se.base.module.Section;
67    import org.qedeq.kernel.se.base.module.SectionList;
68    import org.qedeq.kernel.se.base.module.Specification;
69    import org.qedeq.kernel.se.base.module.Subsection;
70    import org.qedeq.kernel.se.base.module.SubsectionList;
71    import org.qedeq.kernel.se.base.module.SubstFree;
72    import org.qedeq.kernel.se.base.module.SubstFunc;
73    import org.qedeq.kernel.se.base.module.SubstPred;
74    import org.qedeq.kernel.se.base.module.Term;
75    import org.qedeq.kernel.se.base.module.Universal;
76    import org.qedeq.kernel.se.base.module.UsedByList;
77    import org.qedeq.kernel.se.common.ModuleContext;
78    import org.qedeq.kernel.se.common.ModuleDataException;
79    import org.qedeq.kernel.se.visitor.AbstractModuleVisitor;
80    import org.qedeq.kernel.se.visitor.QedeqNotNullTraverser;
81    import org.qedeq.kernel.xml.tracker.SimpleXPath;
82   
83   
84    /**
85    * Map content string to SimpleXPath string. This class makes it possible to transfer an location
86    * of an {@link org.qedeq.kernel.se.base.module.Qedeq} object into an XPath like position description
87    * for an XML file representation of that object.
88    *
89    * <p>
90    * See {@link #getXPath(ModuleContext, Qedeq)} for further details.
91    *
92    * <p>
93    * TODO mime 20070217: It seems to work this way but: this class assumes that we can find
94    * QEDEQ/CHAPTER[2]/SECTION[4]/SUBSECTIONS/SUBSECTION[2]
95    * even if we have some ../NODE s inbetween.
96    * (Example: NODE, NODE, SUBSECTION, NODE, SUBSECTION, NODE..)
97    *
98    * Is this still a correct XPath? (Old solution was usage of "*")
99    * Seems ok for official XPath specification, but does it work for our SimpleXPathFinder?
100    *
101    * @author Michael Meyling
102    */
 
103    public final class Context2SimpleXPath extends AbstractModuleVisitor {
104   
105    /** This class. */
106    private static final Class CLASS = Context2SimpleXPath.class;
107   
108    /** Traverse QEDEQ module with this traverser. */
109    private QedeqNotNullTraverser traverser;
110   
111    /** QEDEQ object to work on. */
112    private Qedeq qedeq;
113   
114    /** Search for this context. */
115    private final ModuleContext find;
116   
117    /** We are currently at this position. */
118    private SimpleXPath current;
119   
120    /** Element stack. */
121    private final List elements;
122   
123    /** Current stack level. */
124    private int level;
125   
126    /** Is the current context already matching the beginning of the search context? */
127    private boolean matching;
128   
129    /** Last matching begin of search context. See {@link #matching}. */
130    private String matchingBegin;
131   
132    /** Corresponding XPath for the {@link #matchingBegin}. */
133    private SimpleXPath matchingPath;
134   
135    /**
136    * Constructor.
137    *
138    * @param find Find this location.
139    * @param qedeq Within this QEDEQ object.
140    */
 
141  66844 toggle private Context2SimpleXPath(final ModuleContext find, final Qedeq qedeq) {
142  66844 this.qedeq = qedeq;
143  66844 traverser = new QedeqNotNullTraverser(find.getModuleLocation(), this);
144  66844 this.find = find;
145  66844 elements = new ArrayList(20);
146    }
147   
148    /**
149    * This method finds a {@link ModuleContext} something like<br>
150    * <code>
151    * getChapterList().get(4).getSectionList().get(0).getSubsectionList().get(4).getLatex().get(0)
152    * </code><br>
153    * within a {@link Qedeq} module and returns a kind of XPath location for an associated
154    * XML document:<br>
155    * <code>QEDEQ/CHAPTER[5]/SECTION/SUBSECTIONS/SUBSECTION[2]/TEXT/LATEX</code>
156    *
157    * <p>
158    * At this example one can already see that <code>getSubsectionList().get(4)</code> is
159    * transformed into <code>SUBSECTIONS/SUBSECTION[2]</code>. This is due to the fact that
160    * <code>SUBSECTION</code> contains a sequence of <code>SUBSECTION</code> or <code>NODE</code>
161    * elements. The transformation depends not only from the context but also from
162    * the concrete QEDEQ module.
163    *
164    * <p>
165    * Especially the transformation of formula location information in their XML counterpart
166    * demands parsing the whole formula.
167    *
168    * @param find Find this location.
169    * @param qedeq Within this QEDEQ object.
170    * @return XPath for this location in the XML document.
171    * @throws ModuleDataException Problem with module data.
172    */
 
173  66844 toggle public static SimpleXPath getXPath(final ModuleContext find, final Qedeq qedeq)
174    throws ModuleDataException {
175  66844 final Context2SimpleXPath converter = new Context2SimpleXPath(find, qedeq);
176  66844 return converter.find();
177    }
178   
 
179  66844 toggle private final SimpleXPath find() throws ModuleDataException {
180  66844 final String method = "find()";
181  66844 Trace.paramInfo(CLASS, this, method, "find", find);
182  66844 elements.clear();
183  66844 level = 0;
184  66844 current = new SimpleXPath();
185  66844 try {
186  66844 traverser.accept(qedeq);
187    } catch (LocationFoundException e) {
188  66843 Trace.paramInfo(CLASS, this, method, "location found", current);
189  66843 return current;
190    }
191  1 Trace.param(CLASS, this, method, "level", level); // level should be equal to zero now
192  1 Trace.info(CLASS, this, method, "location was not found");
193    // do we really want to fail?
194  1 if (Boolean.TRUE.toString().equalsIgnoreCase(
195    System.getProperty("qedeq.test.xmlLocationFailures"))) {
196  1 throw new LocationNotFoundException(traverser.getCurrentContext(),
197    matchingBegin, find.getLocationWithinModule());
198    }
199  0 throw new LocationFoundException(new ModuleContext(find.getModuleLocation(),
200    matchingBegin));
201    }
202   
 
203  66844 toggle public final void visitEnter(final Qedeq qedeq) throws ModuleDataException {
204  66844 enter("QEDEQ");
205  66844 final String method = "visitEnter(Qedeq)";
206  66844 Trace.param(CLASS, this, method, "current", current);
207  66844 checkMatching(method);
208    }
209   
 
210  1 toggle public final void visitLeave(final Qedeq qedeq) {
211  1 leave();
212    }
213   
 
214  66841 toggle public final void visitEnter(final Header header) throws ModuleDataException {
215  66841 enter("HEADER");
216  66841 final String method = "visitEnter(Header)";
217  66841 Trace.param(CLASS, this, method, "current", current);
218  66841 final String context = traverser.getCurrentContext().getLocationWithinModule();
219  66841 checkMatching(method);
220   
221  66820 traverser.setLocationWithinModule(context + ".getEmail()");
222  66820 current.setAttribute("email");
223  66820 checkIfFound();
224    }
225   
 
226  66098 toggle public final void visitLeave(final Header header) {
227  66098 leave();
228    }
229   
 
230  892 toggle public final void visitEnter(final Specification specification) throws ModuleDataException {
231  892 enter("SPECIFICATION");
232  892 final String method = "visitEnter(Specification)";
233  892 Trace.param(CLASS, this, method, "current", current);
234  892 final String context = traverser.getCurrentContext().getLocationWithinModule();
235  892 checkMatching(method);
236   
237  820 traverser.setLocationWithinModule(context + ".getName()");
238  820 current.setAttribute("name");
239  820 checkIfFound();
240   
241  786 traverser.setLocationWithinModule(context + ".getRuleVersion()");
242  786 current.setAttribute("ruleVersion");
243  786 checkIfFound();
244    }
245   
 
246  536 toggle public final void visitLeave(final Specification specification) {
247  536 leave();
248    }
249   
 
250  320652 toggle public final void visitEnter(final LatexList latexList) throws ModuleDataException {
251  320652 final String method = "visitEnter(LatexList)";
252  320652 final String context = traverser.getCurrentContext().getLocationWithinModule();
253  320652 final String name;
254  320652 if (context.endsWith(".getTitle()")) {
255  145735 name = "TITLE";
256  174917 } else if (context.endsWith(".getSummary()")) {
257  467 name = "ABSTRACT";
258  174450 } else if (context.endsWith(".getIntroduction()")) {
259  129231 name = "INTRODUCTION";
260  45219 } else if (context.endsWith(".getName()")) {
261  15620 name = "NAME";
262  29599 } else if (context.endsWith(".getPrecedingText()")) {
263  28217 name = "PRECEDING";
264  1382 } else if (context.endsWith(".getSucceedingText()")) {
265  361 name = "SUCCEEDING";
266  1021 } else if (context.endsWith(".getLatex()")) {
267  224 name = "TEXT";
268  797 } else if (context.endsWith(".getDescription()")) {
269  407 if (context.indexOf(".getChangedRuleList().get(") >= 0) {
270  32 name = null;
271    } else {
272  375 name = "DESCRIPTION";
273    }
274  390 } else if (context.endsWith(".getNonFormalProof()")) { // no extra XSD element
275  276 name = null;
276  114 } else if (context.endsWith(".getItem()")) { // no extra XSD element
277  114 name = null;
278    } else { // programming error
279  0 throw new IllegalArgumentException("unknown LatexList " + context);
280    }
281  320652 Trace.param(CLASS, this, method, "name", name);
282  320652 if (name != null) {
283  320230 enter(name);
284    }
285  320652 Trace.param(CLASS, this, method, "current", current);
286   
287  320652 checkMatching(method);
288    }
289   
 
290  313712 toggle public final void visitLeave(final LatexList latexList) {
291  313712 final String context = traverser.getCurrentContext().getLocationWithinModule();
292  313712 if (!context.endsWith(".getNonFormalProof()") // no extra XSD element
293    && !context.endsWith(".getItem()") && !(context.endsWith(".getDescription()")
294    && context.indexOf(".getChangedRuleList().get(") >= 0)) {
295  313712 leave();
296    }
297    }
298   
 
299  5062 toggle public final void visitEnter(final Latex latex) throws ModuleDataException {
300  5062 final String context = traverser.getCurrentContext().getLocationWithinModule();
301  5062 if (context.indexOf(".getAuthorList().get(") >= 0) { // TODO mime 20070216: why is the
302  20 enter("NAME"); // XSD so cruel???
303    }
304  5062 enter("LATEX");
305  5062 final String method = "visitEnter(Latex)";
306  5062 Trace.param(CLASS, this, method, "current", current);
307  5062 checkMatching(method);
308   
309  1520 traverser.setLocationWithinModule(context + ".getLanguage()");
310  1520 current.setAttribute("language");
311  1520 checkIfFound();
312   
313  1520 traverser.setLocationWithinModule(context + ".getLatex()");
314  1520 current.setAttribute(null); // element character data of LATEX is LaTeX content
315  1520 checkIfFound();
316    }
317   
 
318  1520 toggle public final void visitLeave(final Latex latex) {
319    // because NAME of AUTHOR/NAME/LATEX has no equivalent in interfaces:
320  1520 final String context = traverser.getCurrentContext().getLocationWithinModule();
321  1520 if (context.indexOf(".getAuthorList().get(") >= 0) {
322  0 leave();
323    }
324  1520 leave();
325    }
326   
 
327  216 toggle public final void visitEnter(final LocationList locationList) throws ModuleDataException {
328  216 enter("LOCATIONS");
329  216 final String method = "visitEnter(LocationList)";
330  216 Trace.param(CLASS, this, method, "current", current);
331  216 checkMatching(method);
332   
333    }
334   
 
335  0 toggle public final void visitLeave(final LocationList locationList) {
336  0 leave();
337    }
338   
 
339  194 toggle public final void visitEnter(final Location location) throws ModuleDataException {
340  194 enter("LOCATION");
341  194 final String method = "visitEnter(Location)";
342  194 Trace.param(CLASS, this, method, "current", current);
343  194 final String context = traverser.getCurrentContext().getLocationWithinModule();
344  194 checkMatching(method);
345   
346  96 traverser.setLocationWithinModule(context + ".getLocation()");
347  96 current.setAttribute("value");
348  96 checkIfFound();
349    }
350   
 
351  50 toggle public final void visitLeave(final Location location) {
352  50 leave();
353    }
354   
 
355  398 toggle public final void visitEnter(final AuthorList authorList) throws ModuleDataException {
356  398 enter("AUTHORS");
357  398 final String method = "visitEnter(AuthorList)";
358  398 Trace.param(CLASS, this, method, "current", current);
359  398 checkMatching(method);
360    }
361   
 
362  284 toggle public final void visitLeave(final AuthorList authorList) {
363  284 leave();
364    }
365   
 
366  76 toggle public final void visitEnter(final Author author) throws ModuleDataException {
367  76 enter("AUTHOR");
368  76 final String method = "visitEnter(Author)";
369  76 Trace.param(CLASS, this, method, "current", current);
370  76 final String context = traverser.getCurrentContext().getLocationWithinModule();
371  76 checkMatching(method);
372   
373  38 traverser.setLocationWithinModule(context + ".getEmail()");
374  38 current.setAttribute("email");
375  38 checkIfFound();
376    }
377   
 
378  0 toggle public final void visitLeave(final Author author) {
379  0 leave();
380    }
381   
 
382  251 toggle public final void visitEnter(final ImportList importList) throws ModuleDataException {
383  251 enter("IMPORTS");
384  251 final String method = "visitEnter(ImportList)";
385  251 Trace.param(CLASS, this, method, "current", current);
386  251 checkMatching(method);
387    }
388   
 
389  33 toggle public final void visitLeave(final ImportList importList) {
390  33 leave();
391    }
392   
 
393  274 toggle public final void visitEnter(final Import imp) throws ModuleDataException {
394  274 enter("IMPORT");
395  274 final String method = "visitEnter(Import)";
396  274 Trace.param(CLASS, this, method, "current", current);
397  274 final String context = traverser.getCurrentContext().getLocationWithinModule();
398  274 checkMatching(method);
399   
400  252 traverser.setLocationWithinModule(context + ".getLabel()");
401  252 current.setAttribute("label");
402  252 checkIfFound();
403    }
404   
 
405  72 toggle public final void visitLeave(final Import imp) {
406  72 leave();
407    }
408   
 
409  66 toggle public final void visitEnter(final UsedByList usedByList) throws ModuleDataException {
410  66 enter("USEDBY");
411  66 final String method = "visitEnter(UsedByList)";
412  66 Trace.param(CLASS, this, method, "current", current);
413  66 checkMatching(method);
414    }
415   
 
416  0 toggle public final void visitLeave(final UsedByList usedByList) {
417  0 leave();
418    }
419   
 
420  66098 toggle public final void visitEnter(final ChapterList chapterList) throws ModuleDataException {
421  66098 final String method = "visitEnter(ChapterList)";
422    // because no equivalent level of "getChapterList()" exists in the XSD we simply
423    // point to the current location that must be "QEDEQ"
424  66098 checkMatching(method);
425    }
426   
 
427  201 toggle public final void visitLeave(final ChapterList chapterList) {
428  201 traverser.setBlocked(false); // free sub node search
429    }
430   
 
431  236296 toggle public final void visitEnter(final Chapter chapter) throws ModuleDataException {
432  236296 enter("CHAPTER");
433  236296 final String method = "visitEnter(Chapter)";
434  236296 Trace.param(CLASS, this, method, "current", current);
435  236296 final String context = traverser.getCurrentContext().getLocationWithinModule();
436  236296 checkMatching(method);
437   
438  236137 traverser.setLocationWithinModule(context + ".getNoNumber()");
439  236137 current.setAttribute("noNumber");
440  236137 checkIfFound();
441    }
442   
 
443  170419 toggle public final void visitLeave(final Chapter chapter) {
444  170419 leave();
445    }
446   
 
447  65098 toggle public final void visitEnter(final SectionList sectionList) throws ModuleDataException {
448  65098 final String method = "visitEnter(SectionList)";
449    // because no equivalent level of "getSectionList()" exists in the XSD we simply
450    // point to the current location that must be "QEDEQ/CHAPTER[x]"
451  65098 checkMatching(method);
452    }
453   
 
454  1 toggle public final void visitLeave(final SectionList sectionList) {
455  1 traverser.setBlocked(false); // free node search again
456    }
457   
 
458  189534 toggle public final void visitEnter(final Section section) throws ModuleDataException {
459  189534 enter("SECTION");
460  189534 final String method = "visitEnter(Section)";
461  189534 Trace.param(CLASS, this, method, "current", current);
462  189534 final String context = traverser.getCurrentContext().getLocationWithinModule();
463  189534 checkMatching(method);
464   
465  189206 traverser.setLocationWithinModule(context + ".getNoNumber()");
466  189206 current.setAttribute("noNumber");
467  189206 checkIfFound();
468    }
469   
 
470  124547 toggle public final void visitLeave(final Section section) {
471  124547 leave();
472    }
473   
 
474  63427 toggle public final void visitEnter(final SubsectionList subsectionList) throws ModuleDataException {
475  63427 enter("SUBSECTIONS");
476  63427 final String method = "visitEnter(SubsectionList)";
477  63427 Trace.param(CLASS, this, method, "current", current);
478  63427 checkMatching(method);
479    }
480   
 
481  1 toggle public final void visitLeave(final SubsectionList subsectionList) {
482  1 leave();
483    }
484   
 
485  5268 toggle public final void visitEnter(final Subsection subsection) throws ModuleDataException {
486  5268 enter("SUBSECTION");
487  5268 final String method = "visitEnter(Subsection)";
488  5268 Trace.param(CLASS, this, method, "current", current);
489  5268 final String context = traverser.getCurrentContext().getLocationWithinModule();
490  5268 checkMatching(method);
491   
492  5136 traverser.setLocationWithinModule(context + ".getId()");
493  5136 current.setAttribute("id");
494  5136 checkIfFound();
495   
496  5134 traverser.setLocationWithinModule(context + ".getLevel()");
497  5134 current.setAttribute("level");
498  5134 checkIfFound();
499    }
500   
 
501  4778 toggle public final void visitLeave(final Subsection subsection) {
502  4778 leave();
503    }
504   
 
505  285650 toggle public final void visitEnter(final Node node) throws ModuleDataException {
506  285650 enter("NODE");
507  285650 final String method = "visitEnter(Node)";
508  285650 Trace.param(CLASS, this, method, "current", current);
509  285650 final String context = traverser.getCurrentContext().getLocationWithinModule();
510  285650 checkMatching(method);
511   
512  284683 traverser.setLocationWithinModule(context + ".getId()");
513  284683 current.setAttribute("id");
514  284683 checkIfFound();
515   
516  284295 traverser.setLocationWithinModule(context + ".getLevel()");
517  284295 current.setAttribute("level");
518  284295 checkIfFound();
519   
520    // we dont't differentiate the different node types here and point to the parent element
521  284122 traverser.setLocationWithinModule(context + ".getNodeType()");
522  284122 current.setAttribute(null);
523  284122 checkIfFound();
524   
525    }
526   
 
527  222882 toggle public final void visitLeave(final Node node) {
528  222882 leave();
529    }
530   
 
531  4160 toggle public final void visitEnter(final Axiom axiom) throws ModuleDataException {
532  4160 enter("AXIOM");
533  4160 final String method = "visitEnter(Axiom)";
534  4160 Trace.param(CLASS, this, method, "current", current);
535  4160 final String context = traverser.getCurrentContext().getLocationWithinModule();
536  4160 checkMatching(method);
537   
538  3962 traverser.setLocationWithinModule(context + ".getDefinedOperator()");
539  3962 current.setAttribute("definedOperator");
540  3962 checkIfFound();
541    }
542   
 
543  82 toggle public final void visitLeave(final Axiom axiom) {
544  82 leave();
545    }
546   
 
547  48614 toggle public final void visitEnter(final Proposition proposition) throws ModuleDataException {
548  48614 enter("THEOREM");
549  48614 final String method = "visitEnter(Proposition)";
550  48614 Trace.param(CLASS, this, method, "current", current);
551  48614 checkMatching(method);
552    }
553   
 
554  84 toggle public final void visitLeave(final Proposition proposition) {
555  84 leave();
556    }
557   
 
558  622 toggle public final void visitEnter(final ProofList proofList) throws ModuleDataException {
559  622 final String method = "visitEnter(ProofList)";
560    // because no equivalent level of "getProofList()" exists in the XSD we simply
561    // point to the current location that must be within the element "THEOREM" or "RULE"
562  622 checkMatching(method);
563    }
564   
 
565  538 toggle public final void visitEnter(final Proof proof) throws ModuleDataException {
566  538 enter("PROOF");
567  538 final String method = "visitEnter(Proof)";
568  538 Trace.param(CLASS, this, method, "current", current);
569  538 final String context = traverser.getCurrentContext().getLocationWithinModule();
570  538 checkMatching(method);
571   
572  382 traverser.setLocationWithinModule(context + ".getKind()");
573  382 current.setAttribute("kind");
574  382 checkIfFound();
575   
576  342 traverser.setLocationWithinModule(context + ".getLevel()");
577  342 current.setAttribute("level");
578  342 checkIfFound();
579    }
580   
 
581  26 toggle public final void visitLeave(final Proof proof) {
582  26 leave();
583    }
584   
 
585  26982 toggle public final void visitEnter(final FormalProofList proofList) throws ModuleDataException {
586  26982 final String method = "visitEnter(FormalProofList)";
587    // because no equivalent level of "getProofList()" exists in the XSD we simply
588    // point to the current location that must be within the element "THEOREM"
589  26982 checkMatching(method);
590    }
591   
 
592  26878 toggle public final void visitEnter(final FormalProof proof) throws ModuleDataException {
593  26878 enter("FORMAL_PROOF");
594  26878 final String method = "visitEnter(FormalProof)";
595  26878 Trace.param(CLASS, this, method, "current", current);
596  26878 checkMatching(method);
597    }
598   
 
599  0 toggle public final void visitLeave(final FormalProof proof) {
600  0 leave();
601    }
602   
 
603  32788 toggle public final void visitEnter(final FormalProofLineList list) throws ModuleDataException {
604  32788 enter("LINES");
605  32788 final String method = "visitEnter(FormalProofLineList)";
606  32788 Trace.param(CLASS, this, method, "current", current);
607  32788 checkMatching(method);
608    }
609   
 
610  1712 toggle public final void visitLeave(final FormalProofLineList list) {
611  1712 leave();
612    }
613   
 
614  203052 toggle public final void visitEnter(final FormalProofLine line) throws ModuleDataException {
615  203052 enter("L");
616  203052 final String method = "visitEnter(FormalProofLine)";
617  203052 Trace.param(CLASS, this, method, "current", current);
618  203052 final String context = traverser.getCurrentContext().getLocationWithinModule();
619  203052 checkMatching(method);
620   
621  201974 traverser.setLocationWithinModule(context + ".getLabel()");
622  201974 current.setAttribute("label");
623  201974 checkIfFound();
624    }
625   
 
626  178396 toggle public final void visitLeave(final FormalProofLine line) {
627  178396 leave();
628    }
629   
 
630  12428 toggle public final void visitEnter(final ConditionalProof reason) throws ModuleDataException {
631  12428 enter("CP");
632  12428 final String method = "visitEnter(ConditionalProof)";
633  12428 Trace.param(CLASS, this, method, "current", current);
634  12428 checkMatching(method);
635    }
636   
 
637  6212 toggle public final void visitLeave(final ConditionalProof reason) {
638  6212 leave();
639    }
640   
 
641  1683 toggle public final void visitEnter(final Reason reason) throws ModuleDataException {
642    // nothing to enter in XML
643  1683 final String method = "visitEnter(Reason)";
644  1683 Trace.param(CLASS, this, method, "current", current);
645  1683 checkMatching(method);
646   
647    }
648   
 
649  4 toggle public final void visitLeave(final Reason reason) {
650    // nothing to leave in XML
651    }
652   
 
653  137 toggle public final void visitEnter(final Add reason) throws ModuleDataException {
654  137 enter("ADD");
655  137 final String method = "visitEnter(Add)";
656  137 Trace.param(CLASS, this, method, "current", current);
657  137 final String context = traverser.getCurrentContext().getLocationWithinModule();
658  137 checkMatching(method);
659   
660  17 traverser.setLocationWithinModule(context + ".getReference()");
661  17 current.setAttribute("ref");
662  17 checkIfFound();
663    }
664   
 
665  0 toggle public final void visitLeave(final Add reason) {
666  0 leave();
667    }
668   
 
669  175 toggle public final void visitEnter(final ModusPonens reason) throws ModuleDataException {
670  175 enter("MP");
671  175 final String method = "visitEnter(ModusPonens)";
672  175 Trace.param(CLASS, this, method, "current", current);
673  175 final String context = traverser.getCurrentContext().getLocationWithinModule();
674  175 checkMatching(method);
675   
676  23 traverser.setLocationWithinModule(context + ".getReference1()");
677  23 current.setAttribute("ref1");
678  23 checkIfFound();
679   
680  9 traverser.setLocationWithinModule(context + ".getReference2()");
681  9 current.setAttribute("ref2");
682  9 checkIfFound();
683    }
684   
 
685  0 toggle public final void visitLeave(final ModusPonens reason) {
686  0 leave();
687    }
688   
 
689  29 toggle public final void visitEnter(final Rename reason) throws ModuleDataException {
690  29 enter("RENAME");
691  29 final String method = "visitEnter(Add)";
692  29 Trace.param(CLASS, this, method, "current", current);
693  29 final String context = traverser.getCurrentContext().getLocationWithinModule();
694  29 checkMatching(method);
695   
696  3 traverser.setLocationWithinModule(context + ".getReference()");
697  3 current.setAttribute("ref");
698  3 checkIfFound();
699   
700  0 traverser.setLocationWithinModule(context + ".getOccurrence()");
701  0 current.setAttribute("occurrence");
702  0 checkIfFound();
703    }
704   
 
705  0 toggle public final void visitLeave(final Rename reason) {
706  0 leave();
707    }
708   
 
709  16 toggle public final void visitEnter(final SubstFree reason) throws ModuleDataException {
710  16 enter("SUBST_FREE");
711  16 final String method = "visitEnter(SubstFree)";
712  16 Trace.param(CLASS, this, method, "current", current);
713  16 final String context = traverser.getCurrentContext().getLocationWithinModule();
714  16 checkMatching(method);
715   
716  1 traverser.setLocationWithinModule(context + ".getReference()");
717  1 current.setAttribute("ref");
718  1 checkIfFound();
719    }
720   
 
721  0 toggle public final void visitLeave(final SubstFree reason) {
722  0 leave();
723    }
724   
 
725  6 toggle public final void visitEnter(final SubstFunc reason) throws ModuleDataException {
726  6 enter("SUBST_FUNVAR");
727  6 final String method = "visitEnter(SubstFunc)";
728  6 Trace.param(CLASS, this, method, "current", current);
729  6 final String context = traverser.getCurrentContext().getLocationWithinModule();
730  6 checkMatching(method);
731   
732  1 traverser.setLocationWithinModule(context + ".getReference()");
733  1 current.setAttribute("ref");
734  1 checkIfFound();
735    }
736   
 
737  0 toggle public final void visitLeave(final SubstFunc reason) {
738  0 leave();
739    }
740   
 
741  226 toggle public final void visitEnter(final SubstPred reason) throws ModuleDataException {
742  226 enter("SUBST_PREDVAR");
743  226 final String method = "visitEnter(SubstPred)";
744  226 Trace.param(CLASS, this, method, "current", current);
745  226 final String context = traverser.getCurrentContext().getLocationWithinModule();
746  226 checkMatching(method);
747   
748  18 traverser.setLocationWithinModule(context + ".getReference()");
749  18 current.setAttribute("ref");
750  18 checkIfFound();
751    }
752   
 
753  0 toggle public final void visitLeave(final SubstPred reason) {
754  0 leave();
755    }
756   
 
757  4 toggle public final void visitEnter(final Existential reason) throws ModuleDataException {
758  4 enter("EXISTENTIAL");
759  4 final String method = "visitEnter(Existential)";
760  4 Trace.param(CLASS, this, method, "current", current);
761  4 final String context = traverser.getCurrentContext().getLocationWithinModule();
762  4 checkMatching(method);
763   
764  1 traverser.setLocationWithinModule(context + ".getReference()");
765  1 current.setAttribute("ref");
766  1 checkIfFound();
767    }
768   
 
769  1 toggle public final void visitLeave(final Existential reason) {
770  1 leave();
771    }
772   
 
773  16 toggle public final void visitEnter(final Universal reason) throws ModuleDataException {
774  16 enter("UNIVERSAL");
775  16 final String method = "visitEnter(Universal)";
776  16 Trace.param(CLASS, this, method, "current", current);
777  16 final String context = traverser.getCurrentContext().getLocationWithinModule();
778  16 checkMatching(method);
779   
780  4 traverser.setLocationWithinModule(context + ".getReference()");
781  4 current.setAttribute("ref");
782  4 checkIfFound();
783    }
784   
 
785  3 toggle public final void visitLeave(final Universal reason) {
786  3 leave();
787    }
788   
 
789  6116 toggle public final void visitEnter(final Hypothesis hypothesis) throws ModuleDataException {
790  6116 enter("HYPOTHESIS");
791  6116 final String method = "visitEnter(Hypothesis)";
792  6116 Trace.param(CLASS, this, method, "current", current);
793  6116 final String context = traverser.getCurrentContext().getLocationWithinModule();
794  6116 checkMatching(method);
795   
796  6066 traverser.setLocationWithinModule(context + ".getLabel()");
797  6066 current.setAttribute("label");
798  6066 checkIfFound();
799    }
800   
 
801  6066 toggle public final void visitLeave(final Hypothesis hypothesis) {
802  6066 leave();
803    }
804   
 
805  1712 toggle public final void visitEnter(final Conclusion conclusion) throws ModuleDataException {
806  1712 enter("CONCLUSION");
807  1712 final String method = "visitEnter(Conclusion)";
808  1712 Trace.param(CLASS, this, method, "current", current);
809  1712 final String context = traverser.getCurrentContext().getLocationWithinModule();
810  1712 checkMatching(method);
811   
812  1612 traverser.setLocationWithinModule(context + ".getLabel()");
813  1612 current.setAttribute("label");
814  1612 checkIfFound();
815    }
816   
 
817  0 toggle public final void visitLeave(final Conclusion conclusion) {
818  0 leave();
819    }
820   
 
821  182 toggle public final void visitEnter(final InitialPredicateDefinition definition) throws ModuleDataException {
822  182 enter("DEFINITION_PREDICATE_INITIAL");
823  182 final String method = "visitEnter(InitialPredicateDefinition)";
824  182 Trace.param(CLASS, this, method, "current", current);
825  182 final String context = traverser.getCurrentContext().getLocationWithinModule();
826  182 checkMatching(method);
827   
828  158 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
829  158 current.setAttribute("arguments");
830  158 checkIfFound();
831   
832  150 traverser.setLocationWithinModule(context + ".getName()");
833  150 current.setAttribute("name");
834  150 checkIfFound();
835   
836  142 traverser.setLocationWithinModule(context + ".getLatexPattern()");
837  142 enter("LATEXPATTERN");
838  142 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
839    .getLocationWithinModule())) {
840  8 if (definition.getLatexPattern() == null) { // NOT FOUND
841  0 leave();
842    }
843  8 throw new LocationFoundException(traverser.getCurrentContext());
844    }
845  134 leave();
846    }
847   
 
848  26 toggle public final void visitLeave(final InitialPredicateDefinition definition) {
849  26 leave();
850    }
851   
 
852  1264 toggle public final void visitEnter(final PredicateDefinition definition) throws ModuleDataException {
853  1264 enter("DEFINITION_PREDICATE");
854  1264 final String method = "visitEnter(PredicateDefinition)";
855  1264 Trace.param(CLASS, this, method, "current", current);
856  1264 final String context = traverser.getCurrentContext().getLocationWithinModule();
857  1264 checkMatching(method);
858   
859  1210 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
860  1210 current.setAttribute("arguments");
861  1210 checkIfFound();
862   
863  1189 traverser.setLocationWithinModule(context + ".getName()");
864  1189 current.setAttribute("name");
865  1189 checkIfFound();
866   
867  1168 traverser.setLocationWithinModule(context + ".getLatexPattern()");
868  1168 enter("LATEXPATTERN");
869  1168 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
870    .getLocationWithinModule())) {
871  21 if (definition.getLatexPattern() == null) { // NOT FOUND
872  0 leave();
873    }
874  21 throw new LocationFoundException(traverser.getCurrentContext());
875    }
876  1147 leave();
877    }
878   
 
879  63 toggle public final void visitLeave(final PredicateDefinition definition) {
880  63 leave();
881    }
882   
 
883  17 toggle public final void visitEnter(final InitialFunctionDefinition definition) throws ModuleDataException {
884  17 enter("DEFINITION_FUNCTION_INITIAL");
885  17 final String method = "visitEnter(InitialFunctionDefinition)";
886  17 Trace.param(CLASS, this, method, "current", current);
887  17 final String context = traverser.getCurrentContext().getLocationWithinModule();
888  17 checkMatching(method);
889   
890  15 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
891  15 current.setAttribute("arguments");
892  15 checkIfFound();
893   
894  14 traverser.setLocationWithinModule(context + ".getName()");
895  14 current.setAttribute("name");
896  14 checkIfFound();
897   
898  13 traverser.setLocationWithinModule(context + ".getLatexPattern()");
899  13 enter("LATEXPATTERN");
900  13 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
901    .getLocationWithinModule())) {
902  1 if (definition.getLatexPattern() == null) { // NOT FOUND
903  0 leave();
904    }
905  1 throw new LocationFoundException(traverser.getCurrentContext());
906    }
907  12 leave();
908    }
909   
 
910  0 toggle public final void visitLeave(final InitialFunctionDefinition definition) {
911  0 leave();
912    }
913   
 
914  2391 toggle public final void visitEnter(final FunctionDefinition definition) throws ModuleDataException {
915  2391 enter("DEFINITION_FUNCTION");
916  2391 final String method = "visitEnter(FunctionDefinition)";
917  2391 Trace.param(CLASS, this, method, "current", current);
918  2391 final String context = traverser.getCurrentContext().getLocationWithinModule();
919  2391 checkMatching(method);
920   
921  2295 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
922  2295 current.setAttribute("arguments");
923  2295 checkIfFound();
924   
925  2263 traverser.setLocationWithinModule(context + ".getName()");
926  2263 current.setAttribute("name");
927  2263 checkIfFound();
928   
929  2223 traverser.setLocationWithinModule(context + ".getLatexPattern()");
930  2223 enter("LATEXPATTERN");
931  2223 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
932    .getLocationWithinModule())) {
933  32 if (definition.getLatexPattern() == null) { // NOT FOUND
934  0 leave();
935    }
936  32 throw new LocationFoundException(traverser.getCurrentContext());
937    }
938  2191 leave();
939    }
940   
 
941  56 toggle public final void visitLeave(final FunctionDefinition definition) {
942  56 leave();
943    }
944   
 
945  663 toggle public final void visitEnter(final Rule rule) throws ModuleDataException {
946  663 enter("RULE");
947  663 final String method = "visitEnter(Rule)";
948  663 Trace.param(CLASS, this, method, "current", current);
949  663 final String context = traverser.getCurrentContext().getLocationWithinModule();
950  663 checkMatching(method);
951   
952  527 traverser.setLocationWithinModule(context + ".getName()");
953  527 current.setAttribute("name");
954  527 checkIfFound();
955   
956  460 traverser.setLocationWithinModule(context + ".getVersion()");
957  460 current.setAttribute("version");
958  460 checkIfFound();
959    }
960   
 
961  50 toggle public final void visitLeave(final Rule rule) {
962  50 leave();
963    }
964   
 
965  77 toggle public final void visitEnter(final ChangedRuleList list) throws ModuleDataException {
966  77 final String method = "visitEnter(ChangedRuleList)";
967    // because no equivalent level of "getChangedRuleList()" exists in the XSD we simply
968    // point to the current location that must be within the element "RULE"
969  77 checkMatching(method);
970    }
971   
 
972  11 toggle public final void visitLeave(final ChangedRuleList list) {
973  11 traverser.setBlocked(false); // free node search again
974    }
975   
 
976  288 toggle public final void visitEnter(final ChangedRule rule) throws ModuleDataException {
977  288 enter("CHANGED_RULE");
978  288 final String method = "visitEnter(ChangedRule)";
979  288 Trace.param(CLASS, this, method, "current", current);
980  288 final String context = traverser.getCurrentContext().getLocationWithinModule();
981  288 checkMatching(method);
982   
983  272 traverser.setLocationWithinModule(context + ".getName()");
984  272 current.setAttribute("name");
985  272 checkIfFound();
986   
987  264 traverser.setLocationWithinModule(context + ".getVersion()");
988  264 current.setAttribute("version");
989  264 checkIfFound();
990    }
991   
 
992  224 toggle public final void visitLeave(final ChangedRule rule) {
993  224 leave();
994    }
995   
 
996  107 toggle public final void visitEnter(final LinkList linkList) throws ModuleDataException {
997  107 final String method = "visitEnter(LinkList)";
998  107 Trace.param(CLASS, this, method, "current", current);
999  107 final String context = traverser.getCurrentContext().getLocationWithinModule();
1000  107 checkMatching(method);
1001   
1002  276 for (int i = 0; i < linkList.size(); i++) {
1003  181 enter("LINK");
1004  181 if (linkList.get(i) != null) {
1005  181 traverser.setLocationWithinModule(context + ".get(" + i + ")");
1006  181 current.setAttribute("id");
1007  181 checkIfFound();
1008    }
1009  177 leave();
1010  95 };
1011    }
1012   
 
1013  95 toggle public final void visitLeave(final LinkList linkList) {
1014    // nothing to do
1015    }
1016   
 
1017  79932 toggle public final void visitEnter(final Formula formula) throws ModuleDataException {
1018  79932 enter("FORMULA");
1019  79932 final String method = "visitEnter(Formula)";
1020  79932 Trace.param(CLASS, this, method, "current", current);
1021  79932 checkMatching(method);
1022    }
1023   
 
1024  29409 toggle public final void visitLeave(final Formula formula) {
1025  29409 leave();
1026    }
1027   
 
1028  0 toggle public final void visitEnter(final Term term) throws ModuleDataException {
1029  0 enter("TERM");
1030  0 final String method = "visitEnter(Term)";
1031  0 Trace.param(CLASS, this, method, "current", current);
1032  0 checkMatching(method);
1033    }
1034   
 
1035  0 toggle public final void visitLeave(final Term term) {
1036  0 leave();
1037    }
1038   
 
1039  317231 toggle public final void visitEnter(final ElementList list) throws ModuleDataException {
1040  317231 final String operator = list.getOperator();
1041  317231 enter(operator);
1042  317231 final String method = "visitEnter(ElementList)";
1043  317231 Trace.param(CLASS, this, method, "current", current);
1044  317231 String context = traverser.getCurrentContext().getLocationWithinModule();
1045   
1046    // to find something like getElement(0).getList().getElement(0)
1047  317231 if (context.startsWith(find.getLocationWithinModule())) {
1048  46083 throw new LocationFoundException(find);
1049    }
1050   
1051  271148 checkMatching(method);
1052   
1053  271148 traverser.setLocationWithinModule(context + ".getOperator()");
1054  271148 checkIfFound();
1055  271122 traverser.setLocationWithinModule(context);
1056  271122 final boolean firstIsAtom = list.size() > 0 && list.getElement(0).isAtom();
1057  271122 if (firstIsAtom) {
1058  82003 traverser.setLocationWithinModule(context + ".getElement(0)");
1059  82003 if ("VAR".equals(operator) || "PREDVAR".equals(operator)
1060    || "FUNVAR".equals(operator)) {
1061  31250 current.setAttribute("id");
1062  31250 checkIfFound();
1063  31240 traverser.setLocationWithinModule(context + ".getElement(0).getAtom()");
1064  31240 checkIfFound();
1065  50753 } else if ("PREDCON".equals(operator) || "FUNCON".equals(operator)) {
1066  50753 current.setAttribute("ref");
1067  50753 checkIfFound();
1068  50745 traverser.setLocationWithinModule(context + ".getElement(0).getAtom()");
1069  50745 checkIfFound();
1070    } else { // should not occur, but just in case
1071  0 current.setAttribute(null);
1072  0 Trace.info(CLASS, this, method, "unknown operator " + operator);
1073  0 throw new LocationFoundException(traverser.getCurrentContext());
1074    }
1075    }
1076    }
1077   
 
1078  151165 toggle public final void visitLeave(final ElementList list) {
1079  151165 leave();
1080    }
1081   
1082    /* we dont need it any more
1083    public final void visitEnter(final Atom atom) throws ModuleDataException {
1084    final String method = "visitEnter(Atom)";
1085    Trace.param(this, method, "current", current);
1086    final String context = traverser.getCurrentContext().getLocationWithinModule();
1087    // mime 20070217: should never occur
1088    checkMatching(method);
1089    }
1090    */
 
1091  200 toggle public final void visitEnter(final LiteratureItemList list) throws ModuleDataException {
1092  200 enter("BIBLIOGRAPHY");
1093  200 final String method = "visitEnter(LiteratureItemList)";
1094  200 Trace.param(CLASS, this, method, "current", current);
1095  200 checkMatching(method);
1096    }
1097   
 
1098  0 toggle public final void visitLeave(final LiteratureItemList list) {
1099  0 leave();
1100    }
1101   
 
1102  594 toggle public final void visitEnter(final LiteratureItem item) throws ModuleDataException {
1103  594 enter("ITEM");
1104  594 final String method = "visitEnter(LiteratureItem)";
1105  594 Trace.param(CLASS, this, method, "current", current);
1106  594 final String context = traverser.getCurrentContext().getLocationWithinModule();
1107  594 checkMatching(method);
1108   
1109  540 traverser.setLocationWithinModule(context + ".getLabel()");
1110  540 current.setAttribute("label");
1111  540 checkIfFound();
1112    }
1113   
 
1114  402 toggle public final void visitLeave(final LiteratureItem item) {
1115  402 leave();
1116    }
1117   
1118    /**
1119    * Check if searched for context is already reached.
1120    *
1121    * @throws LocationFoundException We have found it.
1122    */
 
1123  4115830 toggle private final void checkIfFound() throws LocationFoundException {
1124  4115830 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
1125    .getLocationWithinModule())) {
1126  20692 throw new LocationFoundException(traverser.getCurrentContext());
1127    }
1128    }
1129   
1130    /**
1131    * Checks if the current context matches the beginning of the context we want to find.
1132    * This method must be called at the beginning of the <code>visitEnter</code> method when
1133    * {@link #current} is correctly set. If the context of a previously visited node was already
1134    * matching and the current node doesn't start with the old matching context any longer we
1135    * throw a {@link LocationNotFoundException}.
1136    *
1137    * @param method Method we were called from.
1138    * @throws LocationNotFoundException Not found.
1139    * @throws LocationFoundException Success!
1140    */
 
1141  2096182 toggle private final void checkMatching(final String method)
1142    throws LocationNotFoundException, LocationFoundException {
1143  2096182 final String context = traverser.getCurrentContext().getLocationWithinModule();
1144  2096182 if (find.getLocationWithinModule().startsWith(context)) {
1145  816973 Trace.info(CLASS, this, method, "beginning matches");
1146  816973 Trace.paramInfo(CLASS, this, method, "context", context);
1147  816973 matching = true;
1148  816973 matchingBegin = context; // remember matching context
1149  816973 matchingPath = new SimpleXPath(current); // remember last matching XPath
1150    } else {
1151  1279209 if (context.startsWith(find.getLocationWithinModule())) {
1152    // our current location is more specific than our search location
1153    // so the current location is the best match for our search
1154  1 throw new LocationFoundException(traverser.getCurrentContext());
1155    }
1156  1279208 if (matching) {
1157    // for example we are looking for "getHeader().getImportList().getImport(2)"
1158    // getHeader() matches, we remember "getHeader()"
1159    // getHeader().getSpecification() doesn't match, but still starts with "getHeader()"
1160    // getHeader().getImportList() matches, we remember "getHeader.getImportList()"
1161    // getHeader().getImportList().get(0) doesn't match but still starts with
1162    // "getHeader.getImportList()"
1163  1279208 if (!context.startsWith(matchingBegin)) {
1164    // Matching lost, that means we will never found the location
1165    // so what can we do? We just return the last matching location and hope
1166    // it is close enough to the searched one. But at least we do some
1167    // logging here:
1168  5 Trace.info(CLASS, this, method, "matching lost, when finding error location");
1169  5 Trace.paramInfo(CLASS, this, method, "last match ", matchingBegin);
1170  5 Trace.paramInfo(CLASS, this, method, "current context", context);
1171  5 Trace.paramInfo(CLASS, this, method, "find context ", find.getLocationWithinModule());
1172   
1173  5 Trace.traceStack(CLASS, this, method);
1174  5 Trace.info(CLASS, this, method, "changing XPath to last matching one");
1175   
1176    // do we really want to fail?
1177  5 if (Boolean.TRUE.toString().equalsIgnoreCase(
1178    System.getProperty("qedeq.test.xmlLocationFailures"))) {
1179  0 throw new LocationNotFoundException(traverser.getCurrentContext(),
1180    matchingBegin, find.getLocationWithinModule());
1181    }
1182   
1183    // now we change the current XPath to the last matching one because the
1184    // contents of "current" is used as the resulting XPath later on when
1185    // catching the exception in {@link #find()}
1186  5 current = matchingPath;
1187  5 throw new LocationFoundException(new ModuleContext(find.getModuleLocation(),
1188    matchingBegin));
1189    }
1190    }
1191  1279203 traverser.setBlocked(true); // block further search in sub nodes
1192    }
1193  2096176 checkIfFound();
1194    }
1195   
1196    /**
1197    * Enter new XML element.
1198    *
1199    * @param element Element name.
1200    */
 
1201  1984923 toggle private final void enter(final String element) {
1202  1984923 level++;
1203  1984923 current.addElement(element, addOccurence(element));
1204    }
1205   
1206    /**
1207    * Leave last XML element.
1208    */
 
1209  1282571 toggle private final void leave() {
1210  1282571 level--;
1211  1282571 current.deleteLastElement();
1212  1282571 traverser.setBlocked(false); // enable further search in nodes
1213    }
1214   
1215    /**
1216    * Add element occurrence. For example we have <code>getHeader().getImportList().get(2)</code>
1217    * and we want to get <code>QEDEQ/HEADER/IMPORTS/IMPORT[3]</code>.
1218    * So we call <code>enter("QEDEQ")</code>, <code>enter("HEADER")</code>,
1219    * <code>enter("IMPORTS")</code> and last but not least
1220    * three times the sequence <code>enter("IMPORT")</code>, <code>leave("IMPORT")</code>,
1221    *
1222    * @param name Element that occurred.
1223    * @return Number of occurrences including this one.
1224    */
 
1225  1984923 toggle private final int addOccurence(final String name) {
1226  1985073 while (level < elements.size()) {
1227  150 elements.remove(elements.size() - 1);
1228    }
1229  2688850 while (level > elements.size()) {
1230  703927 elements.add(new HashMap());
1231    }
1232  1984923 final Map levelMap = (Map) elements.get(level - 1);
1233  1984923 final Enumerator counter;
1234  1984923 if (levelMap.containsKey(name)) {
1235  807092 counter = (Enumerator) levelMap.get(name);
1236  807092 counter.increaseNumber();
1237    } else {
1238  1177831 counter = new Enumerator(1);
1239  1177831 levelMap.put(name, counter);
1240    }
1241  1984923 return counter.getNumber();
1242    }
1243   
1244    }