1 package net.sf.saxon.dom; 2 import net.sf.saxon.om.Item; 3 import net.sf.saxon.om.NodeInfo; 4 import net.sf.saxon.om.SequenceIterator; 5 import net.sf.saxon.om.VirtualNode; 6 import net.sf.saxon.trans.DynamicError; 7 import net.sf.saxon.trans.XPathException; 8 import net.sf.saxon.value.SequenceExtent; 9 import org.w3c.dom.Node ; 10 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 17 18 public final class DOMNodeList implements org.w3c.dom.NodeList { 19 private List sequence; 20 21 25 26 public DOMNodeList(List extent) { 27 sequence = extent; 28 } 29 30 34 35 public static DOMNodeList checkAndMake(SequenceExtent extent) throws XPathException { 36 SequenceIterator it = extent.iterate(null); 37 List list = new ArrayList (extent.getLength()); 38 while (true) { 39 Item next = it.next(); 40 if (next==null) break; 41 Object o = next; 42 if (!(o instanceof NodeInfo)) { 43 throw new DynamicError("Supplied sequence contains an item that is not a Saxon NodeInfo"); 44 } 45 if (o instanceof VirtualNode) { 46 o = ((VirtualNode)o).getUnderlyingNode(); 47 if (!(o instanceof Node)) { 48 throw new DynamicError("Supplied sequence contains an item that is not a wrapper around a DOM Node"); 49 } 50 list.add(o); 51 } 52 53 } 54 return new DOMNodeList(list); 55 } 56 57 60 61 65 68 69 public int getLength() { 70 return sequence.size(); 71 } 72 73 77 78 public Node item(int index) { 79 return (Node)sequence.get(index); 80 } 92 93 } 94 95 113 | Popular Tags |