Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 01:49:02 UTC
../../../../../img/srcFileCovDistChart4.png 87% 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 35.2% 0.352
 
  (12)
 
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  15 toggle private Context2SimpleXPath(final ModuleContext find, final Qedeq qedeq) {
142  15 this.qedeq = qedeq;
143  15 traverser = new QedeqNotNullTraverser(find.getModuleLocation(), this);
144  15 this.find = find;
145  15 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  15 toggle public static SimpleXPath getXPath(final ModuleContext find, final Qedeq qedeq)
174    throws ModuleDataException {
175  15 final Context2SimpleXPath converter = new Context2SimpleXPath(find, qedeq);
176  15 return converter.find();
177    }
178   
 
179  15 toggle private final SimpleXPath find() throws ModuleDataException {
180  15 final String method = "find()";
181  15 Trace.paramInfo(CLASS, this, method, "find", find);
182  15 elements.clear();
183  15 level = 0;
184  15 current = new SimpleXPath();
185  15 try {
186  15 traverser.accept(qedeq);
187    } catch (LocationFoundException e) {
188  14 Trace.paramInfo(CLASS, this, method, "location found", current);
189  14 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  15 toggle public final void visitEnter(final Qedeq qedeq) throws ModuleDataException {
204  15 enter("QEDEQ");
205  15 final String method = "visitEnter(Qedeq)";
206  15 Trace.param(CLASS, this, method, "current", current);
207  15 checkMatching(method);
208    }
209   
 
210  1 toggle public final void visitLeave(final Qedeq qedeq) {
211  1 leave();
212    }
213   
 
214  14 toggle public final void visitEnter(final Header header) throws ModuleDataException {
215  14 enter("HEADER");
216  14 final String method = "visitEnter(Header)";
217  14 Trace.param(CLASS, this, method, "current", current);
218  14 final String context = traverser.getCurrentContext().getLocationWithinModule();
219  14 checkMatching(method);
220   
221  13 traverser.setLocationWithinModule(context + ".getEmail()");
222  13 current.setAttribute("email");
223  13 checkIfFound();
224    }
225   
 
226  13 toggle public final void visitLeave(final Header header) {
227  13 leave();
228    }
229   
 
230  0 toggle public final void visitEnter(final Specification specification) throws ModuleDataException {
231  0 enter("SPECIFICATION");
232  0 final String method = "visitEnter(Specification)";
233  0 Trace.param(CLASS, this, method, "current", current);
234  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
235  0 checkMatching(method);
236   
237  0 traverser.setLocationWithinModule(context + ".getName()");
238  0 current.setAttribute("name");
239  0 checkIfFound();
240   
241  0 traverser.setLocationWithinModule(context + ".getRuleVersion()");
242  0 current.setAttribute("ruleVersion");
243  0 checkIfFound();
244    }
245   
 
246  0 toggle public final void visitLeave(final Specification specification) {
247  0 leave();
248    }
249   
 
250  70 toggle public final void visitEnter(final LatexList latexList) throws ModuleDataException {
251  70 final String method = "visitEnter(LatexList)";
252  70 final String context = traverser.getCurrentContext().getLocationWithinModule();
253  70 final String name;
254  70 if (context.endsWith(".getTitle()")) {
255  31 name = "TITLE";
256  39 } else if (context.endsWith(".getSummary()")) {
257  0 name = "ABSTRACT";
258  39 } else if (context.endsWith(".getIntroduction()")) {
259  24 name = "INTRODUCTION";
260  15 } else if (context.endsWith(".getName()")) {
261  7 name = "NAME";
262  8 } else if (context.endsWith(".getPrecedingText()")) {
263  7 name = "PRECEDING";
264  1 } else if (context.endsWith(".getSucceedingText()")) {
265  1 name = "SUCCEEDING";
266  0 } else if (context.endsWith(".getLatex()")) {
267  0 name = "TEXT";
268  0 } else if (context.endsWith(".getDescription()")) {
269  0 if (context.indexOf(".getChangedRuleList().get(") >= 0) {
270  0 name = null;
271    } else {
272  0 name = "DESCRIPTION";
273    }
274  0 } else if (context.endsWith(".getNonFormalProof()")) { // no extra XSD element
275  0 name = null;
276  0 } else if (context.endsWith(".getItem()")) { // no extra XSD element
277  0 name = null;
278    } else { // programming error
279  0 throw new IllegalArgumentException("unknown LatexList " + context);
280    }
281  70 Trace.param(CLASS, this, method, "name", name);
282  70 if (name != null) {
283  70 enter(name);
284    }
285  70 Trace.param(CLASS, this, method, "current", current);
286   
287  70 checkMatching(method);
288    }
289   
 
290  70 toggle public final void visitLeave(final LatexList latexList) {
291  70 final String context = traverser.getCurrentContext().getLocationWithinModule();
292  70 if (!context.endsWith(".getNonFormalProof()") // no extra XSD element
293    && !context.endsWith(".getItem()") && !(context.endsWith(".getDescription()")
294    && context.indexOf(".getChangedRuleList().get(") >= 0)) {
295  70 leave();
296    }
297    }
298   
 
299  0 toggle public final void visitEnter(final Latex latex) throws ModuleDataException {
300  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
301  0 if (context.indexOf(".getAuthorList().get(") >= 0) { // TODO mime 20070216: why is the
302  0 enter("NAME"); // XSD so cruel???
303    }
304  0 enter("LATEX");
305  0 final String method = "visitEnter(Latex)";
306  0 Trace.param(CLASS, this, method, "current", current);
307  0 checkMatching(method);
308   
309  0 traverser.setLocationWithinModule(context + ".getLanguage()");
310  0 current.setAttribute("language");
311  0 checkIfFound();
312   
313  0 traverser.setLocationWithinModule(context + ".getLatex()");
314  0 current.setAttribute(null); // element character data of LATEX is LaTeX content
315  0 checkIfFound();
316    }
317   
 
318  0 toggle public final void visitLeave(final Latex latex) {
319    // because NAME of AUTHOR/NAME/LATEX has no equivalent in interfaces:
320  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
321  0 if (context.indexOf(".getAuthorList().get(") >= 0) {
322  0 leave();
323    }
324  0 leave();
325    }
326   
 
327  0 toggle public final void visitEnter(final LocationList locationList) throws ModuleDataException {
328  0 enter("LOCATIONS");
329  0 final String method = "visitEnter(LocationList)";
330  0 Trace.param(CLASS, this, method, "current", current);
331  0 checkMatching(method);
332   
333    }
334   
 
335  0 toggle public final void visitLeave(final LocationList locationList) {
336  0 leave();
337    }
338   
 
339  0 toggle public final void visitEnter(final Location location) throws ModuleDataException {
340  0 enter("LOCATION");
341  0 final String method = "visitEnter(Location)";
342  0 Trace.param(CLASS, this, method, "current", current);
343  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
344  0 checkMatching(method);
345   
346  0 traverser.setLocationWithinModule(context + ".getLocation()");
347  0 current.setAttribute("value");
348  0 checkIfFound();
349    }
350   
 
351  0 toggle public final void visitLeave(final Location location) {
352  0 leave();
353    }
354   
 
355  0 toggle public final void visitEnter(final AuthorList authorList) throws ModuleDataException {
356  0 enter("AUTHORS");
357  0 final String method = "visitEnter(AuthorList)";
358  0 Trace.param(CLASS, this, method, "current", current);
359  0 checkMatching(method);
360    }
361   
 
362  0 toggle public final void visitLeave(final AuthorList authorList) {
363  0 leave();
364    }
365   
 
366  0 toggle public final void visitEnter(final Author author) throws ModuleDataException {
367  0 enter("AUTHOR");
368  0 final String method = "visitEnter(Author)";
369  0 Trace.param(CLASS, this, method, "current", current);
370  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
371  0 checkMatching(method);
372   
373  0 traverser.setLocationWithinModule(context + ".getEmail()");
374  0 current.setAttribute("email");
375  0 checkIfFound();
376    }
377   
 
378  0 toggle public final void visitLeave(final Author author) {
379  0 leave();
380    }
381   
 
382  0 toggle public final void visitEnter(final ImportList importList) throws ModuleDataException {
383  0 enter("IMPORTS");
384  0 final String method = "visitEnter(ImportList)";
385  0 Trace.param(CLASS, this, method, "current", current);
386  0 checkMatching(method);
387    }
388   
 
389  0 toggle public final void visitLeave(final ImportList importList) {
390  0 leave();
391    }
392   
 
393  0 toggle public final void visitEnter(final Import imp) throws ModuleDataException {
394  0 enter("IMPORT");
395  0 final String method = "visitEnter(Import)";
396  0 Trace.param(CLASS, this, method, "current", current);
397  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
398  0 checkMatching(method);
399   
400  0 traverser.setLocationWithinModule(context + ".getLabel()");
401  0 current.setAttribute("label");
402  0 checkIfFound();
403    }
404   
 
405  0 toggle public final void visitLeave(final Import imp) {
406  0 leave();
407    }
408   
 
409  0 toggle public final void visitEnter(final UsedByList usedByList) throws ModuleDataException {
410  0 enter("USEDBY");
411  0 final String method = "visitEnter(UsedByList)";
412  0 Trace.param(CLASS, this, method, "current", current);
413  0 checkMatching(method);
414    }
415   
 
416  0 toggle public final void visitLeave(final UsedByList usedByList) {
417  0 leave();
418    }
419   
 
420  13 toggle public final void visitEnter(final ChapterList chapterList) throws ModuleDataException {
421  13 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  13 checkMatching(method);
425    }
426   
 
427  1 toggle public final void visitLeave(final ChapterList chapterList) {
428  1 traverser.setBlocked(false); // free sub node search
429    }
430   
 
431  13 toggle public final void visitEnter(final Chapter chapter) throws ModuleDataException {
432  13 enter("CHAPTER");
433  13 final String method = "visitEnter(Chapter)";
434  13 Trace.param(CLASS, this, method, "current", current);
435  13 final String context = traverser.getCurrentContext().getLocationWithinModule();
436  13 checkMatching(method);
437   
438  12 traverser.setLocationWithinModule(context + ".getNoNumber()");
439  12 current.setAttribute("noNumber");
440  12 checkIfFound();
441    }
442   
 
443  1 toggle public final void visitLeave(final Chapter chapter) {
444  1 leave();
445    }
446   
 
447  12 toggle public final void visitEnter(final SectionList sectionList) throws ModuleDataException {
448  12 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  12 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  12 toggle public final void visitEnter(final Section section) throws ModuleDataException {
459  12 enter("SECTION");
460  12 final String method = "visitEnter(Section)";
461  12 Trace.param(CLASS, this, method, "current", current);
462  12 final String context = traverser.getCurrentContext().getLocationWithinModule();
463  12 checkMatching(method);
464   
465  12 traverser.setLocationWithinModule(context + ".getNoNumber()");
466  12 current.setAttribute("noNumber");
467  12 checkIfFound();
468    }
469   
 
470  1 toggle public final void visitLeave(final Section section) {
471  1 leave();
472    }
473   
 
474  12 toggle public final void visitEnter(final SubsectionList subsectionList) throws ModuleDataException {
475  12 enter("SUBSECTIONS");
476  12 final String method = "visitEnter(SubsectionList)";
477  12 Trace.param(CLASS, this, method, "current", current);
478  12 checkMatching(method);
479    }
480   
 
481  1 toggle public final void visitLeave(final SubsectionList subsectionList) {
482  1 leave();
483    }
484   
 
485  0 toggle public final void visitEnter(final Subsection subsection) throws ModuleDataException {
486  0 enter("SUBSECTION");
487  0 final String method = "visitEnter(Subsection)";
488  0 Trace.param(CLASS, this, method, "current", current);
489  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
490  0 checkMatching(method);
491   
492  0 traverser.setLocationWithinModule(context + ".getId()");
493  0 current.setAttribute("id");
494  0 checkIfFound();
495   
496  0 traverser.setLocationWithinModule(context + ".getLevel()");
497  0 current.setAttribute("level");
498  0 checkIfFound();
499    }
500   
 
501  0 toggle public final void visitLeave(final Subsection subsection) {
502  0 leave();
503    }
504   
 
505  28 toggle public final void visitEnter(final Node node) throws ModuleDataException {
506  28 enter("NODE");
507  28 final String method = "visitEnter(Node)";
508  28 Trace.param(CLASS, this, method, "current", current);
509  28 final String context = traverser.getCurrentContext().getLocationWithinModule();
510  28 checkMatching(method);
511   
512  23 traverser.setLocationWithinModule(context + ".getId()");
513  23 current.setAttribute("id");
514  23 checkIfFound();
515   
516  23 traverser.setLocationWithinModule(context + ".getLevel()");
517  23 current.setAttribute("level");
518  23 checkIfFound();
519   
520    // we dont't differentiate the different node types here and point to the parent element
521  23 traverser.setLocationWithinModule(context + ".getNodeType()");
522  23 current.setAttribute(null);
523  23 checkIfFound();
524   
525    }
526   
 
527  17 toggle public final void visitLeave(final Node node) {
528  17 leave();
529    }
530   
 
531  4 toggle public final void visitEnter(final Axiom axiom) throws ModuleDataException {
532  4 enter("AXIOM");
533  4 final String method = "visitEnter(Axiom)";
534  4 Trace.param(CLASS, this, method, "current", current);
535  4 final String context = traverser.getCurrentContext().getLocationWithinModule();
536  4 checkMatching(method);
537   
538  4 traverser.setLocationWithinModule(context + ".getDefinedOperator()");
539  4 current.setAttribute("definedOperator");
540  4 checkIfFound();
541    }
542   
 
543  0 toggle public final void visitLeave(final Axiom axiom) {
544  0 leave();
545    }
546   
 
547  0 toggle public final void visitEnter(final Proposition proposition) throws ModuleDataException {
548  0 enter("THEOREM");
549  0 final String method = "visitEnter(Proposition)";
550  0 Trace.param(CLASS, this, method, "current", current);
551  0 checkMatching(method);
552    }
553   
 
554  0 toggle public final void visitLeave(final Proposition proposition) {
555  0 leave();
556    }
557   
 
558  0 toggle public final void visitEnter(final ProofList proofList) throws ModuleDataException {
559  0 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  0 checkMatching(method);
563    }
564   
 
565  0 toggle public final void visitEnter(final Proof proof) throws ModuleDataException {
566  0 enter("PROOF");
567  0 final String method = "visitEnter(Proof)";
568  0 Trace.param(CLASS, this, method, "current", current);
569  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
570  0 checkMatching(method);
571   
572  0 traverser.setLocationWithinModule(context + ".getKind()");
573  0 current.setAttribute("kind");
574  0 checkIfFound();
575   
576  0 traverser.setLocationWithinModule(context + ".getLevel()");
577  0 current.setAttribute("level");
578  0 checkIfFound();
579    }
580   
 
581  0 toggle public final void visitLeave(final Proof proof) {
582  0 leave();
583    }
584   
 
585  0 toggle public final void visitEnter(final FormalProofList proofList) throws ModuleDataException {
586  0 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  0 checkMatching(method);
590    }
591   
 
592  0 toggle public final void visitEnter(final FormalProof proof) throws ModuleDataException {
593  0 enter("FORMAL_PROOF");
594  0 final String method = "visitEnter(FormalProof)";
595  0 Trace.param(CLASS, this, method, "current", current);
596  0 checkMatching(method);
597    }
598   
 
599  0 toggle public final void visitLeave(final FormalProof proof) {
600  0 leave();
601    }
602   
 
603  0 toggle public final void visitEnter(final FormalProofLineList list) throws ModuleDataException {
604  0 enter("LINES");
605  0 final String method = "visitEnter(FormalProofLineList)";
606  0 Trace.param(CLASS, this, method, "current", current);
607  0 checkMatching(method);
608    }
609   
 
610  0 toggle public final void visitLeave(final FormalProofLineList list) {
611  0 leave();
612    }
613   
 
614  0 toggle public final void visitEnter(final FormalProofLine line) throws ModuleDataException {
615  0 enter("L");
616  0 final String method = "visitEnter(FormalProofLine)";
617  0 Trace.param(CLASS, this, method, "current", current);
618  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
619  0 checkMatching(method);
620   
621  0 traverser.setLocationWithinModule(context + ".getLabel()");
622  0 current.setAttribute("label");
623  0 checkIfFound();
624    }
625   
 
626  0 toggle public final void visitLeave(final FormalProofLine line) {
627  0 leave();
628    }
629   
 
630  0 toggle public final void visitEnter(final ConditionalProof reason) throws ModuleDataException {
631  0 enter("CP");
632  0 final String method = "visitEnter(ConditionalProof)";
633  0 Trace.param(CLASS, this, method, "current", current);
634  0 checkMatching(method);
635    }
636   
 
637  0 toggle public final void visitLeave(final ConditionalProof reason) {
638  0 leave();
639    }
640   
 
641  0 toggle public final void visitEnter(final Reason reason) throws ModuleDataException {
642    // nothing to enter in XML
643  0 final String method = "visitEnter(Reason)";
644  0 Trace.param(CLASS, this, method, "current", current);
645  0 checkMatching(method);
646   
647    }
648   
 
649  0 toggle public final void visitLeave(final Reason reason) {
650    // nothing to leave in XML
651    }
652   
 
653  0 toggle public final void visitEnter(final Add reason) throws ModuleDataException {
654  0 enter("ADD");
655  0 final String method = "visitEnter(Add)";
656  0 Trace.param(CLASS, this, method, "current", current);
657  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
658  0 checkMatching(method);
659   
660  0 traverser.setLocationWithinModule(context + ".getReference()");
661  0 current.setAttribute("ref");
662  0 checkIfFound();
663    }
664   
 
665  0 toggle public final void visitLeave(final Add reason) {
666  0 leave();
667    }
668   
 
669  0 toggle public final void visitEnter(final ModusPonens reason) throws ModuleDataException {
670  0 enter("MP");
671  0 final String method = "visitEnter(ModusPonens)";
672  0 Trace.param(CLASS, this, method, "current", current);
673  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
674  0 checkMatching(method);
675   
676  0 traverser.setLocationWithinModule(context + ".getReference1()");
677  0 current.setAttribute("ref1");
678  0 checkIfFound();
679   
680  0 traverser.setLocationWithinModule(context + ".getReference2()");
681  0 current.setAttribute("ref2");
682  0 checkIfFound();
683    }
684   
 
685  0 toggle public final void visitLeave(final ModusPonens reason) {
686  0 leave();
687    }
688   
 
689  0 toggle public final void visitEnter(final Rename reason) throws ModuleDataException {
690  0 enter("RENAME");
691  0 final String method = "visitEnter(Add)";
692  0 Trace.param(CLASS, this, method, "current", current);
693  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
694  0 checkMatching(method);
695   
696  0 traverser.setLocationWithinModule(context + ".getReference()");
697  0 current.setAttribute("ref");
698  0 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  0 toggle public final void visitEnter(final SubstFree reason) throws ModuleDataException {
710  0 enter("SUBST_FREE");
711  0 final String method = "visitEnter(SubstFree)";
712  0 Trace.param(CLASS, this, method, "current", current);
713  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
714  0 checkMatching(method);
715   
716  0 traverser.setLocationWithinModule(context + ".getReference()");
717  0 current.setAttribute("ref");
718  0 checkIfFound();
719    }
720   
 
721  0 toggle public final void visitLeave(final SubstFree reason) {
722  0 leave();
723    }
724   
 
725  0 toggle public final void visitEnter(final SubstFunc reason) throws ModuleDataException {
726  0 enter("SUBST_FUNVAR");
727  0 final String method = "visitEnter(SubstFunc)";
728  0 Trace.param(CLASS, this, method, "current", current);
729  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
730  0 checkMatching(method);
731   
732  0 traverser.setLocationWithinModule(context + ".getReference()");
733  0 current.setAttribute("ref");
734  0 checkIfFound();
735    }
736   
 
737  0 toggle public final void visitLeave(final SubstFunc reason) {
738  0 leave();
739    }
740   
 
741  0 toggle public final void visitEnter(final SubstPred reason) throws ModuleDataException {
742  0 enter("SUBST_PREDVAR");
743  0 final String method = "visitEnter(SubstPred)";
744  0 Trace.param(CLASS, this, method, "current", current);
745  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
746  0 checkMatching(method);
747   
748  0 traverser.setLocationWithinModule(context + ".getReference()");
749  0 current.setAttribute("ref");
750  0 checkIfFound();
751    }
752   
 
753  0 toggle public final void visitLeave(final SubstPred reason) {
754  0 leave();
755    }
756   
 
757  0 toggle public final void visitEnter(final Existential reason) throws ModuleDataException {
758  0 enter("EXISTENTIAL");
759  0 final String method = "visitEnter(Existential)";
760  0 Trace.param(CLASS, this, method, "current", current);
761  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
762  0 checkMatching(method);
763   
764  0 traverser.setLocationWithinModule(context + ".getReference()");
765  0 current.setAttribute("ref");
766  0 checkIfFound();
767    }
768   
 
769  0 toggle public final void visitLeave(final Existential reason) {
770  0 leave();
771    }
772   
 
773  0 toggle public final void visitEnter(final Universal reason) throws ModuleDataException {
774  0 enter("UNIVERSAL");
775  0 final String method = "visitEnter(Universal)";
776  0 Trace.param(CLASS, this, method, "current", current);
777  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
778  0 checkMatching(method);
779   
780  0 traverser.setLocationWithinModule(context + ".getReference()");
781  0 current.setAttribute("ref");
782  0 checkIfFound();
783    }
784   
 
785  0 toggle public final void visitLeave(final Universal reason) {
786  0 leave();
787    }
788   
 
789  0 toggle public final void visitEnter(final Hypothesis hypothesis) throws ModuleDataException {
790  0 enter("HYPOTHESIS");
791  0 final String method = "visitEnter(Hypothesis)";
792  0 Trace.param(CLASS, this, method, "current", current);
793  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
794  0 checkMatching(method);
795   
796  0 traverser.setLocationWithinModule(context + ".getLabel()");
797  0 current.setAttribute("label");
798  0 checkIfFound();
799    }
800   
 
801  0 toggle public final void visitLeave(final Hypothesis hypothesis) {
802  0 leave();
803    }
804   
 
805  0 toggle public final void visitEnter(final Conclusion conclusion) throws ModuleDataException {
806  0 enter("CONCLUSION");
807  0 final String method = "visitEnter(Conclusion)";
808  0 Trace.param(CLASS, this, method, "current", current);
809  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
810  0 checkMatching(method);
811   
812  0 traverser.setLocationWithinModule(context + ".getLabel()");
813  0 current.setAttribute("label");
814  0 checkIfFound();
815    }
816   
 
817  0 toggle public final void visitLeave(final Conclusion conclusion) {
818  0 leave();
819    }
820   
 
821  0 toggle public final void visitEnter(final InitialPredicateDefinition definition) throws ModuleDataException {
822  0 enter("DEFINITION_PREDICATE_INITIAL");
823  0 final String method = "visitEnter(InitialPredicateDefinition)";
824  0 Trace.param(CLASS, this, method, "current", current);
825  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
826  0 checkMatching(method);
827   
828  0 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
829  0 current.setAttribute("arguments");
830  0 checkIfFound();
831   
832  0 traverser.setLocationWithinModule(context + ".getName()");
833  0 current.setAttribute("name");
834  0 checkIfFound();
835   
836  0 traverser.setLocationWithinModule(context + ".getLatexPattern()");
837  0 enter("LATEXPATTERN");
838  0 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
839    .getLocationWithinModule())) {
840  0 if (definition.getLatexPattern() == null) { // NOT FOUND
841  0 leave();
842    }
843  0 throw new LocationFoundException(traverser.getCurrentContext());
844    }
845  0 leave();
846    }
847   
 
848  0 toggle public final void visitLeave(final InitialPredicateDefinition definition) {
849  0 leave();
850    }
851   
 
852  3 toggle public final void visitEnter(final PredicateDefinition definition) throws ModuleDataException {
853  3 enter("DEFINITION_PREDICATE");
854  3 final String method = "visitEnter(PredicateDefinition)";
855  3 Trace.param(CLASS, this, method, "current", current);
856  3 final String context = traverser.getCurrentContext().getLocationWithinModule();
857  3 checkMatching(method);
858   
859  3 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
860  3 current.setAttribute("arguments");
861  3 checkIfFound();
862   
863  3 traverser.setLocationWithinModule(context + ".getName()");
864  3 current.setAttribute("name");
865  3 checkIfFound();
866   
867  3 traverser.setLocationWithinModule(context + ".getLatexPattern()");
868  3 enter("LATEXPATTERN");
869  3 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
870    .getLocationWithinModule())) {
871  0 if (definition.getLatexPattern() == null) { // NOT FOUND
872  0 leave();
873    }
874  0 throw new LocationFoundException(traverser.getCurrentContext());
875    }
876  3 leave();
877    }
878   
 
879  1 toggle public final void visitLeave(final PredicateDefinition definition) {
880  1 leave();
881    }
882   
 
883  0 toggle public final void visitEnter(final InitialFunctionDefinition definition) throws ModuleDataException {
884  0 enter("DEFINITION_FUNCTION_INITIAL");
885  0 final String method = "visitEnter(InitialFunctionDefinition)";
886  0 Trace.param(CLASS, this, method, "current", current);
887  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
888  0 checkMatching(method);
889   
890  0 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
891  0 current.setAttribute("arguments");
892  0 checkIfFound();
893   
894  0 traverser.setLocationWithinModule(context + ".getName()");
895  0 current.setAttribute("name");
896  0 checkIfFound();
897   
898  0 traverser.setLocationWithinModule(context + ".getLatexPattern()");
899  0 enter("LATEXPATTERN");
900  0 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
901    .getLocationWithinModule())) {
902  0 if (definition.getLatexPattern() == null) { // NOT FOUND
903  0 leave();
904    }
905  0 throw new LocationFoundException(traverser.getCurrentContext());
906    }
907  0 leave();
908    }
909   
 
