01: package net.sf.saxon.tree;
02:
03: import net.sf.saxon.om.SequenceIterator;
04: import net.sf.saxon.pattern.NodeTest;
05:
06: final class PrecedingEnumeration extends TreeEnumeration {
07:
08: NodeImpl nextAncestor;
09:
10: public PrecedingEnumeration(NodeImpl node, NodeTest nodeTest) {
11: super (node, nodeTest);
12:
13: // we need to avoid returning ancestors of the starting node
14: nextAncestor = (NodeImpl) node.getParent();
15: advance();
16: }
17:
18: /**
19: * Special code to skip the ancestors of the start node
20: */
21:
22: protected boolean conforms(NodeImpl node) {
23: // ASSERT: we'll never test the root node, because it's always
24: // an ancestor, so nextAncestor will never be null.
25: if (node != null) {
26: if (node.isSameNodeInfo(nextAncestor)) {
27: nextAncestor = (NodeImpl) nextAncestor.getParent();
28: return false;
29: }
30: }
31: return super .conforms(node);
32: }
33:
34: protected void step() {
35: next = next.getPreviousInDocument();
36: }
37:
38: /**
39: * Get another enumeration of the same nodes
40: */
41:
42: public SequenceIterator getAnother() {
43: return new PrecedingEnumeration(start, nodeTest);
44: }
45:
46: }
47:
48: //
49: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
50: // you may not use this file except in compliance with the License. You may obtain a copy of the
51: // License at http://www.mozilla.org/MPL/
52: //
53: // Software distributed under the License is distributed on an "AS IS" basis,
54: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
55: // See the License for the specific language governing rights and limitations under the License.
56: //
57: // The Original Code is: all this file.
58: //
59: // The Initial Developer of the Original Code is Michael H. Kay.
60: //
61: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
62: //
63: // Contributor(s): none.
64: //
|