// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.plugin.mfc.eventcore; import de.ugoe.cs.autoquest.IReplayDecorator; import de.ugoe.cs.autoquest.eventcore.IReplayable; import de.ugoe.cs.autoquest.plugin.mfc.MFCReplayDecorator; import de.ugoe.cs.util.StringTools; /** *

* Contains all informations about a windows message, i.e., all parameters that are read when a * windows message is parsed as well as its target, hwnd, etc. *

* * @author Steffen Herbold * @version 1.0 * */ public class ReplayWindowsMessage extends WindowsMessage implements IReplayable { /** *

* Id for object serialization. *

*/ private static final long serialVersionUID = 1L; /** *

* If the LPARAM contains a HWND, this string stores the target of the HWND. *

*/ private String LPARAMasWindowDesc = null; /** *

* If the WPARAM contains a HWND, this string stores the target of the HWND. *

*/ private String WPARAMasWindowDesc = null; /** *

* Delay after sending the messages during a replay. Default: 0 *

*/ private int delay = 0; /** *

* Constructor. Creates a new replay message with a given {@link WindowsMessage}. *

* * @param replayedMessage * message from which the replay is generated */ public ReplayWindowsMessage(WindowsMessage replayedMessage) { super(replayedMessage.getType(), replayedMessage.getTarget(), replayedMessage.getParameters()); // the target may have changed in the meantime. So reset the targetXML to the one stored // with the provided message if (!super.getTargetXML().equals(replayedMessage.getTargetXML())) { setTargetXML(replayedMessage.getTargetXML()); } } /** *

* Constructor. Creates a new message with a given message type. *

* * @param type * type of the message */ public ReplayWindowsMessage(WindowsMessageType type) { super(type); } /** *

* Two {@link ReplayWindowsMessage} are equal, if their {@link #type}, {@link #getTargetXML}, * and {@link #params} are equal. *

* * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object other) { if (other == this) { return true; } boolean isEqual = false; if (other instanceof ReplayWindowsMessage) { isEqual = super.equals(other); } return isEqual; } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return super.hashCode(); } /** *

* Returns a string representation of the message of the form "msg[target=HWND;type=TYPE]". *

* * @see java.lang.Object#toString() */ @Override public String toString() { return "msg[target=" + getParameter("window.hwnd") + ";type=" + type + "]"; } /** *

* Sets the LPARAM of a message. *

* * @param paramValue * value of the LPARAM */ public void setLPARAM(long paramValue) { super.addParameter("LPARAM", paramValue); } /** *

* Sets the WPARAM of a message. *

* * @param paramValue * value of the WPARAM */ public void setWPARAM(long paramValue) { super.addParameter("WPARAM", paramValue); } /** *

* If the LPARAM contains a HWND, this function can be used to set a target string to identify * the HWND at run-time. *

* * @param windowDesc * target string */ public void setLPARAMasWindowDesc(String windowDesc) { LPARAMasWindowDesc = windowDesc; } /** *

* If the WPARAM contains a HWND, this function can be used to set a target string to identify * the HWND at run-time. *

* * @param windowDesc * target string */ public void setWPARAMasWindowDesc(String windowDesc) { WPARAMasWindowDesc = windowDesc; } /** *

* If the LPARAM contains a HWND and the target string for the HWND is set, this function * returns the target string. Otherwise, {@code null} is returned. *

* * @return target string if available; {@code null} otherwise */ public String getLPARAMasWindowDesc() { return LPARAMasWindowDesc; } /** *

* If the WPARAM contains a HWND and the target string for the HWND is set, this function * returns the target string. Otherwise, {@code null} is returned. *

* * @return target string if available; {@code null} otherwise */ public String getWPARAMasWindowDesc() { return WPARAMasWindowDesc; } /** *

* Sets the XML target string. *

* * @param targetXML the target string */ public void setTargetXML(String targetXML) { this.targetXML = targetXML; } /** *

* Returns the delay after this message during replays. *

* * @return delay after this message */ public int getDelay() { return delay; } /** *

* Sets the delay after this message during replays. *

* * @param delay * delay after this message */ public void setDelay(int delay) { this.delay = delay; } /* * (non-Javadoc) * * @see de.ugoe.cs.autoquest.eventcore.IReplayable#getReplay() */ @Override public String getReplay() { StringBuilder currentMsgStr = new StringBuilder(400); currentMsgStr.append(" "); if (LPARAMasWindowDesc != null) { currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(" "); currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(LPARAMasWindowDesc); currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(""); } if (WPARAMasWindowDesc != null) { currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(" "); currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(WPARAMasWindowDesc); currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(" "); } currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(super.getTargetXML()); currentMsgStr.append(StringTools.ENDLINE); currentMsgStr.append(" "); currentMsgStr.append(StringTools.ENDLINE); return currentMsgStr.toString(); } /* * (non-Javadoc) * * @see de.ugoe.cs.autoquest.eventcore.IReplayable#getDecorator() */ @Override public IReplayDecorator getDecorator() { return MFCReplayDecorator.getInstance(); } }