910  0 toggle public final void visitLeave(final InitialFunctionDefinition definition) {
911  0 leave();
912    }
913   
 
914  0 toggle public final void visitEnter(final FunctionDefinition definition) throws ModuleDataException {
915  0 enter("DEFINITION_FUNCTION");
916  0 final String method = "visitEnter(FunctionDefinition)";
917  0 Trace.param(CLASS, this, method, "current", current);
918  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
919  0 checkMatching(method);
920   
921  0 traverser.setLocationWithinModule(context + ".getArgumentNumber()");
922  0 current.setAttribute("arguments");
923  0 checkIfFound();
924   
925  0 traverser.setLocationWithinModule(context + ".getName()");
926  0 current.setAttribute("name");
927  0 checkIfFound();
928   
929  0 traverser.setLocationWithinModule(context + ".getLatexPattern()");
930  0 enter("LATEXPATTERN");
931  0 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
932    .getLocationWithinModule())) {
933  0 if (definition.getLatexPattern() == null) { // NOT FOUND
934  0 leave();
935    }
936  0 throw new LocationFoundException(traverser.getCurrentContext());
937    }
938  0 leave();
939    }
940   
 
941  0 toggle public final void visitLeave(final FunctionDefinition definition) {
942  0 leave();
943    }
944   
 
