1 package net.sf.saxon.tinytree; 2 3 import net.sf.saxon.om.AttributeCollection; 4 import net.sf.saxon.om.NamePool; 5 import net.sf.saxon.event.LocationProvider; 6 import net.sf.saxon.style.StandardNames; 7 8 12 13 public class TinyAttributeCollection implements AttributeCollection { 14 15 int element; 16 TinyTree tree; 17 int firstAttribute; 18 19 public TinyAttributeCollection(TinyTree tree, int element) { 20 this.tree = tree; 21 this.element = element; 22 this.firstAttribute = tree.alpha[element]; 23 } 24 25 29 30 public void setLocationProvider(LocationProvider provider) { 31 } 33 34 39 40 public int getLength() { 41 int i = firstAttribute; 42 while (i < tree.numberOfAttributes && tree.attParent[i] == element) { 43 i++; 44 } 45 return i - firstAttribute; 46 } 47 48 55 56 public int getNameCode(int index) { 57 return tree.attCode[firstAttribute + index]; 58 } 59 60 67 68 public int getTypeAnnotation(int index) { 69 if (tree.attTypeCode == null) { 70 return StandardNames.XDT_UNTYPED_ATOMIC; 71 }; 72 return tree.attTypeCode[firstAttribute + index]; 73 } 74 75 83 84 public int getLocationId(int index) { 85 return 0; 86 } 87 88 100 101 public String getSystemId(int index) { 102 return tree.getSystemId(element); 103 } 104 105 117 118 public int getLineNumber(int index) { 119 return -1; 120 } 121 122 131 132 public int getProperties(int index) { 133 return 0; 134 } 135 136 144 145 public String getPrefix(int index) { 146 return tree.getNamePool().getPrefix(getNameCode(index)); 147 } 148 149 156 157 public String getQName(int index) { 158 return tree.getNamePool().getDisplayName(getNameCode(index)); 159 } 160 161 168 169 public String getLocalName(int index) { 170 return tree.getNamePool().getLocalName(getNameCode(index)); 171 } 172 173 180 181 public String getURI(int index) { 182 return tree.getNamePool().getURI(getNameCode(index)); 183 } 184 185 192 193 public int getIndex(String uri, String localname) { 194 int fingerprint = tree.getNamePool().getFingerprint(uri, localname); 195 return getIndexByFingerprint(fingerprint); 196 } 197 198 201 202 public int getIndexByFingerprint(int fingerprint) { 203 int i = firstAttribute; 204 while (tree.attParent[i] == element) { 205 if ((tree.attCode[i] & NamePool.FP_MASK) == fingerprint) { 206 return i - firstAttribute; 207 } 208 i++; 209 } 210 return -1; 211 } 212 213 216 217 public String getValueByFingerprint(int fingerprint) { 218 return getValue(getIndexByFingerprint(fingerprint)); 219 } 220 221 228 229 public String getValue(String uri, String localname) { 230 return getValue(getIndex(uri, localname)); 231 } 232 233 240 241 public String getValue(int index) { 242 return tree.attValue[firstAttribute + index].toString(); 243 } 244 245 248 249 public boolean isId(int index) { 250 return ((getTypeAnnotation(index) & NamePool.FP_MASK) == StandardNames.XS_ID) || 251 ((getNameCode(index) & NamePool.FP_MASK) == StandardNames.XML_ID); 252 } 253 } 254 | Popular Tags |