1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.axes;
18
19 import org.apache.commons.jxpath.ri.EvalContext;
20 import org.apache.commons.jxpath.ri.compiler.NodeTest;
21 import org.apache.commons.jxpath.ri.model.NodePointer;
22
23
24
25
26
27
28
29 public class ParentContext extends EvalContext {
30 private NodeTest nodeTest;
31 private boolean setStarted = false;
32 private NodePointer currentNodePointer;
33
34
35
36
37
38
39 public ParentContext(EvalContext parentContext, NodeTest nodeTest) {
40 super(parentContext);
41 this.nodeTest = nodeTest;
42 }
43
44 public NodePointer getCurrentNodePointer() {
45 return currentNodePointer;
46 }
47
48 public int getCurrentPosition() {
49 return 1;
50 }
51
52 public int getDocumentOrder() {
53 return -1;
54 }
55
56 public void reset() {
57 super.reset();
58 setStarted = false;
59 }
60
61 public boolean setPosition(int position) {
62 super.setPosition(position);
63 return position == 1;
64 }
65
66 public boolean nextNode() {
67
68 if (setStarted) {
69 return false;
70 }
71 setStarted = true;
72 NodePointer thisLocation = parentContext.getCurrentNodePointer();
73 currentNodePointer = thisLocation.getImmediateParentPointer();
74 while (currentNodePointer != null
75 && currentNodePointer.isContainer()) {
76 currentNodePointer = currentNodePointer.getImmediateParentPointer();
77 }
78 if (currentNodePointer != null
79 && currentNodePointer.testNode(nodeTest)) {
80 position++;
81 return true;
82 }
83 return false;
84 }
85 }