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