PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/saxonB/net/sf/saxon/tinytree/TinyAttributeCollection.java

https://bitbucket.org/dmwelch/phdxnat_pipeline
Java | 283 lines | 89 code | 44 blank | 150 comment | 13 complexity | c30b434298c182650570509a6fbdeba5 MD5 | raw file
  1. package net.sf.saxon.tinytree;
  2. import net.sf.saxon.event.LocationProvider;
  3. import net.sf.saxon.om.AttributeCollection;
  4. import net.sf.saxon.om.NamePool;
  5. import net.sf.saxon.om.StandardNames;
  6. /**
  7. * An implementation of the AttributeCollection interface based directly on the
  8. * TinyTree data structure.
  9. */
  10. public class TinyAttributeCollection implements AttributeCollection {
  11. int element;
  12. TinyTree tree;
  13. int firstAttribute;
  14. public TinyAttributeCollection(TinyTree tree, int element) {
  15. this.tree = tree;
  16. this.element = element;
  17. firstAttribute = tree.alpha[element];
  18. }
  19. /**
  20. * Set the location provider. This must be set if the methods getSystemId() and getLineNumber()
  21. * are to be used to get location information for an attribute.
  22. */
  23. public void setLocationProvider(LocationProvider provider) {
  24. //
  25. }
  26. /**
  27. * Return the number of attributes in the list.
  28. *
  29. * @return The number of attributes in the list.
  30. */
  31. public int getLength() {
  32. int i = firstAttribute;
  33. while (i < tree.numberOfAttributes && tree.attParent[i] == element) {
  34. i++;
  35. }
  36. return i - firstAttribute;
  37. }
  38. /**
  39. * Get the namecode of an attribute (by position).
  40. *
  41. * @param index The position of the attribute in the list.
  42. * @return The display name of the attribute as a string, or null if there
  43. * is no attribute at that position.
  44. */
  45. public int getNameCode(int index) {
  46. return tree.attCode[firstAttribute + index];
  47. }
  48. /**
  49. * Get the type annotation of an attribute (by position).
  50. *
  51. * @param index The position of the attribute in the list.
  52. * @return The type annotation of the attribute as the fingerprint of the type name.
  53. * The bit {@link net.sf.saxon.om.NodeInfo#IS_DTD_TYPE} represents a DTD-derived type.
  54. */
  55. public int getTypeAnnotation(int index) {
  56. if (tree.attTypeCode == null) {
  57. return StandardNames.XS_UNTYPED_ATOMIC;
  58. }
  59. return tree.attTypeCode[firstAttribute + index];
  60. }
  61. /**
  62. * Get the locationID of an attribute (by position)
  63. *
  64. * @param index The position of the attribute in the list.
  65. * @return The location identifier of the attribute. This can be supplied
  66. * to a {@link net.sf.saxon.event.LocationProvider} in order to obtain the
  67. * actual system identifier and line number of the relevant location
  68. */
  69. public int getLocationId(int index) {
  70. return 0;
  71. }
  72. /**
  73. * Get the systemId part of the location of an attribute, at a given index.
  74. * <p/>
  75. * <p>Attribute location information is not available from a SAX parser, so this method
  76. * is not useful for getting the location of an attribute in a source document. However,
  77. * in a Saxon result document, the location information represents the location in the
  78. * stylesheet of the instruction used to generate this attribute, which is useful for
  79. * debugging.</p>
  80. *
  81. * @param index the required attribute
  82. * @return the systemId of the location of the attribute
  83. */
  84. public String getSystemId(int index) {
  85. return tree.getSystemId(element);
  86. }
  87. /**
  88. * Get the line number part of the location of an attribute, at a given index.
  89. * <p/>
  90. * <p>Attribute location information is not available from a SAX parser, so this method
  91. * is not useful for getting the location of an attribute in a source document. However,
  92. * in a Saxon result document, the location information represents the location in the
  93. * stylesheet of the instruction used to generate this attribute, which is useful for
  94. * debugging.</p>
  95. *
  96. * @param index the required attribute
  97. * @return the line number of the location of the attribute
  98. */
  99. public int getLineNumber(int index) {
  100. return -1;
  101. }
  102. /**
  103. * Get the properties of an attribute (by position)
  104. *
  105. * @param index The position of the attribute in the list.
  106. * @return The properties of the attribute. This is a set
  107. * of bit-settings defined in class {@link net.sf.saxon.event.ReceiverOptions}. The
  108. * most interesting of these is {{@link net.sf.saxon.event.ReceiverOptions#DEFAULTED_ATTRIBUTE},
  109. * which indicates an attribute that was added to an element as a result of schema validation.
  110. */
  111. public int getProperties(int index) {
  112. return 0;
  113. }
  114. /**
  115. * Get the prefix of the name of an attribute (by position).
  116. *
  117. * @param index The position of the attribute in the list.
  118. * @return The prefix of the attribute name as a string, or null if there
  119. * is no attribute at that position. Returns "" for an attribute that
  120. * has no prefix.
  121. */
  122. public String getPrefix(int index) {
  123. return tree.getNamePool().getPrefix(getNameCode(index));
  124. }
  125. /**
  126. * Get the lexical QName of an attribute (by position).
  127. *
  128. * @param index The position of the attribute in the list.
  129. * @return The lexical QName of the attribute as a string, or null if there
  130. * is no attribute at that position.
  131. */
  132. public String getQName(int index) {
  133. return tree.getNamePool().getDisplayName(getNameCode(index));
  134. }
  135. /**
  136. * Get the local name of an attribute (by position).
  137. *
  138. * @param index The position of the attribute in the list.
  139. * @return The local name of the attribute as a string, or null if there
  140. * is no attribute at that position.
  141. */
  142. public String getLocalName(int index) {
  143. return tree.getNamePool().getLocalName(getNameCode(index));
  144. }
  145. /**
  146. * Get the namespace URI of an attribute (by position).
  147. *
  148. * @param index The position of the attribute in the list.
  149. * @return The local name of the attribute as a string, or null if there
  150. * is no attribute at that position.
  151. */
  152. public String getURI(int index) {
  153. return tree.getNamePool().getURI(getNameCode(index));
  154. }
  155. /**
  156. * Get the index of an attribute (by name).
  157. *
  158. * @param uri The namespace uri of the attribute.
  159. * @param localname The local name of the attribute.
  160. * @return The index position of the attribute, or -1 if there is no attribute with this name
  161. */
  162. public int getIndex(String uri, String localname) {
  163. int fingerprint = tree.getNamePool().getFingerprint(uri, localname);
  164. return getIndexByFingerprint(fingerprint);
  165. }
  166. /**
  167. * Get the index, given the fingerprint
  168. * @param fingerprint the NamePool fingerprint of the required attribute name
  169. * @return The index position of the attribute, or -1 if there is no attribute with this name
  170. */
  171. public int getIndexByFingerprint(int fingerprint) {
  172. int i = firstAttribute;
  173. while (tree.attParent[i] == element) {
  174. if ((tree.attCode[i] & NamePool.FP_MASK) == fingerprint) {
  175. return i - firstAttribute;
  176. }
  177. i++;
  178. }
  179. return -1;
  180. }
  181. /**
  182. * Get the attribute value using its fingerprint
  183. */
  184. public String getValueByFingerprint(int fingerprint) {
  185. return getValue(getIndexByFingerprint(fingerprint));
  186. }
  187. /**
  188. * Get the value of an attribute (by name).
  189. *
  190. * @param uri The namespace uri of the attribute.
  191. * @param localname The local name of the attribute.
  192. * @return The index position of the attribute
  193. */
  194. public String getValue(String uri, String localname) {
  195. return getValue(getIndex(uri, localname));
  196. }
  197. /**
  198. * Get the value of an attribute (by position).
  199. *
  200. * @param index The position of the attribute in the list.
  201. * @return The attribute value as a string, or null if
  202. * there is no attribute at that position.
  203. */
  204. public String getValue(int index) {
  205. CharSequence cs = tree.attValue[firstAttribute + index];
  206. return (cs==null ? null : cs.toString());
  207. }
  208. /**
  209. * Determine whether a given attribute has the is-ID property set
  210. */
  211. public boolean isId(int index) {
  212. return ((getTypeAnnotation(index) & NamePool.FP_MASK) == StandardNames.XS_ID) ||
  213. ((getNameCode(index) & NamePool.FP_MASK) == StandardNames.XML_ID);
  214. }
  215. /**
  216. * Determine whether a given attribute has the is-idref property set
  217. */
  218. public boolean isIdref(int index) {
  219. return ((getTypeAnnotation(index) & NamePool.FP_MASK) == StandardNames.XS_IDREF) ||
  220. ((getTypeAnnotation(index) & NamePool.FP_MASK) == StandardNames.XS_IDREFS);
  221. }
  222. }
  223. //
  224. // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
  225. // you may not use this file except in compliance with the License. You may obtain a copy of the
  226. // License at http://www.mozilla.org/MPL/
  227. //
  228. // Software distributed under the License is distributed on an "AS IS" basis,
  229. // WITHOUT WARRANTY OF ANY KIND, either express or implied.
  230. // See the License for the specific language governing rights and limitations under the License.
  231. //
  232. // The Original Code is: all this file.
  233. //
  234. // The Initial Developer of the Original Code is Michael H. Kay
  235. //
  236. // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
  237. //
  238. // Contributor(s): none.
  239. //