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