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.Pointer;
20 import org.apache.commons.jxpath.ri.EvalContext;
21 import org.apache.commons.jxpath.ri.compiler.NodeTest;
22 import org.apache.commons.jxpath.ri.model.NodePointer;
23
24
25
26
27
28
29
30
31 public class SelfContext extends EvalContext {
32 private NodeTest nodeTest;
33 private boolean startedSet = false;
34 private NodePointer nodePointer;
35
36
37
38
39
40
41 public SelfContext(EvalContext parentContext, NodeTest nodeTest) {
42 super(parentContext);
43 this.nodeTest = nodeTest;
44 }
45
46 public Pointer getSingleNodePointer() {
47 return parentContext.getSingleNodePointer();
48 }
49
50 public NodePointer getCurrentNodePointer() {
51 if (position == 0 && !setPosition(1)) {
52 return null;
53 }
54 return nodePointer;
55 }
56
57 public boolean nextNode() {
58 return setPosition(getCurrentPosition() + 1);
59 }
60
61 public void reset() {
62 super.reset();
63 startedSet = false;
64 }
65
66 public boolean setPosition(int position) {
67 if (position != 1) {
68 return false;
69 }
70 super.setPosition(position);
71 if (!startedSet) {
72 startedSet = true;
73 nodePointer = parentContext.getCurrentNodePointer();
74 }
75
76 if (nodePointer == null) {
77 return false;
78 }
79
80 return nodeTest == null || nodePointer.testNode(nodeTest);
81 }
82 }