Changeset 171 for trunk/EventBenchConsole/src/de/ugoe
- Timestamp:
- 09/09/11 06:23:36 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench
- Files:
-
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/ReplayGenerator.java
r98 r171 12 12 import de.ugoe.cs.util.console.Console; 13 13 14 /** 15 * <p> 16 * This class provides the functionality to generate replay files from sequences 17 * if {@link ReplayableEvent}s. 18 * </p> 19 * 20 * @author Steffen Herbold 21 * @version 1.0 22 */ 14 23 public class ReplayGenerator { 15 24 25 /** 26 * <p> 27 * {@link IReplayDecorator} to be used. If this field is {@code null}, no 28 * decorator is used. Default: {@code null} 29 * </p> 30 */ 16 31 private IReplayDecorator decorator = null; 17 32 33 /** 34 * <p> 35 * Id of the current session. The starting id is 1. 36 * </p> 37 */ 18 38 int sessionId = 1; 19 20 public void createLogfileMultipleSessions(List<List<ReplayableEvent<?>>> sequences, String filename) { 39 40 /** 41 * <p> 42 * Creates a replay file that contains multiple event sequences. 43 * </p> 44 * 45 * @param sequences 46 * collection of event sequences from which the sessions are 47 * generated 48 * @param filename 49 * name and path of the replay file 50 */ 51 public void createLogfileMultipleSessions( 52 List<List<ReplayableEvent<?>>> sequences, String filename) { 21 53 OutputStreamWriter writer = openReplayFile(filename); 22 if ( writer!=null ) {54 if (writer != null) { 23 55 try { 24 56 decorator = sequences.get(0).get(0).getReplayDecorator(); 25 if ( decorator!=null) {57 if (decorator != null) { 26 58 writer.write(decorator.getHeader()); 27 59 } 28 for ( List<ReplayableEvent<?>> actions : sequences) {60 for (List<ReplayableEvent<?>> actions : sequences) { 29 61 writeSession(actions, writer); 30 62 } 31 if( decorator!=null ) { 32 writer.write(decorator.getFooter()); 33 } 34 decorator = null; 35 writer.close(); 36 } catch (IOException e) { 37 Console.printerrln("Unable to write replay file " + filename); 38 } 39 } 40 } 41 42 public void createLogfileSingleSession(List<ReplayableEvent<?>> actions, String filename) { 43 OutputStreamWriter writer = openReplayFile(filename); 44 if( writer!=null ) { 45 try { 46 actions.get(0).getReplayDecorator(); 47 if( decorator!=null ) { 48 writer.write(decorator.getHeader()); 49 } 50 writeSession(actions, writer); 51 if( decorator!=null ) { 63 if (decorator != null) { 52 64 writer.write(decorator.getFooter()); 53 65 } … … 60 72 } 61 73 74 /** 75 * <p> 76 * Creates a replay file that from a single event sequence. 77 * </p> 78 * 79 * @param actions 80 * event sequence from which the sessions are generated 81 * @param filename 82 * name and path of the replay file 83 */ 84 public void createLogfileSingleSession(List<ReplayableEvent<?>> actions, 85 String filename) { 86 OutputStreamWriter writer = openReplayFile(filename); 87 if (writer != null) { 88 try { 89 actions.get(0).getReplayDecorator(); 90 if (decorator != null) { 91 writer.write(decorator.getHeader()); 92 } 93 writeSession(actions, writer); 94 if (decorator != null) { 95 writer.write(decorator.getFooter()); 96 } 97 decorator = null; 98 writer.close(); 99 } catch (IOException e) { 100 Console.printerrln("Unable to write replay file " + filename); 101 } 102 } 103 } 104 105 /** 106 * <p> 107 * Helper function that opens the replay file for writing. 108 * </p> 109 * 110 * @param filename 111 * name and path of the replay file 112 * @return {@link OutputStreamWriter} that writes to the replay file 113 */ 62 114 private OutputStreamWriter openReplayFile(String filename) { 63 115 File file = new File(filename); … … 65 117 try { 66 118 fileCreated = file.createNewFile(); 67 if ( !fileCreated) {119 if (!fileCreated) { 68 120 Console.traceln("Created logfile " + filename); 69 121 } else { … … 76 128 OutputStreamWriter writer = null; 77 129 try { 78 writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-16"); 130 writer = new OutputStreamWriter(new FileOutputStream(file), 131 "UTF-16"); 79 132 } catch (IOException e) { 80 Console.printerrln("Unable to open file for writing (read-only file):" + filename); 133 Console.printerrln("Unable to open file for writing (read-only file):" 134 + filename); 81 135 Console.printStacktrace(e); 82 136 } 83 137 return writer; 84 138 } 85 86 private void writeSession(List<ReplayableEvent<?>> actions, OutputStreamWriter writer) 87 throws IOException { 88 if( decorator!=null ) { 139 140 /** 141 * <p> 142 * Helper function that adds an event sequence to the replay. 143 * </p> 144 * 145 * @param actions 146 * event sequences to be added 147 * @param writer 148 * {@link OutputStreamWriter} to which the replay is added 149 * @throws IOException 150 * thrown if there is a problem writing to writer 151 */ 152 private void writeSession(List<ReplayableEvent<?>> actions, 153 OutputStreamWriter writer) throws IOException { 154 if (decorator != null) { 89 155 writer.write(decorator.getSessionHeader(sessionId)); 90 156 } 91 for( ReplayableEvent<?> currentAction : actions ) { 92 93 List<? extends IReplayable> replayables = currentAction.getReplayMessages(); 94 for( IReplayable replayble : replayables ) { 95 writer.write(replayble.getReplay()+StringTools.ENDLINE); 157 for (ReplayableEvent<?> currentAction : actions) { 158 159 List<? extends IReplayable> replayables = currentAction 160 .getReplayMessages(); 161 for (IReplayable replayble : replayables) { 162 writer.write(replayble.getReplay() + StringTools.ENDLINE); 96 163 writer.flush(); 97 164 } 98 165 } 99 if ( decorator!=null) {166 if (decorator != null) { 100 167 writer.write(decorator.getSessionFooter(sessionId)); 101 168 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/Runner.java
r112 r171 2 2 3 3 import de.ugoe.cs.util.console.CommandExecuter; 4 import de.ugoe.cs.util.console.Console; 4 5 import de.ugoe.cs.util.console.TextConsole; 5 6 7 /** 8 * <p> 9 * Start-up class of the application. 10 * </p> 11 * <p> 12 * It sets up and starts the {@link Console}. 13 * </p> 14 * 15 * @author Steffen Herbold 16 * @version 1.0 17 */ 6 18 public class Runner { 7 19 8 20 /** 21 * <p> 22 * Main method of the application. 23 * </p> 24 * 9 25 * @param args 26 * if parameters are defined, they are interpreted as commands 27 * for the {@link Console} and executed before the user can use 28 * the console; can be used to perform batch operations 10 29 */ 11 30 public static void main(String[] args) { 12 CommandExecuter.getInstance().addCommandPackage("de.ugoe.cs.eventbench.commands"); 13 CommandExecuter.getInstance().addCommandPackage("de.ugoe.cs.eventbench.windows.commands"); 14 CommandExecuter.getInstance().addCommandPackage("de.ugoe.cs.eventbench.web.commands"); 31 CommandExecuter.getInstance().addCommandPackage( 32 "de.ugoe.cs.eventbench.commands"); 33 CommandExecuter.getInstance().addCommandPackage( 34 "de.ugoe.cs.eventbench.windows.commands"); 35 CommandExecuter.getInstance().addCommandPackage( 36 "de.ugoe.cs.eventbench.web.commands"); 15 37 TextConsole textConsole = new TextConsole(); 16 if ( args.length>=1) {17 for ( String command : args) {38 if (args.length >= 1) { 39 for (String command : args) { 18 40 CommandExecuter.getInstance().exec(command); 19 41 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcCoverage.java
r130 r171 13 13 import de.ugoe.cs.util.console.Console; 14 14 15 /** 16 * <p> 17 * Command to calculate the coverage of a test suite. 18 * </p> 19 * 20 * @author Steffen Herbold 21 * @version 1.0 22 */ 15 23 public class CMDcalcCoverage implements Command { 16 24 25 /* 26 * (non-Javadoc) 27 * 28 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 29 */ 17 30 @SuppressWarnings("unchecked") 18 31 @Override 19 32 public void run(List<Object> parameters) { 20 String modelname; 33 String modelname; 21 34 String[] sequenceNames; 22 35 int minLength; … … 28 41 minLength = Integer.parseInt((String) parameters.get(2)); 29 42 maxLength = Integer.parseInt((String) parameters.get(3)); 30 if ( parameters.size()==5) {43 if (parameters.size() == 5) { 31 44 observedName = (String) parameters.get(1); 32 45 } 33 } 34 catch (Exception e) { 46 } catch (Exception e) { 35 47 throw new InvalidParameterException(); 36 48 } 37 38 IStochasticProcess process = null; 49 50 IStochasticProcess process = null; 39 51 Collection<List<? extends Event<?>>> observedSequences = null; 40 52 Collection<List<? extends Event<?>>> sequences = null; 41 Object dataObjectProcess = GlobalDataContainer.getInstance().getData(modelname); 42 Object dataObjectObserved = GlobalDataContainer.getInstance().getData(observedName); 43 if( dataObjectProcess==null ) { 53 Object dataObjectProcess = GlobalDataContainer.getInstance().getData( 54 modelname); 55 Object dataObjectObserved = GlobalDataContainer.getInstance().getData( 56 observedName); 57 if (dataObjectProcess == null) { 44 58 Console.printerrln("Model " + modelname + " not found in storage."); 45 59 return; 46 60 } 47 if( !(dataObjectProcess instanceof IStochasticProcess) ) { 48 Console.printerrln("Object " + modelname + " not of type IStochasticProcess!"); 61 if (!(dataObjectProcess instanceof IStochasticProcess)) { 62 Console.printerrln("Object " + modelname 63 + " not of type IStochasticProcess!"); 49 64 return; 50 65 } 51 if ( dataObjectObserved==null) {66 if (dataObjectObserved == null) { 52 67 Console.printerrln("Observed sequences not found in storage."); 53 68 return; 54 69 } 55 if ( !(dataObjectObserved instanceof Collection<?>)) {70 if (!(dataObjectObserved instanceof Collection<?>)) { 56 71 // weak instance check! 57 72 Console.printerrln("Object " + observedName + " not a Collection!"); … … 60 75 process = (IStochasticProcess) dataObjectProcess; 61 76 observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved; 62 63 77 64 78 Console.print("seqName"); 65 for ( int length=minLength ; length<=maxLength; length++) {79 for (int length = minLength; length <= maxLength; length++) { 66 80 Console.print(";numObs_" + length); 67 81 Console.print(";numCov_" + length); … … 78 92 } 79 93 Console.println(""); 80 for( String sequenceName : sequenceNames ) { 81 Object dataObjectSequences = GlobalDataContainer.getInstance().getData(sequenceName); 82 if( dataObjectSequences==null ) { 83 Console.println("Sequences " + sequenceName + " not found in storage."); 84 } 85 else if( !(dataObjectSequences instanceof Collection<?>) ) { 86 // cannot really perform type check at runtime! this is an approximative substitute 87 Console.printerrln("Object " + sequenceName + "not of type Collection<?>!"); 94 for (String sequenceName : sequenceNames) { 95 Object dataObjectSequences = GlobalDataContainer.getInstance() 96 .getData(sequenceName); 97 if (dataObjectSequences == null) { 98 Console.println("Sequences " + sequenceName 99 + " not found in storage."); 100 } else if (!(dataObjectSequences instanceof Collection<?>)) { 101 // cannot really perform type check at runtime! this is an 102 // approximative substitute 103 Console.printerrln("Object " + sequenceName 104 + "not of type Collection<?>!"); 88 105 return; 89 106 } 90 107 sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences; 91 108 Console.print(sequenceName); 92 for( int length=minLength ; length<=maxLength ; length++) { 93 CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(process, sequences, length); 94 CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(observedSequences, sequences, length); 109 for (int length = minLength; length <= maxLength; length++) { 110 CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess( 111 process, sequences, length); 112 CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved( 113 observedSequences, sequences, length); 95 114 Console.print(";" + covCalcObs.getNumObserved()); 96 115 Console.print(";" + covCalcObs.getNumCovered()); … … 101 120 Console.print(";" + covCalcProc.getCoveragePossibleWeight()); 102 121 Console.print(";" + covCalcObs.getCoverageObserved()); 103 Console.print(";" + covCalcObs.getCoverageObservedWeigth(process)); 122 Console.print(";" 123 + covCalcObs.getCoverageObservedWeigth(process)); 104 124 Console.print(";" + covCalcObs.getNewPercentage()); 105 125 Console.print(";" + covCalcObs.getCoveragePossibleNew(process)); 106 Console.print(";" + covCalcObs.getCoveragePossibleNewWeight(process)); 126 Console.print(";" 127 + covCalcObs.getCoveragePossibleNewWeight(process)); 107 128 } 108 129 Console.println(""); … … 110 131 } 111 132 133 /* 134 * (non-Javadoc) 135 * 136 * @see de.ugoe.cs.util.console.Command#help() 137 */ 112 138 @Override 113 139 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDcalcEntropy.java
r82 r171 8 8 import de.ugoe.cs.util.console.Console; 9 9 10 10 /** 11 * <p> 12 * Command to calculate the entropy of first-order Markov models. 13 * </p> 14 * 15 * @author Steffen Herbold 16 * @version 1.0 17 */ 11 18 public class CMDcalcEntropy implements Command { 12 19 20 /* (non-Javadoc) 21 * @see de.ugoe.cs.util.console.Command#help() 22 */ 13 23 @Override 14 24 public void help() { … … 16 26 } 17 27 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 30 */ 18 31 @Override 19 32 public void run(List<Object> parameters) { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateFixedLengthSequences.java
r128 r171 17 17 import de.ugoe.cs.util.console.Console; 18 18 19 /** 20 * <p> 21 * Command to generate all sequences of a given length. 22 * </p> 23 * 24 * @author Steffen Herbold 25 * @version 1.0 26 */ 19 27 public class CMDgenerateFixedLengthSequences implements Command { 20 28 29 /* 30 * (non-Javadoc) 31 * 32 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 33 */ 21 34 @Override 22 35 public void run(List<Object> parameters) { … … 32 45 minLength = Integer.parseInt((String) parameters.get(2)); 33 46 maxLength = Integer.parseInt((String) parameters.get(3)); 34 if ( parameters.size()>=5) {47 if (parameters.size() >= 5) { 35 48 all = Boolean.parseBoolean((String) parameters.get(4)); 36 49 } 37 if ( parameters.size()==6) {38 numSequences = Integer.parseInt((String) parameters.get(5)); 50 if (parameters.size() == 6) { 51 numSequences = Integer.parseInt((String) parameters.get(5)); 39 52 } 40 } 41 catch (Exception e) { 53 } catch (Exception e) { 42 54 throw new InvalidParameterException(); 43 55 } 44 45 IStochasticProcess model = null; 46 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 47 if( dataObject==null ) { 56 57 IStochasticProcess model = null; 58 Object dataObject = GlobalDataContainer.getInstance() 59 .getData(modelname); 60 if (dataObject == null) { 48 61 Console.println("Model " + modelname + " not found in storage."); 49 } 50 else if( !(dataObject instanceof IStochasticProcess) ) { 62 } else if (!(dataObject instanceof IStochasticProcess)) { 51 63 Console.println("Object " + modelname + " not of type MarkovModel!"); 52 64 } else { 53 65 model = (IStochasticProcess) dataObject; 54 66 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 55 for ( int length=minLength; length<=maxLength; length++) {56 sequences.addAll(model.generateValidSequences(length +2));67 for (int length = minLength; length <= maxLength; length++) { 68 sequences.addAll(model.generateValidSequences(length + 2)); 57 69 } 58 70 Console.traceln("" + sequences.size() + " possible"); 59 if( !all && numSequences<sequences.size() ) { 60 List<Double> probabilities = new ArrayList<Double>(sequences.size()); 71 if (!all && numSequences < sequences.size()) { 72 List<Double> probabilities = new ArrayList<Double>( 73 sequences.size()); 61 74 double probSum = 0.0; 62 for ( List<? extends Event<?>> sequence : sequences) {75 for (List<? extends Event<?>> sequence : sequences) { 63 76 double prob = model.getProbability(sequence); 64 77 probabilities.add(prob); … … 67 80 Set<Integer> drawnSequences = new HashSet<Integer>(numSequences); 68 81 Random r = new Random(); 69 while ( drawnSequences.size()<numSequences) {70 double randVal = r.nextDouble() *probSum;82 while (drawnSequences.size() < numSequences) { 83 double randVal = r.nextDouble() * probSum; 71 84 double sum = 0.0d; 72 85 int index = -1; 73 while ( sum<randVal) {86 while (sum < randVal) { 74 87 index++; 75 88 double currentProb = probabilities.get(index); 76 89 sum += currentProb; 77 90 } 78 if ( !drawnSequences.contains(index)) {91 if (!drawnSequences.contains(index)) { 79 92 drawnSequences.add(index); 80 93 probSum -= probabilities.get(index); … … 84 97 Collection<List<? extends Event<?>>> retainedSequences = new LinkedList<List<? extends Event<?>>>(); 85 98 int index = 0; 86 for (List<? extends Event<?>> sequence : sequences) {87 if ( drawnSequences.contains(index)) {99 for (List<? extends Event<?>> sequence : sequences) { 100 if (drawnSequences.contains(index)) { 88 101 retainedSequences.add(sequence); 89 102 } … … 92 105 sequences = retainedSequences; 93 106 } 94 if( GlobalDataContainer.getInstance().addData(sequencesName, sequences) ) { 95 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 107 if (GlobalDataContainer.getInstance().addData(sequencesName, 108 sequences)) { 109 Console.traceln("Old data \"" + sequencesName 110 + "\" overwritten"); 96 111 } 97 112 Console.println("" + sequences.size() + " sequences generated"); … … 99 114 } 100 115 116 /* 117 * (non-Javadoc) 118 * 119 * @see de.ugoe.cs.util.console.Command#help() 120 */ 101 121 @Override 102 122 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomReplay.java
r18 r171 12 12 import de.ugoe.cs.util.console.Console; 13 13 14 /** 15 * <p> 16 * Command to create a replay file with randomly generated sessions. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 14 22 public class CMDgenerateRandomReplay implements Command { 15 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#help() 28 */ 16 29 @Override 17 30 public void help() { … … 19 32 } 20 33 34 /* 35 * (non-Javadoc) 36 * 37 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 38 */ 21 39 @SuppressWarnings("unchecked") 22 40 @Override … … 28 46 modelname = (String) parameters.get(0); 29 47 filename = (String) parameters.get(1); 30 if ( parameters.size()<3) {48 if (parameters.size() < 3) { 31 49 numSessions = Integer.parseInt((String) parameters.get(2)); 32 50 } 33 } 34 catch (Exception e) { 51 } catch (Exception e) { 35 52 throw new InvalidParameterException(); 36 53 } 37 38 IStochasticProcess model = null; 39 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 40 if( dataObject==null ) { 54 55 IStochasticProcess model = null; 56 Object dataObject = GlobalDataContainer.getInstance() 57 .getData(modelname); 58 if (dataObject == null) { 41 59 Console.println("Model " + modelname + " not found in storage."); 42 } 43 else if( !(dataObject instanceof IStochasticProcess) ) { 60 } else if (!(dataObject instanceof IStochasticProcess)) { 44 61 Console.println("Object " + modelname + " not of type MarkovModel!"); 45 62 } else { … … 47 64 List<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>(); 48 65 try { 49 for( int i=0 ; i<numSessions ; i++ ) { 50 sequences.add((List<ReplayableEvent<?>>) model.randomSequence()); 66 for (int i = 0; i < numSessions; i++) { 67 sequences.add((List<ReplayableEvent<?>>) model 68 .randomSequence()); 51 69 } 52 70 } catch (ClassCastException e) { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomSequences.java
r121 r171 12 12 import de.ugoe.cs.util.console.Console; 13 13 14 /** 15 * <p>Command to generate random sessions.</p> 16 * @author Steffen Herbold 17 * @version 1.0 18 */ 14 19 public class CMDgenerateRandomSequences implements Command { 15 20 21 /* (non-Javadoc) 22 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 23 */ 16 24 @Override 17 25 public void run(List<Object> parameters) { … … 68 76 } 69 77 78 /* (non-Javadoc) 79 * @see de.ugoe.cs.util.console.Command#help() 80 */ 70 81 @Override 71 82 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateReplayfile.java
r98 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p>Command to create a replay file from stored sessions.</p> 15 * @author Steffen Herbold 16 * @version 1.0 17 */ 13 18 public class CMDgenerateReplayfile implements Command { 14 19 20 /* (non-Javadoc) 21 * @see de.ugoe.cs.util.console.Command#help() 22 */ 15 23 @Override 16 24 public void help() { … … 18 26 } 19 27 28 /* (non-Javadoc) 29 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 30 */ 20 31 @SuppressWarnings("unchecked") 21 32 @Override -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDlistSymbols.java
r130 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command to list all events (symbols) known to a usage profile (stochastic 15 * process). 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 12 21 public class CMDlistSymbols implements Command { 13 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 27 */ 14 28 @Override 15 29 public void run(List<Object> parameters) { … … 18 32 try { 19 33 modelname = (String) parameters.get(0); 20 if ( parameters.size()==2) {34 if (parameters.size() == 2) { 21 35 sort = Boolean.parseBoolean((String) parameters.get(1)); 22 36 } … … 24 38 throw new InvalidParameterException(); 25 39 } 26 27 IStochasticProcess model = null; 28 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 29 if( dataObject==null ) { 40 41 IStochasticProcess model = null; 42 Object dataObject = GlobalDataContainer.getInstance() 43 .getData(modelname); 44 if (dataObject == null) { 30 45 Console.println("Model " + modelname + "not found in storage."); 31 } 32 else if( !(dataObject instanceof IStochasticProcess) ) {33 Console.println("Object " + modelname+ " is not a stochastic process!");46 } else if (!(dataObject instanceof IStochasticProcess)) { 47 Console.println("Object " + modelname 48 + " is not a stochastic process!"); 34 49 } else { 35 50 model = (IStochasticProcess) dataObject; 36 51 String[] stateStrings = model.getSymbolStrings(); 37 if ( sort) {52 if (sort) { 38 53 Arrays.sort(stateStrings); 39 54 } 40 for ( String stateString : stateStrings) {55 for (String stateString : stateStrings) { 41 56 Console.println(stateString); 42 57 } … … 44 59 } 45 60 61 /* 62 * (non-Javadoc) 63 * 64 * @see de.ugoe.cs.util.console.Command#help() 65 */ 46 66 @Override 47 67 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDload.java
r89 r171 7 7 import java.util.List; 8 8 9 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 9 10 import de.ugoe.cs.util.console.Command; 10 11 import de.ugoe.cs.util.console.Console; 11 12 13 /** 14 * <p> 15 * Command that loads a previously serialized {@link GlobalDataContainer}. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 12 21 public class CMDload implements Command { 13 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 27 */ 14 28 @Override 15 29 public void run(List<Object> parameters) { … … 35 49 } 36 50 51 /* 52 * (non-Javadoc) 53 * 54 * @see de.ugoe.cs.util.console.Command#help() 55 */ 37 56 @Override 38 57 public void help() { 39 58 Console.println("Usage: loadObject <filename>"); 40 59 } 41 60 42 61 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDloadObject.java
r89 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to load a previously serialized object and store it in the 16 * {@link GlobalDataContainer}. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 13 22 public class CMDloadObject implements Command { 14 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 28 */ 15 29 @Override 16 30 public void run(List<Object> parameters) { … … 37 51 ex.printStackTrace(); 38 52 } 39 if ( GlobalDataContainer.getInstance().addData(objectName, data )) {53 if (GlobalDataContainer.getInstance().addData(objectName, data)) { 40 54 Console.traceln("Old data \"" + objectName + "\" overwritten"); 41 55 } 42 56 } 43 57 58 /* 59 * (non-Javadoc) 60 * 61 * @see de.ugoe.cs.util.console.Command#help() 62 */ 44 63 @Override 45 64 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDmodelSize.java
r131 r171 1 /**2 *3 */4 1 package de.ugoe.cs.eventbench.commands; 5 2 … … 13 10 14 11 /** 15 * @author sherbold 16 * 12 * <p> 13 * Command that prints the size of a stochastic process to the console. 14 * </p> 15 * 16 * @author Steffen Herbold 17 * @version 1.0 17 18 */ 18 19 public class CMDmodelSize implements Command { 19 20 20 /* (non-Javadoc) 21 /* 22 * (non-Javadoc) 23 * 21 24 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 22 25 */ … … 29 32 throw new InvalidParameterException(); 30 33 } 31 32 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 33 if( dataObject==null ) { 34 35 Object dataObject = GlobalDataContainer.getInstance() 36 .getData(modelname); 37 if (dataObject == null) { 34 38 Console.printerrln("No model with name " + modelname + "found"); 35 39 return; 36 40 } 37 if( !(dataObject instanceof IStochasticProcess) ) { 38 Console.printerrln("Object " + modelname + " not of type IStochasticProcess!"); 41 if (!(dataObject instanceof IStochasticProcess)) { 42 Console.printerrln("Object " + modelname 43 + " not of type IStochasticProcess!"); 39 44 return; 40 45 } 41 46 42 47 IStochasticProcess process = (IStochasticProcess) dataObject; 43 Console.println("#symbols: " + process.getNumSymbols() + " ; #FOMstates " + process.getNumFOMStates()); 48 Console.println("#symbols: " + process.getNumSymbols() 49 + " ; #FOMstates " + process.getNumFOMStates()); 44 50 } 45 51 46 /* (non-Javadoc) 52 /* 53 * (non-Javadoc) 54 * 47 55 * @see de.ugoe.cs.util.console.Command#help() 48 56 */ -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintDot.java
r26 r171 9 9 import de.ugoe.cs.util.console.Console; 10 10 11 /** 12 * <p> 13 * Command that prints a dot representation of a model (if supported) to the 14 * console. 15 * </p> 16 * 17 * @author Steffen Herbold 18 * @version 1.0 19 */ 11 20 public class CMDprintDot implements Command { 12 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see de.ugoe.cs.util.console.Command#help() 26 */ 13 27 @Override 14 28 public void help() { … … 16 30 } 17 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 36 */ 18 37 @Override 19 38 public void run(List<Object> parameters) { … … 24 43 throw new InvalidParameterException(); 25 44 } 26 27 IDotCompatible model = null; 28 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 29 if( dataObject==null ) { 45 46 IDotCompatible model = null; 47 Object dataObject = GlobalDataContainer.getInstance() 48 .getData(modelname); 49 if (dataObject == null) { 30 50 Console.println("Model " + modelname + "not found in storage."); 31 } 32 else if( !(dataObject instanceof IDotCompatible) ) {33 Console.println("Object " + modelname+ " does not implement IDotCompatible!");51 } else if (!(dataObject instanceof IDotCompatible)) { 52 Console.println("Object " + modelname 53 + " does not implement IDotCompatible!"); 34 54 } else { 35 55 model = (IDotCompatible) dataObject; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintRandomSession.java
r18 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command that prints a randomly generated sessions of events to the console. 15 * </p> 16 * 17 * @author Steffen Herbold 18 * @version 1.0 19 */ 12 20 public class CMDprintRandomSession implements Command { 13 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see de.ugoe.cs.util.console.Command#help() 26 */ 14 27 @Override 15 28 public void help() { … … 17 30 } 18 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 36 */ 19 37 @Override 20 38 public void run(List<Object> parameters) { … … 22 40 try { 23 41 modelname = (String) parameters.get(0); 24 } 25 catch (Exception e) { 42 } catch (Exception e) { 26 43 throw new InvalidParameterException(); 27 44 } 28 29 IStochasticProcess model = null; 30 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 31 if( dataObject==null ) { 45 46 IStochasticProcess model = null; 47 Object dataObject = GlobalDataContainer.getInstance() 48 .getData(modelname); 49 if (dataObject == null) { 32 50 Console.println("Model " + modelname + " not found in storage."); 33 } 34 else if( !(dataObject instanceof IStochasticProcess) ) { 51 } else if (!(dataObject instanceof IStochasticProcess)) { 35 52 Console.println("Object " + modelname + " not of type MarkovModel!"); 36 53 } else { 37 54 model = (IStochasticProcess) dataObject; 38 for ( Event<?> event : model.randomSequence()) {55 for (Event<?> event : model.randomSequence()) { 39 56 Console.println(event.toString()); 40 57 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDprintTrieDot.java
r31 r171 5 5 6 6 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 7 import de.ugoe.cs.eventbench.models.Trie; 7 8 import de.ugoe.cs.eventbench.models.TrieBasedModel; 8 9 import de.ugoe.cs.util.console.Command; 9 10 import de.ugoe.cs.util.console.Console; 10 11 12 /** 13 * <p> 14 * Command that prints the {@link Trie} of a {@link TrieBasedModel} as dot to 15 * the console. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 20 */ 11 21 public class CMDprintTrieDot implements Command { 12 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#help() 27 */ 13 28 @Override 14 29 public void help() { … … 16 31 } 17 32 33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 37 */ 18 38 @Override 19 39 public void run(List<Object> parameters) { … … 24 44 throw new InvalidParameterException(); 25 45 } 26 27 TrieBasedModel model = null; 28 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 29 if( dataObject==null ) { 46 47 TrieBasedModel model = null; 48 Object dataObject = GlobalDataContainer.getInstance() 49 .getData(modelname); 50 if (dataObject == null) { 30 51 Console.println("Model " + modelname + "not found in storage."); 31 } 32 else if( !(dataObject instanceof TrieBasedModel) ) { 52 } else if (!(dataObject instanceof TrieBasedModel)) { 33 53 Console.println("Object " + modelname + " is not a TrieBasedModel!"); 34 54 } else { … … 37 57 } 38 58 } 39 59 40 60 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsave.java
r88 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to save the {@link GlobalDataContainer} through serialization. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 13 21 public class CMDsave implements Command { 14 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 27 */ 15 28 @Override 16 29 public void run(List<Object> parameters) { … … 18 31 try { 19 32 filename = (String) parameters.get(0); 20 } 21 catch (Exception e) { 33 } catch (Exception e) { 22 34 throw new InvalidParameterException(); 23 35 } 24 25 36 26 37 FileOutputStream fos = null; 27 38 ObjectOutputStream out = null; … … 36 47 } 37 48 49 /* 50 * (non-Javadoc) 51 * 52 * @see de.ugoe.cs.util.console.Command#help() 53 */ 38 54 @Override 39 55 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsaveObject.java
r90 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command that saves an object contained in the {@link GlobalDataContainer} 16 * through serialization. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 21 */ 13 22 public class CMDsaveObject implements Command { 14 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 28 */ 15 29 @Override 16 30 public void run(List<Object> parameters) { … … 20 34 filename = (String) parameters.get(0); 21 35 objectName = (String) parameters.get(1); 22 } 23 catch (Exception e) { 36 } catch (Exception e) { 24 37 throw new InvalidParameterException(); 25 38 } 26 27 Object dataObject = GlobalDataContainer.getInstance().getData(objectName); 28 if( dataObject==null ) { 39 40 Object dataObject = GlobalDataContainer.getInstance().getData( 41 objectName); 42 if (dataObject == null) { 29 43 Console.println("Object " + objectName + " not found in storage."); 30 44 } 31 45 32 46 FileOutputStream fos = null; 33 47 ObjectOutputStream out = null; … … 42 56 } 43 57 58 /* 59 * (non-Javadoc) 60 * 61 * @see de.ugoe.cs.util.console.Command#help() 62 */ 44 63 @Override 45 64 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsequenceStatistics.java
r113 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to print basic statistical information about stored sequences, e.g., 16 * how many there are of which lenght. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 13 22 public class CMDsequenceStatistics implements Command { 14 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 28 */ 15 29 @SuppressWarnings("unchecked") 16 30 @Override 17 31 public void run(List<Object> parameters) { 18 32 String sequencesName = "sequences"; 19 if ( parameters.size()==1) {33 if (parameters.size() == 1) { 20 34 sequencesName = (String) parameters.get(0); 21 35 } 22 23 36 24 37 List<List<Event<?>>> sequences = null; 25 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 26 38 Object dataObject = GlobalDataContainer.getInstance().getData( 39 sequencesName); 40 27 41 try { 28 42 sequences = (List<List<Event<?>>>) dataObject; 29 43 Console.traceln("Number of Sequences: " + sequences.size()); 30 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>();31 for ( List<Event<?>> sequence : sequences) {44 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>(); 45 for (List<Event<?>> sequence : sequences) { 32 46 Integer currentSize = sequence.size(); 33 if ( lengthMap.containsKey(currentSize)) {34 lengthMap.put(currentSize, lengthMap.get(currentSize) +1);47 if (lengthMap.containsKey(currentSize)) { 48 lengthMap.put(currentSize, lengthMap.get(currentSize) + 1); 35 49 } else { 36 50 lengthMap.put(currentSize, 1); 37 51 } 38 52 } 39 for( Entry<Integer, Integer> entry : lengthMap.entrySet() ) { 40 Console.traceln("Of length " + entry.getKey() + ": " + entry.getValue()); 53 for (Entry<Integer, Integer> entry : lengthMap.entrySet()) { 54 Console.traceln("Of length " + entry.getKey() + ": " 55 + entry.getValue()); 41 56 } 42 43 } 44 catch(ClassCastException e) { 57 58 } catch (ClassCastException e) { 45 59 Console.println("Sequences not found"); 46 60 } 47 61 } 48 62 63 /* 64 * (non-Javadoc) 65 * 66 * @see de.ugoe.cs.util.console.Command#help() 67 */ 49 68 @Override 50 69 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowMarkovModel.java
r18 r171 23 23 import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position; 24 24 25 /** 26 * <p> 27 * Command that visualizes first-order Markov models. 28 * </p> 29 * 30 * @author Steffen Herbold 31 * @version 1.0 32 */ 25 33 public class CMDshowMarkovModel implements Command { 26 34 35 /* 36 * (non-Javadoc) 37 * 38 * @see de.ugoe.cs.util.console.Command#help() 39 */ 27 40 @Override 28 41 public void help() { … … 30 43 } 31 44 45 /* 46 * (non-Javadoc) 47 * 48 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 49 */ 32 50 @Override 33 51 public void run(List<Object> parameters) { … … 36 54 try { 37 55 modelname = (String) parameters.get(0); 38 if( parameters.size()==2 ) { 39 showNodeNames = Boolean.parseBoolean((String) parameters.get(1)); 56 if (parameters.size() == 2) { 57 showNodeNames = Boolean 58 .parseBoolean((String) parameters.get(1)); 40 59 } 41 60 } catch (Exception e) { 42 61 throw new InvalidParameterException(); 43 62 } 44 45 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 46 if( dataObject==null ) { 63 64 Object dataObject = GlobalDataContainer.getInstance() 65 .getData(modelname); 66 if (dataObject == null) { 47 67 Console.printerrln("No model with name " + modelname + "found"); 48 68 } else { 49 69 FirstOrderMarkovModel mm = (FirstOrderMarkovModel) dataObject; 50 70 51 71 Graph<String, MarkovEdge> graph = mm.getGraph(); 52 Layout<String, MarkovEdge> layout = new ISOMLayout<String, MarkovEdge>(graph); 53 layout.setSize(new Dimension(1000,800)); // sets the initial size of the space 54 // The BasicVisualizationServer<V,E> is parameterized by the edge types 55 BasicVisualizationServer<String,MarkovEdge> vv = 56 new BasicVisualizationServer<String,MarkovEdge>(layout); 57 vv.setPreferredSize(new Dimension(1100,850)); //Sets the viewing area size 72 Layout<String, MarkovEdge> layout = new ISOMLayout<String, MarkovEdge>( 73 graph); 74 layout.setSize(new Dimension(1000, 800)); // sets the initial size 75 // of the space 76 // The BasicVisualizationServer<V,E> is parameterized by the edge 77 // types 78 BasicVisualizationServer<String, MarkovEdge> vv = new BasicVisualizationServer<String, MarkovEdge>( 79 layout); 80 vv.setPreferredSize(new Dimension(1100, 850)); // Sets the viewing 81 // area size 58 82 59 if ( showNodeNames) {83 if (showNodeNames) { 60 84 final Rectangle rect = new Rectangle(240, 20); 61 62 Transformer<String, Shape> vertexShapeTransformer = 63 new Transformer<String, Shape>() { 64 public Shape transform(String s) { 65 return rect; 66 } 85 86 Transformer<String, Shape> vertexShapeTransformer = new Transformer<String, Shape>() { 87 public Shape transform(String s) { 88 return rect; 89 } 67 90 }; 68 vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); 69 vv.getRenderContext().setVertexShapeTransformer(vertexShapeTransformer); 70 vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); 91 vv.getRenderer().getVertexLabelRenderer() 92 .setPosition(Position.CNTR); 93 vv.getRenderContext().setVertexShapeTransformer( 94 vertexShapeTransformer); 95 vv.getRenderContext().setVertexLabelTransformer( 96 new ToStringLabeller<String>()); 71 97 } 72 73 vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<MarkovEdge>()); 74 98 99 vv.getRenderContext().setEdgeLabelTransformer( 100 new ToStringLabeller<MarkovEdge>()); 101 75 102 JFrame frame = new JFrame("Markov Model"); 76 103 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDshowTrie.java
r24 r171 12 12 13 13 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 14 import de.ugoe.cs.eventbench.models.Trie; 14 15 import de.ugoe.cs.eventbench.models.Trie.Edge; 15 16 import de.ugoe.cs.eventbench.models.Trie.TrieVertex; … … 24 25 import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position; 25 26 27 /** 28 * <p> 29 * Command that visualizes the {@link Trie} of a {@link TrieBasedModel}. 30 * </p> 31 * 32 * @author Steffen Herbold 33 * @version 1.0 34 */ 26 35 public class CMDshowTrie implements Command { 27 36 37 /* 38 * (non-Javadoc) 39 * 40 * @see de.ugoe.cs.util.console.Command#help() 41 */ 28 42 @Override 29 43 public void help() { 30 44 Console.println("Usage: showTrie <modelName>"); 31 45 } 32 46 47 /* 48 * (non-Javadoc) 49 * 50 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 51 */ 33 52 @Override 34 53 public void run(List<Object> parameters) { … … 39 58 throw new InvalidParameterException(); 40 59 } 41 42 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 43 if( dataObject==null ) { 60 61 Object dataObject = GlobalDataContainer.getInstance() 62 .getData(modelname); 63 if (dataObject == null) { 44 64 Console.printerrln("No model with name " + modelname + "found"); 45 65 } else { 46 66 TrieBasedModel model = (TrieBasedModel) dataObject; 47 67 Tree<TrieVertex, Edge> graph = model.getTrieGraph(); 48 Layout<TrieVertex, Edge> layout = new TreeLayout<TrieVertex, Edge>(graph, 60); 49 // The BasicVisualizationServer<V,E> is parameterized by the edge types 50 BasicVisualizationServer<TrieVertex,Edge> vv = 51 new BasicVisualizationServer<TrieVertex,Edge>(layout); 52 vv.setPreferredSize(new Dimension(1100,850)); //Sets the viewing area size 53 54 68 Layout<TrieVertex, Edge> layout = new TreeLayout<TrieVertex, Edge>( 69 graph, 60); 70 // The BasicVisualizationServer<V,E> is parameterized by the edge 71 // types 72 BasicVisualizationServer<TrieVertex, Edge> vv = new BasicVisualizationServer<TrieVertex, Edge>( 73 layout); 74 vv.setPreferredSize(new Dimension(1100, 850)); // Sets the viewing 75 // area size 76 55 77 final Rectangle rect = new Rectangle(40, 20); 56 57 Transformer<TrieVertex, Shape> vertexShapeTransformer = 58 new Transformer<TrieVertex, Shape>() { 59 public Shape transform(TrieVertex s) { 60 return rect; 61 } 78 79 Transformer<TrieVertex, Shape> vertexShapeTransformer = new Transformer<TrieVertex, Shape>() { 80 public Shape transform(TrieVertex s) { 81 return rect; 82 } 62 83 }; 63 vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); 64 vv.getRenderContext().setVertexShapeTransformer(vertexShapeTransformer); 65 vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<TrieVertex>()); 66 84 vv.getRenderer().getVertexLabelRenderer() 85 .setPosition(Position.CNTR); 86 vv.getRenderContext().setVertexShapeTransformer( 87 vertexShapeTransformer); 88 vv.getRenderContext().setVertexLabelTransformer( 89 new ToStringLabeller<TrieVertex>()); 90 67 91 JFrame frame = new JFrame("Trie"); 68 92 frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); … … 73 97 } 74 98 75 76 77 99 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainDFA.java
r96 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command to train a Deterministic Finite Automaton (DFA). 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 13 21 public class CMDtrainDFA implements Command { 14 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#help() 27 */ 15 28 @Override 16 29 public void help() { … … 18 31 } 19 32 33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 37 */ 20 38 @SuppressWarnings("unchecked") 21 39 @Override … … 27 45 throw new InvalidParameterException(); 28 46 } 29 47 30 48 List<List<Event<?>>> sequences = null; 31 Object dataObject = GlobalDataContainer.getInstance().getData("sequences"); 32 49 Object dataObject = GlobalDataContainer.getInstance().getData( 50 "sequences"); 51 33 52 try { 34 53 sequences = (List<List<Event<?>>>) dataObject; 35 if( sequences.size()>0 ) { 36 if( sequences.get(0).get(0) instanceof Event ) { 37 DeterministicFiniteAutomaton model = new DeterministicFiniteAutomaton(new Random()); 54 if (sequences.size() > 0) { 55 if (sequences.get(0).get(0) instanceof Event) { 56 DeterministicFiniteAutomaton model = new DeterministicFiniteAutomaton( 57 new Random()); 38 58 model.train(sequences); 39 if( GlobalDataContainer.getInstance().addData(modelname, model) ) { 40 Console.traceln("Old data \"" + modelname + "\" overwritten"); 59 if (GlobalDataContainer.getInstance().addData(modelname, 60 model)) { 61 Console.traceln("Old data \"" + modelname 62 + "\" overwritten"); 41 63 } 42 64 } else { … … 45 67 } 46 68 } 47 } 48 catch(ClassCastException e) { 69 } catch (ClassCastException e) { 49 70 Console.println("Sequences need to be loaded first using parseXML"); 50 71 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainMarkovModel.java
r116 r171 1 1 package de.ugoe.cs.eventbench.commands; 2 3 2 4 3 import java.security.InvalidParameterException; … … 13 12 import de.ugoe.cs.util.console.Console; 14 13 14 /** 15 * <p> 16 * Command to train first-order and high-order Markov models. 17 * </p> 18 * 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 15 22 public class CMDtrainMarkovModel implements Command { 16 23 24 /* 25 * (non-Javadoc) 26 * 27 * @see de.ugoe.cs.util.console.Command#help() 28 */ 17 29 @Override 18 30 public void help() { … … 20 32 } 21 33 34 /* 35 * (non-Javadoc) 36 * 37 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 38 */ 22 39 @SuppressWarnings("unchecked") 23 40 @Override … … 27 44 try { 28 45 modelname = (String) parameters.get(0); 29 if ( parameters.size()==2) {46 if (parameters.size() == 2) { 30 47 order = Integer.parseInt((String) parameters.get(1)); 31 48 } … … 33 50 throw new InvalidParameterException(); 34 51 } 35 52 36 53 List<List<Event<?>>> sequences = null; 37 Object dataObject = GlobalDataContainer.getInstance().getData("sequences"); 38 54 Object dataObject = GlobalDataContainer.getInstance().getData( 55 "sequences"); 56 39 57 try { 40 58 sequences = (List<List<Event<?>>>) dataObject; 41 if ( sequences.size()>0) {42 if ( sequences.get(0).get(0) instanceof Event) {59 if (sequences.size() > 0) { 60 if (sequences.get(0).get(0) instanceof Event) { 43 61 HighOrderMarkovModel model; 44 if ( order==1) {62 if (order == 1) { 45 63 model = new FirstOrderMarkovModel(new Random()); 46 64 } else { … … 48 66 } 49 67 model.train(sequences); 50 if( GlobalDataContainer.getInstance().addData(modelname, model) ) { 51 Console.traceln("Old data \"" + modelname + "\" overwritten"); 68 if (GlobalDataContainer.getInstance().addData(modelname, 69 model)) { 70 Console.traceln("Old data \"" + modelname 71 + "\" overwritten"); 52 72 } 53 73 } else { … … 56 76 } 57 77 } 58 } 59 catch(ClassCastException e) { 78 } catch (ClassCastException e) { 60 79 Console.println("Sequences need to be loaded first using parseXML"); 61 80 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDtrainPPM.java
r116 r171 11 11 import de.ugoe.cs.util.console.Console; 12 12 13 /** 14 * <p> 15 * Command that trains Prediction by Partial Match (PPM) models. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 13 21 public class CMDtrainPPM implements Command { 14 22 23 /* 24 * (non-Javadoc) 25 * 26 * @see de.ugoe.cs.util.console.Command#help() 27 */ 15 28 @Override 16 29 public void help() { … … 18 31 } 19 32 33 /* 34 * (non-Javadoc) 35 * 36 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 37 */ 20 38 @SuppressWarnings("unchecked") 21 39 @Override … … 29 47 probEscape = Double.parseDouble((String) parameters.get(1)); 30 48 maxOrder = Integer.parseInt((String) parameters.get(2)); 31 if ( parameters.size()==4) {49 if (parameters.size() == 4) { 32 50 minOrder = Integer.parseInt((String) parameters.get(3)); 33 51 } … … 35 53 throw new InvalidParameterException(); 36 54 } 37 55 38 56 List<List<Event<?>>> sequences = null; 39 Object dataObject = GlobalDataContainer.getInstance().getData("sequences"); 40 57 Object dataObject = GlobalDataContainer.getInstance().getData( 58 "sequences"); 59 41 60 try { 42 61 sequences = (List<List<Event<?>>>) dataObject; 43 if( sequences.size()>0 ) { 44 if( sequences.get(0).get(0) instanceof Event ) { 45 PredictionByPartialMatch model = new PredictionByPartialMatch(maxOrder, minOrder, new Random(), probEscape); 62 if (sequences.size() > 0) { 63 if (sequences.get(0).get(0) instanceof Event) { 64 PredictionByPartialMatch model = new PredictionByPartialMatch( 65 maxOrder, minOrder, new Random(), probEscape); 46 66 model.train(sequences); 47 if( GlobalDataContainer.getInstance().addData(modelname, model) ) { 48 Console.traceln("Old data \"" + modelname + "\" overwritten"); 49 } 67 if (GlobalDataContainer.getInstance().addData(modelname, 68 model)) { 69 Console.traceln("Old data \"" + modelname 70 + "\" overwritten"); 71 } 50 72 } else { 51 73 Console.traceln("Illegal use of \"sequences\" parameter in the GlobalDataContainer."); … … 53 75 } 54 76 } 55 } 56 catch(ClassCastException e) { 77 } catch (ClassCastException e) { 57 78 Console.println("Sequences need to be loaded first using parseXML"); 58 79 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/data/GlobalDataContainer.java
r88 r171 8 8 import java.util.Map; 9 9 10 /** 11 * <p> 12 * This data structure can be used by the commands to store any {@link Object}. 13 * The data is stored in a key-value map, with strings as keys. 14 * </p> 15 * <p> 16 * This class is implemented as a singleton, as more than one data container 17 * does not serves no purpose. 18 * </p> 19 * 20 * @author Steffen Herbold 21 * @version 1.0 22 */ 10 23 public class GlobalDataContainer implements Serializable { 11 24 12 25 /** 26 * <p> 13 27 * Id for object serialization. 28 * </p> 14 29 */ 15 30 private static final long serialVersionUID = 1L; 16 31 32 /** 33 * <p> 34 * Instance of the {@link GlobalDataContainer} (implemented as singleton). 35 * </p> 36 */ 17 37 transient private static GlobalDataContainer theInstance = null; 18 38 39 /** 40 * <p> 41 * Internal storage of the data. 42 * </p> 43 */ 19 44 private Map<String, Object> dataObjects; 20 45 46 /** 47 * <p> 48 * Returns the instance of the container. If it does not yet exist, the data 49 * container is created. 50 * </p> 51 * 52 * @return instance of the container 53 */ 21 54 public static GlobalDataContainer getInstance() { 22 if ( theInstance==null) {55 if (theInstance == null) { 23 56 theInstance = new GlobalDataContainer(); 24 57 } 25 58 return theInstance; 26 59 } 27 60 61 /** 62 * <p> 63 * Manual serialization of the object. Necessary to guarantee the singleton 64 * property. 65 * </p> 66 * 67 * @param s 68 * output stream for the serialization 69 * @throws IOException 70 * thrown if there is problem writing to the output stream 71 */ 28 72 private void writeObject(ObjectOutputStream s) throws IOException { 29 73 s.defaultWriteObject(); 30 74 s.writeObject(dataObjects); 31 75 } 32 76 77 /** 78 * <p> 79 * Manual de-serialization of the object. Necessary to guarantee the 80 * singleton property. 81 * 82 * @param s 83 * input stream for the de-serialization 84 * @throws IOException 85 * thrown if there is problem reading from the input stream 86 * @throws ClassNotFoundException 87 * thrown if there is a problem reading from the input stream 88 */ 33 89 @SuppressWarnings("unchecked") 34 private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { 90 private void readObject(ObjectInputStream s) throws IOException, 91 ClassNotFoundException { 35 92 s.defaultReadObject(); 36 if ( theInstance==null) {93 if (theInstance == null) { 37 94 theInstance = new GlobalDataContainer(); 38 95 } 39 96 theInstance.dataObjects = (Map<String, Object>) s.readObject(); 40 97 } 41 98 99 /** 100 * <p> 101 * Manual de-serialization to guarantee the singleton property. 102 * </p> 103 * 104 * @return instance of the container 105 */ 42 106 private Object readResolve() { 43 107 return theInstance; 44 108 } 45 109 110 /** 111 * <p> 112 * Constructor. Creates a new GlobalDataContainer. Private to guarantee the 113 * singleton property. 114 * </p> 115 */ 46 116 private GlobalDataContainer() { 47 117 dataObjects = new HashMap<String, Object>(); 48 118 } 49 119 120 /** 121 * <p> 122 * Adds data to the container. 123 * </p> 124 * 125 * @param key 126 * key that identifies the data 127 * @param data 128 * data that is stored 129 * @return true, if an old entry was overwritten; false otherwise 130 */ 50 131 public boolean addData(String key, Object data) { 51 132 Object previousEntry = dataObjects.put(key, data); 52 return previousEntry !=null;133 return previousEntry != null; 53 134 } 54 135 136 /** 137 * <p> 138 * Removes data from the container. 139 * </p> 140 * 141 * @param key 142 * key of the data to be removed 143 * @return true, if the object was removed; false if it was not present 144 */ 55 145 public boolean removeData(String key) { 56 146 Object previousEntry = dataObjects.remove(key); 57 return previousEntry ==null;147 return previousEntry != null; 58 148 } 59 149 150 /** 151 * <p> 152 * Returns the data associated with a key or {@code null} if no data is 153 * stored for the key. 154 * </p> 155 * 156 * @param key 157 * key whose data is returned 158 * @return data associated with the key; {@code null} if no data is 159 * available 160 */ 60 161 public Object getData(String key) { 61 162 return dataObjects.get(key); 62 163 } 63 164 165 /** 166 * <p> 167 * Resets the data container, i.e., deletes all its contents. 168 * </p> 169 */ 64 170 public void reset() { 65 171 dataObjects = new HashMap<String, Object>(); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/web/WeblogParser.java
r111 r171 17 17 import de.ugoe.cs.util.console.Console; 18 18 19 /** 20 * <p> 21 * Provides functionality to parse log files with web request. 22 * </p> 23 * 24 * @author Steffen Herbold 25 * @version 1.0 26 */ 19 27 public class WeblogParser { 20 28 29 /** 30 * <p> 31 * Timeout between two sessions in milliseconds. 32 * </p> 33 */ 21 34 private long timeout; 22 35 36 /** 37 * <p> 38 * Minimal length of a session. All shorter sessions will be pruned. 39 * Default: 2 40 * </p> 41 */ 23 42 private int minLength = 2; 24 43 44 /** 45 * <p> 46 * Collection of generated sequences. 47 * </p> 48 */ 25 49 private List<List<WebEvent>> sequences; 26 50 51 /** 52 * <p> 53 * Name and path of the robot filter. 54 * </p> 55 */ 27 56 private static final String ROBOTFILTERFILE = "misc/robotfilter.txt"; 28 29 private String robotRegex = ".*"; 30 57 58 /** 59 * <p> 60 * Field that contains a regular expression that matches all robots 61 * contained in {@link #ROBOTFILTERFILE}. 62 * </p> 63 */ 64 private String robotRegex = null; 65 66 /** 67 * <p> 68 * Constructor. Creates a new WeblogParser with a default timeout of 69 * 3,600,000 milliseconds (1 hour). 70 * </p> 71 */ 31 72 public WeblogParser() { 32 timeout = 3600000; // 1 hour session-timeout as default 33 } 34 73 this(3600000); 74 } 75 76 /** 77 * <p> 78 * Constructor. Creates a new WeblogParser. 79 * </p> 80 * 81 * @param timeout 82 * session timeout 83 */ 35 84 public WeblogParser(long timeout) { 36 85 this.timeout = timeout; 37 86 } 38 87 88 /** 89 * <p> 90 * Returns the generated event sequences. 91 * </p> 92 * 93 * @return generated event sequences 94 */ 39 95 public List<List<WebEvent>> getSequences() { 40 return sequences; 41 } 42 96 return sequences; 97 } 98 99 /** 100 * <p> 101 * Sets the session timeout. 102 * </p> 103 * 104 * @param timeout 105 * new session timeout 106 */ 43 107 public void setTimeout(long timeout) { 44 108 this.timeout = timeout; 45 109 } 46 110 111 /** 112 * <p> 113 * Sets the minimal length of a session. All sessions that contain less 114 * events will be pruned. 115 * </p> 116 * 117 * @param minLength 118 * new minimal length 119 */ 47 120 public void setMinLength(int minLength) { 48 121 this.minLength = minLength; 49 122 } 50 51 public void parseFile(String filename) throws IOException, FileNotFoundException, ParseException, URISyntaxException { 123 124 /** 125 * <p> 126 * Parses a web log file. 127 * </p> 128 * 129 * @param filename 130 * name and path of the log file 131 * @throws IOException 132 * thrown if there is a problem with reading the log file 133 * @throws FileNotFoundException 134 * thrown if the log file is not found 135 * @throws ParseException 136 * thrown the date format is invalid 137 * @throws URISyntaxException 138 * thrown if the URI is invalid 139 */ 140 public void parseFile(String filename) throws IOException, 141 FileNotFoundException, ParseException, URISyntaxException { 52 142 String[] lines = FileTools.getLinesFromFile(filename); 53 143 54 144 Map<String, List<Integer>> cookieSessionMap = new HashMap<String, List<Integer>>(); 55 145 int lastId = -1; 56 57 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 146 147 SimpleDateFormat dateFormat = new SimpleDateFormat( 148 "yyyy-MM-dd HH:mm:ss"); 58 149 loadRobotRegex(); 59 150 60 151 sequences = new ArrayList<List<WebEvent>>(); 61 62 for( String line : lines ) { 63 String[] values = line.substring(1, line.length()-1).split("\" \""); 64 152 153 for (String line : lines) { 154 String[] values = line.substring(1, line.length() - 1).split( 155 "\" \""); 156 65 157 // use cookie as session identifier 66 158 int cookieStart = values[0].lastIndexOf('.'); 67 String cookie = values[0].substring(cookieStart +1);159 String cookie = values[0].substring(cookieStart + 1); 68 160 String dateString = values[1]; 69 161 long timestamp = dateFormat.parse(dateString).getTime(); … … 71 163 // String ref = values[3]; // referer is not yet used! 72 164 String agent; 73 if ( values.length>4) {165 if (values.length > 4) { 74 166 agent = values[4]; 75 167 } else { 76 168 agent = "noagent"; 77 169 } 78 170 79 171 List<String> postedVars = new ArrayList<String>(); 80 if ( values.length==6) { // post vars found81 for ( String postVar : values[5].trim().split(" ")) {172 if (values.length == 6) { // post vars found 173 for (String postVar : values[5].trim().split(" ")) { 82 174 postedVars.add(postVar); 83 175 } 84 176 } 85 if ( !isRobot(agent)) {177 if (!isRobot(agent)) { 86 178 URI uri = new URI(uriString); 87 88 String path = uri.getPath(); 179 180 String path = uri.getPath(); 89 181 List<String> getVars = extractGetVarsFromUri(uri); 90 91 WebEvent event = new WebEvent(path, timestamp, postedVars, getVars); 92 182 183 WebEvent event = new WebEvent(path, timestamp, postedVars, 184 getVars); 185 93 186 // find session and add event 94 187 List<Integer> sessionIds = cookieSessionMap.get(cookie); 95 if ( sessionIds==null) {188 if (sessionIds == null) { 96 189 sessionIds = new ArrayList<Integer>(); 97 190 // start new session … … 99 192 cookieSessionMap.put(cookie, sessionIds); 100 193 sequences.add(new LinkedList<WebEvent>()); 101 } 102 Integer lastSessionIndex = sessionIds.get(sessionIds.size()-1); 194 } 195 Integer lastSessionIndex = sessionIds 196 .get(sessionIds.size() - 1); 103 197 List<WebEvent> lastSession = sequences.get(lastSessionIndex); 104 198 long lastEventTime = timestamp; 105 if( !lastSession.isEmpty() ) { 106 lastEventTime = lastSession.get(lastSession.size()-1).getTimestamp(); 107 } 108 if( timestamp-lastEventTime>timeout ) { 199 if (!lastSession.isEmpty()) { 200 lastEventTime = lastSession.get(lastSession.size() - 1) 201 .getTimestamp(); 202 } 203 if (timestamp - lastEventTime > timeout) { 109 204 sessionIds.add(++lastId); 110 205 List<WebEvent> newSession = new LinkedList<WebEvent>(); … … 119 214 } 120 215 216 /** 217 * <p> 218 * Prunes sequences shorter than {@link #minLength}. 219 * </p> 220 */ 121 221 private void pruneShortSequences() { 122 Console.traceln("" +sequences.size()+ " user sequences found");222 Console.traceln("" + sequences.size() + " user sequences found"); 123 223 // prune sequences shorter than min-length 124 int i =0;125 while ( i<sequences.size()) {126 if ( sequences.get(i).size()<minLength) {224 int i = 0; 225 while (i < sequences.size()) { 226 if (sequences.get(i).size() < minLength) { 127 227 sequences.remove(i); 128 228 } else { … … 130 230 } 131 231 } 132 Console.traceln(""+sequences.size()+ " remaining after pruning of sequences shorter than " + minLength); 133 } 134 232 Console.traceln("" + sequences.size() 233 + " remaining after pruning of sequences shorter than " 234 + minLength); 235 } 236 237 /** 238 * <p> 239 * Reads {@link #ROBOTFILTERFILE} and creates a regular expression that 240 * matches all the robots defined in the file. The regular expression is 241 * stored in the field {@link #robotRegex}. 242 * </p> 243 * 244 * @throws IOException 245 * thrown if there is a problem reading the robot filter 246 * @throws FileNotFoundException 247 * thrown if the robot filter is not found 248 */ 135 249 private void loadRobotRegex() throws IOException, FileNotFoundException { 136 250 String[] lines = FileTools.getLinesFromFile(ROBOTFILTERFILE); 137 251 StringBuilder regex = new StringBuilder(); 138 for ( int i=0; i<lines.length; i++) {139 regex.append("(.*" +lines[i]+".*)");140 if ( i!=lines.length-1) {252 for (int i = 0; i < lines.length; i++) { 253 regex.append("(.*" + lines[i] + ".*)"); 254 if (i != lines.length - 1) { 141 255 regex.append("|"); 142 256 } … … 144 258 robotRegex = regex.toString(); 145 259 } 146 260 261 /** 262 * <p> 263 * Checks whether an agent is a robot. 264 * </p> 265 * 266 * @param agent 267 * agent that is checked 268 * @return true, if the agent is a robot; false otherwise 269 */ 147 270 private boolean isRobot(String agent) { 148 271 return agent.matches(robotRegex); 149 272 } 150 273 274 /** 275 * <p> 276 * Parses the URI and extracts the GET variables that have been passed. 277 * </p> 278 * 279 * @param uri 280 * URI that is parsed 281 * @return a list with all GET variables 282 */ 151 283 private List<String> extractGetVarsFromUri(URI uri) { 152 284 List<String> getVars = new ArrayList<String>(); 153 285 String query = uri.getQuery(); 154 if ( query!=null) {286 if (query != null) { 155 287 String[] paramPairs = query.split("&"); 156 for ( String paramPair : paramPairs) {288 for (String paramPair : paramPairs) { 157 289 String[] paramSplit = paramPair.split("="); 158 290 getVars.add(paramSplit[0]); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/web/commands/CMDloadSessionsFromClickstream.java
r111 r171 13 13 import de.ugoe.cs.util.console.Console; 14 14 15 /** 16 * <p> 17 * Command to load sessions from a web log. 18 * </p> 19 * @author Steffen Herbold 20 * @version 1.0 21 */ 15 22 public class CMDloadSessionsFromClickstream implements Command { 16 23 24 /* (non-Javadoc) 25 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 26 */ 17 27 @Override 18 28 public void run(List<Object> parameters) { … … 52 62 } 53 63 64 /* (non-Javadoc) 65 * @see de.ugoe.cs.util.console.Command#help() 66 */ 54 67 @Override 55 68 public void help() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/web/data/WebEvent.java
r111 r171 5 5 import de.ugoe.cs.eventbench.data.ReplayableEvent; 6 6 7 /** 8 * <p> 9 * This class defines web events (of PHP-based web applications). 10 * </p> 11 * 12 * @author Steffen Herbold 13 * @version 1.0 14 * 15 */ 7 16 public class WebEvent extends ReplayableEvent<WebRequest> { 8 17 … … 13 22 */ 14 23 private static final long serialVersionUID = 1L; 15 24 25 /** 26 * Timestamp of the event. 27 */ 16 28 private final long timestamp; 17 18 19 private final static String makeType(String path, List<String> postVars, List<String> getVars) { 29 30 /** 31 * <p> 32 * Helper method that generates the type of the event based on the of the 33 * URI, the POST variables, and the GET variables. 34 * </p> 35 * 36 * @param path 37 * path of the URI of the event 38 * @param postVars 39 * POST variables send with the event 40 * @param getVars 41 * GET variables send with the event 42 * @return type of the event 43 */ 44 private final static String makeType(String path, List<String> postVars, 45 List<String> getVars) { 20 46 String type = path; 21 if ( getVars!=null && !getVars.isEmpty()) {22 type += "+GET" +getVars.toString().replace(" ", "");47 if (getVars != null && !getVars.isEmpty()) { 48 type += "+GET" + getVars.toString().replace(" ", ""); 23 49 } 24 if ( postVars!=null && !postVars.isEmpty()) {25 type += "+POST" +postVars.toString().replace(" ", "");50 if (postVars != null && !postVars.isEmpty()) { 51 type += "+POST" + postVars.toString().replace(" ", ""); 26 52 } 27 53 return type; 28 54 } 29 30 public WebEvent(String path, long timestamp, List<String> postVars, List<String> getVars) { 55 56 /** 57 * <p> 58 * Constructor. Creates a new WebEvent. 59 * </p> 60 * 61 * @param path 62 * path of the URI 63 * @param timestamp 64 * timestamp of when the event took place 65 * @param postVars 66 * POST variables send with the event 67 * @param getVars 68 * GET variables send with the event 69 */ 70 public WebEvent(String path, long timestamp, List<String> postVars, 71 List<String> getVars) { 31 72 super(makeType(path, postVars, getVars)); 32 73 this.timestamp = timestamp; 33 74 addReplayEvent(new WebRequest(path, postVars, getVars)); 34 75 } 35 76 77 /** 78 * <p> 79 * Returns the timestamp of the event. 80 * </p> 81 * 82 * @return timestamp of th event 83 */ 36 84 public long getTimestamp() { 37 85 return timestamp; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/web/data/WebRequest.java
r111 r171 6 6 import de.ugoe.cs.eventbench.data.IReplayable; 7 7 8 /** 9 * <p> 10 * Contains all information related to a web request, i.e., the path, the POST 11 * variables and the GET variables. 12 * </p> 13 * 14 * @author Steffen Herbold 15 * @version 1.0 16 */ 8 17 public class WebRequest implements IReplayable { 9 18 10 19 /** 20 * <p> 11 21 * Id for object serialization. 22 * </p> 12 23 */ 13 24 private static final long serialVersionUID = 1L; 14 25 26 /** 27 * <p> 28 * POST variables of the web request. 29 * </p> 30 */ 15 31 List<String> postVars; 32 33 /** 34 * <p> 35 * GET variables of the web request. 36 * </p> 37 */ 16 38 List<String> getVars; 17 39 40 /** 41 * <p> 42 * URI of the web request. 43 * </p> 44 */ 18 45 String targetUri; 19 46 47 /** 48 * <p> 49 * Constructor. Creates a new WebRequest. 50 * </p> 51 * 52 * @param uri 53 * URI of the request 54 * @param postVars 55 * POST variables of the request 56 * @param getVars 57 * GET variables of the request 58 */ 20 59 public WebRequest(String uri, List<String> postVars, List<String> getVars) { 21 60 targetUri = uri; … … 23 62 this.getVars = new ArrayList<String>(getVars); 24 63 } 25 64 65 /* 66 * (non-Javadoc) 67 * 68 * @see de.ugoe.cs.eventbench.data.IReplayable#getReplay() 69 */ 26 70 @Override 27 71 public String getReplay() { … … 30 74 } 31 75 76 /* 77 * (non-Javadoc) 78 * 79 * @see de.ugoe.cs.eventbench.data.IReplayable#getTarget() 80 */ 32 81 @Override 33 82 public String getTarget() { … … 35 84 return null; 36 85 } 37 86 87 /** 88 * <p> 89 * Two {@link WebRequest}s are equal, if their {@link #targetUri}, 90 * {@link #postVars}, and {@link #getVars} are equal. 91 * </p> 92 * 93 * @see java.lang.Object#equals(java.lang.Object) 94 */ 38 95 @Override 39 96 public boolean equals(Object other) { 40 if ( this==other) {97 if (this == other) { 41 98 return true; 42 99 } 43 if( other instanceof WebRequest ) { 44 return targetUri.equals(((WebRequest) other).targetUri) && postVars.equals(((WebRequest) other).postVars); 100 if (other instanceof WebRequest) { 101 return targetUri.equals(((WebRequest) other).targetUri) 102 && postVars.equals(((WebRequest) other).postVars) 103 && getVars.equals(((WebRequest) other).getVars); 45 104 } 46 105 return false; 47 106 } 48 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see java.lang.Object#hashCode() 112 */ 49 113 @Override 50 114 public int hashCode() { … … 54 118 hash = multiplier * hash + targetUri.hashCode(); 55 119 hash = multiplier * hash + postVars.hashCode(); 120 hash = multiplier * hash + getVars.hashCode(); 56 121 57 122 return hash; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/EventGenerator.java
r141 r171 17 17 import org.jdom.input.SAXBuilder; 18 18 19 import de.ugoe.cs.eventbench.data.Event; 19 20 import de.ugoe.cs.eventbench.windows.data.WindowTree; 20 21 import de.ugoe.cs.eventbench.windows.data.WindowTreeNode; … … 24 25 /** 25 26 * <p> 26 * Translates sequences of windows messages into events that can be used by the27 * Logalyzer core libraries for usage analysis.27 * Translates sequences of windows messages into {@link WindowsEvent}s that can 28 * be used by the EventBench core libraries. 28 29 * </p> 29 30 * 30 31 * @author Steffen Herbold 31 * 32 * @version 1.0 32 33 */ 33 34 public class EventGenerator { … … 214 215 } 215 216 216 private boolean createSequenceLParam( 217 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, 218 int constMsgType, Element termElement) 219 throws NoSuchElementException { 220 Iterator<WindowsMessage> seqIterator = generatedMessageSeq.iterator(); 221 if (termElement.getName().equals("seqValue")) { 222 String obj = termElement.getAttributeValue("seqObj"); 223 List<WindowsMessage> seqVar = getStoredSeqVariable(obj); 224 if (msgsGenerated && seqVar.size() != generatedMessageSeq.size()) { 225 throw new InvalidParameterException( 226 "Failure generating replay sequence for rule " 227 + currentRuleName 228 + ": One or more of the sequence variables used to generate a sequence have different lenghts."); 229 } 230 for (WindowsMessage msg : seqVar) { 231 WindowsMessage currentSeqMsg = getCurrentSeqMsg( 232 generatedMessageSeq, msgsGenerated, constMsgType, 233 seqIterator); 234 String paramValueStr = msg.getParameter(termElement 235 .getAttributeValue("param")); 236 int paramValue = 0; 237 try { 238 paramValue = Integer.parseInt(paramValueStr); 239 currentSeqMsg.setLPARAM(paramValue); 240 } catch (NumberFormatException e) { 241 currentSeqMsg.setLPARAMasWindowDesc(paramValueStr); 242 } 243 } 244 if (seqIterator.hasNext()) { 245 // the first seq-var has a different number of elements than the 246 // current one 247 throw new NoSuchElementException(); 248 } 249 msgsGenerated = true; 250 } else { // const value 251 int paramValue = Integer.parseInt(getTermValue(null, termElement)); 252 while (seqIterator.hasNext()) { 253 seqIterator.next().setLPARAM(paramValue); 254 } 255 } 256 return msgsGenerated; 257 } 258 259 private boolean createSequenceTarget( 260 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, 261 int constMsgType, Element termElement) 262 throws NoSuchElementException { 263 Iterator<WindowsMessage> seqIterator = generatedMessageSeq.iterator(); 264 if (termElement.getName().equals("seqValue")) { 265 String obj = termElement.getAttributeValue("seqObj"); 266 List<WindowsMessage> seqVar = getStoredSeqVariable(obj); 267 if (msgsGenerated && seqVar.size() != generatedMessageSeq.size()) { 268 throw new InvalidParameterException( 269 "Failure generating replay sequence for rule " 270 + currentRuleName 271 + ": One or more of the sequence variables used to generate a sequence have different lenghts."); 272 } 273 for (WindowsMessage msg : seqVar) { 274 WindowsMessage currentSeqMsg = getCurrentSeqMsg( 275 generatedMessageSeq, msgsGenerated, constMsgType, 276 seqIterator); 277 String targetString = msg.getParameter(termElement 278 .getAttributeValue("param")); 279 currentSeqMsg.setXmlWindowDescription(targetString); 280 } 281 msgsGenerated = true; 282 } else { // const value 283 throw new AssertionError("target must be a sequence variable!"); 217 // //////////////////////////////////////////////////////////// 218 // Helper functions for matching of events, i.e., msg-nodes // 219 // //////////////////////////////////////////////////////////// 220 221 /** 222 * <p> 223 * Handles msg-nodes where multiple is not true, i.e., not a sequences. 224 * </p> 225 * 226 * @param messageElement 227 * {@link Element} representing the msg-node 228 * @return true, if a match is found; false otherwise 229 */ 230 private boolean matchSingleMessage(Element messageElement) { 231 boolean isMatch = false; 232 WindowsMessage currentMessage = null; 233 234 int type = Integer.parseInt(messageElement.getAttributeValue("type")); 235 236 while (!isMatch && sequenceIterator.hasNext()) { 284 237 /* 285 * If target would not be a variable, the message-elements could not 286 * yet be created and the whole sequence might be broken. If this is 287 * to be changed, createSequenceLParam and createSequenceWParam need 288 * to be addepted, too. 238 * traverses the messages from the current position forward till a 239 * message with the correct type is found 289 240 */ 290 } 291 return msgsGenerated; 292 } 293 294 private boolean createSequenceWParam( 295 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, 296 int constMsgType, Element termElement) 297 throws NoSuchElementException { 298 Iterator<WindowsMessage> seqIterator = generatedMessageSeq.iterator(); 299 if (termElement.getName().equals("seqValue")) { 300 String obj = termElement.getAttributeValue("seqObj"); 301 List<WindowsMessage> seqVar = getStoredSeqVariable(obj); 302 if (msgsGenerated && seqVar.size() != generatedMessageSeq.size()) { 303 throw new InvalidParameterException( 304 "Failure generating replay sequence for rule " 305 + currentRuleName 306 + ": One or more of the sequence variables used to generate a sequence have different lenghts."); 307 } 308 for (WindowsMessage msg : seqVar) { 309 WindowsMessage currentSeqMsg = getCurrentSeqMsg( 310 generatedMessageSeq, msgsGenerated, constMsgType, 311 seqIterator); 312 String paramValueStr = msg.getParameter(termElement 313 .getAttributeValue("param")); 314 int paramValue = 0; 315 try { 316 paramValue = Integer.parseInt(paramValueStr); 317 currentSeqMsg.setWPARAM(paramValue); 318 } catch (NumberFormatException e) { 319 currentSeqMsg.setWPARAMasWindowDesc(paramValueStr); 320 } 321 } 322 if (seqIterator.hasNext()) { 323 // the first seq-var has a different number of elements than the 324 // current one 325 throw new NoSuchElementException(); 326 } 327 msgsGenerated = true; 328 } else { // const value 329 int paramValue = Integer.parseInt(getTermValue(null, termElement)); 330 while (seqIterator.hasNext()) { 331 seqIterator.next().setWPARAM(paramValue); 332 } 333 } 334 return msgsGenerated; 335 } 336 241 currentMessage = sequenceIterator.next(); 242 if (type == currentMessage.getType()) { 243 // message with the correct type found 244 // eval child nodes for further matching/storing 245 isMatch = evalEqualRestrictions(currentMessage, messageElement); 246 247 // in case the message is a match, eval storage children 248 if (isMatch) { 249 handleStorage(messageElement, currentMessage); 250 currentToken.setTarget(currentMessage 251 .getXmlWindowDescription()); 252 currentToken 253 .setTargetShort(currentMessage.getParentNames()); 254 } 255 } 256 } 257 258 return isMatch; 259 } 260 261 /** 262 * <p> 263 * Handles msg-nodes where multiple is true, i.e., sequences. Requires 264 * knowledge about the next msg-node to determine the end of the sequence. 265 * </p> 266 * 267 * @param messageElement 268 * {@link Element} representing the msg-node 269 * @param nextMessageElement 270 * {@link Element} representing the next msg-node; {@code null} 271 * if the current node is the last one 272 * @return true, if a sequence is matched; false otherwise 273 */ 274 private boolean matchMultipleMessages(Element messageElement, 275 Element nextMessageElement) { 276 boolean isMatch = false; 277 boolean isCurrentMatch = false; 278 boolean nextMatchFound = false; 279 WindowsMessage currentMessage = null; 280 WindowsMessage nextMessage = null; 281 282 int type = Integer.parseInt(messageElement.getAttributeValue("type")); 283 284 int nextType = -1; 285 if (nextMessageElement != null) { 286 nextType = Integer.parseInt(nextMessageElement 287 .getAttributeValue("type")); 288 } 289 290 while (!nextMatchFound && sequenceIterator.hasNext()) { 291 currentMessage = sequenceIterator.next(); 292 if (type == currentMessage.getType()) { 293 isCurrentMatch = evalEqualRestrictions(currentMessage, 294 messageElement); 295 isMatch = isMatch || isCurrentMatch; 296 297 if (isCurrentMatch) { 298 handleStorage(messageElement, currentMessage); 299 currentToken.setTarget(currentMessage 300 .getXmlWindowDescription()); 301 currentToken 302 .setTargetShort(currentMessage.getParentNames()); 303 } 304 } 305 if (nextMessageElement != null && isMatch) { 306 // peek next message to check if the sequence ends and the next 307 // match is found 308 if (!sequenceIterator.hasNext()) { 309 return false; // sequence is over, but not all messages are 310 // found 311 } 312 nextMessage = sequenceIterator.next(); 313 sequenceIterator.previous(); 314 315 if (nextType == nextMessage.getType()) { 316 nextMatchFound = evalEqualRestrictions(nextMessage, 317 nextMessageElement); 318 } 319 320 } 321 } 322 323 return isMatch; 324 } 325 326 /** 327 * <p> 328 * Handles equals-nodes. 329 * </p> 330 * 331 * @param currentMessage 332 * {@link Element} representing the msg-node the equals-node 333 * belongs to 334 * @param messageElement 335 * {@link Element} representing the equals-node to be evaluated 336 * @return true, if constraint is fulfilled; false otherwise 337 */ 337 338 @SuppressWarnings("unchecked") 338 339 private boolean evalEqualRestrictions(WindowsMessage currentMessage, … … 354 355 "equalsSeq", rulesNamespace)) { 355 356 List<Element> termElements = childElement.getChildren(); 356 List<String> values1 = getTermValueSeq(currentMessage, 357 termElements.get(0)); 358 List<String> values2 = getTermValueSeq(currentMessage, 359 termElements.get(0)); 357 List<String> values1 = getTermValueSeq(termElements.get(0)); 358 List<String> values2 = getTermValueSeq(termElements.get(0)); 360 359 if (values1 == null || values2 == null) { 361 360 isMatch = false; … … 367 366 } 368 367 368 /** 369 * <p> 370 * Handles store-nodes and storeSeq-nodes. 371 * </p> 372 * 373 * @param messageElement 374 * {@link Element} representing the msg-node that is currently 375 * being evaluated 376 * @param currentMessage 377 * current message in the message sequence that is matched; this 378 * is the message that is stored 379 */ 380 @SuppressWarnings("unchecked") 381 private void handleStorage(Element messageElement, 382 WindowsMessage currentMessage) { 383 for (Element childElement : (List<Element>) messageElement.getChildren( 384 "store", rulesNamespace)) { 385 String identifier = childElement.getAttributeValue("var"); 386 messageStorage.put(identifier, currentMessage); 387 resolveHwnd(currentMessage, childElement); 388 } 389 for (Element childElement : (List<Element>) messageElement.getChildren( 390 "storeSeq", rulesNamespace)) { 391 String identifier = childElement.getAttributeValue("varSeq"); 392 Object tmp = messageStorage.get(identifier); 393 List<WindowsMessage> storedSequence; 394 if (tmp == null || tmp instanceof WindowsMessage) { 395 storedSequence = new LinkedList<WindowsMessage>(); 396 storedSequence.add(currentMessage); 397 messageStorage.put(identifier, storedSequence); 398 } else if (tmp instanceof List<?>) { 399 storedSequence = (List<WindowsMessage>) tmp; 400 storedSequence.add(currentMessage); 401 messageStorage.put(identifier, storedSequence); 402 } 403 resolveHwnd(currentMessage, childElement); 404 } 405 } 406 407 /** 408 * <p> 409 * Resolves a parameter that contains a HWND of a message to the target 410 * string of the HWND and stores it. 411 * </p> 412 * 413 * @param currentMessage 414 * message whose HWND is resolved 415 * @param childElement 416 * child element of the store node that represents the resolve 417 */ 418 @SuppressWarnings("unchecked") 419 private void resolveHwnd(WindowsMessage currentMessage, Element childElement) { 420 List<Element> resolveElements = childElement.getChildren("resolveHwnd", 421 rulesNamespace); 422 for (Element resolveElement : resolveElements) { 423 String param = resolveElement.getAttributeValue("param"); 424 String storeParam = resolveElement.getAttributeValue("storeParam"); 425 int paramHwnd = Integer 426 .parseInt(currentMessage.getParameter(param)); 427 WindowTreeNode node = WindowTree.getInstance().find(paramHwnd); 428 if (node != null) { 429 currentMessage.addParameter(storeParam, 430 node.xmlRepresentation()); 431 } 432 } 433 } 434 435 // ///////////////////////////////////////////////////// 436 // Helper functions for generating the replay, i.e., 437 // parsing of genMsg und genMsgSeq-nodes 438 // ///////////////////////////////////////////////////// 439 440 /** 441 * <p> 442 * Handles genMsg-nodes and adds the replay to the {@link Event} that is 443 * generated. 444 * </p> 445 * 446 * @param genMsgElement 447 * {@link Element} representing the genMsg-node 448 */ 369 449 @SuppressWarnings("unchecked") 370 450 private void generateReplayMessage(Element genMsgElement) { … … 396 476 String paramValueStr = getTermValue(null, termElement); 397 477 long paramValue = 0; 398 Element loword = genMsgChild.getChild("LOWORD", rulesNamespace); 399 if( loword!=null ) { 478 Element loword = genMsgChild.getChild("LOWORD", 479 rulesNamespace); 480 if (loword != null) { 400 481 paramValue = loHiWord(genMsgChild); 401 482 generatedMessage.setLPARAM(paramValue); … … 405 486 generatedMessage.setLPARAM(paramValue); 406 487 } catch (NumberFormatException e) { 407 generatedMessage.setLPARAMasWindowDesc(paramValueStr); 488 generatedMessage 489 .setLPARAMasWindowDesc(paramValueStr); 408 490 } 409 491 } … … 411 493 String paramValueStr = getTermValue(null, termElement); 412 494 long paramValue = 0; 413 Element loword = genMsgChild.getChild("LOWORD", rulesNamespace); 414 if( loword!=null ) { 495 Element loword = genMsgChild.getChild("LOWORD", 496 rulesNamespace); 497 if (loword != null) { 415 498 paramValue = loHiWord(genMsgChild); 416 499 generatedMessage.setWPARAM(paramValue); … … 420 503 generatedMessage.setWPARAM(paramValue); 421 504 } catch (NumberFormatException e) { 422 generatedMessage.setWPARAMasWindowDesc(paramValueStr); 505 generatedMessage 506 .setWPARAMasWindowDesc(paramValueStr); 423 507 } 424 508 } … … 436 520 } 437 521 522 /** 523 * Handles genMsgSeq-nodes and adds the replay to the {@link Event} that is 524 * generated.</p> 525 * 526 * @param genMsgElement 527 * {@link Element} representing the genMsgSeq-node. 528 */ 438 529 @SuppressWarnings("unchecked") 439 530 private void generateReplaySequence(Element genMsgElement) { … … 479 570 } 480 571 572 /** 573 * <p> 574 * Creates the targets for replay sequences generated with genMsgSeq-nodes. 575 * </p> 576 * 577 * @param generatedMessageSeq 578 * list of the messages that is being generated 579 * @param msgsGenerated 580 * boolean stating if the list of messages is already generated 581 * or if the generation has to be handles by this method 582 * @param constMsgType 583 * a constant message type that is used for message generation, 584 * in case the list of message is generated by this method 585 * @param termElement 586 * {@link Element} representing the term-node describing the 587 * target 588 * @return true, if the list of message is generated after calling this 589 * method; false otherwise 590 * @throws NoSuchElementException 591 * thrown if the seqVar referred to in the termElement contains 592 * a different number of messages than is contained in 593 * messageSeq 594 */ 595 private boolean createSequenceTarget( 596 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, 597 int constMsgType, Element termElement) 598 throws NoSuchElementException { 599 Iterator<WindowsMessage> seqIterator = generatedMessageSeq.iterator(); 600 if (termElement.getName().equals("seqValue")) { 601 String obj = termElement.getAttributeValue("seqObj"); 602 List<WindowsMessage> seqVar = getStoredSeqVariable(obj); 603 if (msgsGenerated && seqVar.size() != generatedMessageSeq.size()) { 604 throw new InvalidParameterException( 605 "Failure generating replay sequence for rule " 606 + currentRuleName 607 + ": One or more of the sequence variables used to generate a sequence have different lenghts."); 608 } 609 for (WindowsMessage msg : seqVar) { 610 WindowsMessage currentSeqMsg = getCurrentSeqMsg( 611 generatedMessageSeq, msgsGenerated, constMsgType, 612 seqIterator); 613 String targetString = msg.getParameter(termElement 614 .getAttributeValue("param")); 615 currentSeqMsg.setXmlWindowDescription(targetString); 616 } 617 msgsGenerated = true; 618 } else { // const value 619 throw new AssertionError("target must be a sequence variable!"); 620 /* 621 * If target would not be a variable, the message-elements could not 622 * yet be created and the whole sequence might be broken. If this is 623 * to be changed, createSequenceLParam and createSequenceWParam need 624 * to be addepted, too. 625 */ 626 } 627 return msgsGenerated; 628 } 629 630 /** 631 * <p> 632 * Creates the LPARAMs for replay sequences generated with genMsgSeq-nodes. 633 * </p> 634 * 635 * @param generatedMessageSeq 636 * list of the messages that is being generated 637 * @param msgsGenerated 638 * boolean stating if the list of messages is already generated 639 * or if the generation has to be handles by this method 640 * @param constMsgType 641 * a constant message type that is used for message generation, 642 * in case the list of message is generated by this method 643 * @param termElement 644 * {@link Element} representing the term-node describing the 645 * LPARAM 646 * @return true, if the list of message is generated after calling this 647 * method; false otherwise 648 * @throws NoSuchElementException 649 * thrown if the seqVar referred to in the termElement contains 650 * a different number of messages than is contained in 651 * messageSeq 652 */ 653 private boolean createSequenceLParam( 654 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, 655 int constMsgType, Element termElement) 656 throws NoSuchElementException { 657 Iterator<WindowsMessage> seqIterator = generatedMessageSeq.iterator(); 658 if (termElement.getName().equals("seqValue")) { 659 String obj = termElement.getAttributeValue("seqObj"); 660 List<WindowsMessage> seqVar = getStoredSeqVariable(obj); 661 if (msgsGenerated && seqVar.size() != generatedMessageSeq.size()) { 662 throw new InvalidParameterException( 663 "Failure generating replay sequence for rule " 664 + currentRuleName 665 + ": One or more of the sequence variables used to generate a sequence have different lenghts."); 666 } 667 for (WindowsMessage msg : seqVar) { 668 WindowsMessage currentSeqMsg = getCurrentSeqMsg( 669 generatedMessageSeq, msgsGenerated, constMsgType, 670 seqIterator); 671 String paramValueStr = msg.getParameter(termElement 672 .getAttributeValue("param")); 673 int paramValue = 0; 674 try { 675 paramValue = Integer.parseInt(paramValueStr); 676 currentSeqMsg.setLPARAM(paramValue); 677 } catch (NumberFormatException e) { 678 currentSeqMsg.setLPARAMasWindowDesc(paramValueStr); 679 } 680 } 681 if (seqIterator.hasNext()) { 682 // the first seq-var has a different number of elements than the 683 // current one 684 throw new NoSuchElementException(); 685 } 686 msgsGenerated = true; 687 } else { // const value 688 int paramValue = Integer.parseInt(getTermValue(null, termElement)); 689 while (seqIterator.hasNext()) { 690 seqIterator.next().setLPARAM(paramValue); 691 } 692 } 693 return msgsGenerated; 694 } 695 696 /** 697 * <p> 698 * Creates the WPARAMs for replay sequences generated with genMsgSeq-nodes. 699 * </p> 700 * 701 * @param generatedMessageSeq 702 * list of the messages that is being generated 703 * @param msgsGenerated 704 * boolean stating if the list of messages is already generated 705 * or if the generation has to be handles by this method 706 * @param constMsgType 707 * a constant message type that is used for message generation, 708 * in case the list of message is generated by this method 709 * @param termElement 710 * {@link Element} representing the term-node describing the 711 * WPARAM 712 * @return true, if the list of message is generated after calling this 713 * method; false otherwise 714 * @throws NoSuchElementException 715 * thrown if the seqVar referred to in the termElement contains 716 * a different number of messages than is contained in 717 * messageSeq 718 */ 719 private boolean createSequenceWParam( 720 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, 721 int constMsgType, Element termElement) 722 throws NoSuchElementException { 723 Iterator<WindowsMessage> seqIterator = generatedMessageSeq.iterator(); 724 if (termElement.getName().equals("seqValue")) { 725 String obj = termElement.getAttributeValue("seqObj"); 726 List<WindowsMessage> seqVar = getStoredSeqVariable(obj); 727 if (msgsGenerated && seqVar.size() != generatedMessageSeq.size()) { 728 throw new InvalidParameterException( 729 "Failure generating replay sequence for rule " 730 + currentRuleName 731 + ": One or more of the sequence variables used to generate a sequence have different lenghts."); 732 } 733 for (WindowsMessage msg : seqVar) { 734 WindowsMessage currentSeqMsg = getCurrentSeqMsg( 735 generatedMessageSeq, msgsGenerated, constMsgType, 736 seqIterator); 737 String paramValueStr = msg.getParameter(termElement 738 .getAttributeValue("param")); 739 int paramValue = 0; 740 try { 741 paramValue = Integer.parseInt(paramValueStr); 742 currentSeqMsg.setWPARAM(paramValue); 743 } catch (NumberFormatException e) { 744 currentSeqMsg.setWPARAMasWindowDesc(paramValueStr); 745 } 746 } 747 if (seqIterator.hasNext()) { 748 // the first seq-var has a different number of elements than the 749 // current one 750 throw new NoSuchElementException(); 751 } 752 msgsGenerated = true; 753 } else { // const value 754 int paramValue = Integer.parseInt(getTermValue(null, termElement)); 755 while (seqIterator.hasNext()) { 756 seqIterator.next().setWPARAM(paramValue); 757 } 758 } 759 return msgsGenerated; 760 } 761 762 /** 763 * <p> 764 * If a message sequence is already generated, i.e., msgsGenerated is true, 765 * the seqIterator is used to iterate through these messages and return the 766 * current one. If the message sequence is not yet generated, i.e., 767 * msgsGenerated is false, the message sequence is generated on the fly 768 * during each call of this message and the newly generated messages are 769 * returned. 770 * </p> 771 * 772 * @param generatedMessageSeq 773 * message sequence 774 * @param msgsGenerated 775 * indicates if generatedMessageSeq is already generated or has 776 * to be generated on the fly by this method 777 * @param constMsgType 778 * type of the message to be used for message generation 779 * @param seqIterator 780 * iterates through an already generated message sequence; must 781 * not be {@code null}, if msgsGenerated is true 782 * @return current message 783 */ 481 784 private WindowsMessage getCurrentSeqMsg( 482 785 List<WindowsMessage> generatedMessageSeq, boolean msgsGenerated, … … 492 795 } 493 796 797 // //////////////////////////// 798 // General helper functions // 799 // //////////////////////////// 800 801 /** 802 * <p> 803 * Retrieves a message from the storage for, e.g., comparison or replay. 804 * "this" is used to refer to the current message. 805 * </p> 806 * 807 * @param currentMessage 808 * current message during the parsing; passed to handle "this" 809 * @param obj 810 * object identifier in the storage 811 * @return message retrieved from the storage 812 * @throws InvalidParameterException 813 * thrown in case of invalid uses of "this" or if no message 814 * with the identifier obj is found in the storage 815 */ 494 816 private WindowsMessage getStoredMessageVariable( 495 817 WindowsMessage currentMessage, String obj) … … 518 840 } 519 841 842 /** 843 * <p> 844 * Retrieves a stored message sequence from the storage. 845 * </p> 846 * 847 * @param obj 848 * object identifier in the storage 849 * @return message sequence retrieved from the storage 850 * @throws InvalidParameterException 851 * thrown if no message sequences with the identifier obj is 852 * found in the storage 853 */ 520 854 @SuppressWarnings("unchecked") 521 855 private List<WindowsMessage> getStoredSeqVariable(String obj) … … 533 867 } 534 868 869 /** 870 * <p> 871 * Handles term-nodes and returns the value of the described term. 872 * </p> 873 * 874 * @param currentMessage 875 * current message during the parsing; required to resolve 876 * references to "this" in a term 877 * @param termElement 878 * {@link Element} representing the term node 879 * @return value of the term or {@code null} of the term node could not be 880 * evaluated 881 */ 535 882 private String getTermValue(WindowsMessage currentMessage, 536 883 Element termElement) { … … 560 907 String target = varMessage.getXmlWindowDescription(); 561 908 int index = target.lastIndexOf("<"); 562 if ( index==0) {909 if (index == 0) { 563 910 Console.println("Trying to adress parent of top-level window! Replay probably invalid!"); 564 911 } … … 583 930 } 584 931 585 private List<String> getTermValueSeq(WindowsMessage currentMessage, 586 Element termElement) { 932 /** 933 * <p> 934 * Handles term-nodes contained by equalSeq nodes. 935 * </p> 936 * 937 * @param termElement 938 * {@link Element} representing the term-node 939 * @return list of values of the term 940 */ 941 private List<String> getTermValueSeq(Element termElement) { 587 942 List<String> values = new LinkedList<String>(); 588 943 if (termElement.getName().equals("seqValue")) { … … 600 955 } 601 956 602 @SuppressWarnings("unchecked") 603 private void handleStorage(Element messageElement, 604 WindowsMessage currentMessage) { 605 for (Element childElement : (List<Element>) messageElement.getChildren( 606 "store", rulesNamespace)) { 607 String identifier = childElement.getAttributeValue("var"); 608 messageStorage.put(identifier, currentMessage); 609 resolveHwnd(currentMessage, childElement); 610 } 611 for (Element childElement : (List<Element>) messageElement.getChildren( 612 "storeSeq", rulesNamespace)) { 613 String identifier = childElement.getAttributeValue("varSeq"); 614 Object tmp = messageStorage.get(identifier); 615 List<WindowsMessage> storedSequence; 616 if (tmp == null || tmp instanceof WindowsMessage) { 617 storedSequence = new LinkedList<WindowsMessage>(); 618 storedSequence.add(currentMessage); 619 messageStorage.put(identifier, storedSequence); 620 } else if (tmp instanceof List<?>) { 621 storedSequence = (List<WindowsMessage>) tmp; 622 storedSequence.add(currentMessage); 623 messageStorage.put(identifier, storedSequence); 624 } 625 resolveHwnd(currentMessage, childElement); 626 } 627 } 628 629 private boolean matchMultipleMessages(Element messageElement, 630 Element nextMessageElement) { 631 boolean isMatch = false; 632 boolean isCurrentMatch = false; 633 boolean nextMatchFound = false; 634 WindowsMessage currentMessage = null; 635 WindowsMessage nextMessage = null; 636 637 int type = Integer.parseInt(messageElement.getAttributeValue("type")); 638 639 int nextType = -1; 640 if (nextMessageElement != null) { 641 nextType = Integer.parseInt(nextMessageElement 642 .getAttributeValue("type")); 643 } 644 645 while (!nextMatchFound && sequenceIterator.hasNext()) { 646 currentMessage = sequenceIterator.next(); 647 if (type == currentMessage.getType()) { 648 isCurrentMatch = evalEqualRestrictions(currentMessage, 649 messageElement); 650 isMatch = isMatch || isCurrentMatch; 651 652 if (isCurrentMatch) { 653 handleStorage(messageElement, currentMessage); 654 currentToken.setTarget(currentMessage 655 .getXmlWindowDescription()); 656 currentToken 657 .setTargetShort(currentMessage.getParentNames()); 658 } 659 } 660 if (nextMessageElement != null && isMatch) { 661 // peek next message to check if the sequence ends and the next 662 // match is found 663 if (!sequenceIterator.hasNext()) { 664 return false; // sequence is over, but not all messages are 665 // found 666 } 667 nextMessage = sequenceIterator.next(); 668 sequenceIterator.previous(); 669 670 if (nextType == nextMessage.getType()) { 671 nextMatchFound = evalEqualRestrictions(nextMessage, 672 nextMessageElement); 673 } 674 675 } 676 } 677 678 return isMatch; 679 } 680 681 private boolean matchSingleMessage(Element messageElement) { 682 boolean isMatch = false; 683 WindowsMessage currentMessage = null; 684 685 int type = Integer.parseInt(messageElement.getAttributeValue("type")); 686 687 while (!isMatch && sequenceIterator.hasNext()) { 688 // traverses the messages from the current position forward till a 689 // message with the correct type is found 690 currentMessage = sequenceIterator.next(); 691 if (type == currentMessage.getType()) { 692 // message with the correct type found 693 // eval child nodes for further matching/storing 694 isMatch = evalEqualRestrictions(currentMessage, messageElement); 695 696 // in case the message is a match, eval storage children 697 if (isMatch) { 698 handleStorage(messageElement, currentMessage); 699 currentToken.setTarget(currentMessage 700 .getXmlWindowDescription()); 701 currentToken 702 .setTargetShort(currentMessage.getParentNames()); 703 } 704 } 705 } 706 707 return isMatch; 708 } 709 710 @SuppressWarnings("unchecked") 711 private void resolveHwnd(WindowsMessage currentMessage, Element childElement) { 712 List<Element> resolveElements = childElement.getChildren("resolveHwnd", 713 rulesNamespace); 714 for (Element resolveElement : resolveElements) { 715 String param = resolveElement.getAttributeValue("param"); 716 String storeParam = resolveElement.getAttributeValue("storeParam"); 717 int paramHwnd = Integer 718 .parseInt(currentMessage.getParameter(param)); 719 WindowTreeNode node = WindowTree.getInstance().find(paramHwnd); 720 if (node != null) { 721 currentMessage.addParameter(storeParam, 722 node.xmlRepresentation()); 723 } 724 } 725 } 726 957 /** 958 * <p> 959 * Handles LOWORD and HIWORD child nodes of LPARAM and WPARAM nodes. The 960 * returned value is the LPARAM/WPARAM value based on the LOWORD and HIWORD. 961 * </p> 962 * 963 * @param param 964 * {@link Element} representing the LPARAM/WPARAM node 965 * @return value of the LPARAM/WPARAM 966 */ 727 967 private long loHiWord(Element param) { 728 968 Element loword = param.getChild("LOWORD", rulesNamespace); 729 969 Element hiword = param.getChild("HIWORD", rulesNamespace); 730 String lowordStr = getTermValue(null, (Element) loword.getChildren().get(0)); 731 String hiwordStr = getTermValue(null, (Element) hiword.getChildren().get(0)); 732 return MAKEPARAM(Short.parseShort(lowordStr), Short.parseShort(hiwordStr)); 733 } 734 970 String lowordStr = getTermValue(null, (Element) loword.getChildren() 971 .get(0)); 972 String hiwordStr = getTermValue(null, (Element) hiword.getChildren() 973 .get(0)); 974 return MAKEPARAM(Short.parseShort(lowordStr), 975 Short.parseShort(hiwordStr)); 976 } 977 978 /** 979 * <p> 980 * Takes to short integers and combines them into the high and low order 981 * bits of an integer. 982 * </p> 983 * 984 * @param loword 985 * low word 986 * @param hiword 987 * high word 988 * @return combined integer 989 */ 735 990 private static int MAKEPARAM(short loword, short hiword) { 736 return loword | ((int) hiword) << Short.SIZE;991 return loword | ((int) hiword) << Short.SIZE; 737 992 } 738 993 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/HandlerCreate.java
r156 r171 3 3 import de.ugoe.cs.eventbench.windows.data.WindowTree; 4 4 5 /** 6 * <p> 7 * Message handler for {@code WM_CREATE} messages. The handler maintains the 8 * {@link WindowTree}. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 */ 5 14 public class HandlerCreate extends MessageHandler { 6 15 16 /** 17 * <p> 18 * Constructor. Creates a new HandlerCreate. 19 * </p> 20 */ 7 21 public HandlerCreate() { 8 22 super(); 9 23 } 10 24 25 /** 26 * <p> 27 * Name of the created window. 28 * </p> 29 */ 11 30 private String windowName; 31 32 /** 33 * <p> 34 * HWND of the created window. 35 * </p> 36 */ 12 37 private int hwnd; 38 39 /** 40 * <p> 41 * HWND of the created window's parent. 42 * </p> 43 */ 13 44 private int parentHwnd; 45 46 /** 47 * <p> 48 * Resource Id of the created window. 49 * </p> 50 */ 14 51 private int resourceId; 52 53 /** 54 * <p> 55 * Window class of the created window. 56 * </p> 57 */ 15 58 private String className; 59 60 /** 61 * <p> 62 * Modality of the created window. 63 * </p> 64 */ 16 65 private boolean isModal; 17 66 67 /* 68 * (non-Javadoc) 69 * 70 * @see de.ugoe.cs.eventbench.windows.MessageHandler#onEndElement() 71 */ 18 72 @Override 19 73 public void onEndElement() { 20 if( hwnd!=0 ) { 21 WindowTree.getInstance().add(parentHwnd, hwnd, windowName, resourceId, className, isModal); 74 if (hwnd != 0) { 75 WindowTree.getInstance().add(parentHwnd, hwnd, windowName, 76 resourceId, className, isModal); 22 77 } 23 78 } 24 79 80 /* 81 * (non-Javadoc) 82 * 83 * @see 84 * de.ugoe.cs.eventbench.windows.MessageHandler#onParameter(java.lang.String 85 * , java.lang.String) 86 */ 25 87 @Override 26 88 public void onParameter(String name, String value) { 27 if ( name.equals("window.hwnd")) {89 if (name.equals("window.hwnd")) { 28 90 hwnd = Integer.parseInt(value); 29 } 30 else if( name.equals("window.name") ) { 91 } else if (name.equals("window.name")) { 31 92 windowName = value; 32 } 33 else if( name.equals("window.parent.hwnd") ) { 93 } else if (name.equals("window.parent.hwnd")) { 34 94 parentHwnd = Integer.parseInt(value); 35 } 36 else if( name.equals("window.resourceId") ) { 95 } else if (name.equals("window.resourceId")) { 37 96 resourceId = Integer.parseInt(value); 38 } 39 else if( name.equals("window.class") ) { 40 if( value.startsWith("Afx:") ) { 97 } else if (name.equals("window.class")) { 98 if (value.startsWith("Afx:")) { 41 99 className = "Afx:"; 42 100 } else { 43 101 className = value; 44 102 } 45 } 46 else if( name.equals("window.ismodal") ) { 47 if( value.equals("true") || value.equals("1") ) { 103 } else if (name.equals("window.ismodal")) { 104 if (value.equals("true") || value.equals("1")) { 48 105 isModal = true; 49 106 } … … 51 108 } 52 109 110 /* 111 * (non-Javadoc) 112 * 113 * @see de.ugoe.cs.eventbench.windows.MessageHandler#onStartElement() 114 */ 53 115 @Override 54 116 public void onStartElement() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/HandlerDestroy.java
r75 r171 3 3 import de.ugoe.cs.eventbench.windows.data.WindowTree; 4 4 5 /** 6 * <p> 7 * Handler for {@code WM_DESTROY} message. The handler maintains the 8 * {@link WindowTree}. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 */ 5 14 public class HandlerDestroy extends MessageHandler { 6 15 16 /** 17 * <p> 18 * Constructor. Creates a new HandlerDestroy. 19 * </p> 20 */ 7 21 public HandlerDestroy() { 8 22 super(); 9 23 } 10 24 25 /** 26 * <p> 27 * HWND of the window that is destroyed. 28 * </p> 29 */ 11 30 private int hwnd; 12 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.eventbench.windows.MessageHandler#onEndElement() 36 */ 13 37 @Override 14 38 public void onEndElement() { 15 if ( hwnd!=0) {39 if (hwnd != 0) { 16 40 WindowTree.getInstance().remove(hwnd); 17 41 } 18 42 } 19 43 44 /* 45 * (non-Javadoc) 46 * 47 * @see 48 * de.ugoe.cs.eventbench.windows.MessageHandler#onParameter(java.lang.String 49 * , java.lang.String) 50 */ 20 51 @Override 21 52 public void onParameter(String name, String value) { 22 if ( name.equals("window.hwnd")) {53 if (name.equals("window.hwnd")) { 23 54 hwnd = Integer.parseInt(value); 24 55 } 25 56 } 26 57 58 /* 59 * (non-Javadoc) 60 * 61 * @see de.ugoe.cs.eventbench.windows.MessageHandler#onStartElement() 62 */ 27 63 @Override 28 64 public void onStartElement() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/HandlerSetText.java
r75 r171 4 4 import de.ugoe.cs.eventbench.windows.data.WindowTreeNode; 5 5 6 /** 7 * <p> 8 * Handles {@code WM_SETTEXT} messages. Handler maintains the {@link WindowTree}. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 */ 6 14 public class HandlerSetText extends MessageHandler { 7 15 16 /** 17 * <p> 18 * Constructor. Creates a new HanderSetText. 19 * </p> 20 */ 8 21 public HandlerSetText() { 9 22 super(); 10 23 } 11 24 25 /** 26 * <p> 27 * New name of the window. 28 * </p> 29 */ 12 30 private String windowName; 31 32 /** 33 * <p> 34 * HWND of the window. 35 * </p> 36 */ 13 37 private int hwnd; 14 38 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.eventbench.windows.MessageHandler#onEndElement() 43 */ 15 44 @Override 16 45 public void onEndElement() { … … 21 50 } 22 51 52 /* 53 * (non-Javadoc) 54 * 55 * @see 56 * de.ugoe.cs.eventbench.windows.MessageHandler#onParameter(java.lang.String 57 * , java.lang.String) 58 */ 23 59 @Override 24 60 public void onParameter(String name, String value) { … … 30 66 } 31 67 68 /* 69 * (non-Javadoc) 70 * 71 * @see de.ugoe.cs.eventbench.windows.MessageHandler#onStartElement() 72 */ 32 73 @Override 33 74 public void onStartElement() { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/LogParser.java
r77 r171 28 28 import de.ugoe.cs.util.console.Console; 29 29 30 /** 31 * <p> 32 * This class provides functionality to parse XML log files generated by the 33 * MFCUsageMonitor of EventBench. The result of parsing a file is a collection 34 * of event sequences. It uses the {@link SequenceSplitter} and the 35 * {@link EventGenerator} as well as custom defined {@link MessageHandler} for 36 * the parsing. 37 * </p> 38 * 39 * @author Steffen Herbold 40 * @version 1.0 41 */ 30 42 public class LogParser extends DefaultHandler { 31 43 44 /** 45 * <p> 46 * If a custom message handler is used, this field contains its handle. 47 * Otherwise this field is {@code null}. 48 * </p> 49 */ 32 50 private MessageHandler currentHandler; 33 51 52 /** 53 * <p> 54 * Handle to the message that is currently parsed. 55 * </p> 56 */ 34 57 private WindowsMessage currentMessage; 35 58 59 /** 60 * <p> 61 * {@link SequenceSplitter} instance used by the {@link LogParser}. 62 * </p> 63 */ 36 64 private SequenceSplitter sequenceSplitter; 37 65 66 /** 67 * <p> 68 * Collection of event sequences that is contained in the log file, which is 69 * parsed. 70 * </p> 71 */ 38 72 private List<List<WindowsEvent>> sequences; 39 73 74 /** 75 * <p> 76 * Debugging variable that allows the analysis which message type occurs how 77 * often in the log file. Can be used to enhance the message filter. 78 * </p> 79 */ 40 80 private SortedMap<Integer, Integer> typeCounter; 41 81 82 /** 83 * <p> 84 * Debugging variable that enables the counting of the occurrences of each 85 * message. Used in combination with {@link #typeCounter}. 86 * </p> 87 */ 42 88 private boolean countMessageOccurences; 43 89 90 /** 91 * <p> 92 * Constructor. Creates a new LogParser that does not count message 93 * occurrences. 94 * </p> 95 */ 44 96 public LogParser() { 45 97 this(false); 46 98 } 47 99 100 /** 101 * <p> 102 * Constructor. Creates a new LogParser. 103 * </p> 104 * 105 * @param countMessageOccurences 106 * if true, the occurrences of each message type in the log is 107 * counted. 108 */ 48 109 public LogParser(boolean countMessageOccurences) { 49 110 sequenceSplitter = new SequenceSplitter(); … … 51 112 currentHandler = null; 52 113 this.countMessageOccurences = countMessageOccurences; 53 if (countMessageOccurences) {114 if (countMessageOccurences) { 54 115 typeCounter = new TreeMap<Integer, Integer>(); 55 116 } 56 57 } 58 117 118 } 119 120 /** 121 * <p> 122 * Returns the collection of event sequences that is obtained from parsing 123 * log files. 124 * </p> 125 * 126 * @return collection of event sequences 127 */ 59 128 public List<List<WindowsEvent>> getSequences() { 60 129 return sequences; 61 130 } 62 131 132 /* 133 * (non-Javadoc) 134 * 135 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, 136 * java.lang.String, java.lang.String, org.xml.sax.Attributes) 137 */ 63 138 @Override 64 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { 65 if( qName.equals("session") ) { 139 public void startElement(String uri, String localName, String qName, 140 Attributes atts) throws SAXException { 141 if (qName.equals("session")) { 66 142 Console.traceln("start of session"); 67 143 sequenceSplitter = new SequenceSplitter(); 68 } 69 else if( qName.equals("msg") ) { 144 } else if (qName.equals("msg")) { 70 145 String msgType = atts.getValue("type"); 71 146 int msgInt = -1; 72 147 try { 73 148 msgInt = Integer.parseInt(msgType); 74 75 if ( countMessageOccurences) {149 150 if (countMessageOccurences) { 76 151 Integer currentCount = typeCounter.get(msgInt); 77 if ( currentCount==null) {152 if (currentCount == null) { 78 153 typeCounter.put(msgInt, 1); 79 154 } else { 80 typeCounter.put(msgInt, currentCount +1);155 typeCounter.put(msgInt, currentCount + 1); 81 156 } 82 157 } 83 84 if ( msgInt==MessageDefs.WM_CREATE) {158 159 if (msgInt == MessageDefs.WM_CREATE) { 85 160 currentHandler = new HandlerCreate(); 86 161 currentHandler.onStartElement(); 87 } 88 else if( msgInt==MessageDefs.WM_DESTROY ) { 162 } else if (msgInt == MessageDefs.WM_DESTROY) { 89 163 currentHandler = new HandlerDestroy(); 90 164 currentHandler.onStartElement(); 91 } 92 else if( msgInt==MessageDefs.WM_SETTEXT ) { 165 } else if (msgInt == MessageDefs.WM_SETTEXT) { 93 166 currentHandler = new HandlerSetText(); 94 167 currentHandler.onStartElement(); … … 96 169 currentMessage = new WindowsMessage(msgInt); 97 170 } 98 } catch (NumberFormatException e) {171 } catch (NumberFormatException e) { 99 172 Console.printerrln("Invalid message type: type not a number"); 100 173 e.printStackTrace(); 101 174 } 102 } 103 else if( qName.equals("param")) {104 if( currentHandler!=null ) {105 currentHandler.onParameter(atts.getValue("name"),atts.getValue("value"));175 } else if (qName.equals("param")) { 176 if (currentHandler != null) { 177 currentHandler.onParameter(atts.getValue("name"), 178 atts.getValue("value")); 106 179 } else { 107 currentMessage.addParameter(atts.getValue("name"), atts.getValue("value")); 108 } 109 } 110 } 111 180 currentMessage.addParameter(atts.getValue("name"), 181 atts.getValue("value")); 182 } 183 } 184 } 185 186 /* 187 * (non-Javadoc) 188 * 189 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, 190 * java.lang.String, java.lang.String) 191 */ 112 192 @Override 113 public void endElement(String uri, String localName, String qName) throws SAXException { 114 if( qName.equals("msg") ) { 115 if( currentHandler!=null ) { 193 public void endElement(String uri, String localName, String qName) 194 throws SAXException { 195 if (qName.equals("msg")) { 196 if (currentHandler != null) { 116 197 currentHandler.onEndElement(); 117 198 currentHandler = null; … … 121 202 sequenceSplitter.addMessage(currentMessage); 122 203 } catch (InvalidParameterException e) { 123 Console.traceln(e.getMessage() + " WindowsMessage " + currentMessage + " ignored.");124 }125 }126 }127 else if(qName.equals("session")) {204 Console.traceln(e.getMessage() + " WindowsMessage " 205 + currentMessage + " ignored."); 206 } 207 } 208 } else if (qName.equals("session")) { 128 209 sequenceSplitter.endSession(); 129 210 sequences.add(sequenceSplitter.getSequence()); … … 131 212 } 132 213 } 133 214 215 /** 216 * <p> 217 * Parses a given log file and adds its contents to the collection of event 218 * sequences. 219 * </p> 220 * 221 * @param filename 222 * name and path of the log file 223 */ 134 224 public void parseFile(String filename) { 135 if ( filename==null) {225 if (filename == null) { 136 226 throw new InvalidParameterException("filename must not be null"); 137 227 } 138 228 139 229 SAXParserFactory spf = SAXParserFactory.newInstance(); 140 230 spf.setValidating(true); 141 231 142 232 SAXParser saxParser = null; 143 233 InputSource inputSource = null; 144 234 try { 145 235 saxParser = spf.newSAXParser(); 146 inputSource = new InputSource(new InputStreamReader(new FileInputStream(filename), "UTF-16")); 236 inputSource = new InputSource(new InputStreamReader( 237 new FileInputStream(filename), "UTF-16")); 147 238 } catch (UnsupportedEncodingException e) { 148 239 e.printStackTrace(); … … 154 245 e.printStackTrace(); 155 246 } 156 if( inputSource!=null ) { 157 inputSource.setSystemId("file://" + new File(filename).getAbsolutePath()); 158 try { 159 if( saxParser==null) { 160 throw new RuntimeException("SAXParser creation failed"); 161 } 247 if (inputSource != null) { 248 inputSource.setSystemId("file://" 249 + new File(filename).getAbsolutePath()); 250 try { 251 if (saxParser == null) { 252 throw new RuntimeException("SAXParser creation failed"); 253 } 162 254 saxParser.parse(inputSource, this); 163 } catch (SAXParseException e) { 164 Console.printerrln("Failure parsing file in line " + e.getLineNumber() + ", column " + e.getColumnNumber() +"."); 165 e.printStackTrace(); 255 } catch (SAXParseException e) { 256 Console.printerrln("Failure parsing file in line " 257 + e.getLineNumber() + ", column " + e.getColumnNumber() 258 + "."); 259 e.printStackTrace(); 166 260 } catch (SAXException e) { 167 261 e.printStackTrace(); … … 170 264 } 171 265 } 172 if ( countMessageOccurences) {266 if (countMessageOccurences) { 173 267 Console.println("Message statistics:"); 174 Console.println(typeCounter.toString().replace(" ", StringTools.ENDLINE).replaceAll("[\\{\\}]","")); 268 Console.println(typeCounter.toString() 269 .replace(" ", StringTools.ENDLINE) 270 .replaceAll("[\\{\\}]", "")); 175 271 } 176 272 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/LogPreprocessor.java
r75 r171 13 13 import de.ugoe.cs.util.console.Console; 14 14 15 /** 16 * <p> 17 * Pre-processes log files generated by the EventBench's MFCUsageMonitor. It 18 * decodes Base64 encoding into UTF-16. It removes all lines of the log file, 19 * that do not start with the prefix "UL:", end everything before the prefix and 20 * the prefix itself. 21 * </p> 22 * 23 * @author Steffen Herbold 24 * @version 1.0 25 */ 15 26 public class LogPreprocessor { 16 27 28 /** 29 * <p> 30 * Internal flag that monitors whether there is an open session-node in the 31 * XML file to ensure that there is a closing session-node for each opening 32 * session node and, thereby, ensure that the XML file is well formed. 33 * </p> 34 */ 17 35 private boolean sessionOpen = false; 36 37 /** 38 * <p> 39 * Internal flag that monitors whether a message node is longer than one 40 * line, as the prefix handling is different in this case. 41 * </p> 42 */ 18 43 private boolean msgIncomplete = false; 19 44 45 /** 46 * <p> 47 * Flag that marks whether the log file is Base64 encoded. 48 * </p> 49 */ 20 50 private boolean base64; 21 51 52 /** 53 * <p> 54 * Constructor. Creates a new LogPreprocessor that does not decode Base64. 55 * </p> 56 */ 22 57 public LogPreprocessor() { 23 58 this(false); 24 59 } 25 60 61 /** 62 * <p> 63 * Constructor. Creates a new LogPreprocessor. 64 * </p> 65 * 66 * @param base64 67 * if true, Base64 will be decoded. 68 */ 26 69 public LogPreprocessor(boolean base64) { 27 70 this.base64 = base64; 28 71 } 29 30 public void convertToXml(String source, String target) throws IOException, FileNotFoundException { 31 OutputStreamWriter targetFile = new OutputStreamWriter(new FileOutputStream(target), "UTF-16"); 32 targetFile.write("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" + StringTools.ENDLINE); 72 73 /** 74 * <p> 75 * Pre-processes a single log file. 76 * </p> 77 * 78 * @param source 79 * name and path of the source file 80 * @param target 81 * name and path of the target file 82 * @throws IOException 83 * thrown if there is a problem with reading from or writing to 84 * the source, respectively target file 85 * @throws FileNotFoundException 86 * thrown if the source file is not found 87 */ 88 public void convertToXml(String source, String target) throws IOException, 89 FileNotFoundException { 90 OutputStreamWriter targetFile = new OutputStreamWriter( 91 new FileOutputStream(target), "UTF-16"); 92 targetFile.write("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" 93 + StringTools.ENDLINE); 33 94 targetFile.write("<log>" + StringTools.ENDLINE); 34 95 processFile(source, targetFile); 35 if ( sessionOpen) {96 if (sessionOpen) { 36 97 targetFile.write(" </session>" + StringTools.ENDLINE); 37 98 } … … 39 100 targetFile.close(); 40 101 } 41 42 43 public void convertDirToXml(String path, String target) throws IOException, FileNotFoundException { 44 OutputStreamWriter targetFile = new OutputStreamWriter(new FileOutputStream(target), "UTF-16"); 45 targetFile.write("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" + StringTools.ENDLINE); 102 103 /** 104 * <p> 105 * Pre-processes all files in a given source folder. 106 * </p> 107 * 108 * @param source 109 * path of the source folder 110 * @param target 111 * name and path of the target file 112 * @throws IOException 113 * thrown if there is a problem with reading from or writing to 114 * the source, respectively target file 115 * @throws FileNotFoundException 116 * thrown if the source file is not found 117 */ 118 public void convertDirToXml(String path, String target) throws IOException, 119 FileNotFoundException { 120 OutputStreamWriter targetFile = new OutputStreamWriter( 121 new FileOutputStream(target), "UTF-16"); 122 targetFile.write("<?xml version=\"1.0\" encoding=\"UTF-16\"?>" 123 + StringTools.ENDLINE); 46 124 targetFile.write("<log>" + StringTools.ENDLINE); 47 125 File folder = new File(path); 48 if ( !folder.isDirectory()) {126 if (!folder.isDirectory()) { 49 127 throw new IOException(path + " is not a directory"); 50 128 } 51 129 String absolutPath = folder.getAbsolutePath(); 52 for ( String filename : folder.list()) {130 for (String filename : folder.list()) { 53 131 String source = absolutPath + "/" + filename; 54 132 Console.traceln("Processing file: " + source); 55 133 processFile(source, targetFile); 56 134 } 57 58 if ( sessionOpen) {135 136 if (sessionOpen) { 59 137 targetFile.write(" </session>" + StringTools.ENDLINE); 60 138 } … … 63 141 } 64 142 143 /** 144 * <p> 145 * Internal function that pre-processes a log file. 146 * </p> 147 * 148 * @param source 149 * name and path of the source file 150 * @param target 151 * name and path of the target file 152 * @throws IOException 153 * thrown if there is a problem with reading from or writing to 154 * the source, respectively target file 155 * @throws FileNotFoundException 156 * thrown if the source file is not found 157 */ 65 158 private void processFile(String source, OutputStreamWriter targetFile) 66 159 throws FileNotFoundException, IOException { … … 68 161 String incompleteLine = ""; 69 162 // Open source and read line by line 70 for ( String currentLine : lines) {71 if (currentLine.contains("UL: <session>")) {72 if (sessionOpen) {163 for (String currentLine : lines) { 164 if (currentLine.contains("UL: <session>")) { 165 if (sessionOpen) { 73 166 targetFile.write(" </session>" + StringTools.ENDLINE); 74 167 targetFile.write(" <session>" + StringTools.ENDLINE); … … 77 170 sessionOpen = true; 78 171 } 79 } else if (currentLine.contains("UL: </session>")) {80 if (sessionOpen) {172 } else if (currentLine.contains("UL: </session>")) { 173 if (sessionOpen) { 81 174 targetFile.write(" </session>" + StringTools.ENDLINE); 82 175 sessionOpen = false; 83 176 } 84 } else if (msgIncomplete || currentLine.contains("UL: ")) {85 177 } else if (msgIncomplete || currentLine.contains("UL: ")) { 178 86 179 String currentContent; 87 180 String actualLine; 88 if ( msgIncomplete) {181 if (msgIncomplete) { 89 182 actualLine = currentLine; 90 183 } else { … … 92 185 actualLine = splitResult[1]; 93 186 } 94 if ( base64) {187 if (base64) { 95 188 Base64 decoder = new Base64(); 96 189 byte[] decoded = decoder.decode(actualLine); 97 190 currentContent = new String(decoded, "UTF-16LE"); 98 currentContent = currentContent.substring(0, currentContent.length()-1); 191 currentContent = currentContent.substring(0, 192 currentContent.length() - 1); 99 193 } else { 100 194 currentContent = actualLine; 101 195 } 102 if ( msgIncomplete) {196 if (msgIncomplete) { 103 197 incompleteLine += currentContent; 104 if ( incompleteLine.contains("</msg>")) {198 if (incompleteLine.contains("</msg>")) { 105 199 msgIncomplete = false; 106 200 targetFile.write(incompleteLine + StringTools.ENDLINE); … … 108 202 } 109 203 } else { 110 if( currentContent.contains("<msg") && sessionOpen ) { 111 if( currentContent.contains("</msg>") ) { 112 targetFile.write(" " + currentContent + StringTools.ENDLINE); 204 if (currentContent.contains("<msg") && sessionOpen) { 205 if (currentContent.contains("</msg>")) { 206 targetFile.write(" " + currentContent 207 + StringTools.ENDLINE); 113 208 } else { 114 209 msgIncomplete = true; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/MFCReplayDecorator.java
r98 r171 4 4 import de.ugoe.cs.util.StringTools; 5 5 6 /** 7 * <p> 8 * {@link IReplayDecorator} for replay generated for EventBench's MFCReplay tool. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 */ 6 14 public class MFCReplayDecorator implements IReplayDecorator { 7 15 8 16 /** 17 * <p> 9 18 * Id for object serialization. 19 * </p> 10 20 */ 11 21 private static final long serialVersionUID = 1L; 12 22 23 /** 24 * <p> 25 * The instance of the {@link MFCReplayDecorator} (implemented as 26 * singleton). 27 * </p> 28 */ 13 29 transient private static MFCReplayDecorator theInstance; 14 15 private MFCReplayDecorator() {}; 16 30 31 /** 32 * <p> 33 * Constructor. Private to guarantee that only one instance of the replay 34 * generator exists. 35 * </p> 36 */ 37 private MFCReplayDecorator() { 38 }; 39 40 /** 41 * <p> 42 * Returns the instance of the MFCReplayDecorator. 43 * </p> 44 * 45 * @return instance of the MFCReplayDecorator. 46 */ 17 47 public static MFCReplayDecorator getInstance() { 18 if ( theInstance==null) {48 if (theInstance == null) { 19 49 theInstance = new MFCReplayDecorator(); 20 50 } 21 51 return theInstance; 22 52 } 23 53 54 /* 55 * (non-Javadoc) 56 * 57 * @see de.ugoe.cs.eventbench.IReplayDecorator#getHeader() 58 */ 24 59 @Override 25 60 public String getHeader() { 26 return "<?xml version=\"1.0\" encoding=\"UTF-16\"?>" + StringTools.ENDLINE +27 28 61 return "<?xml version=\"1.0\" encoding=\"UTF-16\"?>" 62 + StringTools.ENDLINE + "<log>" + StringTools.ENDLINE; 63 29 64 } 30 65 66 /* 67 * (non-Javadoc) 68 * 69 * @see de.ugoe.cs.eventbench.IReplayDecorator#getFooter() 70 */ 31 71 @Override 32 72 public String getFooter() { … … 34 74 } 35 75 76 /* 77 * (non-Javadoc) 78 * 79 * @see de.ugoe.cs.eventbench.IReplayDecorator#getSessionHeader(int) 80 */ 36 81 @Override 37 82 public String getSessionHeader(int sessionId) { 38 return " <session id=\"" +sessionId+"\">" + StringTools.ENDLINE;83 return " <session id=\"" + sessionId + "\">" + StringTools.ENDLINE; 39 84 } 40 85 86 /* 87 * (non-Javadoc) 88 * 89 * @see de.ugoe.cs.eventbench.IReplayDecorator#getSessionFooter(int) 90 */ 41 91 @Override 42 92 public String getSessionFooter(int sessionId) { 43 93 return " </session>" + StringTools.ENDLINE; 44 94 } 45 46 95 47 96 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/MessageDefs.java
r76 r171 1 1 package de.ugoe.cs.eventbench.windows; 2 2 3 /** 4 * <p> 5 * Contains definitions of windows message codes, such that they can be used 6 * internally by their name and not their integer value, to improve the 7 * readability of the source code. 8 * </p> 9 * 10 * @author Steffen Herbold 11 * @version 1.0 12 */ 3 13 public interface MessageDefs { 4 14 5 15 public static final int WM_NULL = 0; 6 16 public static final int WM_CREATE = 1; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/MessageHandler.java
r75 r171 1 1 package de.ugoe.cs.eventbench.windows; 2 2 3 /** 4 * <p> 5 * Base class to define custom message handlers, for messages that shall be 6 * handled differently during the parsing of usage logs. It provides dummy 7 * implementations for all required methods, such that implementations can only 8 * overwrite the parts they actually require and ignore the rest. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 */ 14 public class MessageHandler { 3 15 4 public class MessageHandler { 5 6 protected MessageHandler() {} 7 8 public void onStartElement() {} 9 public void onParameter(String name, String value) {} 10 public void onEndElement() {} 16 /** 17 * <p> 18 * Constructor. Protected to prohibit initialization of the base class 19 * itself. 20 * </p> 21 */ 22 protected MessageHandler() { 23 } 24 25 /** 26 * <p> 27 * Called in the startElement() method of the {@link LogParser} when a 28 * msg-node begins. 29 * </p> 30 */ 31 public void onStartElement() { 32 } 33 34 /** 35 * <p> 36 * Called by the {@link LogParser} to handle param-nodes. 37 * </p> 38 * 39 * @param name 40 * name (type) of the parameter 41 * @param value 42 * value of the parameter 43 */ 44 public void onParameter(String name, String value) { 45 } 46 47 /** 48 * <p> 49 * Called in the endElement() method of {@link LogParser} when a msg-node 50 * ends. 51 * </p> 52 */ 53 public void onEndElement() { 54 } 11 55 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/SequenceSplitter.java
r77 r171 4 4 import java.util.List; 5 5 6 import de.ugoe.cs.eventbench.data.Event; 6 7 import de.ugoe.cs.eventbench.windows.data.WindowsMessage; 7 8 import de.ugoe.cs.util.console.Console; 8 9 10 /** 11 * <p> 12 * Responsible to split sequences into subsequences, such that each subsequences 13 * contains exactly one event. 14 * </p> 15 * 16 * @author Steffen Herbold 17 * @version 1.0 18 */ 9 19 public class SequenceSplitter { 10 20 21 /** 22 * <p> 23 * Contains the current subsequence. 24 * </p> 25 */ 11 26 private List<WindowsMessage> currentSequence; 12 27 28 /** 29 * <p> 30 * Number of messages in the current sequences, that signal that a key or 31 * mouse button has been pressed down to which not yet a message has been 32 * found, that signals that the button has been released. 33 * </p> 34 */ 13 35 private int openDowns; 14 36 37 /** 38 * <p> 39 * Internal flag that signals if {@link #currentSequence} needs to be 40 * initialized. 41 * </p> 42 */ 15 43 private boolean initMessages; 16 44 45 /** 46 * <p> 47 * The {@link EventGenerator} used to convert the subsequences into 48 * {@link Event}s 49 * </p> 50 */ 17 51 private EventGenerator tokenGenerator; 18 52 53 /** 54 * <p> 55 * The event sequence generated. 56 * </p> 57 */ 19 58 private List<WindowsEvent> actionSequence; 20 59 60 /** 61 * <p> 62 * Constructor. Creates a new SequenceSplitter. 63 * </p> 64 */ 21 65 public SequenceSplitter() { 22 66 currentSequence = new LinkedList<WindowsMessage>(); … … 26 70 actionSequence = new LinkedList<WindowsEvent>(); 27 71 } 28 72 73 /** 74 * <p> 75 * Called by the {@link LogParser} every time a message is parsed. 76 * </p> 77 * 78 * @param msg 79 * message to be added 80 */ 29 81 public void addMessage(WindowsMessage msg) { 30 if( startOfSequence(msg) ) { 31 if( !initMessages ) { 32 WindowsEvent currentAction = tokenGenerator.generateEvent(currentSequence); 33 if( currentAction!=null ) { 82 if (startOfSequence(msg)) { 83 if (!initMessages) { 84 WindowsEvent currentAction = tokenGenerator 85 .generateEvent(currentSequence); 86 if (currentAction != null) { 34 87 actionSequence.add(currentAction); 35 88 } 36 if ( isKeyMessage(msg.getType()) && openDowns>0) {89 if (isKeyMessage(msg.getType()) && openDowns > 0) { 37 90 Console.traceln("Key message found with open down mouse messages - will probabably result in a faulty sequence."); 38 91 } … … 41 94 } 42 95 currentSequence = new LinkedList<WindowsMessage>(); 43 } 44 if ( isUpMessage(msg.getType())) {45 if ( openDowns>0 ) {96 } 97 if (isUpMessage(msg.getType())) { 98 if (openDowns > 0) { 46 99 openDowns--; 47 100 } … … 49 102 currentSequence.add(msg); 50 103 } 51 104 105 /** 106 * <p> 107 * Returns the event sequence generated from the message that have been 108 * added. 109 * </p> 110 * 111 * @return generated event sequence 112 */ 52 113 public List<WindowsEvent> getSequence() { 53 114 return actionSequence; 54 115 } 55 116 117 /** 118 * <p> 119 * Called when a session in the log file is finished, i.e., a closing 120 * session-node is found. 121 * </p> 122 */ 56 123 public void endSession() { 57 WindowsEvent currentAction = tokenGenerator.generateEvent(currentSequence); 58 if( currentAction!=null ) { 124 WindowsEvent currentAction = tokenGenerator 125 .generateEvent(currentSequence); 126 if (currentAction != null) { 59 127 actionSequence.add(currentAction); 60 128 } 61 129 } 62 130 131 /** 132 * <p> 133 * Checks if the message starts a new subsequence and returns the result. 134 * </p> 135 * 136 * @param msg 137 * message that is checked 138 * @return true, if a new subsequence begins 139 */ 63 140 private boolean startOfSequence(WindowsMessage msg) { 64 141 boolean isStart = false; 65 142 int msgType = msg.getType(); 66 if ( isKeyMessage(msgType)) {143 if (isKeyMessage(msgType)) { 67 144 isStart = true; 68 145 } 69 if ( isDownMessage(msgType)) {146 if (isDownMessage(msgType)) { 70 147 openDowns++; 71 if ( openDowns==1) {148 if (openDowns == 1) { 72 149 isStart = true; 73 150 } 74 151 } 75 if ( isDblclkMessage(msgType)) {152 if (isDblclkMessage(msgType)) { 76 153 openDowns++; 77 154 } … … 79 156 } 80 157 158 /** 159 * <p> 160 * Checks if the type of a message is generated is a keyboard interaction. 161 * </p> 162 * 163 * @param msgType 164 * type of the message 165 * @return true if it is a keyboard interaction; false otherwise 166 */ 81 167 private boolean isKeyMessage(int msgType) { 82 168 boolean isKeyMsg = false; 83 169 switch (msgType) { 84 85 86 87 88 89 90 91 170 case MessageDefs.WM_KEYDOWN: 171 case MessageDefs.WM_KEYUP: 172 case MessageDefs.WM_SYSKEYDOWN: 173 case MessageDefs.WM_SYSKEYUP: 174 isKeyMsg = true; 175 break; 176 default: 177 break; 92 178 } 93 179 return isKeyMsg; 94 180 } 95 181 182 /** 183 * <p> 184 * Checks if the type of a message indicates that the mouse has been pressed 185 * down. 186 * </p> 187 * 188 * @param msgType 189 * type of the message 190 * @return true if it is mouse-down message; false otherwise 191 */ 96 192 private boolean isDownMessage(int msgType) { 97 193 boolean isDownMsg = false; 98 194 switch (msgType) { 99 100 101 102 103 104 105 106 107 108 109 110 195 case MessageDefs.WM_LBUTTONDOWN: 196 case MessageDefs.WM_RBUTTONDOWN: 197 case MessageDefs.WM_MBUTTONDOWN: 198 case MessageDefs.WM_XBUTTONDOWN: 199 case MessageDefs.WM_NCLBUTTONDOWN: 200 case MessageDefs.WM_NCRBUTTONDOWN: 201 case MessageDefs.WM_NCMBUTTONDOWN: 202 case MessageDefs.WM_NCXBUTTONDOWN: 203 isDownMsg = true; 204 break; 205 default: 206 break; 111 207 } 112 208 return isDownMsg; 113 209 } 114 210 211 /** 212 * <p> 213 * Checks if the type of a message indicates that a double click has been 214 * performed. 215 * </p> 216 * 217 * @param msgType 218 * type of the message 219 * @return true if it is a double click message; false otherwise 220 */ 115 221 private boolean isDblclkMessage(int msgType) { 116 222 boolean isDblclkMsg = false; 117 223 switch (msgType) { 118 119 120 121 122 123 124 125 126 127 128 129 224 case MessageDefs.WM_LBUTTONDBLCLK: 225 case MessageDefs.WM_RBUTTONDBLCLK: 226 case MessageDefs.WM_MBUTTONDBLCLK: 227 case MessageDefs.WM_XBUTTONDBLCLK: 228 case MessageDefs.WM_NCLBUTTONDBLCLK: 229 case MessageDefs.WM_NCRBUTTONDBLCLK: 230 case MessageDefs.WM_NCMBUTTONDBLCLK: 231 case MessageDefs.WM_NCXBUTTONDBLCLK: 232 isDblclkMsg = true; 233 break; 234 default: 235 break; 130 236 } 131 237 return isDblclkMsg; 132 238 } 133 239 240 /** 241 * <p> 242 * Checks if the type of a message indicates that the mouse has been 243 * released. 244 * </p> 245 * 246 * @param msgType 247 * type of the message 248 * @return true if it is mouse-up message; false otherwise 249 */ 134 250 private boolean isUpMessage(int msgType) { 135 251 boolean isUpMsg = false; 136 252 switch (msgType) { 137 138 139 140 141 142 143 144 145 146 147 148 253 case MessageDefs.WM_LBUTTONUP: 254 case MessageDefs.WM_RBUTTONUP: 255 case MessageDefs.WM_MBUTTONUP: 256 case MessageDefs.WM_XBUTTONUP: 257 case MessageDefs.WM_NCLBUTTONUP: 258 case MessageDefs.WM_NCRBUTTONUP: 259 case MessageDefs.WM_NCMBUTTONUP: 260 case MessageDefs.WM_NCXBUTTONUP: 261 isUpMsg = true; 262 break; 263 default: 264 break; 149 265 } 150 266 return isUpMsg; 151 267 } 152 268 153 269 } -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/WindowsEvent.java
r87 r171 4 4 import de.ugoe.cs.eventbench.windows.data.WindowsMessage; 5 5 6 7 // convenience class 6 /** 7 * <p> 8 * Convenience class for working with Windows MFC events. 9 * </p> 10 * 11 * @author Steffen Herbold 12 * @version 1.0 13 */ 8 14 public class WindowsEvent extends ReplayableEvent<WindowsMessage> { 9 15 10 16 /** 17 * <p> 11 18 * Id for object serialization. 19 * </p> 12 20 */ 13 21 private static final long serialVersionUID = 1L; 14 22 23 /** 24 * <p> 25 * Constructor. Creates a new WindowEvent. 26 * </p> 27 * 28 * @see de.ugoe.cs.eventbench.data.Event#Event(String) 29 * @param type 30 * type of the event. 31 */ 15 32 public WindowsEvent(String type) { 16 33 super(type); -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/commands/CMDconvertDirToXml.java
r52 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command to pre-process all files in a folder. 15 * </p> 16 * 17 * @author Steffen Herbold 18 * @version 1.0 19 */ 12 20 public class CMDconvertDirToXml implements Command { 13 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see de.ugoe.cs.util.console.Command#help() 26 */ 14 27 @Override 15 28 public void help() { … … 17 30 } 18 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 36 */ 19 37 @Override 20 38 public void run(List<Object> parameters) { 21 if ( parameters.size() < 2) {39 if (parameters.size() < 2) { 22 40 throw new InvalidParameterException(); 23 41 } … … 25 43 String target = (String) parameters.get(1); 26 44 boolean base64 = false; 27 if ( parameters.size() == 3) {45 if (parameters.size() == 3) { 28 46 base64 = Boolean.parseBoolean((String) parameters.get(2)); 29 47 } 30 48 31 49 try { 32 50 new LogPreprocessor(base64).convertDirToXml(path, target); … … 36 54 Console.println(e.getMessage()); 37 55 } 38 56 39 57 } 40 58 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/commands/CMDconvertToXml.java
r52 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command to pre-process a single file. 15 * </p> 16 * 17 * @author Steffen Herbold 18 * @version 1.0 19 */ 12 20 public class CMDconvertToXml implements Command { 13 21 22 /* 23 * (non-Javadoc) 24 * 25 * @see de.ugoe.cs.util.console.Command#help() 26 */ 14 27 @Override 15 28 public void help() { … … 17 30 } 18 31 32 /* 33 * (non-Javadoc) 34 * 35 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 36 */ 19 37 @Override 20 38 public void run(List<Object> parameters) { 21 if ( parameters.size() < 2) {39 if (parameters.size() < 2) { 22 40 throw new InvalidParameterException(); 23 41 } … … 25 43 String target = (String) parameters.get(1); 26 44 boolean base64 = false; 27 if ( parameters.size() == 3) {45 if (parameters.size() == 3) { 28 46 base64 = Boolean.parseBoolean((String) parameters.get(2)); 29 47 } 30 48 31 49 try { 32 50 new LogPreprocessor(base64).convertToXml(source, target); … … 36 54 Console.println(e.getMessage()); 37 55 } 38 56 39 57 } 40 58 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/commands/CMDparseXML.java
r84 r171 10 10 import de.ugoe.cs.util.console.Console; 11 11 12 /** 13 * <p> 14 * Command to parse an XML file with sessions monitored by EventBench's 15 * MFCUsageMonitor. 16 * </p> 17 * 18 * @author Steffen Herbold 19 * @version 1.0 20 */ 12 21 public class CMDparseXML implements Command { 13 22 23 /* (non-Javadoc) 24 * @see de.ugoe.cs.util.console.Command#help() 25 */ 14 26 @Override 15 27 public void help() { … … 17 29 } 18 30 31 /* (non-Javadoc) 32 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 33 */ 19 34 @Override 20 35 public void run(List<Object> parameters) { 21 36 String filename; 22 37 boolean countMessageOccurences = false; 23 38 24 39 try { 25 40 filename = (String) parameters.get(0); 26 if( parameters.size()==2 ) { 27 countMessageOccurences = Boolean.parseBoolean((String) parameters.get(1)); 41 if (parameters.size() == 2) { 42 countMessageOccurences = Boolean 43 .parseBoolean((String) parameters.get(1)); 28 44 } 29 45 } catch (Exception e) { 30 46 throw new InvalidParameterException(); 31 47 } 32 48 33 49 LogParser parser = new LogParser(countMessageOccurences); 34 50 parser.parseFile(filename); 35 51 36 52 List<List<WindowsEvent>> sequences = parser.getSequences(); 37 38 if ( GlobalDataContainer.getInstance().addData("sequences", sequences )) {53 54 if (GlobalDataContainer.getInstance().addData("sequences", sequences)) { 39 55 Console.traceln("Old data \"" + "sequences" + "\" overwritten"); 40 } 56 } 41 57 } 42 58 -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/data/WindowTree.java
r157 r171 28 28 * 29 29 * @author Steffen Herbold 30 * @version 1.0 30 31 */ 31 32 public class WindowTree { -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/data/WindowTreeNode.java
r52 r171 18 18 * 19 19 * @author Steffen Herbold 20 * @version 1.0 20 21 */ 21 22 public class WindowTreeNode { … … 69 70 */ 70 71 private List<WindowTreeNode> children; 71 72 72 73 /** 73 74 * <p> … … 263 264 xmlString = parent.xmlRepresentation(); 264 265 } 265 xmlString += "<window name=\"" + StringTools.xmlEntityReplacement(windowName) + "\" class=\"" 266 + StringTools.xmlEntityReplacement(className) + "\" resourceId=\"" + resourceId + "\" isModal=\"" 267 + isModal + "\"/>"; 266 xmlString += "<window name=\"" 267 + StringTools.xmlEntityReplacement(windowName) + "\" class=\"" 268 + StringTools.xmlEntityReplacement(className) 269 + "\" resourceId=\"" + resourceId + "\" isModal=\"" + isModal 270 + "\"/>"; 268 271 return xmlString; 269 272 } 270 273 274 /** 275 * <p> 276 * Returns the names of the parents and itself separated by dots, e.g., 277 * "GrandParent.Parent.windowName" 278 * </p> 279 * 280 * @return names of the parents separated by dots 281 */ 271 282 public String getParentNames() { 272 283 String parentNames = ""; 273 if (parent != null 274 parentNames = parent.getParentNames() +".";284 if (parent != null) { 285 parentNames = parent.getParentNames() + "."; 275 286 } 276 287 parentNames += windowName; -
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/windows/data/WindowsMessage.java
r141 r171 8 8 import de.ugoe.cs.util.StringTools; 9 9 10 /** 11 * <p> 12 * Contains all informations about a windows message, i.e., all parameters that 13 * are read when a windows message is parsed as well as its target, hwnd, etc. 14 * </p> 15 * 16 * @author Steffen Herbold 17 * @version 1.0 18 * 19 */ 10 20 public class WindowsMessage implements IReplayable { 11 /** 12 * Id for object serialization. 21 22 /** 23 * <p> 24 * Id for object serialization. 25 * </p> 13 26 */ 14 27 private static final long serialVersionUID = 1L; 15 28 29 /** 30 * <p> 31 * Type of the message. 32 * </p> 33 */ 16 34 final int type; 35 36 /** 37 * <p> 38 * Window class of the message target. Default: "" 39 * </p> 40 */ 17 41 private String windowClass = ""; 42 43 /** 44 * <p> 45 * Resource Id of the message target. Default: 0 46 * </p> 47 */ 18 48 private int resourceId = 0; 49 50 /** 51 * <p> 52 * XML representation of the message target. 53 * </p> 54 */ 19 55 private String xmlWindowDescription = ""; 56 57 /** 58 * <p> 59 * String that contains the names of all parent widgets and itself, separated by dots, 60 * e.g., "GrandParent.Parent.self". 61 * </p> 62 */ 20 63 private String parentNames = null; 64 65 /** 66 * <p> 67 * String that contains the window class of the parent widget. 68 * </p> 69 */ 21 70 private String parentClass = null; 22 71 72 /** 73 * <p> 74 * LPARAM of the message. Default: 0 75 * </p> 76 */ 23 77 private long LPARAM = 0; 78 79 /** 80 * <p> 81 * WPARAM of the message. Default: 0 82 * </p> 83 */ 24 84 private long WPARAM = 0; 25 85 86 /** 87 * <p> 88 * If the LPARAM contains a HWND, this string stores the target of the HWND. 89 * </p> 90 */ 26 91 private String LPARAMasWindowDesc = null; 92 93 /** 94 * <p> 95 * If the WPARAM contains a HWND, this string stores the target of the HWND. 96 * </p> 97 */ 27 98 private String WPARAMasWindowDesc = null; 28 99 100 /** 101 * <p> 102 * Delay after sending the messages during a replay. Default: 0 103 * </p> 104 */ 29 105 private int delay = 0; 30 106 107 /** 108 * <p> 109 * A map of all parameters, associated with the message, created during the 110 * parsing of messages from the logs {@code param}-nodes. 111 * </p> 112 */ 31 113 private Map<String, String> params = new HashMap<String, String>(); 32 114 115 /** 116 * <p> 117 * Constructor. Creates a new message with a given message type. 118 * </p> 119 * 120 * @param type 121 * type of the message 122 */ 33 123 public WindowsMessage(int type) { 34 124 this.type = type; 35 125 } 36 126 127 /** 128 * <p> 129 * Adds a parameter to the message. 130 * </p> 131 * 132 * @param type 133 * type descriptor of the parameter 134 * @param value 135 * value of the parameter 136 */ 37 137 public void addParameter(String type, String value) { 38 138 params.put(type, value); … … 44 144 } 45 145 146 /** 147 * <p> 148 * Returns the type of the message. 149 * </p> 150 * 151 * @return type of the message 152 */ 46 153 public int getType() { 47 154 return type; 48 155 } 49 156 157 /** 158 * <p> 159 * Returns the value of a parameter, given its type. If the parameter is not 160 * found, {@code null} is returned. 161 * </p> 162 * 163 * @param type 164 * type of the parameter 165 * @return value of the parameter 166 */ 50 167 public String getParameter(String type) { 51 168 return params.get(type); 52 169 } 53 170 171 /** 172 * <p> 173 * Returns the window class of the message target. 174 * </p> 175 * 176 * @return window class of the message target 177 */ 54 178 public String getWindowClass() { 55 179 return windowClass; 56 180 } 57 181 182 /** 183 * <p> 184 * Returns the HWND the message is addressed to. 185 * </p> 186 * 187 * @return HWND the message is addressed to 188 */ 58 189 public int getHwnd() { 59 190 int hwnd = -1; … … 67 198 } 68 199 200 /** 201 * <p> 202 * Returns the resource Id of the message target. 203 * </p> 204 * 205 * @return resource Id of the message target 206 */ 69 207 public int getWindowResourceId() { 70 208 return resourceId; 71 209 } 72 210 211 /** 212 * <p> 213 * Two {@link WindowsMessage} are equal, if their {@link #type}, 214 * {@link #xmlWindowDescription}, and {@link #params} are equal. 215 * </p> 216 * 217 * @see java.lang.Object#equals(java.lang.Object) 218 */ 73 219 @Override 74 220 public boolean equals(Object other) { 75 if ( other==this) {221 if (other == this) { 76 222 return true; 77 223 } … … 86 232 } 87 233 234 /* 235 * (non-Javadoc) 236 * 237 * @see java.lang.Object#hashCode() 238 */ 88 239 @Override 89 240 public int hashCode() { … … 98 249 } 99 250 251 /** 252 * <p> 253 * Returns a string representation of the message of the form 254 * "msg[target=HWND;type=TYPE]". 255 * </p> 256 * 257 * @see java.lang.Object#toString() 258 */ 100 259 @Override 101 260 public String toString() { … … 104 263 } 105 264 265 /** 266 * <p> 267 * Retrieves the target string of a message from a given {@link WindowTree} 268 * through looking up the HWND the message is addressed to in the window 269 * tree. 270 * </p> 271 * 272 * @param windowTree 273 * {@link WindowTree} from which the target is extracted 274 * @throws InvalidParameterException 275 * thrown if HWND is not contained in windowTree 276 */ 106 277 public void setTarget(WindowTree windowTree) 107 278 throws InvalidParameterException { … … 117 288 parentNames = node.getParentNames(); 118 289 WindowTreeNode parent = node.getParent(); 119 if ( parent==null) {290 if (parent == null) { 120 291 parentClass = ""; 121 292 } else { … … 125 296 } 126 297 298 /** 299 * <p> 300 * Sets the LPARAM of a message. 301 * </p> 302 * 303 * @param paramValue 304 * value of the LPARAM 305 */ 127 306 public void setLPARAM(long paramValue) { 128 307 LPARAM = paramValue; 129 308 } 130 309 310 /** 311 * <p> 312 * Sets the WPARAM of a message. 313 * </p> 314 * 315 * @param paramValue 316 * value of the WPARAM 317 */ 131 318 public void setWPARAM(long paramValue) { 132 319 WPARAM = paramValue; 133 320 } 134 321 322 /** 323 * <p> 324 * Returns the LPARAM of a message. 325 * </p> 326 * 327 * @return LPARAM of the message 328 */ 135 329 public long getLPARAM() { 136 330 return LPARAM; 137 331 } 138 332 333 /** 334 * <p> 335 * Returns the WPARAM of a message. 336 * </p> 337 * 338 * @return WPARAM of the message 339 */ 139 340 public long getWPARAM() { 140 341 return WPARAM; 141 342 } 142 343 344 /** 345 * <p> 346 * If the LPARAM contains a HWND, this function can be used to set a target 347 * string to identify the HWND at run-time. 348 * </p> 349 * 350 * @param windowDesc 351 * target string 352 */ 143 353 public void setLPARAMasWindowDesc(String windowDesc) { 144 354 LPARAMasWindowDesc = windowDesc; 145 355 } 146 356 357 /** 358 * <p> 359 * If the WPARAM contains a HWND, this function can be used to set a target 360 * string to identify the HWND at run-time. 361 * </p> 362 * 363 * @param windowDesc 364 * target string 365 */ 147 366 public void setWPARAMasWindowDesc(String windowDesc) { 148 367 WPARAMasWindowDesc = windowDesc; 149 368 } 150 369 370 /** 371 * <p> 372 * If the LPARAM contains a HWND and the target string for the HWND is set, 373 * this function returns the target string. Otherwise, {@code null} is 374 * returned. 375 * </p> 376 * 377 * @return target string if available; {@code null} otherwise 378 */ 151 379 public String getLPARAMasWindowDesc() { 152 380 return LPARAMasWindowDesc; 153 381 } 154 382 383 /** 384 * <p> 385 * If the WPARAM contains a HWND and the target string for the HWND is set, 386 * this function returns the target string. Otherwise, {@code null} is 387 * returned. 388 * </p> 389 * 390 * @return target string if available; {@code null} otherwise 391 */ 155 392 public String getWPARAMasWindowDesc() { 156 393 return WPARAMasWindowDesc; 157 394 } 158 395 396 /** 397 * <p> 398 * Returns the target string of the message. 399 * </p> 400 * 401 * @return target string of the message 402 */ 159 403 public String getXmlWindowDescription() { 160 404 return xmlWindowDescription; 161 405 } 162 406 407 /** 408 * <p> 409 * Sets the target string manually. 410 * </p> 411 * 412 * @param xmlWindowDescription 413 * target string 414 */ 163 415 public void setXmlWindowDescription(String xmlWindowDescription) { 164 416 this.xmlWindowDescription = xmlWindowDescription; 165 417 } 166 418 419 /** 420 * <p> 421 * Returns the delay after this message during replays. 422 * </p> 423 * 424 * @return delay after this message 425 */ 167 426 public int getDelay() { 168 427 return delay; 169 428 } 170 429 430 /** 431 * <p> 432 * Sets the delay after this message during replays. 433 * </p> 434 * 435 * @param delay 436 * delay after this message 437 */ 171 438 public void setDelay(int delay) { 172 439 this.delay = delay; 173 440 } 174 441 442 /** 443 * <p> 444 * Returns the parent names separated by dots, e.g., "GrandParent.Parent". 445 * </p> 446 * 447 * @return names of the parents 448 */ 175 449 public String getParentNames() { 176 450 return parentNames; 177 451 } 178 452 453 /** 454 * <p> 455 * Returns the window class of the parent. 456 * </p> 457 * 458 * @return window classes of the parents 459 */ 179 460 public String getParentClass() { 180 461 return parentClass; 181 462 } 182 463 464 /** 465 * <p> 466 * Returns the number of parameters stored together with this message. 467 * </p> 468 * 469 * @return 470 */ 183 471 public int getNumParams() { 184 472 return params.size(); 185 473 } 186 474 475 /* 476 * (non-Javadoc) 477 * 478 * @see de.ugoe.cs.eventbench.data.IReplayable#getReplay() 479 */ 480 @Override 187 481 public String getReplay() { 188 482 StringBuilder currentMsgStr = new StringBuilder(400); 189 currentMsgStr.append(" <msg type=\"" +type+"\" ");190 currentMsgStr.append("LPARAM=\"" +LPARAM+"\" ");191 currentMsgStr.append("WPARAM=\"" +WPARAM+"\" ");192 currentMsgStr.append("delay=\"" +delay+"\">");193 if ( LPARAMasWindowDesc!=null) {483 currentMsgStr.append(" <msg type=\"" + type + "\" "); 484 currentMsgStr.append("LPARAM=\"" + LPARAM + "\" "); 485 currentMsgStr.append("WPARAM=\"" + WPARAM + "\" "); 486 currentMsgStr.append("delay=\"" + delay + "\">"); 487 if (LPARAMasWindowDesc != null) { 194 488 currentMsgStr.append(StringTools.ENDLINE); 195 489 currentMsgStr.append(" <LPARAM>"); … … 198 492 currentMsgStr.append(StringTools.ENDLINE); 199 493 currentMsgStr.append("</LPARAM>"); 200 } 201 if ( WPARAMasWindowDesc!=null) {494 } 495 if (WPARAMasWindowDesc != null) { 202 496 currentMsgStr.append(StringTools.ENDLINE); 203 497 currentMsgStr.append(" <WPARAM>"); … … 214 508 return currentMsgStr.toString(); 215 509 } 216 510 511 /* 512 * (non-Javadoc) 513 * 514 * @see de.ugoe.cs.eventbench.data.IReplayable#getTarget() 515 */ 516 @Override 217 517 public String getTarget() { 218 518 return xmlWindowDescription;
Note: See TracChangeset
for help on using the changeset viewer.