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.QName;
19 import org.apache.commons.jxpath.ri.EvalContext;
20
21 /***
22 * An element of the compile tree holding a variable reference.
23 *
24 * @author Dmitri Plotnikov
25 * @version $Revision: 1.9 $ $Date: 2004/02/29 14:17:38 $
26 */
27 public class VariableReference extends Expression {
28
29 private QName varName;
30
31 public VariableReference(QName varName) {
32 this.varName = varName;
33 }
34
35 public QName getVariableName() {
36 return varName;
37 }
38
39 public String toString() {
40 return "$" + varName;
41 }
42
43 public boolean isContextDependent() {
44 return false;
45 }
46
47 public boolean computeContextDependent() {
48 return false;
49 }
50
51 public Object compute(EvalContext context) {
52 return computeValue(context);
53 }
54
55 /***
56 * Returns the value of the variable.
57 */
58 public Object computeValue(EvalContext context) {
59 return context.getRootContext().getVariableContext(varName);
60 }
61 }