[619] | 1 | |
---|
| 2 | package de.ugoe.cs.quest.plugin.mfc.eventcore; |
---|
| 3 | |
---|
| 4 | import de.ugoe.cs.quest.IReplayDecorator; |
---|
| 5 | import de.ugoe.cs.quest.eventcore.IReplayable; |
---|
| 6 | import de.ugoe.cs.quest.plugin.mfc.MFCReplayDecorator; |
---|
| 7 | import de.ugoe.cs.util.StringTools; |
---|
| 8 | |
---|
| 9 | /** |
---|
| 10 | * <p> |
---|
| 11 | * Contains all informations about a windows message, i.e., all parameters that are read when a |
---|
| 12 | * windows message is parsed as well as its target, hwnd, etc. |
---|
| 13 | * </p> |
---|
| 14 | * |
---|
| 15 | * @author Steffen Herbold |
---|
| 16 | * @version 1.0 |
---|
| 17 | * |
---|
| 18 | */ |
---|
| 19 | public class ReplayWindowsMessage extends WindowsMessage implements IReplayable { |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * <p> |
---|
| 23 | * Id for object serialization. |
---|
| 24 | * </p> |
---|
| 25 | */ |
---|
| 26 | private static final long serialVersionUID = 1L; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * <p> |
---|
| 30 | * If the LPARAM contains a HWND, this string stores the target of the HWND. |
---|
| 31 | * </p> |
---|
| 32 | */ |
---|
| 33 | private String LPARAMasWindowDesc = null; |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | * <p> |
---|
| 37 | * If the WPARAM contains a HWND, this string stores the target of the HWND. |
---|
| 38 | * </p> |
---|
| 39 | */ |
---|
| 40 | private String WPARAMasWindowDesc = null; |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * <p> |
---|
| 44 | * Delay after sending the messages during a replay. Default: 0 |
---|
| 45 | * </p> |
---|
| 46 | */ |
---|
| 47 | private int delay = 0; |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * <p> |
---|
| 51 | * Constructor. Creates a new message with a given message type. |
---|
| 52 | * </p> |
---|
| 53 | * |
---|
| 54 | * @param type |
---|
| 55 | * type of the message |
---|
| 56 | * @param currentMessageParameters |
---|
| 57 | * @param target |
---|
| 58 | */ |
---|
| 59 | public ReplayWindowsMessage(WindowsMessage replayedMessage) |
---|
| 60 | { |
---|
| 61 | super(replayedMessage.getType(), |
---|
| 62 | replayedMessage.getTarget(), |
---|
| 63 | replayedMessage.getParameters()); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * <p> |
---|
| 68 | * Constructor. Creates a new message with a given message type. |
---|
| 69 | * </p> |
---|
| 70 | * |
---|
| 71 | * @param type |
---|
| 72 | * type of the message |
---|
| 73 | */ |
---|
| 74 | public ReplayWindowsMessage(WindowsMessageType type) |
---|
| 75 | { |
---|
| 76 | super(type); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * <p> |
---|
| 81 | * Two {@link ReplayWindowsMessage} are equal, if their {@link #type}, {@link #xmlWindowDescription}, |
---|
| 82 | * and {@link #params} are equal. |
---|
| 83 | * </p> |
---|
| 84 | * |
---|
| 85 | * @see java.lang.Object#equals(java.lang.Object) |
---|
| 86 | */ |
---|
| 87 | @Override |
---|
| 88 | public boolean equals(Object other) { |
---|
| 89 | if (other == this) { |
---|
| 90 | return true; |
---|
| 91 | } |
---|
| 92 | boolean isEqual = false; |
---|
| 93 | if (other instanceof ReplayWindowsMessage) { |
---|
| 94 | isEqual = super.equals(other); |
---|
| 95 | } |
---|
| 96 | return isEqual; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /* |
---|
| 100 | * (non-Javadoc) |
---|
| 101 | * |
---|
| 102 | * @see java.lang.Object#hashCode() |
---|
| 103 | */ |
---|
| 104 | @Override |
---|
| 105 | public int hashCode() { |
---|
| 106 | return super.hashCode(); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * <p> |
---|
| 111 | * Returns a string representation of the message of the form "msg[target=HWND;type=TYPE]". |
---|
| 112 | * </p> |
---|
| 113 | * |
---|
| 114 | * @see java.lang.Object#toString() |
---|
| 115 | */ |
---|
| 116 | @Override |
---|
| 117 | public String toString() { |
---|
| 118 | return "msg[target=" + getParameter("window.hwnd") + ";type=" + type + "]"; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * <p> |
---|
| 123 | * Sets the LPARAM of a message. |
---|
| 124 | * </p> |
---|
| 125 | * |
---|
| 126 | * @param paramValue |
---|
| 127 | * value of the LPARAM |
---|
| 128 | */ |
---|
| 129 | public void setLPARAM(long paramValue) { |
---|
| 130 | super.addParameter("LPARAM", paramValue); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | * <p> |
---|
| 135 | * Sets the WPARAM of a message. |
---|
| 136 | * </p> |
---|
| 137 | * |
---|
| 138 | * @param paramValue |
---|
| 139 | * value of the WPARAM |
---|
| 140 | */ |
---|
| 141 | public void setWPARAM(long paramValue) { |
---|
| 142 | super.addParameter("WPARAM", paramValue); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * <p> |
---|
| 147 | * If the LPARAM contains a HWND, this function can be used to set a target string to identify |
---|
| 148 | * the HWND at run-time. |
---|
| 149 | * </p> |
---|
| 150 | * |
---|
| 151 | * @param windowDesc |
---|
| 152 | * target string |
---|
| 153 | */ |
---|
| 154 | public void setLPARAMasWindowDesc(String windowDesc) { |
---|
| 155 | LPARAMasWindowDesc = windowDesc; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | /** |
---|
| 159 | * <p> |
---|
| 160 | * If the WPARAM contains a HWND, this function can be used to set a target string to identify |
---|
| 161 | * the HWND at run-time. |
---|
| 162 | * </p> |
---|
| 163 | * |
---|
| 164 | * @param windowDesc |
---|
| 165 | * target string |
---|
| 166 | */ |
---|
| 167 | public void setWPARAMasWindowDesc(String windowDesc) { |
---|
| 168 | WPARAMasWindowDesc = windowDesc; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | /** |
---|
| 172 | * <p> |
---|
| 173 | * If the LPARAM contains a HWND and the target string for the HWND is set, this function |
---|
| 174 | * returns the target string. Otherwise, {@code null} is returned. |
---|
| 175 | * </p> |
---|
| 176 | * |
---|
| 177 | * @return target string if available; {@code null} otherwise |
---|
| 178 | */ |
---|
| 179 | public String getLPARAMasWindowDesc() { |
---|
| 180 | return LPARAMasWindowDesc; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | /** |
---|
| 184 | * <p> |
---|
| 185 | * If the WPARAM contains a HWND and the target string for the HWND is set, this function |
---|
| 186 | * returns the target string. Otherwise, {@code null} is returned. |
---|
| 187 | * </p> |
---|
| 188 | * |
---|
| 189 | * @return target string if available; {@code null} otherwise |
---|
| 190 | */ |
---|
| 191 | public String getWPARAMasWindowDesc() { |
---|
| 192 | return WPARAMasWindowDesc; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | * <p> |
---|
| 197 | * TODO: comment |
---|
| 198 | * </p> |
---|
| 199 | * |
---|
| 200 | * @param termValue |
---|
| 201 | */ |
---|
| 202 | public void setTargetXML(String targetXML) { |
---|
| 203 | this.targetXML = targetXML; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | /** |
---|
| 207 | * <p> |
---|
| 208 | * Returns the delay after this message during replays. |
---|
| 209 | * </p> |
---|
| 210 | * |
---|
| 211 | * @return delay after this message |
---|
| 212 | */ |
---|
| 213 | public int getDelay() { |
---|
| 214 | return delay; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | /** |
---|
| 218 | * <p> |
---|
| 219 | * Sets the delay after this message during replays. |
---|
| 220 | * </p> |
---|
| 221 | * |
---|
| 222 | * @param delay |
---|
| 223 | * delay after this message |
---|
| 224 | */ |
---|
| 225 | public void setDelay(int delay) { |
---|
| 226 | this.delay = delay; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | /* |
---|
| 230 | * (non-Javadoc) |
---|
| 231 | * |
---|
| 232 | * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() |
---|
| 233 | */ |
---|
| 234 | @Override |
---|
| 235 | public String getReplay() { |
---|
| 236 | StringBuilder currentMsgStr = new StringBuilder(400); |
---|
| 237 | currentMsgStr.append(" <msg type=\"" + type.getNumber() + "\" "); |
---|
| 238 | currentMsgStr.append("LPARAM=\"" + super.getLPARAM() + "\" "); |
---|
| 239 | currentMsgStr.append("WPARAM=\"" + super.getWPARAM() + "\" "); |
---|
| 240 | currentMsgStr.append("delay=\"" + delay + "\">"); |
---|
| 241 | if (LPARAMasWindowDesc != null) { |
---|
| 242 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 243 | currentMsgStr.append(" <LPARAM>"); |
---|
| 244 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 245 | currentMsgStr.append(LPARAMasWindowDesc); |
---|
| 246 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 247 | currentMsgStr.append("</LPARAM>"); |
---|
| 248 | } |
---|
| 249 | if (WPARAMasWindowDesc != null) { |
---|
| 250 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 251 | currentMsgStr.append(" <WPARAM>"); |
---|
| 252 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 253 | currentMsgStr.append(WPARAMasWindowDesc); |
---|
| 254 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 255 | currentMsgStr.append(" </WPARAM>"); |
---|
| 256 | } |
---|
| 257 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 258 | currentMsgStr.append(super.getTargetXML()); |
---|
| 259 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 260 | currentMsgStr.append(" </msg>"); |
---|
| 261 | currentMsgStr.append(StringTools.ENDLINE); |
---|
| 262 | return currentMsgStr.toString(); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | /* |
---|
| 266 | * (non-Javadoc) |
---|
| 267 | * |
---|
| 268 | * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator() |
---|
| 269 | */ |
---|
| 270 | @Override |
---|
| 271 | public IReplayDecorator getDecorator() { |
---|
| 272 | return MFCReplayDecorator.getInstance(); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | } |
---|