Changeset 619 for trunk/quest-plugin-mfc/src/main/java/de/ugoe/cs/quest/plugin/mfc/eventcore/MFCEvent.java
- Timestamp:
- 08/27/12 11:45:09 (12 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-mfc/src/main/java/de/ugoe/cs/quest/plugin/mfc/eventcore/MFCEvent.java
r578 r619 1 1 2 package de.ugoe.cs.quest.plugin.mfc.eventcore; 2 3 3 import java.security.InvalidParameterException; 4 import java.util.HashMap; 5 import java.util.Map; 6 7 import de.ugoe.cs.quest.IReplayDecorator; 8 import de.ugoe.cs.quest.eventcore.IReplayable; 9 import de.ugoe.cs.quest.plugin.mfc.MFCReplayDecorator; 10 import de.ugoe.cs.util.StringTools; 4 import de.ugoe.cs.quest.eventcore.Event; 5 import de.ugoe.cs.quest.eventcore.IEventType; 6 import de.ugoe.cs.quest.eventcore.guimodel.GUIModel; 7 import de.ugoe.cs.quest.plugin.mfc.guimodel.MFCGUIElement; 11 8 12 9 /** 13 10 * <p> 14 * Contains all informations about a windows message, i.e., all parameters that 15 * are read when awindows message is parsed as well as its target, hwnd, etc.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. 16 13 * </p> 17 14 * … … 20 17 * 21 18 */ 22 public class WindowsMessage implements IReplayable{19 public class MFCEvent extends Event { 23 20 24 25 26 27 28 29 21 /** 22 * <p> 23 * Id for object serialization. 24 * </p> 25 */ 26 private static final long serialVersionUID = 1L; 30 27 31 /** 32 * <p> 33 * Type of the message. 34 * </p> 35 */ 36 final int type; 28 /** 29 * <p> 30 * TODO: comment 31 * </p> 32 * 33 * @param eventType 34 * @param target 35 * @param currentMessageParameters 36 */ 37 public MFCEvent(IEventType eventType, 38 MFCGUIElement target, 39 GUIModel guiModel) 40 { 41 super(eventType); 42 super.setTarget(target); 43 } 37 44 38 /** 39 * <p> 40 * Window class of the message target. Default: "" 41 * </p> 42 */ 43 private String windowClass = ""; 44 45 /** 46 * <p> 47 * Resource Id of the message target. Default: 0 48 * </p> 49 */ 50 private int resourceId = 0; 51 52 /** 53 * <p> 54 * XML representation of the message target. 55 * </p> 56 */ 57 private String xmlWindowDescription = ""; 58 59 /** 60 * <p> 61 * String that contains the names of all parent widgets and itself, separated by dots, 62 * e.g., "GrandParent.Parent.self". 63 * </p> 64 */ 65 private String parentNames = null; 66 67 /** 68 * <p> 69 * String that contains the window class of the parent widget. 70 * </p> 71 */ 72 private String parentClass = null; 73 74 /** 75 * <p> 76 * LPARAM of the message. Default: 0 77 * </p> 78 */ 79 private long LPARAM = 0; 80 81 /** 82 * <p> 83 * WPARAM of the message. Default: 0 84 * </p> 85 */ 86 private long WPARAM = 0; 87 88 /** 89 * <p> 90 * If the LPARAM contains a HWND, this string stores the target of the HWND. 91 * </p> 92 */ 93 private String LPARAMasWindowDesc = null; 94 95 /** 96 * <p> 97 * If the WPARAM contains a HWND, this string stores the target of the HWND. 98 * </p> 99 */ 100 private String WPARAMasWindowDesc = null; 101 102 /** 103 * <p> 104 * Delay after sending the messages during a replay. Default: 0 105 * </p> 106 */ 107 private int delay = 0; 108 109 /** 110 * <p> 111 * A map of all parameters, associated with the message, created during the 112 * parsing of messages from the logs {@code param}-nodes. 113 * </p> 114 */ 115 private Map<String, String> params = new HashMap<String, String>(); 116 117 /** 118 * <p> 119 * Constructor. Creates a new message with a given message type. 120 * </p> 121 * 122 * @param type 123 * type of the message 124 */ 125 public WindowsMessage(int type) { 126 this.type = type; 127 } 128 129 /** 130 * <p> 131 * Adds a parameter to the message. 132 * </p> 133 * 134 * @param type 135 * type descriptor of the parameter 136 * @param value 137 * value of the parameter 138 */ 139 public void addParameter(String type, String value) { 140 params.put(type, value); 141 if (type.equals("LPARAM")) { 142 LPARAM = Long.parseLong(value); 143 } else if (type.equals("WPARAM")) { 144 WPARAM = Long.parseLong(value); 145 } 146 } 147 148 /** 149 * <p> 150 * Returns the type of the message. 151 * </p> 152 * 153 * @return type of the message 154 */ 155 public int getType() { 156 return type; 157 } 158 159 /** 160 * <p> 161 * Returns the value of a parameter, given its type. If the parameter is not 162 * found, {@code null} is returned. 163 * </p> 164 * 165 * @param type 166 * type of the parameter 167 * @return value of the parameter 168 */ 169 public String getParameter(String type) { 170 return params.get(type); 171 } 172 173 /** 174 * <p> 175 * Returns the window class of the message target. 176 * </p> 177 * 178 * @return window class of the message target 179 */ 180 public String getWindowClass() { 181 return windowClass; 182 } 183 184 /** 185 * <p> 186 * Returns the HWND the message is addressed to. 187 * </p> 188 * 189 * @return HWND the message is addressed to 190 */ 191 public int getHwnd() { 192 int hwnd = -1; 193 String hwndString = getParameter("window.hwnd"); // possible, as 194 // "window.hwnd" is 195 // mandatory 196 if (hwndString != null) { 197 hwnd = Integer.parseInt(hwndString); 198 } 199 return hwnd; 200 } 201 202 /** 203 * <p> 204 * Returns the resource Id of the message target. 205 * </p> 206 * 207 * @return resource Id of the message target 208 */ 209 public int getWindowResourceId() { 210 return resourceId; 211 } 212 213 /** 214 * <p> 215 * Two {@link WindowsMessage} are equal, if their {@link #type}, 216 * {@link #xmlWindowDescription}, and {@link #params} are equal. 217 * </p> 218 * 219 * @see java.lang.Object#equals(java.lang.Object) 220 */ 221 @Override 222 public boolean equals(Object other) { 223 if (other == this) { 224 return true; 225 } 226 boolean isEqual = false; 227 if (other instanceof WindowsMessage) { 228 isEqual = ((WindowsMessage) other).type == this.type 229 && ((WindowsMessage) other).xmlWindowDescription 230 .equals(this.xmlWindowDescription) 231 && ((WindowsMessage) other).params.equals(this.params); 232 } 233 return isEqual; 234 } 235 236 /* 237 * (non-Javadoc) 238 * 239 * @see java.lang.Object#hashCode() 240 */ 241 @Override 242 public int hashCode() { 243 int multiplier = 17; 244 int hash = 42; 245 246 hash = multiplier * hash + type; 247 hash = multiplier * hash + xmlWindowDescription.hashCode(); 248 hash = multiplier * hash + params.hashCode(); 249 250 return hash; 251 } 252 253 /** 254 * <p> 255 * Returns a string representation of the message of the form 256 * "msg[target=HWND;type=TYPE]". 257 * </p> 258 * 259 * @see java.lang.Object#toString() 260 */ 261 @Override 262 public String toString() { 263 return "msg[target=" + getParameter("window.hwnd") + ";type=" + type 264 + "]"; 265 } 266 267 /** 268 * <p> 269 * Retrieves the target string of a message from a given {@link WindowTree} 270 * through looking up the HWND the message is addressed to in the window 271 * tree. 272 * </p> 273 * 274 * @param windowTree 275 * {@link WindowTree} from which the target is extracted 276 * @throws InvalidParameterException 277 * thrown if HWND is not contained in windowTree 278 */ 279 public void setTarget(WindowTree windowTree) 280 throws InvalidParameterException { 281 int hwnd = Integer.parseInt(getParameter("window.hwnd")); 282 WindowTreeNode node = windowTree.find(hwnd); 283 if (node == null) { 284 throw new InvalidParameterException("No window with HWND " + hwnd 285 + " found in window tree!"); 286 } else { 287 windowClass = node.getClassName(); 288 resourceId = node.getResourceId(); 289 xmlWindowDescription = node.xmlRepresentation(); 290 parentNames = node.getParentNames(); 291 WindowTreeNode parent = node.getParent(); 292 if (parent == null) { 293 parentClass = ""; 294 } else { 295 parentClass = parent.getClassName(); 296 } 297 } 298 } 299 300 /** 301 * <p> 302 * Sets the LPARAM of a message. 303 * </p> 304 * 305 * @param paramValue 306 * value of the LPARAM 307 */ 308 public void setLPARAM(long paramValue) { 309 LPARAM = paramValue; 310 } 311 312 /** 313 * <p> 314 * Sets the WPARAM of a message. 315 * </p> 316 * 317 * @param paramValue 318 * value of the WPARAM 319 */ 320 public void setWPARAM(long paramValue) { 321 WPARAM = paramValue; 322 } 323 324 /** 325 * <p> 326 * Returns the LPARAM of a message. 327 * </p> 328 * 329 * @return LPARAM of the message 330 */ 331 public long getLPARAM() { 332 return LPARAM; 333 } 334 335 /** 336 * <p> 337 * Returns the WPARAM of a message. 338 * </p> 339 * 340 * @return WPARAM of the message 341 */ 342 public long getWPARAM() { 343 return WPARAM; 344 } 345 346 /** 347 * <p> 348 * If the LPARAM contains a HWND, this function can be used to set a target 349 * string to identify the HWND at run-time. 350 * </p> 351 * 352 * @param windowDesc 353 * target string 354 */ 355 public void setLPARAMasWindowDesc(String windowDesc) { 356 LPARAMasWindowDesc = windowDesc; 357 } 358 359 /** 360 * <p> 361 * If the WPARAM contains a HWND, this function can be used to set a target 362 * string to identify the HWND at run-time. 363 * </p> 364 * 365 * @param windowDesc 366 * target string 367 */ 368 public void setWPARAMasWindowDesc(String windowDesc) { 369 WPARAMasWindowDesc = windowDesc; 370 } 371 372 /** 373 * <p> 374 * If the LPARAM contains a HWND and the target string for the HWND is set, 375 * this function returns the target string. Otherwise, {@code null} is 376 * returned. 377 * </p> 378 * 379 * @return target string if available; {@code null} otherwise 380 */ 381 public String getLPARAMasWindowDesc() { 382 return LPARAMasWindowDesc; 383 } 384 385 /** 386 * <p> 387 * If the WPARAM contains a HWND and the target string for the HWND is set, 388 * this function returns the target string. Otherwise, {@code null} is 389 * returned. 390 * </p> 391 * 392 * @return target string if available; {@code null} otherwise 393 */ 394 public String getWPARAMasWindowDesc() { 395 return WPARAMasWindowDesc; 396 } 397 398 /** 399 * <p> 400 * Returns the target string of the message. 401 * </p> 402 * 403 * @return target string of the message 404 */ 405 public String getXmlWindowDescription() { 406 return xmlWindowDescription; 407 } 408 409 /** 410 * <p> 411 * Sets the target string manually. 412 * </p> 413 * 414 * @param xmlWindowDescription 415 * target string 416 */ 417 public void setXmlWindowDescription(String xmlWindowDescription) { 418 this.xmlWindowDescription = xmlWindowDescription; 419 } 420 421 /** 422 * <p> 423 * Returns the delay after this message during replays. 424 * </p> 425 * 426 * @return delay after this message 427 */ 428 public int getDelay() { 429 return delay; 430 } 431 432 /** 433 * <p> 434 * Sets the delay after this message during replays. 435 * </p> 436 * 437 * @param delay 438 * delay after this message 439 */ 440 public void setDelay(int delay) { 441 this.delay = delay; 442 } 443 444 /** 445 * <p> 446 * Returns the parent names separated by dots, e.g., "GrandParent.Parent". 447 * </p> 448 * 449 * @return names of the parents 450 */ 451 public String getParentNames() { 452 return parentNames; 453 } 454 455 /** 456 * <p> 457 * Returns the window class of the parent. 458 * </p> 459 * 460 * @return window classes of the parents 461 */ 462 public String getParentClass() { 463 return parentClass; 464 } 465 466 /** 467 * <p> 468 * Returns the number of parameters stored together with this message. 469 * </p> 470 * 471 * @return number of parameters stored with this message 472 */ 473 public int getNumParams() { 474 return params.size(); 475 } 476 477 /* 478 * (non-Javadoc) 479 * 480 * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() 481 */ 482 @Override 483 public String getReplay() { 484 StringBuilder currentMsgStr = new StringBuilder(400); 485 currentMsgStr.append(" <msg type=\"" + type + "\" "); 486 currentMsgStr.append("LPARAM=\"" + LPARAM + "\" "); 487 currentMsgStr.append("WPARAM=\"" + WPARAM + "\" "); 488 currentMsgStr.append("delay=\"" + delay + "\">"); 489 if (LPARAMasWindowDesc != null) { 490 currentMsgStr.append(StringTools.ENDLINE); 491 currentMsgStr.append(" <LPARAM>"); 492 currentMsgStr.append(StringTools.ENDLINE); 493 currentMsgStr.append(LPARAMasWindowDesc); 494 currentMsgStr.append(StringTools.ENDLINE); 495 currentMsgStr.append("</LPARAM>"); 496 } 497 if (WPARAMasWindowDesc != null) { 498 currentMsgStr.append(StringTools.ENDLINE); 499 currentMsgStr.append(" <WPARAM>"); 500 currentMsgStr.append(StringTools.ENDLINE); 501 currentMsgStr.append(WPARAMasWindowDesc); 502 currentMsgStr.append(StringTools.ENDLINE); 503 currentMsgStr.append(" </WPARAM>"); 504 } 505 currentMsgStr.append(StringTools.ENDLINE); 506 currentMsgStr.append(xmlWindowDescription); 507 currentMsgStr.append(StringTools.ENDLINE); 508 currentMsgStr.append(" </msg>"); 509 currentMsgStr.append(StringTools.ENDLINE); 510 return currentMsgStr.toString(); 511 } 512 513 /* (non-Javadoc) 514 * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator() 45 /** 46 * <p> 47 * Two {@link WindowsMessage} are equal, if their {@link #type}, {@link #xmlWindowDescription}, 48 * and {@link #params} are equal. 49 * </p> 50 * 51 * @see java.lang.Object#equals(java.lang.Object) 515 52 */ 516 53 @Override 517 public IReplayDecorator getDecorator() { 518 return MFCReplayDecorator.getInstance(); 54 public boolean equals(Object other) { 55 if (other == this) { 56 return true; 57 } 58 boolean isEqual = false; 59 if (other instanceof MFCEvent) { 60 isEqual = 61 ((MFCEvent) other).type == this.type && 62 ((MFCEvent) other).target.equals(this.target); 63 } 64 return isEqual; 519 65 } 66 67 /* 68 * (non-Javadoc) 69 * 70 * @see java.lang.Object#hashCode() 71 */ 72 @Override 73 public int hashCode() { 74 int multiplier = 17; 75 int hash = 42; 76 77 hash = multiplier * hash + type.hashCode(); 78 hash = multiplier * hash + target.hashCode(); 79 80 return hash; 81 } 82 520 83 }
Note: See TracChangeset
for help on using the changeset viewer.