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