01: package net.sf.saxon.expr;
02:
03: import net.sf.saxon.om.SequenceIterator;
04: import net.sf.saxon.om.Item;
05: import net.sf.saxon.trans.XPathException;
06:
07: /**
08: * Iterator that concatenates the results of two supplied iterators
09: */
10:
11: public class AppendIterator implements SequenceIterator {
12:
13: private SequenceIterator first;
14: private Expression second;
15: private XPathContext context;
16: private SequenceIterator currentIterator;
17: private int position = 0;
18:
19: /**
20: * This form of constructor is designed to delay getting an iterator for the second
21: * expression until it is actually needed. This gives savings in cases where the
22: * iteration is aborted prematurely.
23: * @param first Iterator over the first operand
24: * @param second The second operand
25: * @param context The dynamic context for evaluation of the second operand
26: */
27:
28: public AppendIterator(SequenceIterator first, Expression second,
29: XPathContext context) {
30: this .first = first;
31: this .second = second;
32: this .context = context;
33: this .currentIterator = first;
34: }
35:
36: public Item next() throws XPathException {
37: Item n = currentIterator.next();
38: if (n == null && currentIterator == first) {
39: currentIterator = second.iterate(context);
40: n = currentIterator.next();
41: }
42: if (n == null) {
43: position = -1;
44: } else {
45: position++;
46: }
47: return n;
48: }
49:
50: public Item current() {
51: return currentIterator.current();
52: }
53:
54: public int position() {
55: return position;
56: }
57:
58: public SequenceIterator getAnother() throws XPathException {
59: return new AppendIterator(first.getAnother(), second, context);
60: }
61:
62: /**
63: * Get properties of this iterator, as a bit-significant integer.
64: *
65: * @return the properties of this iterator. This will be some combination of
66: * properties such as {@link GROUNDED}, {@link LAST_POSITION_FINDER},
67: * and {@link LOOKAHEAD}. It is always
68: * acceptable to return the value zero, indicating that there are no known special properties.
69: * It is acceptable for the properties of the iterator to change depending on its state.
70: */
71:
72: public int getProperties() {
73: return 0;
74: }
75: }
76:
77: //
78: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
79: // you may not use this file except in compliance with the License. You may obtain a copy of the
80: // License at http://www.mozilla.org/MPL/
81: //
82: // Software distributed under the License is distributed on an "AS IS" basis,
83: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
84: // See the License for the specific language governing rights and limitations under the License.
85: //
86: // The Original Code is: all this file.
87: //
88: // The Initial Developer of the Original Code is Michael H. Kay
89: //
90: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
91: //
92: // Contributor(s): none.
93: //
|