| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.om; |
| 9 | |
| 10 | |
| 11 | import net.sf.saxon.expr.parser.Location; |
| 12 | import net.sf.saxon.type.SimpleType; |
| 13 | |
| 14 | /** |
| 15 | * AttributeCollection represents the collection of attributes available on a particular element |
| 16 | * node. It is modelled on the SAX2 Attributes interface, but is extended firstly to work with |
| 17 | * Saxon NamePools, and secondly to provide type information as required by the XPath 2.0 data model. |
| 18 | */ |
| 19 | |
| 20 | public interface AttributeCollection { |
| 21 | |
| 22 | /** |
| 23 | * Return the number of attributes in the list. |
| 24 | * |
| 25 | * @return The number of attributes in the list. |
| 26 | */ |
| 27 | |
| 28 | int getLength(); |
| 29 | |
| 30 | /** |
| 31 | * Get the node name of an attribute (by position) |
| 32 | * |
| 33 | * @param index The position of the attribute in the list |
| 34 | * @return The node name of the attribute, or null if there is no attribute in that position |
| 35 | */ |
| 36 | |
| 37 | NodeName getNodeName(int index); |
| 38 | |
| 39 | /** |
| 40 | * Get the fingerprint of an attribute (by position). |
| 41 | * |
| 42 | * @param index The position of the attribute in the list. |
| 43 | * @return The name code of the attribute, or -1 if there is no attribute at that position. |
| 44 | */ |
| 45 | |
| 46 | int getFingerprint(int index); |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * Get the type annotation of an attribute (by position). |
| 51 | * |
| 52 | * @param index The position of the attribute in the list. |
| 53 | * @return The type annotation |
| 54 | */ |
| 55 | |
| 56 | SimpleType getTypeAnnotation(int index); |
| 57 | |
| 58 | /** |
| 59 | * Get the location of an attribute (by position) |
| 60 | * |
| 61 | * @param index The position of the attribute in the list. |
| 62 | * @return The location identifier of the attribute. |
| 63 | */ |
| 64 | |
| 65 | Location getLocation(int index); |
| 66 | |
| 67 | /** |
| 68 | * Get the systemId part of the location of an attribute, at a given index. |
| 69 | * <p>Attribute location information is not available from a SAX parser, so this method |
| 70 | * is not useful for getting the location of an attribute in a source document. However, |
| 71 | * in a Saxon result document, the location information represents the location in the |
| 72 | * stylesheet of the instruction used to generate this attribute, which is useful for |
| 73 | * debugging.</p> |
| 74 | * |
| 75 | * @param index the required attribute |
| 76 | * @return the systemId of the location of the attribute |
| 77 | */ |
| 78 | |
| 79 | String getSystemId(int index); |
| 80 | |
| 81 | /** |
| 82 | * Get the line number part of the location of an attribute, at a given index. |
| 83 | * <p>Attribute location information is not available from a SAX parser, so this method |
| 84 | * is not useful for getting the location of an attribute in a source document. However, |
| 85 | * in a Saxon result document, the location information represents the location in the |
| 86 | * stylesheet of the instruction used to generate this attribute, which is useful for |
| 87 | * debugging.</p> |
| 88 | * |
| 89 | * @param index the required attribute |
| 90 | * @return the line number of the location of the attribute |
| 91 | */ |
| 92 | |
| 93 | int getLineNumber(int index); |
| 94 | |
| 95 | /** |
| 96 | * Get the properties of an attribute (by position) |
| 97 | * |
| 98 | * @param index The position of the attribute in the list. |
| 99 | * @return The properties of the attribute. This is a set |
| 100 | * of bit-settings defined in class {@link net.sf.saxon.event.ReceiverOptions}. The |
| 101 | * most interesting of these is {{@link net.sf.saxon.event.ReceiverOptions#DEFAULTED_ATTRIBUTE}, |
| 102 | * which indicates an attribute that was added to an element as a result of schema validation. |
| 103 | */ |
| 104 | |
| 105 | int getProperties(int index); |
| 106 | |
| 107 | /** |
| 108 | * Get the prefix of the name of an attribute (by position). |
| 109 | * |
| 110 | * @param index The position of the attribute in the list. |
| 111 | * @return The prefix of the attribute name as a string, or null if there |
| 112 | * is no attribute at that position. Returns "" for an attribute that |
| 113 | * has no prefix. |
| 114 | */ |
| 115 | |
| 116 | String getPrefix(int index); |
| 117 | |
| 118 | /** |
| 119 | * Get the lexical QName of an attribute (by position). |
| 120 | * |
| 121 | * @param index The position of the attribute in the list. |
| 122 | * @return The lexical QName of the attribute as a string, or null if there |
| 123 | * is no attribute at that position. |
| 124 | */ |
| 125 | |
| 126 | String getQName(int index); |
| 127 | |
| 128 | /** |
| 129 | * Get the local name of an attribute (by position). |
| 130 | * |
| 131 | * @param index The position of the attribute in the list. |
| 132 | * @return The local name of the attribute as a string, or null if there |
| 133 | * is no attribute at that position. |
| 134 | */ |
| 135 | |
| 136 | String getLocalName(int index); |
| 137 | |
| 138 | /** |
| 139 | * Get the namespace URI of an attribute (by position). |
| 140 | * |
| 141 | * @param index The position of the attribute in the list. |
| 142 | * @return The namespace URI of the attribute as a string |
| 143 | * (empty string for an attribute in no namespace), or null if there |
| 144 | * is no attribute at that position. |
| 145 | */ |
| 146 | |
| 147 | String getURI(int index); |
| 148 | |
| 149 | /** |
| 150 | * Get the index of an attribute (by name). |
| 151 | * |
| 152 | * @param uri The namespace uri of the attribute. |
| 153 | * @param localname The local name of the attribute. |
| 154 | * @return The index position of the attribute, or -1 if absent |
| 155 | */ |
| 156 | |
| 157 | int getIndex(String uri, String localname); |
| 158 | |
| 159 | /** |
| 160 | * Get the index, given the fingerprint |
| 161 | */ |
| 162 | |
| 163 | int getIndexByFingerprint(int fingerprint); |
| 164 | |
| 165 | /** |
| 166 | * Get the attribute value using its fingerprint |
| 167 | */ |
| 168 | |
| 169 | String getValueByFingerprint(int fingerprint); |
| 170 | |
| 171 | /** |
| 172 | * Get the value of an attribute (by name). |
| 173 | * |
| 174 | * @param uri The namespace uri of the attribute. |
| 175 | * @param localname The local name of the attribute. |
| 176 | * @return The value of the attribute |
| 177 | */ |
| 178 | |
| 179 | public String getValue(String uri, String localname); |
| 180 | |
| 181 | /** |
| 182 | * Get the value of an attribute (by position). |
| 183 | * |
| 184 | * @param index The position of the attribute in the list. |
| 185 | * @return The attribute value as a string, or null if |
| 186 | * there is no attribute at that position. |
| 187 | */ |
| 188 | |
| 189 | String getValue(int index); |
| 190 | |
| 191 | /** |
| 192 | * Determine whether a given attribute has the is-ID property set |
| 193 | */ |
| 194 | |
| 195 | boolean isId(int index); |
| 196 | |
| 197 | /** |
| 198 | * Determine whether a given attribute has the is-idref property set |
| 199 | */ |
| 200 | |
| 201 | boolean isIdref(int index); |
| 202 | } |
| 203 |