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