1 package com.icl.saxon.tree; 2 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 ElementImpl element; 15 private NodeTest nodeTest; 16 private NodeInfo next; 17 private int index; 18 private int length; 19 private int last = -1; 20 21 29 30 public AttributeEnumeration(NodeImpl node, NodeTest nodeTest) { 31 32 this.nodeTest = nodeTest; 33 34 if (node.getNodeType()==NodeInfo.ELEMENT) { 35 element = (ElementImpl)node; 36 AttributeCollection attlist = element.getAttributeList(); 37 index = 0; 38 39 if (nodeTest instanceof NameTest) { 40 NameTest test = (NameTest)nodeTest; 41 index = attlist.getIndexByFingerprint(test.getFingerprint()); 42 43 if (index<0) { 44 next = null; 45 } else { 46 next = new AttributeImpl(element, index); 47 index = 0; 48 length = 0; } 50 51 } else { 52 index = 0; 53 length = attlist.getLength(); 54 advance(); 55 } 56 } 57 else { next = null; 60 index = 0; 61 length = 0; 62 } 63 } 64 65 69 70 public boolean hasMoreElements() { 71 return next != null; 72 } 73 74 78 79 public NodeInfo nextElement() { 80 NodeInfo node = next; 81 advance(); 82 return node; 83 } 84 85 88 89 private void advance() { 90 do { 91 if (index<length) { 92 next = new AttributeImpl(element, index); 93 index++; 94 } else { 95 next = null; 96 return; 97 } 98 } while (!nodeTest.matches(next)); 99 } 100 101 public boolean isSorted() { 102 return true; } 104 105 public boolean isReverseSorted() { 106 return false; 107 } 108 109 public boolean isPeer() { 110 return true; 111 } 112 113 116 117 public int getLastPosition() { 118 if (last >= 0) return last; 119 AttributeEnumeration enum = 120 new AttributeEnumeration(element, nodeTest); 121 last=0; 122 while (enum.hasMoreElements()) { 123 enum.nextElement(); 124 last++; 125 } 126 return last; 127 } 128 } 129 130 131 132
| Popular Tags
|