Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
../../../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
42   147   17   6
18   77   0.4   7
7     2.43  
1    
 
  PluginResultManager       Line # 30 42 17 67.2% 0.67164177
 
  (106)
 
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.bo.service.internal;
17   
18    import java.util.HashMap;
19    import java.util.Iterator;
20    import java.util.Map;
21   
22    import org.qedeq.kernel.bo.service.basis.ModuleServicePlugin;
23    import org.qedeq.kernel.bo.service.basis.ModuleServicePluginResults;
24    import org.qedeq.kernel.se.common.ModuleService;
25    import org.qedeq.kernel.se.common.SourceFileExceptionList;
26   
27    /**
28    * Holds all known QEDEQ modules.
29    */
 
30    public class PluginResultManager {
31   
32    /** Maps plugins to results. */
33    private final Map plugins = new HashMap();
34   
35   
36    /**
37    * Get all used plugins.
38    *
39    * @return Used plugins.
40    */
 
41  0 toggle synchronized ModuleServicePlugin[] getPlugins() {
42  0 return (ModuleServicePlugin[]) plugins.keySet().toArray(new ModuleServicePlugin[] {});
43    }
44   
45    /**
46    * Clear all plugin results.
47    */
 
48  0 toggle public void removeAllResults() {
49  0 plugins.clear();
50    }
51   
52    /**
53    * Set a plugin execution results.
54    *
55    * @param plugin Set results for this plugin.
56    * @param errors Plugin errors.
57    * @param warnings Plugin warnings.
58    */
 
59  0 toggle public synchronized void setResult(final ModuleServicePlugin plugin, final SourceFileExceptionList errors,
60    final SourceFileExceptionList warnings) {
61  0 ModuleServicePluginResults results = (ModuleServicePluginResults) plugins.get(plugin);
62  0 if (results == null) {
63  0 results = new ModuleServicePluginResults();
64  0 plugins.put(plugin, results);
65    }
66  0 results.clear();
67  0 results.addErrors(errors);
68  0 results.addWarnings(warnings);
69    }
70   
71    /**
72    * Add results of a plugin.
73    *
74    * @param plugin Add results for this plugin.
75    * @param errors Plugin errors.
76    * @param warnings Plugin warnings.
77    */
 
78  113 toggle public synchronized void addResult(final ModuleService plugin, final SourceFileExceptionList errors,
79    final SourceFileExceptionList warnings) {
80  113 ModuleServicePluginResults results = (ModuleServicePluginResults) plugins.get(plugin);
81  113 if (results == null) {
82  111 results = new ModuleServicePluginResults();
83  111 plugins.put(plugin, results);
84    }
85  113 results.addErrors(errors);
86  113 results.addWarnings(warnings);
87    }
88   
89    /**
90    * Get all errors that occurred. The resulting object is never <code>null</code>.
91    *
92    * @return Error list.
93    */
 
94  1282 toggle public SourceFileExceptionList getAllErrors() {
95  1282 final SourceFileExceptionList errors = new SourceFileExceptionList();
96  1282 Iterator iterator = plugins.keySet().iterator();
97  1583 while (iterator.hasNext()) {
98  301 errors.add(((ModuleServicePluginResults) plugins.get(iterator.next())).getErrors());
99    }
100  1282 return errors;
101    }
102   
103    /**
104    * Get all warnings that occurred. The resulting object is never <code>null</code>.
105    *
106    * @return Warnings list.
107    */
 
108  224 toggle public SourceFileExceptionList getAllWarnings() {
109  224 final SourceFileExceptionList warnings = new SourceFileExceptionList();
110  224 Iterator iterator = plugins.keySet().iterator();
111  519 while (iterator.hasNext()) {
112  295 warnings.add(((ModuleServicePluginResults) plugins.get(iterator.next())).getWarnings());
113    }
114  224 return warnings;
115    }
116   
117    /**
118    * Get plugin states description.
119    *
120    * @return Textual description of plugin states.
121    */
 
122  60 toggle public synchronized String getPluginStateDescription() {
123  60 final StringBuffer text = new StringBuffer();
124  60 Iterator iterator = plugins.keySet().iterator();
125  63 while (iterator.hasNext()) {
126  3 if (text.length() > 0) {
127  0 text.append(", ");
128    }
129  3 final ModuleServicePlugin key = (ModuleServicePlugin) iterator.next();
130  3 ModuleServicePluginResults result = (ModuleServicePluginResults) plugins.get(key);
131  3 text.append(key.getServiceAction());
132  3 text.append(" ");
133  3 if (result.hasErrors() && result.hasWarnings()) {
134  0 text.append("has errors and warnings");
135  3 } else if (result.hasErrors()) {
136  0 text.append("has errors");
137  3 } else if (result.hasWarnings()) {
138  0 text.append("has warnings");
139    } else {
140  3 text.append("successful");
141    }
142    }
143  60 return text.toString();
144    }
145   
146    }
147