1 | package de.ugoe.cs.eventbench.windows.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.SortedSet;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
9 | import de.ugoe.cs.eventbench.windows.LogParser;
|
---|
10 | import de.ugoe.cs.eventbench.windows.data.WindowTree;
|
---|
11 | import de.ugoe.cs.eventbench.windows.data.WindowsEvent;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * <p>
|
---|
17 | * Command to parse an XML file with sessions monitored by EventBench's
|
---|
18 | * MFCUsageMonitor.
|
---|
19 | * </p>
|
---|
20 | *
|
---|
21 | * @author Steffen Herbold
|
---|
22 | * @version 1.0
|
---|
23 | */
|
---|
24 | public class CMDparseXML implements Command {
|
---|
25 |
|
---|
26 | /*
|
---|
27 | * (non-Javadoc)
|
---|
28 | *
|
---|
29 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
30 | */
|
---|
31 | @Override
|
---|
32 | public void help() {
|
---|
33 | Console.println("Usage: parseXML <filename> {<sequencesName>} {<countMessageOccurences>}");
|
---|
34 | }
|
---|
35 |
|
---|
36 | /*
|
---|
37 | * (non-Javadoc)
|
---|
38 | *
|
---|
39 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
40 | */
|
---|
41 | @Override
|
---|
42 | public void run(List<Object> parameters) {
|
---|
43 | String filename;
|
---|
44 | String sequencesName = "sequences";
|
---|
45 | boolean countMessageOccurences = false;
|
---|
46 |
|
---|
47 | try {
|
---|
48 | filename = (String) parameters.get(0);
|
---|
49 | if (parameters.size() >= 2) {
|
---|
50 | sequencesName = (String) parameters.get(1);
|
---|
51 | }
|
---|
52 | if (parameters.size() >= 3) {
|
---|
53 | countMessageOccurences = Boolean
|
---|
54 | .parseBoolean((String) parameters.get(2));
|
---|
55 | }
|
---|
56 | } catch (Exception e) {
|
---|
57 | throw new InvalidParameterException();
|
---|
58 | }
|
---|
59 |
|
---|
60 | LogParser parser = new LogParser(countMessageOccurences);
|
---|
61 | parser.parseFile(filename);
|
---|
62 |
|
---|
63 | Collection<List<WindowsEvent>> sequences = parser.getSequences();
|
---|
64 | SortedSet<String> targets = WindowTree.getInstance().getTargets();
|
---|
65 |
|
---|
66 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
67 | Console.traceln("Old data \"" + sequencesName + "\" overwritten");
|
---|
68 | }
|
---|
69 | if( GlobalDataContainer.getInstance().addData(sequencesName+"_targets", targets)) {
|
---|
70 | Console.traceln("Old data \"" + sequencesName+"_targets" + "\" overwritten");
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | }
|
---|