KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > expr > AppendIterator


1 package net.sf.saxon.expr;
2
3 import net.sf.saxon.om.SequenceIterator;
4 import net.sf.saxon.om.Item;
5 import net.sf.saxon.trans.XPathException;
6
7 /**
8 * Iterator that concatenates the results of two supplied iterators
9 */

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, XPathContext context) {
29         this.first = first;
30         this.second = second;
31         this.context = context;
32         this.currentIterator = first;
33     }
34
35     public Item next() throws XPathException {
36         Item n = currentIterator.next();
37         if (n == null && currentIterator==first) {
38             currentIterator = second.iterate(context);
39             n = currentIterator.next();
40         }
41         if (n == null) {
42             position = -1;
43         } else {
44             position++;
45         }
46         return n;
47     }
48
49     public Item current() {
50         return currentIterator.current();
51     }
52
53     public int position() {
54         return position;
55     }
56
57     public SequenceIterator getAnother() throws XPathException {
58         return new AppendIterator(first.getAnother(), second, context);
59     }
60
61     /**
62      * Get properties of this iterator, as a bit-significant integer.
63      *
64      * @return the properties of this iterator. This will be some combination of
65      * properties such as {@link GROUNDED}, {@link LAST_POSITION_FINDER},
66      * and {@link LOOKAHEAD}. It is always
67      * acceptable to return the value zero, indicating that there are no known special properties.
68      * It is acceptable for the properties of the iterator to change depending on its state.
69      */

70
71     public int getProperties() {
72         return 0;
73     }
74 }
75
76 //
77
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
78
// you may not use this file except in compliance with the License. You may obtain a copy of the
79
// License at http://www.mozilla.org/MPL/
80
//
81
// Software distributed under the License is distributed on an "AS IS" basis,
82
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
83
// See the License for the specific language governing rights and limitations under the License.
84
//
85
// The Original Code is: all this file.
86
//
87
// The Initial Developer of the Original Code is Michael H. Kay
88
//
89
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
90
//
91
// Contributor(s): none.
92
//
93
Popular Tags