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 | * TODO comment |
---|
22 | * </p> |
---|
23 | * |
---|
24 | * @author Patrick Harms |
---|
25 | */ |
---|
26 | public class HTMLPageElementSpec extends HTMLGUIElementSpec implements IGUIElementSpec { |
---|
27 | |
---|
28 | /** */ |
---|
29 | private static final long serialVersionUID = 1L; |
---|
30 | |
---|
31 | /** */ |
---|
32 | private HTMLPageSpec page; |
---|
33 | |
---|
34 | /** */ |
---|
35 | private String tag; |
---|
36 | |
---|
37 | /** */ |
---|
38 | private String id; |
---|
39 | |
---|
40 | /** */ |
---|
41 | private int index; |
---|
42 | |
---|
43 | /** |
---|
44 | * <p> |
---|
45 | * TODO: comment |
---|
46 | * </p> |
---|
47 | * |
---|
48 | * @param type |
---|
49 | * @param index |
---|
50 | * @param id |
---|
51 | */ |
---|
52 | public HTMLPageElementSpec(HTMLPageSpec page, String tag, String id, int index) { |
---|
53 | super(tag); |
---|
54 | |
---|
55 | if (page == null) { |
---|
56 | throw new IllegalArgumentException("page must not be null"); |
---|
57 | } |
---|
58 | else if (tag == null) { |
---|
59 | throw new IllegalArgumentException("tag must not be null"); |
---|
60 | } |
---|
61 | else if ((id == null) && (index < 0)) { |
---|
62 | throw new IllegalArgumentException |
---|
63 | ("either id must not be null or the index must be greater or equal to 0"); |
---|
64 | } |
---|
65 | |
---|
66 | this.page = page; |
---|
67 | this.tag = tag; |
---|
68 | this.id = id; |
---|
69 | this.index = index; |
---|
70 | } |
---|
71 | |
---|
72 | /* (non-Javadoc) |
---|
73 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) |
---|
74 | */ |
---|
75 | @Override |
---|
76 | public boolean getSimilarity(IGUIElementSpec other) { |
---|
77 | if (other instanceof HTMLPageElementSpec) { |
---|
78 | HTMLPageElementSpec otherSpec = (HTMLPageElementSpec) other; |
---|
79 | |
---|
80 | if (!super.getSimilarity(otherSpec)) { |
---|
81 | return false; |
---|
82 | } |
---|
83 | else if (!page.getSimilarity(otherSpec.page)) { |
---|
84 | return false; |
---|
85 | } |
---|
86 | else if (!tag.equals(otherSpec.tag)) { |
---|
87 | return false; |
---|
88 | } |
---|
89 | |
---|
90 | if (id != null) { |
---|
91 | return id.equals(otherSpec.id); |
---|
92 | } |
---|
93 | else if (index >= 0) { |
---|
94 | return index == otherSpec.index; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | return false; |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * <p> |
---|
103 | * TODO: comment |
---|
104 | * </p> |
---|
105 | * |
---|
106 | * @return |
---|
107 | */ |
---|
108 | HTMLPageSpec getPage() { |
---|
109 | return page; |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * <p> |
---|
114 | * TODO: comment |
---|
115 | * </p> |
---|
116 | * |
---|
117 | * @return |
---|
118 | */ |
---|
119 | String getTag() { |
---|
120 | return tag; |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * <p> |
---|
125 | * TODO: comment |
---|
126 | * </p> |
---|
127 | * |
---|
128 | * @return |
---|
129 | */ |
---|
130 | String getTagId() { |
---|
131 | return id; |
---|
132 | } |
---|
133 | |
---|
134 | /** |
---|
135 | * <p> |
---|
136 | * TODO: comment |
---|
137 | * </p> |
---|
138 | * |
---|
139 | * @return |
---|
140 | */ |
---|
141 | int getTagIndex() { |
---|
142 | return index; |
---|
143 | } |
---|
144 | |
---|
145 | } |
---|