source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/data/WindowsMessage.java @ 1

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