1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.plugin.http.eventcore; |
---|
16 | |
---|
17 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
18 | import de.ugoe.cs.autoquest.httpmonitor.exchange.HttpExchange; |
---|
19 | import de.ugoe.cs.autoquest.plugin.http.HTTPUtils; |
---|
20 | |
---|
21 | /** |
---|
22 | * <p> |
---|
23 | * the event type for HTTP events. Holds a reference to the HTTP exchange recorded by the HTTP |
---|
24 | * monitor. |
---|
25 | * </p> |
---|
26 | * |
---|
27 | * @author Patrick Harms |
---|
28 | */ |
---|
29 | public class HTTPEventType implements IEventType { |
---|
30 | |
---|
31 | /** */ |
---|
32 | private static final long serialVersionUID = 1L; |
---|
33 | |
---|
34 | /** |
---|
35 | * <p> |
---|
36 | * the HTTP exchange recorded by the HTTP monitor |
---|
37 | * </p> |
---|
38 | */ |
---|
39 | private HttpExchange exchange; |
---|
40 | |
---|
41 | /** |
---|
42 | * <p> |
---|
43 | * the name of the event type as required by AutoQUEST's framework |
---|
44 | * </p> |
---|
45 | */ |
---|
46 | private String name; |
---|
47 | |
---|
48 | /** |
---|
49 | * <p> |
---|
50 | * initializes this event with the represented HTTP exchange |
---|
51 | * </p> |
---|
52 | * |
---|
53 | * @param exchange the HTTP exchange recorded by the HTTP monitor |
---|
54 | */ |
---|
55 | public HTTPEventType(HttpExchange exchange) { |
---|
56 | if (exchange == null) { |
---|
57 | throw new IllegalArgumentException("exchange must not be null"); |
---|
58 | } |
---|
59 | |
---|
60 | this.exchange = exchange; |
---|
61 | |
---|
62 | StringBuffer nameBuffer = new StringBuffer("HTTPEvent"); |
---|
63 | |
---|
64 | boolean somethingAdded = false; |
---|
65 | |
---|
66 | if ((this.exchange.getRequest() != null) && |
---|
67 | (this.exchange.getRequest().getMethod() != null)) |
---|
68 | { |
---|
69 | nameBuffer.append("("); |
---|
70 | nameBuffer.append(this.exchange.getRequest().getMethod()); |
---|
71 | somethingAdded = true; |
---|
72 | } |
---|
73 | |
---|
74 | String senderStr = HTTPUtils.toString(this.exchange.getSender()); |
---|
75 | String receiverStr = HTTPUtils.toString(this.exchange.getReceiver()); |
---|
76 | |
---|
77 | if ((senderStr != null) && (receiverStr != null)) { |
---|
78 | nameBuffer.append(somethingAdded ? ", " : "("); |
---|
79 | nameBuffer.append(senderStr); |
---|
80 | nameBuffer.append(" --> "); |
---|
81 | nameBuffer.append(receiverStr); |
---|
82 | somethingAdded = true; |
---|
83 | } |
---|
84 | else if (senderStr != null) { |
---|
85 | nameBuffer.append(somethingAdded ? ", " : "("); |
---|
86 | nameBuffer.append(senderStr); |
---|
87 | somethingAdded = true; |
---|
88 | } |
---|
89 | else if (receiverStr != null) { |
---|
90 | nameBuffer.append(somethingAdded ? ", " : "("); |
---|
91 | nameBuffer.append(receiverStr); |
---|
92 | somethingAdded = true; |
---|
93 | } |
---|
94 | |
---|
95 | if (somethingAdded) { |
---|
96 | nameBuffer.append(")"); |
---|
97 | } |
---|
98 | |
---|
99 | this.name = nameBuffer.toString(); |
---|
100 | } |
---|
101 | |
---|
102 | /* (non-Javadoc) |
---|
103 | * @see de.ugoe.cs.autoquest.eventcore.IEventType#getName() |
---|
104 | */ |
---|
105 | @Override |
---|
106 | public String getName() { |
---|
107 | return name; |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * @return the HTTP exchange recorded by the HTTP monitor |
---|
112 | */ |
---|
113 | public HttpExchange getExchange() { |
---|
114 | return exchange; |
---|
115 | } |
---|
116 | |
---|
117 | /* (non-Javadoc) |
---|
118 | * @see java.lang.Object#toString() |
---|
119 | */ |
---|
120 | @Override |
---|
121 | public String toString() { |
---|
122 | return name; |
---|
123 | } |
---|
124 | |
---|
125 | /* (non-Javadoc) |
---|
126 | * @see java.lang.Object#equals(java.lang.Object) |
---|
127 | */ |
---|
128 | @Override |
---|
129 | public boolean equals(Object obj) { |
---|
130 | return super.equals(obj); |
---|
131 | } |
---|
132 | |
---|
133 | /* (non-Javadoc) |
---|
134 | * @see java.lang.Object#hashCode() |
---|
135 | */ |
---|
136 | @Override |
---|
137 | public int hashCode() { |
---|
138 | return super.hashCode(); |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|