View Javadoc

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