1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jxpath.ri.axes;
19
20 import org.apache.commons.jxpath.Pointer;
21 import org.apache.commons.jxpath.ri.EvalContext;
22 import org.apache.commons.jxpath.ri.model.NodePointer;
23
24
25
26
27
28 public class InitialContext extends EvalContext {
29
30 private boolean started;
31 private boolean collection;
32 private final NodePointer nodePointer;
33
34
35
36
37
38
39 public InitialContext(final EvalContext parentContext) {
40 super(parentContext);
41 nodePointer = (NodePointer) parentContext.getCurrentNodePointer().clone();
42 if (nodePointer != null) {
43 collection = nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION;
44 }
45 }
46
47 @Override
48 public NodePointer getCurrentNodePointer() {
49 return nodePointer;
50 }
51
52 @Override
53 public Pointer getSingleNodePointer() {
54 return nodePointer;
55 }
56
57 @Override
58 public Object getValue() {
59 return nodePointer.getValue();
60 }
61
62 @Override
63 public boolean nextNode() {
64 return setPosition(position + 1);
65 }
66
67 @Override
68 public boolean nextSet() {
69 if (started) {
70 return false;
71 }
72 started = true;
73 return true;
74 }
75
76 @Override
77 public boolean setPosition(final int position) {
78 this.position = position;
79 if (collection) {
80 if (position >= 1 && position <= nodePointer.getLength()) {
81 nodePointer.setIndex(position - 1);
82 return true;
83 }
84 return false;
85 }
86 return position == 1;
87 }
88 }