Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 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
 
  (91)
 
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.bo.service.control;
17   
18    import java.util.HashMap;
19    import java.util.Iterator;
20    import java.util.Map;
21   
22    import org.qedeq.kernel.bo.module.PluginBo;
23    import org.qedeq.kernel.bo.module.PluginResults;
24    import org.qedeq.kernel.se.common.Plugin;
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 PluginBo[] getPlugins() {
42  0 return (PluginBo[]) plugins.keySet().toArray(new PluginBo[] {});
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 PluginBo plugin, final SourceFileExceptionList errors,
60    final SourceFileExceptionList warnings) {
61  0 PluginResults results = (PluginResults) plugins.get(plugin);
62  0 if (results == null) {
63  0 results = new PluginResults();
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  71 toggle public synchronized void addResult(final Plugin plugin, final SourceFileExceptionList errors,
79    final SourceFileExceptionList warnings) {
80  71 PluginResults results = (PluginResults) plugins.get(plugin);
81  71 if (results == null) {
82  69 results = new PluginResults();
83  69 plugins.put(plugin, results);
84    }
85  71 results.addErrors(errors);
86  71 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  1195 toggle public SourceFileExceptionList getAllErrors() {
95  1195 final SourceFileExceptionList errors = new SourceFileExceptionList();
96  1195 Iterator iterator = plugins.keySet().iterator();
97  1379 while (iterator.hasNext()) {
98  184 errors.add(((PluginResults) plugins.get(iterator.next())).getErrors());
99    }
100  1195 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  181 toggle public SourceFileExceptionList getAllWarnings() {
109  181 final SourceFileExceptionList warnings = new SourceFileExceptionList();
110  181 Iterator iterator = plugins.keySet().iterator();
111  362 while (iterator.hasNext()) {
112  181 warnings.add(((PluginResults) plugins.get(iterator.next())).getWarnings());
113    }
114  181 return warnings;
115    }
116   
117    /**
118    * Get plugin states description.
119    *
120    * @return Textual description of plugin states.
121    */
 
122  57 toggle public synchronized String getPluginStateDescription() {
123  57 final StringBuffer text = new StringBuffer();
124  57 Iterator iterator = plugins.keySet().iterator();
125  60 while (iterator.hasNext()) {
126  3 if (text.length() > 0) {
127  0 text.append(", ");
128    }
129  3 final PluginBo key = (PluginBo) iterator.next();
130  3 PluginResults result = (PluginResults) 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  57 return text.toString();
144    }
145   
146    }
147