1 package com.icl.saxon.tinytree; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.NodeInfo; 4 import com.icl.saxon.om.AxisEnumeration; 5 import com.icl.saxon.pattern.NodeTest; 6 import com.icl.saxon.pattern.NameTest; 7 8 11 12 final class AttributeEnumeration implements AxisEnumeration { 13 14 private TinyDocumentImpl doc; 15 private int element; 16 private NodeTest nodeTest; 17 private int index; 18 private int last = -1; 19 20 30 31 protected AttributeEnumeration(TinyDocumentImpl doc, int element, NodeTest nodeTest) { 32 33 this.nodeTest = nodeTest; 34 this.doc = doc; 35 this.element = element; 36 37 index = doc.offset[element]; 38 advance(); 39 } 40 41 45 46 public boolean hasMoreElements() { 47 return index >=0; 48 } 49 50 54 55 public NodeInfo nextElement() { 56 int node = index++; 57 if (nodeTest instanceof NameTest) { 58 index = -1; 60 } else { 61 advance(); 62 } 63 return doc.getAttributeNode(node); 64 } 65 66 69 70 private void advance() { 71 do { 72 if (index >= doc.numberOfAttributes || doc.attParent[index] != element) { 73 index = -1; 74 return; 75 } 76 if (nodeTest.matches(NodeInfo.ATTRIBUTE, doc.attCode[index])) { 77 return; 78 } 79 index++; 80 } while (true); 81 } 82 83 public boolean isSorted() { 84 return true; } 86 87 public boolean isReverseSorted() { 88 return false; 89 } 90 91 public boolean isPeer() { 92 return true; 93 } 94 95 98 99 public int getLastPosition() { 100 if (last>=0) return last; 101 AttributeEnumeration enum = 102 new AttributeEnumeration(doc, element, nodeTest); 103 last = 0; 104 while (enum.hasMoreElements()) { 105 enum.nextElement(); 106 last++; 107 } 108 return last; 109 } 110 } 111 112 113 114 | Popular Tags |