1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.compiler;
18
19 import org.apache.commons.jxpath.ri.EvalContext;
20 import org.apache.commons.jxpath.ri.axes.InitialContext;
21
22
23
24
25
26 public class LocationPath extends Path {
27
28 private boolean absolute;
29
30
31
32
33
34
35 public LocationPath(boolean absolute, Step[] steps) {
36 super(steps);
37 this.absolute = absolute;
38 }
39
40
41
42
43
44 public boolean isAbsolute() {
45 return absolute;
46 }
47
48 public boolean computeContextDependent() {
49 return !absolute || super.computeContextDependent();
50 }
51
52 public String toString() {
53 StringBuffer buffer = new StringBuffer();
54 Step[] steps = getSteps();
55 if (steps != null) {
56 for (int i = 0; i < steps.length; i++) {
57 if (i > 0 || absolute) {
58 buffer.append('/');
59 }
60 buffer.append(steps[i]);
61 }
62 }
63 return buffer.toString();
64 }
65
66 public Object compute(EvalContext context) {
67
68 EvalContext rootContext;
69 if (isAbsolute()) {
70 rootContext = context.getRootContext().getAbsoluteRootContext();
71 }
72 else {
73 rootContext = new InitialContext(context);
74 }
75 return evalSteps(rootContext);
76 }
77
78 public Object computeValue(EvalContext context) {
79
80 EvalContext rootContext;
81 if (isAbsolute()) {
82 rootContext = context.getRootContext().getAbsoluteRootContext();
83 }
84 else {
85 rootContext = new InitialContext(context);
86 }
87 return getSingleNodePointerForSteps(rootContext);
88 }
89 }