01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.betwixt.expression;
18:
19: /** <p><code>ConstantExpression</code> represents a constant expression.</p>
20: *
21: * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
22: *
23: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
24: * @version $Revision: 438373 $
25: */
26: public class ConstantExpression implements Expression {
27:
28: /** The value of this expression */
29: private Object value;
30:
31: /** Base constructor
32: */
33: public ConstantExpression() {
34: }
35:
36: /**
37: * Convenience constructor sets <code>value</code> property.
38: * @param value the Object which is the constant value for this expression
39: */
40: public ConstantExpression(Object value) {
41: this .value = value;
42: }
43:
44: /**
45: * Evaluate expression against given context.
46: *
47: * @param context evaluate expression against this context
48: * @return current value of <code>value</code> property
49: */
50: public Object evaluate(Context context) {
51: return value;
52: }
53:
54: /**
55: * Do nothing
56: * @see org.apache.commons.betwixt.expression.Expression
57: */
58: public void update(Context context, String newValue) {
59: // do nothing
60: }
61:
62: /**
63: * Gets the constant value of this expression
64: * @return this expression's constant value
65: */
66: public Object getValue() {
67: return value;
68: }
69:
70: /**
71: * Sets the constant value of this expression
72: * @param value the constant value for this expression
73: */
74: public void setValue(Object value) {
75: this .value = value;
76: }
77:
78: /**
79: * Returns something useful for logging
80: * @return something useful for logging
81: */
82: public String toString() {
83: return "ConstantExpression [value=" + value + "]";
84: }
85: }
|