1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.betwixt.expression;
17
18 /*** <p><code>VariableExpression</code> represents a variable expression such as
19 * <code>$foo</code> which returns the value of the given variable.</p>
20 *
21 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
22 * @version $Revision: 1.6 $
23 */
24 public class VariableExpression implements Expression {
25
26 /*** The variable name */
27 private String variableName;
28
29 /*** Base constructor */
30 public VariableExpression() {
31 }
32
33 /***
34 * Convenience constructor sets <code>VariableName</code> property
35 * @param variableName the name of the context variable
36 * whose value will be returned by an evaluation
37 */
38 public VariableExpression(String variableName) {
39 this.variableName = variableName;
40 }
41
42 /*** Return the value of a context variable.
43 *
44 * @param context evaluate against this context
45 * @return the value of the context variable named by the <code>VariableName</code> property
46 */
47 public Object evaluate(Context context) {
48 return context.getVariable( variableName );
49 }
50
51 /***
52 * Gets the variable name
53 * @return the name of the context variable whose value will be returned by an evaluation
54 */
55 public String getVariableName() {
56 return variableName;
57 }
58
59 /***
60 * Sets the variable name
61 * @param variableName the name of the context variable
62 * whose value will be returned by an evaluation
63 */
64 public void setVariableName(String variableName) {
65 this.variableName = variableName;
66 }
67
68 /***
69 * Do nothing
70 * @see org.apache.commons.betwixt.expression.Expression
71 */
72 public void update(Context context, String newValue) {
73
74 }
75
76 /***
77 * Returns something useful for logging
78 * @return something useful for logging
79 */
80 public String toString() {
81 return "VariableExpression [variable name=" + variableName + "]";
82 }
83 }