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

Last change on this file since 655 was 655, checked in by pharms, 12 years ago
  • removed old copyright file header
File size: 5.8 KB
Line 
1package de.ugoe.cs.quest.plugin.mfc.eventcore;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import de.ugoe.cs.quest.plugin.mfc.guimodel.MFCGUIElement;
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 WindowsMessage {
19
20    /**
21     * <p>
22     * Type of the message.
23     * </p>
24     */
25    final WindowsMessageType type;
26
27    /**
28     * <p>
29     * LPARAM of the message. Default: 0
30     * </p>
31     */
32    private long LPARAM = 0;
33
34    /**
35     * <p>
36     * WPARAM of the message. Default: 0
37     * </p>
38     */
39    private long WPARAM = 0;
40
41    /**
42     * <p>
43     * A map of all parameters, associated with the message, created during the parsing of messages
44     * from the logs {@code param}-nodes.
45     * </p>
46     */
47    private Map<String, Object> params = new HashMap<String, Object>();
48
49    /**
50     * <p>
51     * the target GUI element to which the message was sent
52     * </p>
53     */
54    private MFCGUIElement target;
55
56    /**
57     * <p>
58     * an XML representation of the target to preserve it as it was when this message was created
59     * </p>
60     */
61    protected String targetXML;
62
63    /**
64     * <p>
65     * Constructor. Creates a new message with a given message type.
66     * </p>
67     *
68     * @param type
69     *            type of the message
70     * @param currentMessageParameters
71     * @param target
72     */
73    public WindowsMessage(WindowsMessageType  type,
74                          MFCGUIElement       target,
75                          Map<String, Object> messageParameters)
76    {
77        this.type = type;
78        setTarget(target);
79       
80        for (Map.Entry<String, Object> entry : messageParameters.entrySet()) {
81            addParameter(entry.getKey(), entry.getValue());
82        }
83    }
84
85    /**
86     * <p>
87     * Constructor. Creates a new message with a given message type.
88     * </p>
89     *
90     * @param type
91     *            type of the message
92     */
93    public WindowsMessage(WindowsMessageType type)
94    {
95        this.type = type;
96    }
97
98    /**
99     * <p>
100     * Adds a parameter to the message.
101     * </p>
102     *
103     * @param type
104     *            type descriptor of the parameter
105     * @param value
106     *            value of the parameter
107     */
108    public void addParameter(String type, Object value) {
109        params.put(type, value);
110        if (type.equals("LPARAM")) {
111            LPARAM = (Long) value;
112        }
113        else if (type.equals("WPARAM")) {
114            WPARAM = (Long) value;
115        }
116    }
117
118    /**
119     * <p>
120     * Returns the type of the message.
121     * </p>
122     *
123     * @return type of the message
124     */
125    public WindowsMessageType getType() {
126        return type;
127    }
128
129    /**
130     * <p>
131     * TODO: comment
132     * </p>
133     *
134     * @param target2
135     */
136    public void setTarget(MFCGUIElement target) {
137        this.target = target;
138        this.targetXML = target.toXML();
139    }
140
141    /**
142     * <p>
143     * TODO: comment
144     * </p>
145     *
146     * @return
147     */
148    public MFCGUIElement getTarget() {
149        return target;
150    }
151   
152    /**
153     * <p>
154     * Returns the value of a parameter, given its type. If the parameter is not found, {@code null}
155     * is returned.
156     * </p>
157     *
158     * @param type
159     *            type of the parameter
160     * @return value of the parameter
161     */
162    public Object getParameter(String type) {
163        return params.get(type);
164    }
165
166    /**
167     * <p>
168     * Two {@link WindowsMessage} are equal, if their {@link #type}, {@link #xmlWindowDescription},
169     * and {@link #params} are equal.
170     * </p>
171     *
172     * @see java.lang.Object#equals(java.lang.Object)
173     */
174    @Override
175    public boolean equals(Object other) {
176        if (other == this) {
177            return true;
178        }
179        boolean isEqual = false;
180        if (other instanceof WindowsMessage) {
181            isEqual =
182                ((WindowsMessage) other).type == this.type &&
183                ((WindowsMessage) other).target.equals(this.target) &&
184                ((WindowsMessage) other).params.equals(this.params);
185        }
186        return isEqual;
187    }
188
189    /*
190     * (non-Javadoc)
191     *
192     * @see java.lang.Object#hashCode()
193     */
194    @Override
195    public int hashCode() {
196        int multiplier = 17;
197        int hash = 42;
198
199        hash = multiplier * hash + type.hashCode();
200        hash = multiplier * hash + target.hashCode();
201        hash = multiplier * hash + params.hashCode();
202
203        return hash;
204    }
205
206    /**
207     * <p>
208     * Returns a string representation of the message of the form "msg[target=HWND;type=TYPE]".
209     * </p>
210     *
211     * @see java.lang.Object#toString()
212     */
213    @Override
214    public String toString() {
215        return "msg[target=" + getParameter("window.hwnd") + ";type=" + type + "]";
216    }
217
218    /**
219     * <p>
220     * Returns the LPARAM of a message.
221     * </p>
222     *
223     * @return LPARAM of the message
224     */
225    public long getLPARAM() {
226        return LPARAM;
227    }
228
229    /**
230     * <p>
231     * Returns the WPARAM of a message.
232     * </p>
233     *
234     * @return WPARAM of the message
235     */
236    public long getWPARAM() {
237        return WPARAM;
238    }
239
240    /**
241     * <p>
242     * Returns the number of parameters stored together with this message.
243     * </p>
244     *
245     * @return number of parameters stored with this message
246     */
247    public int getNumParams() {
248        return params.size();
249    }
250
251    /**
252     * <p>
253     * TODO: comment
254     * </p>
255     *
256     * @return
257     */
258    protected Map<String, Object> getParameters() {
259        return params;
260    }
261
262    /**
263     * <p>
264     * TODO: comment
265     * </p>
266     *
267     * @return
268     */
269    public String getTargetXML() {
270        return targetXML;
271    }
272
273}
Note: See TracBrowser for help on using the repository browser.