Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
29   196   19   2.23
10   82   0.66   13
13     1.46  
1    
 
  ControlVisitor       Line # 34 29 19 92.3% 0.9230769
 
  (48)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, 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.bo.module;
17   
18    import org.qedeq.kernel.common.DefaultSourceFileExceptionList;
19    import org.qedeq.kernel.common.ModuleContext;
20    import org.qedeq.kernel.common.ModuleDataException;
21    import org.qedeq.kernel.common.Plugin;
22    import org.qedeq.kernel.common.SourceFileException;
23    import org.qedeq.kernel.common.SourceFileExceptionList;
24    import org.qedeq.kernel.visitor.AbstractModuleVisitor;
25    import org.qedeq.kernel.visitor.QedeqNotNullTraverser;
26   
27   
28    /**
29    * Basic visitor that gives some error collecting features. Also hides the
30    * traverser that does the work.
31    *
32    * @author Michael Meyling
33    */
 
34    public abstract class ControlVisitor extends AbstractModuleVisitor {
35   
36    /** This plugin we work for. */
37    private final Plugin plugin;
38   
39    /** QEDEQ BO object to work on. */
40    private final KernelQedeqBo prop;
41   
42    /** Traverse QEDEQ module with this traverser. */
43    private final QedeqNotNullTraverser traverser;
44   
45    /** List of Exceptions of type error during Module visit. */
46    private DefaultSourceFileExceptionList errorList;
47   
48    /** List of Exceptions of type warnings during Module visit. */
49    private DefaultSourceFileExceptionList warningList;
50   
51   
52    /**
53    * Constructor. Can only be used if instance also implements {@link Plugin}.
54    *
55    * @param prop Internal QedeqBo.
56    */
 
57  98 toggle protected ControlVisitor(final KernelQedeqBo prop) {
58  98 if (prop.getQedeq() == null) {
59  0 throw new NullPointerException("Programming error, Module not loaded: "
60    + prop.getModuleAddress());
61    }
62  98 this.prop = prop;
63  98 this.plugin = (Plugin) this;
64  98 this.traverser = new QedeqNotNullTraverser(prop.getModuleAddress(), this);
65    }
66   
67    /**
68    * Constructor.
69    *
70    * @param plugin This plugin we work for.
71    * @param prop Internal QedeqBo.
72    */
 
73  401 toggle protected ControlVisitor(final Plugin plugin, final KernelQedeqBo prop) {
74  401 if (prop.getQedeq() == null) {
75  0 throw new NullPointerException("Programming error, Module not loaded: "
76    + prop.getModuleAddress());
77    }
78  401 this.plugin = plugin;
79  401 this.prop = prop;
80  401 this.traverser = new QedeqNotNullTraverser(prop.getModuleAddress(), this);
81    }
82   
83    /**
84    * Get QedeqBo.
85    *
86    * @return QedeqBo.
87    */
 
88  2371 toggle protected KernelQedeqBo getQedeqBo() {
89  2371 return this.prop;
90    }
91   
92    /**
93    * Start traverse of QedeqBo. If during the traverse a {@link ModuleDataException}
94    * occurs it is thrown till high level and transformed into a
95    * {@link DefaultSourceFileExceptionList}. Otherwise all collected exceptions
96    * (via {@link #addError(ModuleDataException)} and
97    * {@link #addError(SourceFileException)}) are thrown.
98    *
99    * @throws SourceFileExceptionList All collected exceptions.
100    */
 
101  494 toggle public void traverse() throws SourceFileExceptionList {
102  494 try {
103  494 this.traverser.accept(this.prop.getQedeq());
104    } catch (ModuleDataException me) {
105  5 addError(me);
106    }
107  494 if (errorList != null) {
108  22 throw errorList;
109    }
110    }
111   
 
112  36513 toggle protected ModuleContext getCurrentContext() {
113  36513 return this.traverser.getCurrentContext();
114    }
115   
116    /**
117    * Add exception to error collection.
118    *
119    * @param me Exception to be added.
120    */
 
121  28 toggle protected void addError(final ModuleDataException me) {
122  28 addError(prop.createSourceFileException(getPlugin(), me));
123    }
124   
125    /**
126    * Add exception to error collection.
127    *
128    * @param sf Exception to be added.
129    */
 
130  28 toggle protected void addError(final SourceFileException sf) {
131  28 if (errorList == null) {
132  25 errorList = new DefaultSourceFileExceptionList(sf);
133    } else {
134  3 errorList.add(sf);
135    }
136    }
137   
138    /**
139    * Get list of errors that occurred during visit.
140    *
141    * @return Exception list.
142    */
 
143  188 toggle public SourceFileExceptionList getErrorList() {
144  188 return errorList;
145    }
146   
147    /**
148    * Add exception to warning collection.
149    *
150    * @param me Exception to be added.
151    */
 
152  4 toggle protected void addWarning(final ModuleDataException me) {
153  4 addWarning(prop.createSourceFileException(getPlugin(), me));
154    }
155   
156    /**
157    * Add exception to warning collection.
158    *
159    * @param sf Exception to be added.
160    */
 
161  4 toggle protected void addWarning(final SourceFileException sf) {
162  4 if (warningList == null) {
163  2 warningList = new DefaultSourceFileExceptionList(sf);
164    } else {
165  2 warningList.add(sf);
166    }
167    }
168   
169    /**
170    * Get list of warnings that occurred during visit.
171    *
172    * @return Exception list.
173    */
 
174  24 toggle public SourceFileExceptionList getWarningList() {
175  24 return warningList;
176    }
177   
178    /**
179    * Set if further traverse is blocked.
180    *
181    * @param blocked Further traverse blocked?
182    */
 
183  15470 toggle protected void setBlocked(final boolean blocked) {
184  15470 traverser.setBlocked(blocked);
185    }
186   
187    /**
188    * Get plugin we work for.
189    *
190    * @return Plugin we work for.
191    */
 
192  32 toggle public Plugin getPlugin() {
193  32 return plugin;
194    }
195   
196    }