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

Last change on this file since 87 was 87, checked in by sherbold, 13 years ago
  • made event implementations serializable

+ added commands saveObject and loadObject to save data stored in the global data container

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