source: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/guimodel/HTMLServerSpec.java @ 2146

Last change on this file since 2146 was 2146, checked in by pharms, 7 years ago
  • refactored GUI model so that hierarchical event target structures can also be used and created by plugins not being strictly for GUIs
File size: 3.4 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin.html.guimodel;
16
17import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec;
18import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
19
20/**
21 * <p>
22 * a GUI element specification of 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 */
28public class HTMLServerSpec extends HTMLGUIElementSpec implements IGUIElementSpec {
29
30    /**
31     * <p>
32     * default serial version UID
33     * </p>
34     */
35    private static final long serialVersionUID = 1L;
36   
37    /**
38     * <p>
39     * the host of the server
40     * </p>
41     */
42    private String host;
43   
44    /**
45     * <p>
46     * the port of the server
47     * </p>
48     */
49    private int port;
50
51    /**
52     * <p>
53     * initialize the server specification with a host and a port.
54     * </p>
55     *
56     * @param host the host name of the server
57     * @param port the port number of the server
58     *
59     * @throws IllegalArgumentException if one of the parameters is invalid (e.g. host = null)
60     */
61    public HTMLServerSpec(String host, int port) {
62        super("server", (host != null ? host.hashCode() : 0) + port);
63       
64        if (host == null) {
65            throw new IllegalArgumentException("host must not be null");
66        }
67       
68        if ((port < -1) || (port > 65536)) {
69            throw new IllegalArgumentException("port " + port + " is not a valid port");
70        }
71
72        this.host = host;
73        this.port = port;
74    }
75
76    /* (non-Javadoc)
77     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
78     */
79    @Override
80    public boolean getSimilarity(IEventTargetSpec other) {
81        if (other instanceof HTMLServerSpec) {
82            HTMLServerSpec otherSpec = (HTMLServerSpec) other;
83           
84            if (!super.getSimilarity(otherSpec)) {
85                return false;
86            }
87            else if (!host.equals(otherSpec.host)) {
88                return false;
89            }
90            else {
91                return (port == otherSpec.port);
92            }
93        }
94       
95        return false;
96    }
97
98    /* (non-Javadoc)
99     * @see java.lang.Object#toString()
100     */
101    @Override
102    public String toString() {
103        String str = "Server(" + getHost();
104
105        if (getPort() > -1 ) {
106            str += ":" + getPort();
107        }
108       
109        str += ")";
110        return str;
111    }
112
113    /**
114     * <p>
115     * returns the host of the represented server
116     * </p>
117     *
118     * @return the host
119     */
120    String getHost() {
121        return this.host;
122    }
123
124    /**
125     * <p>
126     * returns the port of the represented server
127     * </p>
128     *
129     * @return the port
130     */
131    int getPort() {
132        return this.port;
133    }
134
135}
Note: See TracBrowser for help on using the repository browser.