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

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