945  0 toggle public final void visitEnter(final Rule rule) throws ModuleDataException {
946  0 enter("RULE");
947  0 final String method = "visitEnter(Rule)";
948  0 Trace.param(CLASS, this, method, "current", current);
949  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
950  0 checkMatching(method);
951   
952  0 traverser.setLocationWithinModule(context + ".getName()");
953  0 current.setAttribute("name");
954  0 checkIfFound();
955   
956  0 traverser.setLocationWithinModule(context + ".getVersion()");
957  0 current.setAttribute("version");
958  0 checkIfFound();
959    }
960   
 
961  0 toggle public final void visitLeave(final Rule rule) {
962  0 leave();
963    }
964   
 
965  0 toggle public final void visitEnter(final ChangedRuleList list) throws ModuleDataException {
966  0 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  0 checkMatching(method);
970    }
971   
 
972  0 toggle public final void visitLeave(final ChangedRuleList list) {
973  0 traverser.setBlocked(false); // free node search again
974    }
975   
 
976  0 toggle public final void visitEnter(final ChangedRule rule) throws ModuleDataException {
977  0 enter("CHANGED_RULE");
978  0 final String method = "visitEnter(ChangedRule)";
979  0 Trace.param(CLASS, this, method, "current", current);
980  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
981  0 checkMatching(method);
982   
983  0 traverser.setLocationWithinModule(context + ".getName()");
984  0 current.setAttribute("name");
985  0 checkIfFound();
986   
987  0 traverser.setLocationWithinModule(context + ".getVersion()");
988  0 current.setAttribute("version");
989  0 checkIfFound();
990    }
991   
 
