KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > expression > VariableExpression


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>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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc newValue) {
73         // do nothing
74
}
75
76     /**
77      * Returns something useful for logging
78      * @return something useful for logging
79      */

80     public String JavaDoc toString() {
81         return "VariableExpression [variable name=" + variableName + "]";
82     }
83 }
84
Popular Tags