- Timestamp:
- 08/17/12 09:21:33 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-assertions/src/main/java/de/ugoe/cs/quest/assertions/FileEqualsReplay.java
r559 r560 4 4 import java.security.InvalidParameterException; 5 5 6 import de.ugoe.cs.quest.IReplayDecorator; 6 7 import de.ugoe.cs.quest.eventcore.IReplayable; 7 8 import de.ugoe.cs.util.StringTools; … … 79 80 } 80 81 82 /* 83 * (non-Javadoc) 84 * 85 * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator() 86 */ 87 @Override 88 public IReplayDecorator getDecorator() { 89 return null; 90 } 91 81 92 } -
trunk/quest-core-assertions/src/main/java/de/ugoe/cs/quest/assertions/TextEqualsReplay.java
r559 r560 4 4 import java.security.InvalidParameterException; 5 5 6 import de.ugoe.cs.quest.IReplayDecorator; 6 7 import de.ugoe.cs.quest.eventcore.IReplayable; 7 8 import de.ugoe.cs.util.StringTools; … … 92 93 } 93 94 95 /* 96 * (non-Javadoc) 97 * 98 * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator() 99 */ 100 @Override 101 public IReplayDecorator getDecorator() { 102 return null; 103 } 104 94 105 } -
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/IReplayable.java
r541 r560 2 2 3 3 import java.io.Serializable; 4 5 import de.ugoe.cs.quest.IReplayDecorator; 4 6 5 7 /** … … 24 26 */ 25 27 String getReplay(); 28 29 /** 30 * <p> 31 * Returns the replay decorator associated with the replayable. Returns null if no replay decorator is associated with the replayable. 32 * </p> 33 * 34 * @return replay decorator 35 */ 36 IReplayDecorator getDecorator(); 26 37 } -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ReplayGenerator.java
r547 r560 1 1 2 package de.ugoe.cs.quest; 2 3 … … 16 17 /** 17 18 * <p> 18 * This class provides the functionality to generate replay files from sequences 19 * if{@link ReplayableEvent}s.19 * This class provides the functionality to generate replay files from sequences if 20 * {@link ReplayableEvent}s. 20 21 * </p> 21 22 * 22 * TODO: Figure our how to handle {@link IReplayDecorator}23 23 * TODO: Add appropriate checks if Events are replayable 24 24 * … … 28 28 public class ReplayGenerator { 29 29 30 31 32 * {@link IReplayDecorator} to be used. If this field is {@code null}, no 33 * decorator is used.Default: {@code null}34 35 36 30 /** 31 * <p> 32 * {@link IReplayDecorator} to be used. If this field is {@code null}, no decorator is used. 33 * Default: {@code null} 34 * </p> 35 */ 36 private IReplayDecorator decorator = null; 37 37 38 39 40 41 42 43 38 /** 39 * <p> 40 * Id of the current session. The starting id is 1. 41 * </p> 42 */ 43 int sessionId = 1; 44 44 45 /** 46 * <p> 47 * Creates a replay file that contains multiple event sequences. 48 * </p> 49 * 50 * @param sequences 51 * collection of event sequences from which the sessions are 52 * generated 53 * @param filename 54 * name and path of the replay file 55 */ 56 public void createLogfileMultipleSessions( 57 Collection<List<Event>> sequences, String filename) { 58 OutputStreamWriter writer = openReplayFile(filename); 59 if (writer != null) { 60 try { 61 decorator = sequences.iterator().next().get(0).getReplayDecorator(); 62 if (decorator != null) { 63 writer.write(decorator.getHeader()); 64 } 65 for (List<Event> actions : sequences) { 66 writeSession(actions, writer); 67 } 68 if (decorator != null) { 69 writer.write(decorator.getFooter()); 70 } 71 decorator = null; 72 writer.close(); 73 } catch (IOException e) { 74 Console.printerrln("Unable to write replay file " + filename); 75 } 76 } 77 } 45 /** 46 * <p> 47 * Creates a replay file that contains multiple event sequences. 48 * </p> 49 * 50 * @param sequences 51 * collection of event sequences from which the sessions are generated 52 * @param filename 53 * name and path of the replay file 54 */ 55 public void createLogfileMultipleSessions(Collection<List<Event>> sequences, String filename) { 56 OutputStreamWriter writer = openReplayFile(filename); 57 if (writer != null) { 58 try { 59 try { 60 decorator = 61 sequences.iterator().next().get(0).getReplayables().get(0).getDecorator(); 62 } 63 catch (Exception e) { 64 // in the above line, many things can go wrong: emtpy sequences, null 65 // references, etc. However, all failures just indicate that no replay decorator 66 // should be used, hence, we ignore the exception 67 } 68 if (decorator != null) { 69 writer.write(decorator.getHeader()); 70 } 71 for (List<Event> actions : sequences) { 72 writeSession(actions, writer); 73 } 74 if (decorator != null) { 75 writer.write(decorator.getFooter()); 76 } 77 decorator = null; 78 writer.close(); 79 } 80 catch (IOException e) { 81 Console.printerrln("Unable to write replay file " + filename); 82 } 83 } 84 } 78 85 79 /** 80 * <p> 81 * Creates a replay file that from a single event sequence. 82 * </p> 83 * 84 * @param actions 85 * event sequence from which the sessions are generated 86 * @param filename 87 * name and path of the replay file 88 */ 89 public void createLogfileSingleSession(List<Event> actions, 90 String filename) { 91 OutputStreamWriter writer = openReplayFile(filename); 92 if (writer != null) { 93 try { 94 actions.get(0).getReplayDecorator(); 95 if (decorator != null) { 96 writer.write(decorator.getHeader()); 97 } 98 writeSession(actions, writer); 99 if (decorator != null) { 100 writer.write(decorator.getFooter()); 101 } 102 decorator = null; 103 writer.close(); 104 } catch (IOException e) { 105 Console.printerrln("Unable to write replay file " + filename); 106 } 107 } 108 } 86 /** 87 * <p> 88 * Creates a replay file that from a single event sequence. 89 * </p> 90 * 91 * @param actions 92 * event sequence from which the sessions are generated 93 * @param filename 94 * name and path of the replay file 95 */ 96 public void createLogfileSingleSession(List<Event> actions, String filename) { 97 OutputStreamWriter writer = openReplayFile(filename); 98 if (writer != null) { 99 try { 100 try { 101 decorator = actions.get(0).getReplayables().get(0).getDecorator(); 102 } 103 catch (Exception e) { 104 // in the above line, many things can go wrong: emtpy sequences, null 105 // references, etc. However, all failures just indicate that no replay decorator 106 // should be used, hence, we ignore the exception 107 } 108 if (decorator != null) { 109 writer.write(decorator.getHeader()); 110 } 111 writeSession(actions, writer); 112 if (decorator != null) { 113 writer.write(decorator.getFooter()); 114 } 115 decorator = null; 116 writer.close(); 117 } 118 catch (IOException e) { 119 Console.printerrln("Unable to write replay file " + filename); 120 } 121 } 122 } 109 123 110 /** 111 * <p> 112 * Helper function that opens the replay file for writing. 113 * </p> 114 * 115 * @param filename 116 * name and path of the replay file 117 * @return {@link OutputStreamWriter} that writes to the replay file 118 */ 119 private OutputStreamWriter openReplayFile(String filename) { 120 File file = new File(filename); 121 boolean fileCreated; 122 try { 123 fileCreated = file.createNewFile(); 124 if (!fileCreated) { 125 Console.traceln("Created logfile " + filename); 126 } else { 127 Console.traceln("Overwrote existing logfile " + filename); 128 } 129 } catch (IOException e) { 130 Console.printerrln("Unable to create file " + filename); 131 Console.logException(e); 132 } 133 OutputStreamWriter writer = null; 134 try { 135 writer = new OutputStreamWriter(new FileOutputStream(file), 136 "UTF-16"); 137 } catch (IOException e) { 138 Console.printerrln("Unable to open file for writing (read-only file):" 139 + filename); 140 Console.logException(e); 141 } 142 return writer; 143 } 124 /** 125 * <p> 126 * Helper function that opens the replay file for writing. 127 * </p> 128 * 129 * @param filename 130 * name and path of the replay file 131 * @return {@link OutputStreamWriter} that writes to the replay file 132 */ 133 private OutputStreamWriter openReplayFile(String filename) { 134 File file = new File(filename); 135 boolean fileCreated; 136 try { 137 fileCreated = file.createNewFile(); 138 if (!fileCreated) { 139 Console.traceln("Created logfile " + filename); 140 } 141 else { 142 Console.traceln("Overwrote existing logfile " + filename); 143 } 144 } 145 catch (IOException e) { 146 Console.printerrln("Unable to create file " + filename); 147 Console.logException(e); 148 } 149 OutputStreamWriter writer = null; 150 try { 151 writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-16"); 152 } 153 catch (IOException e) { 154 Console.printerrln("Unable to open file for writing (read-only file):" + filename); 155 Console.logException(e); 156 } 157 return writer; 158 } 144 159 145 /** 146 * <p> 147 * Helper function that adds an event sequence to the replay. 148 * </p> 149 * 150 * @param actions 151 * event sequences to be added 152 * @param writer 153 * {@link OutputStreamWriter} to which the replay is added 154 * @throws IOException 155 * thrown if there is a problem writing to writer 156 */ 157 private void writeSession(List<Event> actions, 158 OutputStreamWriter writer) throws IOException { 159 if (decorator != null) { 160 writer.write(decorator.getSessionHeader(sessionId)); 161 } 162 for (Event currentAction : actions) { 160 /** 161 * <p> 162 * Helper function that adds an event sequence to the replay. 163 * </p> 164 * 165 * @param actions 166 * event sequences to be added 167 * @param writer 168 * {@link OutputStreamWriter} to which the replay is added 169 * @throws IOException 170 * thrown if there is a problem writing to writer 171 */ 172 private void writeSession(List<Event> actions, OutputStreamWriter writer) throws IOException { 173 if (decorator != null) { 174 writer.write(decorator.getSessionHeader(sessionId)); 175 } 176 for (Event currentAction : actions) { 163 177 164 List<? extends IReplayable> replayables = currentAction 165 .getReplayMessages(); 166 for (IReplayable replayble : replayables) { 167 writer.write(replayble.getReplay() + StringTools.ENDLINE); 168 writer.flush(); 169 } 170 } 171 if (decorator != null) { 172 writer.write(decorator.getSessionFooter(sessionId)); 173 } 174 sessionId++; 175 } 178 List<? extends IReplayable> replayables = currentAction.getReplayables(); 179 for (IReplayable replayble : replayables) { 180 writer.write(replayble.getReplay() + StringTools.ENDLINE); 181 writer.flush(); 182 } 183 } 184 if (decorator != null) { 185 writer.write(decorator.getSessionFooter(sessionId)); 186 } 187 sessionId++; 188 } 176 189 177 190 } -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/guitar/eventcore/GUITARReplayable.java
r556 r560 1 1 2 package de.ugoe.cs.quest.plugin.guitar.eventcore; 2 3 4 import de.ugoe.cs.quest.IReplayDecorator; 3 5 import de.ugoe.cs.quest.eventcore.IReplayable; 6 import de.ugoe.cs.quest.plugin.guitar.EFGReplayDecorator; 4 7 import de.ugoe.cs.util.StringTools; 5 8 … … 14 17 public class GUITARReplayable implements IReplayable { 15 18 16 17 18 19 20 21 19 /** 20 * <p> 21 * EventId in the EFG and GUI files. 22 * </p> 23 */ 24 String eventId; 22 25 23 24 25 26 27 28 26 /** 27 * <p> 28 * Id for object serialization. 29 * </p> 30 */ 31 private static final long serialVersionUID = 1L; 29 32 30 31 32 33 34 35 36 37 38 39 33 /** 34 * <p> 35 * Constructor. Creates a new {@link GUITARReplayable}. 36 * </p> 37 * 38 * @param eventId 39 */ 40 public GUITARReplayable(String eventId) { 41 this.eventId = eventId; 42 } 40 43 41 /* 42 * (non-Javadoc) 43 * 44 * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() 45 */ 46 @Override 47 public String getReplay() { 48 StringBuilder replay = new StringBuilder(); 49 replay.append("<Step>" + StringTools.ENDLINE); 50 replay.append("<EventId>" + eventId + "</EventId>" + StringTools.ENDLINE); 51 replay.append("<ReachingStep>false</ReachingStep>" + StringTools.ENDLINE); 52 replay.append("</Step>" + StringTools.ENDLINE); 53 return replay.toString(); 54 } 44 /* 45 * (non-Javadoc) 46 * 47 * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() 48 */ 49 @Override 50 public String getReplay() { 51 StringBuilder replay = new StringBuilder(); 52 replay.append("<Step>" + StringTools.ENDLINE); 53 replay.append("<EventId>" + eventId + "</EventId>" + StringTools.ENDLINE); 54 replay.append("<ReachingStep>false</ReachingStep>" + StringTools.ENDLINE); 55 replay.append("</Step>" + StringTools.ENDLINE); 56 return replay.toString(); 57 } 58 59 /* 60 * (non-Javadoc) 61 * 62 * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator() 63 */ 64 @Override 65 public IReplayDecorator getDecorator() { 66 return EFGReplayDecorator.getInstance(); 67 } 55 68 56 69 } -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php/eventcore/WebRequest.java
r554 r560 5 5 import java.util.List; 6 6 7 import de.ugoe.cs.quest.IReplayDecorator; 7 8 import de.ugoe.cs.quest.eventcore.IReplayable; 8 9 … … 158 159 } 159 160 161 /* 162 * (non-Javadoc) 163 * 164 * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator() 165 */ 166 @Override 167 public IReplayDecorator getDecorator() { 168 return null; 169 } 170 160 171 }
Note: See TracChangeset
for help on using the changeset viewer.