1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.expression;
17
18 import org.apache.commons.jelly.JellyContext;
19
20 /*** <p><code>ConstantExpression</code> represents a constant expression.</p>
21 *
22 * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
23 *
24 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
25 * @version $Revision: 155420 $
26 */
27 public class ConstantExpression extends ExpressionSupport {
28
29 /*** The value of this expression */
30 private Object value;
31
32 /*** Base constructor
33 */
34 public ConstantExpression() {
35 }
36
37 /*** Convenience constructor sets <code>value</code> property.
38 */
39 public ConstantExpression(Object value) {
40 this.value = value;
41 }
42
43 public String toString() {
44 return super.toString() + "[value=" + value +"]";
45 }
46
47 public String getExpressionText() {
48 return value == null ? "null" : value.toString();
49 }
50
51 /***
52 * Evaluate expression against given context.
53 *
54 * @param context evaluate expression against this context
55 * @return current value of <code>value</code> property
56 */
57 public Object evaluate(JellyContext context) {
58 return value;
59 }
60
61 /*** Gets the constant value of this expression */
62 public Object getValue() {
63 return value;
64 }
65
66 /*** Sets the constant value of this expression */
67 public void setValue(Object value) {
68 this.value = value;
69 }
70 }