1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jxpath.ri.axes;
17
18 import org.apache.commons.jxpath.Pointer;
19 import org.apache.commons.jxpath.ri.EvalContext;
20 import org.apache.commons.jxpath.ri.model.NodePointer;
21
22 /***
23 * A single-set EvalContext that provides access to the current node of
24 * the parent context and nothing else. It does not pass the iteration
25 * on to the parent context.
26 *
27 * @author Dmitri Plotnikov
28 * @version $Revision: 1.15 $ $Date: 2004/07/30 13:51:01 $
29 */
30 public class InitialContext extends EvalContext {
31 private boolean startedSet = false;
32 private boolean started = false;
33 private boolean collection;
34 private NodePointer nodePointer;
35
36 public InitialContext(EvalContext parentContext) {
37 super(parentContext);
38 nodePointer =
39 (NodePointer) parentContext.getCurrentNodePointer().clone();
40 if (nodePointer != null) {
41 collection =
42 (nodePointer.getIndex() == NodePointer.WHOLE_COLLECTION);
43 }
44 }
45
46 public Pointer getSingleNodePointer() {
47 return nodePointer;
48 }
49
50 public NodePointer getCurrentNodePointer() {
51 return nodePointer;
52 }
53
54 public Object getValue() {
55 return nodePointer.getValue();
56 }
57
58 public boolean nextNode() {
59 return setPosition(position + 1);
60 }
61
62 public boolean setPosition(int position) {
63 this.position = position;
64 if (collection) {
65 if (position >= 1 && position <= nodePointer.getLength()) {
66 nodePointer.setIndex(position - 1);
67 return true;
68 }
69 return false;
70 }
71 else {
72 return position == 1;
73 }
74 }
75
76 public boolean nextSet() {
77 if (started) {
78 return false;
79 }
80 started = true;
81 return true;
82 }
83 }