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

Last change on this file since 1436 was 1436, checked in by pharms, 10 years ago
  • corrected a bug in creating hashcodes for GUI elements (they changed after storing a GUI model to a file and then reloading it)
File size: 4.8 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.guimodel.IGUIElementSpec;
18
19/**
20 * <p>
21 * a GUI element specification of an HTML document, i.e., a page on an HTML server. This is the
22 * element for a GUI model of an HTML web site being always and only the children of servers. It
23 * is identified through the server on which it resists, its path, a potential query, and a title.
24 * Its children are HTML page elements
25 * </p>
26 *
27 * @author Patrick Harms
28 */
29public class HTMLDocumentSpec extends HTMLGUIElementSpec implements IGUIElementSpec {
30
31    /**
32     * <p>
33     * default serial version UID
34     * </p>
35     */
36    private static final long serialVersionUID = 1L;
37   
38    /**
39     * <p>
40     * the server on which the document resists
41     * </p>
42     */
43    private HTMLServerSpec server;
44   
45    /**
46     * <p>
47     * the path in the URL of the document
48     * </p>
49     */
50    private String path;
51   
52    /**
53     * <p>
54     * the query in the URL of the document
55     * </p>
56     */
57    private String query;
58   
59    /**
60     * <p>
61     * the title of the document
62     * </p>
63     */
64    private String title;
65   
66    /**
67     * <p>
68     * initializes the document with its server, path, query, and title
69     * </p>
70     *
71     * @param server the server on which the document resists
72     * @param path   the path in the URL of the document
73     * @param query  the query in the URL of the document
74     * @param title  the title of the document
75     *
76     * @throws IllegalArgumentException if the server or path are invalid, i.e. null
77     */
78    public HTMLDocumentSpec(HTMLServerSpec server, String path, String query, String title) {
79        super("document", (server != null ? server.hashCode() : 0) +
80              (path != null ? path.hashCode() : 0) + (query != null ? query.hashCode() : 0) +
81              (title != null ? title.hashCode() : 0));
82       
83        if (server == null) {
84            throw new IllegalArgumentException("server must not be null");
85        }
86        else if (path == null) {
87            throw new IllegalArgumentException("pagePath must not be null");
88        }
89       
90        this.server = server;
91        this.path = path;
92        this.query = query;
93        this.title = title;
94    }
95
96    /* (non-Javadoc)
97     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec)
98     */
99    @Override
100    public boolean getSimilarity(IGUIElementSpec other) {
101        if (other instanceof HTMLDocumentSpec) {
102            HTMLDocumentSpec otherSpec = (HTMLDocumentSpec) other;
103           
104            if (!super.getSimilarity(otherSpec)) {
105                return false;
106            }
107            else if (!server.getSimilarity(otherSpec.server)) {
108                return false;
109            }
110            else if (!path.equals(otherSpec.path)) {
111                return false;
112            }
113            else if (query != null ? !query.equals(otherSpec.query) : otherSpec.query != null) {
114                return false;
115            }
116            else {
117                return (title != null ? title.equals(otherSpec.title) : otherSpec.title == null);
118            }
119        }
120       
121        return false;
122    }
123
124    /* (non-Javadoc)
125     * @see java.lang.Object#toString()
126     */
127    @Override
128    public String toString() {
129        return "Document(" + getPath() + ", \"" + getTitle() + "\")";
130    }
131
132    /**
133     * <p>
134     * returns the server on which the document resists
135     * </p>
136     *
137     * @return the server on which the document resists
138     */
139    public HTMLServerSpec getServer() {
140        return server;
141    }
142
143    /**
144     * <p>
145     * returns the path in the URL of the document
146     * </p>
147     *
148     * @return the path in the URL of the document
149     */
150    String getPath() {
151        return path;
152    }
153
154    /**
155     * <p>
156     * returns the query in the URL of the document
157     * </p>
158     *
159     * @return the query in the URL of the document
160     */
161    String getQuery() {
162        return query;
163    }
164
165    /**
166     * <p>
167     * returns the title of the document
168     * </p>
169     *
170     * @return the title of the document
171     */
172    String getTitle() {
173        return title;
174    }
175
176}
Note: See TracBrowser for help on using the repository browser.