[961] | 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 | /** */ |
---|
[1069] | 32 | private HTMLDocumentSpec page; |
---|
[961] | 33 | |
---|
| 34 | /** */ |
---|
[1069] | 35 | private String tagName; |
---|
[961] | 36 | |
---|
| 37 | /** */ |
---|
[1069] | 38 | private String htmlId; |
---|
[961] | 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 | */ |
---|
[1069] | 52 | public HTMLPageElementSpec(HTMLDocumentSpec page, String tagName, String htmlId, int index) { |
---|
| 53 | super(tagName); |
---|
[961] | 54 | |
---|
| 55 | if (page == null) { |
---|
| 56 | throw new IllegalArgumentException("page must not be null"); |
---|
| 57 | } |
---|
[1069] | 58 | else if (tagName == null) { |
---|
[961] | 59 | throw new IllegalArgumentException("tag must not be null"); |
---|
| 60 | } |
---|
[1069] | 61 | else if ((htmlId == null) && (index < 0)) { |
---|
[961] | 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; |
---|
[1069] | 67 | this.tagName = tagName; |
---|
| 68 | this.htmlId = htmlId; |
---|
[961] | 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 | } |
---|
[1069] | 86 | else if (!tagName.equals(otherSpec.tagName)) { |
---|
[961] | 87 | return false; |
---|
| 88 | } |
---|
| 89 | |
---|
[1069] | 90 | if (htmlId != null) { |
---|
| 91 | return htmlId.equals(otherSpec.htmlId); |
---|
[961] | 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 | */ |
---|
[1069] | 108 | HTMLDocumentSpec getPage() { |
---|
[961] | 109 | return page; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * <p> |
---|
| 114 | * TODO: comment |
---|
| 115 | * </p> |
---|
| 116 | * |
---|
| 117 | * @return |
---|
| 118 | */ |
---|
[1069] | 119 | String getTagName() { |
---|
| 120 | return tagName; |
---|
[961] | 121 | } |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | * <p> |
---|
| 125 | * TODO: comment |
---|
| 126 | * </p> |
---|
| 127 | * |
---|
| 128 | * @return |
---|
| 129 | */ |
---|
[1069] | 130 | String getHtmlId() { |
---|
| 131 | return htmlId; |
---|
[961] | 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * <p> |
---|
| 136 | * TODO: comment |
---|
| 137 | * </p> |
---|
| 138 | * |
---|
| 139 | * @return |
---|
| 140 | */ |
---|
[1069] | 141 | int getIndex() { |
---|
[961] | 142 | return index; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | } |
---|