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

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