[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 | |
---|
| 17 | import java.net.URL; |
---|
| 18 | |
---|
| 19 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * <p> |
---|
| 23 | * TODO comment |
---|
| 24 | * </p> |
---|
| 25 | * |
---|
| 26 | * @author Patrick Harms |
---|
| 27 | */ |
---|
| 28 | public class HTMLServerSpec extends HTMLGUIElementSpec implements IGUIElementSpec { |
---|
| 29 | |
---|
| 30 | /** */ |
---|
| 31 | private static final long serialVersionUID = 1L; |
---|
| 32 | |
---|
| 33 | /** */ |
---|
| 34 | private String host; |
---|
| 35 | |
---|
| 36 | /** */ |
---|
| 37 | private int port; |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * <p> |
---|
| 41 | * TODO: comment |
---|
| 42 | * </p> |
---|
| 43 | * |
---|
| 44 | * @param serverName |
---|
| 45 | * @param port |
---|
| 46 | */ |
---|
[1059] | 47 | public HTMLServerSpec(String host, int port) { |
---|
[961] | 48 | super("server"); |
---|
| 49 | |
---|
| 50 | if (host == null) { |
---|
| 51 | throw new IllegalArgumentException("host must not be null"); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | if ((port < -1) || (port > 65536)) { |
---|
| 55 | throw new IllegalArgumentException("port " + port + " is not a valid port"); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | this.host = host; |
---|
| 59 | this.port = port; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * <p> |
---|
| 64 | * TODO: comment |
---|
| 65 | * </p> |
---|
| 66 | * |
---|
| 67 | * @param pageURL |
---|
| 68 | */ |
---|
[1059] | 69 | public HTMLServerSpec(URL pageURL) { |
---|
[961] | 70 | super("server"); |
---|
| 71 | |
---|
| 72 | if (pageURL == null) { |
---|
| 73 | throw new IllegalArgumentException("page URL must not be null"); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | this.host = pageURL.getHost(); |
---|
| 77 | this.port = pageURL.getPort(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /* (non-Javadoc) |
---|
| 81 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) |
---|
| 82 | */ |
---|
| 83 | @Override |
---|
| 84 | public boolean getSimilarity(IGUIElementSpec other) { |
---|
| 85 | if (other instanceof HTMLServerSpec) { |
---|
| 86 | HTMLServerSpec otherSpec = (HTMLServerSpec) other; |
---|
| 87 | |
---|
| 88 | if (!super.getSimilarity(otherSpec)) { |
---|
| 89 | return false; |
---|
| 90 | } |
---|
| 91 | else if (!host.equals(otherSpec.host)) { |
---|
| 92 | return false; |
---|
| 93 | } |
---|
| 94 | else { |
---|
| 95 | return (port == otherSpec.port); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | return false; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * <p> |
---|
| 104 | * TODO: comment |
---|
| 105 | * </p> |
---|
| 106 | * |
---|
| 107 | * @return |
---|
| 108 | */ |
---|
| 109 | String getHost() { |
---|
| 110 | return this.host; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /** |
---|
| 114 | * <p> |
---|
| 115 | * TODO: comment |
---|
| 116 | * </p> |
---|
| 117 | * |
---|
| 118 | * @return |
---|
| 119 | */ |
---|
| 120 | int getPort() { |
---|
| 121 | return this.port; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | } |
---|