1 | package de.ugoe.cs.eventbench.windows.data;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Map;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.data.IReplayable;
|
---|
8 | import de.ugoe.cs.util.StringTools;
|
---|
9 |
|
---|
10 | public class WindowsMessage implements IReplayable {
|
---|
11 | /**
|
---|
12 | * Id for object serialization.
|
---|
13 | */
|
---|
14 | private static final long serialVersionUID = 1L;
|
---|
15 |
|
---|
16 | final int type;
|
---|
17 | private String windowClass = "";
|
---|
18 | private int resourceId = 0;
|
---|
19 | private String xmlWindowDescription = "";
|
---|
20 | private String parentNames = null;
|
---|
21 | private String parentClass = null;
|
---|
22 |
|
---|
23 | private long LPARAM = 0;
|
---|
24 | private long WPARAM = 0;
|
---|
25 |
|
---|
26 | private String LPARAMasWindowDesc = null;
|
---|
27 | private String WPARAMasWindowDesc = null;
|
---|
28 |
|
---|
29 | private int delay = 0;
|
---|
30 |
|
---|
31 | private Map<String, String> params = new HashMap<String, String>();
|
---|
32 |
|
---|
33 | public WindowsMessage(int type) {
|
---|
34 | this.type = type;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public void addParameter(String type, String value) {
|
---|
38 | params.put(type, value);
|
---|
39 | if (type.equals("LPARAM")) {
|
---|
40 | LPARAM = Long.parseLong(value);
|
---|
41 | } else if (type.equals("WPARAM")) {
|
---|
42 | WPARAM = Long.parseLong(value);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public int getType() {
|
---|
47 | return type;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public String getParameter(String type) {
|
---|
51 | return params.get(type);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public String getWindowClass() {
|
---|
55 | return windowClass;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public int getHwnd() {
|
---|
59 | int hwnd = -1;
|
---|
60 | String hwndString = getParameter("window.hwnd"); // possible, as
|
---|
61 | // "window.hwnd" is
|
---|
62 | // mandatory
|
---|
63 | if (hwndString != null) {
|
---|
64 | hwnd = Integer.parseInt(hwndString);
|
---|
65 | }
|
---|
66 | return hwnd;
|
---|
67 | }
|
---|
68 |
|
---|
69 | public int getWindowResourceId() {
|
---|
70 | return resourceId;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public boolean equals(Object other) {
|
---|
75 | if( other==this) {
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 | boolean isEqual = false;
|
---|
79 | if (other instanceof WindowsMessage) {
|
---|
80 | isEqual = ((WindowsMessage) other).type == this.type
|
---|
81 | && ((WindowsMessage) other).xmlWindowDescription
|
---|
82 | .equals(this.xmlWindowDescription)
|
---|
83 | && ((WindowsMessage) other).params.equals(this.params);
|
---|
84 | }
|
---|
85 | return isEqual;
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public int hashCode() {
|
---|
90 | int multiplier = 17;
|
---|
91 | int hash = 42;
|
---|
92 |
|
---|
93 | hash = multiplier * hash + type;
|
---|
94 | hash = multiplier * hash + xmlWindowDescription.hashCode();
|
---|
95 | hash = multiplier * hash + params.hashCode();
|
---|
96 |
|
---|
97 | return hash;
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public String toString() {
|
---|
102 | return "msg[target=" + getParameter("window.hwnd") + ";type=" + type
|
---|
103 | + "]";
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void setTarget(WindowTree windowTree)
|
---|
107 | throws InvalidParameterException {
|
---|
108 | int hwnd = Integer.parseInt(getParameter("window.hwnd"));
|
---|
109 | WindowTreeNode node = windowTree.find(hwnd);
|
---|
110 | if (node == null) {
|
---|
111 | throw new InvalidParameterException("No window with HWND " + hwnd
|
---|
112 | + " found in window tree!");
|
---|
113 | } else {
|
---|
114 | windowClass = node.getClassName();
|
---|
115 | resourceId = node.getResourceId();
|
---|
116 | xmlWindowDescription = node.xmlRepresentation();
|
---|
117 | parentNames = node.getParentNames();
|
---|
118 | WindowTreeNode parent = node.getParent();
|
---|
119 | if( parent==null ) {
|
---|
120 | parentClass = "";
|
---|
121 | } else {
|
---|
122 | parentClass = parent.getClassName();
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | public void setLPARAM(long paramValue) {
|
---|
128 | LPARAM = paramValue;
|
---|
129 | }
|
---|
130 |
|
---|
131 | public void setWPARAM(long paramValue) {
|
---|
132 | WPARAM = paramValue;
|
---|
133 | }
|
---|
134 |
|
---|
135 | public long getLPARAM() {
|
---|
136 | return LPARAM;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public long getWPARAM() {
|
---|
140 | return WPARAM;
|
---|
141 | }
|
---|
142 |
|
---|
143 | public void setLPARAMasWindowDesc(String windowDesc) {
|
---|
144 | LPARAMasWindowDesc = windowDesc;
|
---|
145 | }
|
---|
146 |
|
---|
147 | public void setWPARAMasWindowDesc(String windowDesc) {
|
---|
148 | WPARAMasWindowDesc = windowDesc;
|
---|
149 | }
|
---|
150 |
|
---|
151 | public String getLPARAMasWindowDesc() {
|
---|
152 | return LPARAMasWindowDesc;
|
---|
153 | }
|
---|
154 |
|
---|
155 | public String getWPARAMasWindowDesc() {
|
---|
156 | return WPARAMasWindowDesc;
|
---|
157 | }
|
---|
158 |
|
---|
159 | public String getXmlWindowDescription() {
|
---|
160 | return xmlWindowDescription;
|
---|
161 | }
|
---|
162 |
|
---|
163 | public void setXmlWindowDescription(String xmlWindowDescription) {
|
---|
164 | this.xmlWindowDescription = xmlWindowDescription;
|
---|
165 | }
|
---|
166 |
|
---|
167 | public int getDelay() {
|
---|
168 | return delay;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public void setDelay(int delay) {
|
---|
172 | this.delay = delay;
|
---|
173 | }
|
---|
174 |
|
---|
175 | public String getParentNames() {
|
---|
176 | return parentNames;
|
---|
177 | }
|
---|
178 |
|
---|
179 | public String getParentClass() {
|
---|
180 | return parentClass;
|
---|
181 | }
|
---|
182 |
|
---|
183 | public int getNumParams() {
|
---|
184 | return params.size();
|
---|
185 | }
|
---|
186 |
|
---|
187 | public String getReplay() {
|
---|
188 | StringBuilder currentMsgStr = new StringBuilder(400);
|
---|
189 | currentMsgStr.append(" <msg type=\""+type+"\" ");
|
---|
190 | currentMsgStr.append("LPARAM=\""+LPARAM+"\" ");
|
---|
191 | currentMsgStr.append("WPARAM=\""+WPARAM+"\" ");
|
---|
192 | currentMsgStr.append("delay=\""+delay+"\">");
|
---|
193 | if( LPARAMasWindowDesc!=null ) {
|
---|
194 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
195 | currentMsgStr.append(" <LPARAM>");
|
---|
196 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
197 | currentMsgStr.append(LPARAMasWindowDesc);
|
---|
198 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
199 | currentMsgStr.append("</LPARAM>");
|
---|
200 | }
|
---|
201 | if( WPARAMasWindowDesc!=null ) {
|
---|
202 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
203 | currentMsgStr.append(" <WPARAM>");
|
---|
204 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
205 | currentMsgStr.append(WPARAMasWindowDesc);
|
---|
206 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
207 | currentMsgStr.append(" </WPARAM>");
|
---|
208 | }
|
---|
209 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
210 | currentMsgStr.append(xmlWindowDescription);
|
---|
211 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
212 | currentMsgStr.append(" </msg>");
|
---|
213 | currentMsgStr.append(StringTools.ENDLINE);
|
---|
214 | return currentMsgStr.toString();
|
---|
215 | }
|
---|
216 |
|
---|
217 | public String getTarget() {
|
---|
218 | return xmlWindowDescription;
|
---|
219 | }
|
---|
220 | }
|
---|