[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 de.ugoe.cs.autoquest.eventcore.guimodel.IFrame; |
---|
[1490] | 18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
[1876] | 19 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; |
---|
[961] | 20 | |
---|
| 21 | /** |
---|
| 22 | * <p> |
---|
[1276] | 23 | * a GUI element representing an HTML server. This is the root element for a GUI model of |
---|
| 24 | * an HTML web site. It is identified through a host and a port. Its children are documents. |
---|
[961] | 25 | * </p> |
---|
| 26 | * |
---|
| 27 | * @author Patrick Harms |
---|
| 28 | */ |
---|
| 29 | public class HTMLServer extends HTMLGUIElement implements IFrame { |
---|
| 30 | |
---|
[1276] | 31 | /** |
---|
| 32 | * <p> |
---|
| 33 | * default serial version UID |
---|
| 34 | * </p> |
---|
| 35 | */ |
---|
[961] | 36 | private static final long serialVersionUID = 1L; |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | * <p> |
---|
[1276] | 40 | * instantiates the server with an appropriate specification |
---|
[961] | 41 | * </p> |
---|
| 42 | * |
---|
[1276] | 43 | * @param specification the server specification |
---|
[2210] | 44 | * @param parent the parent of the serve, must always be null. Just included as |
---|
[1276] | 45 | * required by the automatic instantiation mechanism |
---|
| 46 | * |
---|
| 47 | * @throws IllegalArgumentException if the provided parent is not null |
---|
[961] | 48 | */ |
---|
| 49 | public HTMLServer(HTMLServerSpec specification, HTMLGUIElement parent) { |
---|
| 50 | super(specification, null); |
---|
| 51 | |
---|
| 52 | if (parent != null) { |
---|
| 53 | throw new IllegalArgumentException("a GUI element representing the server must not " + |
---|
| 54 | "have a parent GUI element"); |
---|
| 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* |
---|
| 59 | * (non-Javadoc) |
---|
| 60 | * |
---|
| 61 | * @see de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement#getElementDescriptor() |
---|
| 62 | */ |
---|
| 63 | @Override |
---|
| 64 | protected String getElementDescriptor() { |
---|
| 65 | return "Server"; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * <p> |
---|
[1276] | 70 | * returns the host of the represented server |
---|
[961] | 71 | * </p> |
---|
| 72 | * |
---|
[1276] | 73 | * @return the host |
---|
[961] | 74 | */ |
---|
[1222] | 75 | public String getHost() { |
---|
[961] | 76 | return ((HTMLServerSpec) super.getSpecification()).getHost(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * <p> |
---|
[1276] | 81 | * returns the port of the represented server |
---|
[961] | 82 | * </p> |
---|
| 83 | * |
---|
[1276] | 84 | * @return the port |
---|
[961] | 85 | */ |
---|
[1222] | 86 | public int getPort() { |
---|
[961] | 87 | return ((HTMLServerSpec) super.getSpecification()).getPort(); |
---|
| 88 | } |
---|
| 89 | |
---|
[1490] | 90 | /* (non-Javadoc) |
---|
[1876] | 91 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getView() |
---|
| 92 | */ |
---|
| 93 | @Override |
---|
| 94 | public IGUIView getView() { |
---|
| 95 | return null; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | /* (non-Javadoc) |
---|
[1490] | 99 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement) |
---|
| 100 | */ |
---|
| 101 | @Override |
---|
| 102 | public double getDistanceTo(IGUIElement otherElement) { |
---|
| 103 | if (otherElement instanceof HTMLServer) { |
---|
| 104 | if (this.equals(otherElement)) { |
---|
| 105 | return DISTANCE_NONE; |
---|
| 106 | } |
---|
| 107 | else { |
---|
| 108 | return DISTANCE_DISTINCT_SERVER; |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | else if (otherElement instanceof HTMLDocument) { |
---|
| 112 | if (this.equals(((HTMLDocument) otherElement).getServer())) { |
---|
| 113 | return DISTANCE_SAME_SERVER; |
---|
| 114 | } |
---|
| 115 | else { |
---|
| 116 | return DISTANCE_DISTINCT_SERVER; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | else if (otherElement instanceof HTMLPageElement) { |
---|
| 120 | HTMLServerSpec serverSpec = |
---|
| 121 | ((HTMLPageElementSpec) otherElement.getSpecification()).getPage().getServer(); |
---|
| 122 | |
---|
| 123 | if (this.getSpecification().getSimilarity(serverSpec)) { |
---|
| 124 | return DISTANCE_SAME_SERVER; |
---|
| 125 | } |
---|
| 126 | else { |
---|
| 127 | return DISTANCE_DISTINCT_SERVER; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | return DISTANCE_DISTINCT_SERVER; |
---|
| 132 | } |
---|
| 133 | |
---|
[961] | 134 | } |
---|