1 | package de.ugoe.cs.eventbench.windows.data;
|
---|
2 |
|
---|
3 | import java.io.ByteArrayInputStream;
|
---|
4 |
|
---|
5 | import javax.xml.parsers.DocumentBuilder;
|
---|
6 | import javax.xml.parsers.DocumentBuilderFactory;
|
---|
7 |
|
---|
8 | import org.w3c.dom.Document;
|
---|
9 | import org.w3c.dom.Element;
|
---|
10 | import org.w3c.dom.NodeList;
|
---|
11 |
|
---|
12 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * <p>
|
---|
16 | * Convenience class for working with Windows MFC events.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class WindowsEvent extends ReplayableEvent<WindowsMessage> {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * <p>
|
---|
26 | * Id for object serialization.
|
---|
27 | * </p>
|
---|
28 | */
|
---|
29 | private static final long serialVersionUID = 1L;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * <p>
|
---|
33 | * Constructor. Creates a new WindowEvent.
|
---|
34 | * </p>
|
---|
35 | *
|
---|
36 | * @see de.ugoe.cs.eventbench.data.Event#Event(String)
|
---|
37 | * @param type
|
---|
38 | * type of the event.
|
---|
39 | */
|
---|
40 | public WindowsEvent(String type) {
|
---|
41 | super(type);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | protected boolean targetEquals(String otherTarget) {
|
---|
46 | return MFCTargetComparator.compare(target, otherTarget);
|
---|
47 | }
|
---|
48 |
|
---|
49 | int targetHash = 0;
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | protected int targetHashCode() {
|
---|
53 | if( targetHash==0 ) {
|
---|
54 | int multiplier = 17;
|
---|
55 | if (target != null) {
|
---|
56 | Document doc;
|
---|
57 | try {
|
---|
58 | DocumentBuilder documentBuilder = DocumentBuilderFactory
|
---|
59 | .newInstance().newDocumentBuilder();
|
---|
60 | doc = documentBuilder.parse(new ByteArrayInputStream(
|
---|
61 | ("<dummy>" + target + "</dummy>").getBytes("UTF-8")));
|
---|
62 | } catch (Exception e) {
|
---|
63 | e.printStackTrace();
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 | doc.getDocumentElement().normalize();
|
---|
67 | NodeList widgets = doc.getElementsByTagName("window");
|
---|
68 |
|
---|
69 | for (int i = 0; i < widgets.getLength(); i++) {
|
---|
70 | Element currentWidget = (Element) widgets.item(i);
|
---|
71 | targetHash = targetHash* multiplier + widgetHashCode(currentWidget);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | return targetHash;
|
---|
76 | }
|
---|
77 |
|
---|
78 | private int widgetHashCode(Element currentWidget) {
|
---|
79 | int hashCode = 0;
|
---|
80 | int multiplier = 41;
|
---|
81 | hashCode = hashCode * multiplier + currentWidget.getAttribute("class").hashCode();
|
---|
82 | hashCode = hashCode * multiplier + currentWidget.getAttribute("resourceId").hashCode();
|
---|
83 | hashCode = hashCode * multiplier + currentWidget.getAttribute("isModal").hashCode();
|
---|
84 | return hashCode;
|
---|
85 | }
|
---|
86 | }
|
---|