01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02 *
03 * Copyright 2000-2011, Michael Meyling <mime@qedeq.org>.
04 *
05 * "Hilbert II" is free software; you can redistribute
06 * it and/or modify it under the terms of the GNU General Public
07 * License as published by the Free Software Foundation; either
08 * version 2 of the License, or (at your option) any later version.
09 *
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.bo.service.latex;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.qedeq.kernel.bo.module.ControlVisitor;
22 import org.qedeq.kernel.bo.module.KernelQedeqBo;
23 import org.qedeq.kernel.se.base.module.Latex;
24 import org.qedeq.kernel.se.base.module.LatexList;
25 import org.qedeq.kernel.se.common.ModuleContext;
26 import org.qedeq.kernel.se.common.ModuleDataException;
27 import org.qedeq.kernel.se.common.Plugin;
28 import org.qedeq.kernel.se.common.SourceFileExceptionList;
29
30
31 /**
32 * Checks if no duplicate language entries exist.
33 *
34 * @author Michael Meyling
35 */
36 public final class QedeqBoDuplicateLanguageChecker extends ControlVisitor {
37
38 /**
39 * Checks if all formulas of a QEDEQ module are well formed.
40 *
41 * @param plugin Plugin we work for.
42 * @param prop QEDEQ BO.
43 * @throws SourceFileExceptionList An error occurred.
44 */
45 public static void check(final Plugin plugin, final KernelQedeqBo prop) throws SourceFileExceptionList {
46 final QedeqBoDuplicateLanguageChecker checker
47 = new QedeqBoDuplicateLanguageChecker(plugin, prop);
48 checker.traverse();
49 }
50
51 /**
52 * Constructor.
53 *
54 * @param plugin Plugin we work for.
55 * @param bo BO QEDEQ module object.
56 */
57 private QedeqBoDuplicateLanguageChecker(final Plugin plugin, final KernelQedeqBo bo) {
58 super(plugin, bo);
59 }
60
61 public final void visitEnter(final LatexList list) throws ModuleDataException {
62 if (list == null) {
63 return;
64 }
65 final String context = getCurrentContext().getLocationWithinModule();
66 final Map languages = new HashMap();
67 for (int i = 0; i < list.size(); i++) {
68 final Latex latex = list.get(i);
69 setLocationWithinModule(context + ".get(" + i + ")");
70 if (latex == null) {
71 throw new LatexListDataException(1000, "Null pointer not permitted.",
72 getCurrentContext());
73 }
74 if (languages.containsKey(latex.getLanguage())) {
75 throw new LatexListDataException(1001, "Language entry exists already",
76 getCurrentContext(), (ModuleContext) languages.get(latex.getLanguage()));
77 }
78 languages.put(list.get(i).getLanguage(), getCurrentContext());
79 }
80 setLocationWithinModule(context);
81 setBlocked(true);
82 }
83
84 public final void visitLeave(final LatexList list) {
85 setBlocked(false);
86 }
87
88 /**
89 * Set location information where are we within the original module.
90 *
91 * @param locationWithinModule Location within module.
92 */
93 public void setLocationWithinModule(final String locationWithinModule) {
94 getCurrentContext().setLocationWithinModule(locationWithinModule);
95 }
96
97 }
|