KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > process > DumpersManager


1 package net.sf.invicta.process;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6
7 import net.sf.invicta.InvictaException;
8 import net.sf.invicta.Logger;
9 import net.sf.invicta.api.InvictaProject;
10 import net.sf.invicta.dumper.InvictaDumper;
11 import sun.misc.Service;
12
13 /**
14  * Resposible for managing the registered dumpers of Invicta: checking
15  * which dumpers are enabled, checking whether a dumper forces Invicta
16  * processing and executes enabled dumpers.
17  */

18 public class DumpersManager {
19     protected ConfigurationManager configurationManager;
20     protected boolean forceRun = false;
21     protected List JavaDoc dumpers = new ArrayList JavaDoc();
22
23     /**
24      *
25      * @param configurationManager
26      * @throws InvictaException
27      */

28     public DumpersManager(ConfigurationManager configurationManager) throws InvictaException {
29         this.configurationManager = configurationManager;
30         findDumpersList();
31     }
32
33     /**
34      * Returns whether a dumper forces Invicta processing.
35      * @return boolean
36      * @throws InvictaException
37      */

38     public boolean forceRun() throws InvictaException {
39         return this.forceRun;
40     }
41     
42     /**
43      * Perform the actual execution of available dumpers.
44      * @param project
45      * @throws InvictaException
46      */

47     public void dump(InvictaProject project) throws InvictaException {
48         // Go over all dumpers and execute the enabled ones.
49
for (Iterator JavaDoc dumperIter = this.dumpers.iterator(); dumperIter.hasNext();) {
50              InvictaDumper dumper = (InvictaDumper) dumperIter.next();
51              if (dumper.isEnabled()) {
52                  dumper.setProject(project);
53                  Logger.info("Running dumper '" + dumper.getName() + "'...");
54                  dumper.dump();
55              }
56          }
57     }
58     
59     /**
60      * Finds all registered dumpers, check if they are enabled,
61      * initialize the enabled ones, and check whether any dumper
62      * forces Invicta processing.
63      * @throws InvictaException
64      */

65     protected void findDumpersList() throws InvictaException {
66         Iterator JavaDoc dumpersIter =
67             Service.providers(InvictaDumper.class);
68             
69         while (dumpersIter.hasNext()) {
70             InvictaDumper dumper = (InvictaDumper) dumpersIter.next();
71             dumper.init(this.configurationManager);
72             if (dumper.isEnabled()) {
73                 if (dumper.shouldForceRunning())
74                     this.forceRun = true;
75                 this.dumpers.add(dumper);
76                 Logger.debug("Dumper '" + dumper.getName() + "' enabled");
77             } else {
78                 Logger.debug("Dumper '" + dumper.getName() + "' disabled");
79             }
80         }
81     }
82 }
83
Popular Tags