1 package net.sf.saxon.tree; 2 import net.sf.saxon.om.*; 3 import net.sf.saxon.pattern.NameTest; 4 import net.sf.saxon.pattern.NodeTest; 5 import net.sf.saxon.type.Type; 6 7 10 11 final class AttributeEnumeration extends AxisIteratorImpl implements LookaheadIterator { 12 13 private ElementImpl element; 14 private NodeTest nodeTest; 15 private NodeInfo next; 16 private int index; 17 private int length; 18 19 25 26 public AttributeEnumeration(NodeImpl node, NodeTest nodeTest) { 27 28 this.nodeTest = nodeTest; 29 30 if (node.getNodeKind()==Type.ELEMENT) { 31 element = (ElementImpl)node; 32 AttributeCollection attlist = element.getAttributeList(); 33 index = 0; 34 35 if (nodeTest instanceof NameTest) { 36 NameTest test = (NameTest)nodeTest; 37 index = attlist.getIndexByFingerprint(test.getFingerprint()); 38 39 if (index<0) { 40 next = null; 41 } else { 42 next = new AttributeImpl(element, index); 43 index = 0; 44 length = 0; } 46 47 } else { 48 index = 0; 49 length = attlist.getLength(); 50 advance(); 51 } 52 } 53 else { next = null; 56 index = 0; 57 length = 0; 58 } 59 } 60 61 65 66 public boolean hasNext() { 67 return next != null; 68 } 69 70 73 74 public Item next() { 75 if (next == null) { 76 current = null; 77 position = -1; 78 return null; 79 } else { 80 current = next; 81 position++; 82 advance(); 83 return current; 84 } 85 } 86 87 90 91 private void advance() { 92 do { 93 if (index<length) { 94 next = new AttributeImpl(element, index); 95 index++; 96 } else { 97 next = null; 98 return; 99 } 100 } while (!nodeTest.matches(next)); 101 } 102 103 106 107 public SequenceIterator getAnother() { 108 return new AttributeEnumeration(element, nodeTest); 109 } 110 111 120 121 public int getProperties() { 122 return LOOKAHEAD; 123 } 124 } 125 126 127 128 | Popular Tags |