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