[1367] | 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 | * TODO comment |
---|
| 24 | * </p> |
---|
| 25 | * |
---|
| 26 | * @author Patrick Harms |
---|
| 27 | */ |
---|
| 28 | public class HTTPEventType implements IEventType { |
---|
| 29 | |
---|
| 30 | /** */ |
---|
| 31 | private static final long serialVersionUID = 1L; |
---|
| 32 | |
---|
| 33 | /** */ |
---|
| 34 | private HttpExchange exchange; |
---|
| 35 | |
---|
| 36 | /** */ |
---|
| 37 | private String name; |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * |
---|
| 41 | */ |
---|
| 42 | public HTTPEventType(HttpExchange exchange) { |
---|
| 43 | if (exchange == null) { |
---|
| 44 | throw new IllegalArgumentException("exchange must not be null"); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | this.exchange = exchange; |
---|
| 48 | |
---|
| 49 | StringBuffer nameBuffer = new StringBuffer("HTTPEvent"); |
---|
| 50 | |
---|
| 51 | boolean somethingAdded = false; |
---|
| 52 | |
---|
| 53 | if ((this.exchange.getRequest() != null) && |
---|
| 54 | (this.exchange.getRequest().getMethod() != null)) |
---|
| 55 | { |
---|
| 56 | nameBuffer.append("("); |
---|
| 57 | nameBuffer.append(this.exchange.getRequest().getMethod()); |
---|
| 58 | somethingAdded = true; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | String senderStr = HTTPUtils.toString(this.exchange.getSender()); |
---|
| 62 | String receiverStr = HTTPUtils.toString(this.exchange.getReceiver()); |
---|
| 63 | |
---|
| 64 | if ((senderStr != null) && (receiverStr != null)) { |
---|
| 65 | nameBuffer.append(somethingAdded ? ", " : "("); |
---|
| 66 | nameBuffer.append(senderStr); |
---|
| 67 | nameBuffer.append(" --> "); |
---|
| 68 | nameBuffer.append(receiverStr); |
---|
| 69 | somethingAdded = true; |
---|
| 70 | } |
---|
| 71 | else if (senderStr != null) { |
---|
| 72 | nameBuffer.append(somethingAdded ? ", " : "("); |
---|
| 73 | nameBuffer.append(senderStr); |
---|
| 74 | somethingAdded = true; |
---|
| 75 | } |
---|
| 76 | else if (receiverStr != null) { |
---|
| 77 | nameBuffer.append(somethingAdded ? ", " : "("); |
---|
| 78 | nameBuffer.append(receiverStr); |
---|
| 79 | somethingAdded = true; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (somethingAdded) { |
---|
| 83 | nameBuffer.append(")"); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | this.name = nameBuffer.toString(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | /* (non-Javadoc) |
---|
| 90 | * @see de.ugoe.cs.autoquest.eventcore.IEventType#getName() |
---|
| 91 | */ |
---|
| 92 | @Override |
---|
| 93 | public String getName() { |
---|
| 94 | return name; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | * @return the exchange |
---|
| 99 | */ |
---|
| 100 | public HttpExchange getExchange() { |
---|
| 101 | return exchange; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /* (non-Javadoc) |
---|
| 105 | * @see java.lang.Object#toString() |
---|
| 106 | */ |
---|
| 107 | @Override |
---|
| 108 | public String toString() { |
---|
| 109 | return name; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /* (non-Javadoc) |
---|
| 113 | * @see java.lang.Object#equals(java.lang.Object) |
---|
| 114 | */ |
---|
| 115 | @Override |
---|
| 116 | public boolean equals(Object obj) { |
---|
| 117 | return super.equals(obj); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /* (non-Javadoc) |
---|
| 121 | * @see java.lang.Object#hashCode() |
---|
| 122 | */ |
---|
| 123 | @Override |
---|
| 124 | public int hashCode() { |
---|
| 125 | return super.hashCode(); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | } |
---|