KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > tree > PrecedingEnumeration


1 package net.sf.saxon.tree;
2 import net.sf.saxon.om.SequenceIterator;
3 import net.sf.saxon.pattern.NodeTest;
4
5 final class PrecedingEnumeration extends TreeEnumeration {
6
7     NodeImpl nextAncestor;
8     
9     public PrecedingEnumeration(NodeImpl node, NodeTest nodeTest) {
10         super(node, nodeTest);
11
12         // we need to avoid returning ancestors of the starting node
13
nextAncestor = (NodeImpl)node.getParent();
14         advance();
15     }
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
50
51 //
52
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
53
// you may not use this file except in compliance with the License. You may obtain a copy of the
54
// License at http://www.mozilla.org/MPL/
55
//
56
// Software distributed under the License is distributed on an "AS IS" basis,
57
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
58
// See the License for the specific language governing rights and limitations under the License.
59
//
60
// The Original Code is: all this file.
61
//
62
// The Initial Developer of the Original Code is Michael H. Kay.
63
//
64
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
65
//
66
// Contributor(s): none.
67
//
68
Popular Tags