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 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; |
---|
20 | |
---|
21 | /** |
---|
22 | * <p> |
---|
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. |
---|
25 | * </p> |
---|
26 | * |
---|
27 | * @author Patrick Harms |
---|
28 | */ |
---|
29 | public class HTMLServer extends HTMLGUIElement implements IFrame { |
---|
30 | |
---|
31 | /** |
---|
32 | * <p> |
---|
33 | * default serial version UID |
---|
34 | * </p> |
---|
35 | */ |
---|
36 | private static final long serialVersionUID = 1L; |
---|
37 | |
---|
38 | /** |
---|
39 | * <p> |
---|
40 | * instantiates the server with an appropriate specification |
---|
41 | * </p> |
---|
42 | * |
---|
43 | * @param specification the server specification |
---|
44 | * @param parent the parent of the server --> must always be null. Just included as |
---|
45 | * required by the automatic instantiation mechanism |
---|
46 | * |
---|
47 | * @throws IllegalArgumentException if the provided parent is not null |
---|
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> |
---|
70 | * returns the host of the represented server |
---|
71 | * </p> |
---|
72 | * |
---|
73 | * @return the host |
---|
74 | */ |
---|
75 | public String getHost() { |
---|
76 | return ((HTMLServerSpec) super.getSpecification()).getHost(); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * <p> |
---|
81 | * returns the port of the represented server |
---|
82 | * </p> |
---|
83 | * |
---|
84 | * @return the port |
---|
85 | */ |
---|
86 | public int getPort() { |
---|
87 | return ((HTMLServerSpec) super.getSpecification()).getPort(); |
---|
88 | } |
---|
89 | |
---|
90 | /* (non-Javadoc) |
---|
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) |
---|
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 | |
---|
134 | } |
---|