1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001-2006 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: UnionIterator.java,v 1.5 2005/09/28 13:48:38 pvedula Exp $ 22 */ 23 24 package com.sun.org.apache.xalan.internal.xsltc.dom; 25 26 import com.sun.org.apache.xalan.internal.xsltc.DOM; 27 import com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary; 28 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; 29 import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase; 30 31 /** 32 * UnionIterator takes a set of NodeIterators and produces 33 * a merged NodeSet in document order with duplicates removed 34 * The individual iterators are supposed to generate nodes 35 * in document order 36 * @author Jacek Ambroziak 37 * @author Santiago Pericas-Geertsen 38 */ 39 public final class UnionIterator extends MultiValuedNodeHeapIterator { 40 /** wrapper for NodeIterators to support iterator 41 comparison on the value of their next() method 42 */ 43 final private DOM _dom; 44 45 private final class LookAheadIterator 46 extends MultiValuedNodeHeapIterator.HeapNode 47 { 48 public DTMAxisIterator iterator; 49 50 public LookAheadIterator(DTMAxisIterator iterator) { 51 super(); 52 this.iterator = iterator; 53 } 54 55 public int step() { 56 _node = iterator.next(); 57 return _node; 58 } 59 60 public HeapNode cloneHeapNode() { 61 LookAheadIterator clone = (LookAheadIterator) super.cloneHeapNode(); 62 clone.iterator = iterator.cloneIterator(); 63 return clone; 64 } 65 66 public void setMark() { 67 super.setMark(); 68 iterator.setMark(); 69 } 70 71 public void gotoMark() { 72 super.gotoMark(); 73 iterator.gotoMark(); 74 } 75 76 public boolean isLessThan(HeapNode heapNode) { 77 LookAheadIterator comparand = (LookAheadIterator) heapNode; 78 return _dom.lessThan(_node, heapNode._node); 79 } 80 81 public HeapNode setStartNode(int node) { 82 iterator.setStartNode(node); 83 return this; 84 } 85 86 public HeapNode reset() { 87 iterator.reset(); 88 return this; 89 } 90 } // end of LookAheadIterator 91 92 public UnionIterator(DOM dom) { 93 _dom = dom; 94 } 95 96 public UnionIterator addIterator(DTMAxisIterator iterator) { 97 addHeapNode(new LookAheadIterator(iterator)); 98 return this; 99 } 100 }