KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > tree > PrecedingEnumeration


1 package com.icl.saxon.tree;
2 import com.icl.saxon.pattern.NodeTest;
3
4 final class PrecedingEnumeration extends TreeEnumeration {
5
6     NodeImpl nextAncestor;
7     
8     public PrecedingEnumeration(NodeImpl node, NodeTest nodeTest) {
9         super(node, nodeTest);
10
11         // we need to avoid returning ancestors of the starting node
12
nextAncestor = (NodeImpl)node.getParent();
13         advance();
14     }
15
16
17     /**
18     * Special code to skip the ancestors of the start node
19     */

20
21     protected boolean conforms(NodeImpl node) {
22         // ASSERT: we'll never test the root node, because it's always
23
// an ancestor, so nextAncestor will never be null.
24
if (node!=null) {
25             if (node.isSameNode(nextAncestor)) {
26                 nextAncestor = (NodeImpl)nextAncestor.getParent();
27                 return false;
28             }
29         }
30         return super.conforms(node);
31     }
32
33     protected void step() {
34         next = next.getPreviousInDocument();
35     }
36
37     /**
38     * Get the last position, that is the number of nodes in the enumeration
39     */

40
41     public int getLastPosition() {
42         if (last>=0) return last;
43         PrecedingEnumeration enum =
44             new PrecedingEnumeration(start, nodeTest);
45         return enum.count();
46     }
47 }
48
49
50
51
52 //
53
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
54
// you may not use this file except in compliance with the License. You may obtain a copy of the
55
// License at http://www.mozilla.org/MPL/
56
//
57
// Software distributed under the License is distributed on an "AS IS" basis,
58
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
59
// See the License for the specific language governing rights and limitations under the License.
60
//
61
// The Original Code is: all this file.
62
//
63
// The Initial Developer of the Original Code is
64
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
65
//
66
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
67
//
68
// Contributor(s): none.
69
//
70
Popular Tags