source: trunk/quest-plugin-mfc/src/main/java/de/ugoe/cs/quest/plugin/mfc/eventcore/ReplayWindowsMessage.java @ 647

Last change on this file since 647 was 647, checked in by pharms, 12 years ago
  • fixed one of the last bugs in the replay generation after refactoring
File size: 7.3 KB
Line 
1
2package de.ugoe.cs.quest.plugin.mfc.eventcore;
3
4import de.ugoe.cs.quest.IReplayDecorator;
5import de.ugoe.cs.quest.eventcore.IReplayable;
6import de.ugoe.cs.quest.plugin.mfc.MFCReplayDecorator;
7import 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 */
19public 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        // the target may have changed in the meantime. So reset the targetXML to the one stored
66        // with the provided message
67        if (!super.getTargetXML().equals(replayedMessage.getTargetXML())) {
68            setTargetXML(replayedMessage.getTargetXML());
69        }
70    }
71
72    /**
73     * <p>
74     * Constructor. Creates a new message with a given message type.
75     * </p>
76     *
77     * @param type
78     *            type of the message
79     */
80    public ReplayWindowsMessage(WindowsMessageType type)
81    {
82        super(type);
83    }
84
85    /**
86     * <p>
87     * Two {@link ReplayWindowsMessage} are equal, if their {@link #type}, {@link #xmlWindowDescription},
88     * and {@link #params} are equal.
89     * </p>
90     *
91     * @see java.lang.Object#equals(java.lang.Object)
92     */
93    @Override
94    public boolean equals(Object other) {
95        if (other == this) {
96            return true;
97        }
98        boolean isEqual = false;
99        if (other instanceof ReplayWindowsMessage) {
100            isEqual = super.equals(other);
101        }
102        return isEqual;
103    }
104
105    /*
106     * (non-Javadoc)
107     *
108     * @see java.lang.Object#hashCode()
109     */
110    @Override
111    public int hashCode() {
112        return super.hashCode();
113    }
114
115    /**
116     * <p>
117     * Returns a string representation of the message of the form "msg[target=HWND;type=TYPE]".
118     * </p>
119     *
120     * @see java.lang.Object#toString()
121     */
122    @Override
123    public String toString() {
124        return "msg[target=" + getParameter("window.hwnd") + ";type=" + type + "]";
125    }
126
127    /**
128     * <p>
129     * Sets the LPARAM of a message.
130     * </p>
131     *
132     * @param paramValue
133     *            value of the LPARAM
134     */
135    public void setLPARAM(long paramValue) {
136        super.addParameter("LPARAM", paramValue);
137    }
138
139    /**
140     * <p>
141     * Sets the WPARAM of a message.
142     * </p>
143     *
144     * @param paramValue
145     *            value of the WPARAM
146     */
147    public void setWPARAM(long paramValue) {
148        super.addParameter("WPARAM", paramValue);
149    }
150
151    /**
152     * <p>
153     * If the LPARAM contains a HWND, this function can be used to set a target string to identify
154     * the HWND at run-time.
155     * </p>
156     *
157     * @param windowDesc
158     *            target string
159     */
160    public void setLPARAMasWindowDesc(String windowDesc) {
161        LPARAMasWindowDesc = windowDesc;
162    }
163
164    /**
165     * <p>
166     * If the WPARAM contains a HWND, this function can be used to set a target string to identify
167     * the HWND at run-time.
168     * </p>
169     *
170     * @param windowDesc
171     *            target string
172     */
173    public void setWPARAMasWindowDesc(String windowDesc) {
174        WPARAMasWindowDesc = windowDesc;
175    }
176
177    /**
178     * <p>
179     * If the LPARAM contains a HWND and the target string for the HWND is set, this function
180     * returns the target string. Otherwise, {@code null} is returned.
181     * </p>
182     *
183     * @return target string if available; {@code null} otherwise
184     */
185    public String getLPARAMasWindowDesc() {
186        return LPARAMasWindowDesc;
187    }
188
189    /**
190     * <p>
191     * If the WPARAM contains a HWND and the target string for the HWND is set, this function
192     * returns the target string. Otherwise, {@code null} is returned.
193     * </p>
194     *
195     * @return target string if available; {@code null} otherwise
196     */
197    public String getWPARAMasWindowDesc() {
198        return WPARAMasWindowDesc;
199    }
200
201    /**
202     * <p>
203     * TODO: comment
204     * </p>
205     *
206     * @param termValue
207     */
208    public void setTargetXML(String targetXML) {
209        this.targetXML = targetXML;
210    }
211
212    /**
213     * <p>
214     * Returns the delay after this message during replays.
215     * </p>
216     *
217     * @return delay after this message
218     */
219    public int getDelay() {
220        return delay;
221    }
222
223    /**
224     * <p>
225     * Sets the delay after this message during replays.
226     * </p>
227     *
228     * @param delay
229     *            delay after this message
230     */
231    public void setDelay(int delay) {
232        this.delay = delay;
233    }
234
235    /*
236     * (non-Javadoc)
237     *
238     * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay()
239     */
240    @Override
241    public String getReplay() {
242        StringBuilder currentMsgStr = new StringBuilder(400);
243        currentMsgStr.append("  <msg type=\"" + type.getNumber() + "\" ");
244        currentMsgStr.append("LPARAM=\"" + super.getLPARAM() + "\" ");
245        currentMsgStr.append("WPARAM=\"" + super.getWPARAM() + "\" ");
246        currentMsgStr.append("delay=\"" + delay + "\">");
247        if (LPARAMasWindowDesc != null) {
248            currentMsgStr.append(StringTools.ENDLINE);
249            currentMsgStr.append("   <LPARAM>");
250            currentMsgStr.append(StringTools.ENDLINE);
251            currentMsgStr.append(LPARAMasWindowDesc);
252            currentMsgStr.append(StringTools.ENDLINE);
253            currentMsgStr.append("</LPARAM>");
254        }
255        if (WPARAMasWindowDesc != null) {
256            currentMsgStr.append(StringTools.ENDLINE);
257            currentMsgStr.append("   <WPARAM>");
258            currentMsgStr.append(StringTools.ENDLINE);
259            currentMsgStr.append(WPARAMasWindowDesc);
260            currentMsgStr.append(StringTools.ENDLINE);
261            currentMsgStr.append("   </WPARAM>");
262        }
263        currentMsgStr.append(StringTools.ENDLINE);
264        currentMsgStr.append(super.getTargetXML());
265        currentMsgStr.append(StringTools.ENDLINE);
266        currentMsgStr.append("  </msg>");
267        currentMsgStr.append(StringTools.ENDLINE);
268        return currentMsgStr.toString();
269    }
270
271    /*
272     * (non-Javadoc)
273     *
274     * @see de.ugoe.cs.quest.eventcore.IReplayable#getDecorator()
275     */
276    @Override
277    public IReplayDecorator getDecorator() {
278        return MFCReplayDecorator.getInstance();
279    }
280
281}
Note: See TracBrowser for help on using the repository browser.