[961] | 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.html.guimodel; |
---|
| 16 | |
---|
[2146] | 17 | import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec; |
---|
[961] | 18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * <p> |
---|
[1276] | 22 | * a GUI element specification of an HTML server. This is the root element for a GUI model of |
---|
| 23 | * an HTML web site. It is identified through a host and a port. Its children are documents. |
---|
[961] | 24 | * </p> |
---|
| 25 | * |
---|
| 26 | * @author Patrick Harms |
---|
| 27 | */ |
---|
| 28 | public class HTMLServerSpec extends HTMLGUIElementSpec implements IGUIElementSpec { |
---|
| 29 | |
---|
[1276] | 30 | /** |
---|
| 31 | * <p> |
---|
| 32 | * default serial version UID |
---|
| 33 | * </p> |
---|
| 34 | */ |
---|
[961] | 35 | private static final long serialVersionUID = 1L; |
---|
| 36 | |
---|
[1276] | 37 | /** |
---|
| 38 | * <p> |
---|
| 39 | * the host of the server |
---|
| 40 | * </p> |
---|
| 41 | */ |
---|
[961] | 42 | private String host; |
---|
| 43 | |
---|
[1276] | 44 | /** |
---|
| 45 | * <p> |
---|
| 46 | * the port of the server |
---|
| 47 | * </p> |
---|
| 48 | */ |
---|
[961] | 49 | private int port; |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * <p> |
---|
[1276] | 53 | * initialize the server specification with a host and a port. |
---|
[961] | 54 | * </p> |
---|
| 55 | * |
---|
[1276] | 56 | * @param host the host name of the server |
---|
| 57 | * @param port the port number of the server |
---|
| 58 | * |
---|
| 59 | * @throws IllegalArgumentException if one of the parameters is invalid (e.g. host = null) |
---|
[961] | 60 | */ |
---|
[1059] | 61 | public HTMLServerSpec(String host, int port) { |
---|
[1436] | 62 | super("server", (host != null ? host.hashCode() : 0) + port); |
---|
[961] | 63 | |
---|
| 64 | if (host == null) { |
---|
| 65 | throw new IllegalArgumentException("host must not be null"); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | if ((port < -1) || (port > 65536)) { |
---|
| 69 | throw new IllegalArgumentException("port " + port + " is not a valid port"); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | this.host = host; |
---|
| 73 | this.port = port; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /* (non-Javadoc) |
---|
| 77 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) |
---|
| 78 | */ |
---|
| 79 | @Override |
---|
[2146] | 80 | public boolean getSimilarity(IEventTargetSpec other) { |
---|
[961] | 81 | if (other instanceof HTMLServerSpec) { |
---|
| 82 | HTMLServerSpec otherSpec = (HTMLServerSpec) other; |
---|
| 83 | |
---|
| 84 | if (!super.getSimilarity(otherSpec)) { |
---|
| 85 | return false; |
---|
| 86 | } |
---|
| 87 | else if (!host.equals(otherSpec.host)) { |
---|
| 88 | return false; |
---|
| 89 | } |
---|
| 90 | else { |
---|
| 91 | return (port == otherSpec.port); |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | return false; |
---|
| 96 | } |
---|
| 97 | |
---|
[1264] | 98 | /* (non-Javadoc) |
---|
| 99 | * @see java.lang.Object#toString() |
---|
| 100 | */ |
---|
| 101 | @Override |
---|
| 102 | public String toString() { |
---|
| 103 | String str = "Server(" + getHost(); |
---|
| 104 | |
---|
| 105 | if (getPort() > -1 ) { |
---|
| 106 | str += ":" + getPort(); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | str += ")"; |
---|
| 110 | return str; |
---|
| 111 | } |
---|
| 112 | |
---|
[961] | 113 | /** |
---|
| 114 | * <p> |
---|
[1276] | 115 | * returns the host of the represented server |
---|
[961] | 116 | * </p> |
---|
| 117 | * |
---|
[1276] | 118 | * @return the host |
---|
[961] | 119 | */ |
---|
| 120 | String getHost() { |
---|
| 121 | return this.host; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * <p> |
---|
[1276] | 126 | * returns the port of the represented server |
---|
[961] | 127 | * </p> |
---|
| 128 | * |
---|
[1276] | 129 | * @return the port |
---|
[961] | 130 | */ |
---|
| 131 | int getPort() { |
---|
| 132 | return this.port; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | } |
---|