992  0 toggle public final void visitLeave(final ChangedRule rule) {
993  0 leave();
994    }
995   
 
996  0 toggle public final void visitEnter(final LinkList linkList) throws ModuleDataException {
997  0 final String method = "visitEnter(LinkList)";
998  0 Trace.param(CLASS, this, method, "current", current);
999  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
1000  0 checkMatching(method);
1001   
1002  0 for (int i = 0; i < linkList.size(); i++) {
1003  0 enter("LINK");
1004  0 if (linkList.get(i) != null) {
1005  0 traverser.setLocationWithinModule(context + ".get(" + i + ")");
1006  0 current.setAttribute("id");
1007  0 checkIfFound();
1008    }
1009  0 leave();
1010  0 };
1011    }
1012   
 
1013  0 toggle public final void visitLeave(final LinkList linkList) {
1014    // nothing to do
1015    }
1016   
 
1017  7 toggle public final void visitEnter(final Formula formula) throws ModuleDataException {
1018  7 enter("FORMULA");
1019  7 final String method = "visitEnter(Formula)";
1020  7 Trace.param(CLASS, this, method, "current", current);
1021  7 checkMatching(method);
1022    }
1023   
 
1024  1 toggle public final void visitLeave(final Formula formula) {
1025  1 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  21 toggle public final void visitEnter(final ElementList list) throws ModuleDataException {
1040  21 final String operator = list.getOperator();
1041  21 enter(operator);
1042  21 final String method = "visitEnter(ElementList)";
1043  21 Trace.param(CLASS, this, method, "current", current);
1044  21 String context = traverser.getCurrentContext().getLocationWithinModule();
1045   
1046    // to find something like getElement(0).getList().getElement(0)
1047  21 if (context.startsWith(find.getLocationWithinModule())) {
1048  2 throw new LocationFoundException(find);
1049    }
1050   
1051  19 checkMatching(method);
1052   
1053  19 traverser.setLocationWithinModule(context + ".getOperator()");
1054  19 checkIfFound();
1055  19 traverser.setLocationWithinModule(context);
1056  19 final boolean firstIsAtom = list.size() > 0 && list.getElement(0).isAtom();
1057  19 if (firstIsAtom) {
1058  10 traverser.setLocationWithinModule(context + ".getElement(0)");
1059  10 if ("VAR".equals(operator) || "PREDVAR".equals(operator)
1060    || "FUNVAR".equals(operator)) {
1061  4 current.setAttribute("id");
1062  4 checkIfFound();
1063  4 traverser.setLocationWithinModule(context + ".getElement(0).getAtom()");
1064  4 checkIfFound();
1065  6 } else if ("PREDCON".equals(operator) || "FUNCON".equals(operator)) {
1066  6 current.setAttribute("ref");
1067  6 checkIfFound();
1068  2 traverser.setLocationWithinModule(context + ".getElement(0).getAtom()");
1069  2 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  6 toggle public final void visitLeave(final ElementList list) {
1079  6 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  0 toggle public final void visitEnter(final LiteratureItemList list) throws ModuleDataException {
1092  0 enter("BIBLIOGRAPHY");
1093  0 final String method = "visitEnter(LiteratureItemList)";
1094  0 Trace.param(CLASS, this, method, "current", current);
1095  0 checkMatching(method);
1096    }
1097   
 
1098  0 toggle public final void visitLeave(final LiteratureItemList list) {
1099  0 leave();
1100    }
1101   
 
1102  0 toggle public final void visitEnter(final LiteratureItem item) throws ModuleDataException {
1103  0 enter("ITEM");
1104  0 final String method = "visitEnter(LiteratureItem)";
1105  0 Trace.param(CLASS, this, method, "current", current);
1106  0 final String context = traverser.getCurrentContext().getLocationWithinModule();
1107  0 checkMatching(method);
1108   
1109  0 traverser.setLocationWithinModule(context + ".getLabel()");
1110  0 current.setAttribute("label");
1111  0 checkIfFound();
1112    }
1113   
 
1114  0 toggle public final void visitLeave(final LiteratureItem item) {
1115  0 leave();
1116    }
1117   
1118    /**
1119    * Check if searched for context is already reached.
1120    *
1121    * @throws LocationFoundException We have found it.
1122    */
 
1123  371 toggle private final void checkIfFound() throws LocationFoundException {
1124  371 if (find.getLocationWithinModule().equals(traverser.getCurrentContext()
1125    .getLocationWithinModule())) {
1126  10 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  222 toggle private final void checkMatching(final String method)
1142    throws LocationNotFoundException, LocationFoundException {
1143  222 final String context = traverser.getCurrentContext().getLocationWithinModule();
1144  222 if (find.getLocationWithinModule().startsWith(context)) {
1145  113 Trace.info(CLASS, this, method, "beginning matches");
1146  113 Trace.paramInfo(CLASS, this, method, "context", context);
1147  113 matching = true;
1148  113 matchingBegin = context; // remember matching context
1149  113 matchingPath = new SimpleXPath(current); // remember last matching XPath
1150    } else {
1151  109 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  108 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  108 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  1 Trace.info(CLASS, this, method, "matching lost, when finding error location");
1169  1 Trace.paramInfo(CLASS, this, method, "last match ", matchingBegin);
1170  1 Trace.paramInfo(CLASS, this, method, "current context", context);
1171  1 Trace.paramInfo(CLASS, this, method, "find context ", find.getLocationWithinModule());
1172   
1173  1 Trace.traceStack(CLASS, this, method);
1174  1 Trace.info(CLASS, this, method, "changing XPath to last matching one");
1175   
1176    // do we really want to fail?
1177  1 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  1 current = matchingPath;
1187  1 throw new LocationFoundException(new ModuleContext(find.getModuleLocation(),
1188    matchingBegin));
1189    }
1190    }
1191  107 traverser.setBlocked(true); // block further search in sub nodes
1192    }
1193  220 checkIfFound();
1194    }
1195   
1196    /**
1197    * Enter new XML element.
1198    *
1199    * @param element Element name.
1200    */
 
1201  202 toggle private final void enter(final String element) {
1202  202 level++;
1203  202 current.addElement(element, addOccurence(element));
1204    }
1205   
1206    /**
1207    * Leave last XML element.
1208    */
 
1209  115 toggle private final void leave() {
1210  115 level--;
1211  115 current.deleteLastElement();
1212  115 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  202 toggle private final int addOccurence(final String name) {
1226  204 while (level < elements.size()) {
1227  2 elements.remove(elements.size() - 1);
1228    }
1229  296 while (level > elements.size()) {
1230  94 elements.add(new HashMap());
1231    }
1232  202 final Map levelMap = (Map) elements.get(level - 1);
1233  202 final Enumerator counter;
1234  202 if (levelMap.containsKey(name)) {
1235  18 counter = (Enumerator) levelMap.get(name);
1236  18 counter.increaseNumber();
1237    } else {
1238  184 counter = new Enumerator(1);
1239  184 levelMap.put(name, counter);
1240    }
1241  202 return counter.getNumber();
1242    }
1243   
1244    }