01: package net.sf.saxon.tinytree;
02:
03: import net.sf.saxon.om.AxisIteratorImpl;
04: import net.sf.saxon.om.Item;
05: import net.sf.saxon.om.SequenceIterator;
06: import net.sf.saxon.pattern.NodeTest;
07:
08: /**
09: * This class supports the preceding-sibling axis.
10: * The starting node must be an element, text node, comment, or processing instruction:
11: * to ensure this, construct the enumeration using NodeInfo#getEnumeration()
12: */
13:
14: final class PrecedingSiblingEnumeration extends AxisIteratorImpl {
15:
16: private TinyTree document;
17: private TinyNodeImpl startNode;
18: private int nextNodeNr;
19: private NodeTest test;
20: private TinyNodeImpl parentNode;
21:
22: PrecedingSiblingEnumeration(TinyTree doc, TinyNodeImpl node,
23: NodeTest nodeTest) {
24: document = doc;
25: document.ensurePriorIndex();
26: test = nodeTest;
27: startNode = node;
28: nextNodeNr = node.nodeNr;
29: parentNode = node.parent; // doesn't matter if this is null (unknown)
30: }
31:
32: public Item next() {
33: // if (nextNodeNr < 0) {
34: // return null;
35: // }
36: while (true) {
37: nextNodeNr = document.prior[nextNodeNr];
38: if (nextNodeNr < 0) {
39: current = null;
40: position = -1;
41: return null;
42: }
43: if (test.matches(document, nextNodeNr)) {
44: position++;
45: current = document.getNode(nextNodeNr);
46: ((TinyNodeImpl) current).setParentNode(parentNode);
47: return current;
48: }
49: ;
50: }
51: }
52:
53: /**
54: * Get another enumeration of the same nodes
55: */
56:
57: public SequenceIterator getAnother() {
58: return new PrecedingSiblingEnumeration(document, startNode,
59: test);
60: }
61:
62: }
63:
64: //
65: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
66: // you may not use this file except in compliance with the License. You may obtain a copy of the
67: // License at http://www.mozilla.org/MPL/
68: //
69: // Software distributed under the License is distributed on an "AS IS" basis,
70: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
71: // See the License for the specific language governing rights and limitations under the License.
72: //
73: // The Original Code is: all this file.
74: //
75: // The Initial Developer of the Original Code is Michael H. Kay.
76: //
77: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
78: //
79: // Contributor(s): none.
80: //
|