001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.betwixt.expression;
018
019 /** <p><code>ConstantExpression</code> represents a constant expression.</p>
020 *
021 * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
022 *
023 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
024 * @version $Revision: 438373 $
025 */
026 public class ConstantExpression implements Expression {
027
028 /** The value of this expression */
029 private Object value;
030
031 /** Base constructor
032 */
033 public ConstantExpression() {
034 }
035
036 /**
037 * Convenience constructor sets <code>value</code> property.
038 * @param value the Object which is the constant value for this expression
039 */
040 public ConstantExpression(Object value) {
041 this.value = value;
042 }
043
044 /**
045 * Evaluate expression against given context.
046 *
047 * @param context evaluate expression against this context
048 * @return current value of <code>value</code> property
049 */
050 public Object evaluate(Context context) {
051 return value;
052 }
053
054 /**
055 * Do nothing
056 * @see org.apache.commons.betwixt.expression.Expression
057 */
058 public void update(Context context, String newValue) {
059 // do nothing
060 }
061
062 /**
063 * Gets the constant value of this expression
064 * @return this expression's constant value
065 */
066 public Object getValue() {
067 return value;
068 }
069
070 /**
071 * Sets the constant value of this expression
072 * @param value the constant value for this expression
073 */
074 public void setValue(Object value) {
075 this.value = value;
076 }
077
078 /**
079 * Returns something useful for logging
080 * @return something useful for logging
081 */
082 public String toString() {
083 return "ConstantExpression [value=" + value + "]";
084 }
085 }