1 /*
2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package com.teamkonzept.dom4jb.saxon;
19
20 import org.w3c.dom.Node;
21
22 import com.icl.saxon.om.AxisEnumeration;
23 import com.icl.saxon.om.NodeInfo;
24
25 /***
26 * %TODO% wenn möglich sollte versucht werden den DescendantEnumarator zu
27 * verwenden, dh beide iteratoren immer abwechselnd verwenden, je nach dem ob
28 * die entspr. daten zur verfügung stehen
29 */
30 public class PrecedingEnumeration implements AxisEnumeration {
31
32 private final AncestorEnumeration ancestor;
33 private Node currNode;
34 private Node nextNode;
35 private Node skip;
36
37 public PrecedingEnumeration( final AxisNode start,
38 final boolean withAncestors ) {
39 this.currNode = start;
40 this.nextNode = null;
41 if ( !withAncestors ) {
42 this.ancestor = new AncestorEnumeration( start, false );
43 if ( this.ancestor.hasMoreElements() ) {
44 this.skip = (Node)this.ancestor.nextElement();
45 } else {
46 this.skip = null;
47 }
48 } else {
49 this.skip = null;
50 this.ancestor = null;
51 }
52 }
53
54 public int getLastPosition() {
55 return 1; // not used
56 }
57
58 public boolean hasMoreElements() {
59 if ( nextNode != null ) {
60 return true;
61 }
62
63 nextNode = currNode.getPreviousSibling();
64 if ( nextNode != null ) {
65 do {
66 currNode = nextNode;
67 nextNode = currNode.getLastChild();
68 } while ( nextNode != null );
69 nextNode = currNode;
70 return true;
71 }
72
73 nextNode = currNode.getParentNode();
74 if ( skip != null && nextNode == skip ) {
75 currNode = nextNode;
76 if ( ancestor.hasMoreElements() ) {
77 skip = (Node)ancestor.nextElement();
78 } else {
79 skip = null;
80 }
81 nextNode = null;
82 return hasMoreElements();
83 }
84
85 return nextNode != null;
86 }
87
88 public boolean isPeer() {
89 return false;
90 }
91
92 public boolean isReverseSorted() {
93 return true;
94 }
95
96 public boolean isSorted() {
97 return false;
98 }
99
100 public NodeInfo nextElement() {
101 if ( nextNode != null || hasMoreElements() ) {
102 currNode = nextNode;
103 nextNode = null;
104 return (NodeInfo)currNode;
105 }
106 return null;
107 }
108 }
This page was automatically generated by Maven