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