Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
VariableExpression |
|
| 1.0;1 |
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: 155402 $ |
|
23 | */ |
|
24 | public class VariableExpression implements Expression { |
|
25 | ||
26 | /** The variable name */ |
|
27 | private String variableName; |
|
28 | ||
29 | /** Base constructor */ |
|
30 | 0 | public VariableExpression() { |
31 | 0 | } |
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 | 0 | public VariableExpression(String variableName) { |
39 | 0 | this.variableName = variableName; |
40 | 0 | } |
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 evaluate(Context context) { |
|
48 | 0 | 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 getVariableName() { |
|
56 | 0 | 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 variableName) { |
|
65 | 0 | this.variableName = variableName; |
66 | 0 | } |
67 | ||
68 | /** |
|
69 | * Do nothing |
|
70 | * @see org.apache.commons.betwixt.expression.Expression |
|
71 | */ |
|
72 | public void update(Context context, String newValue) { |
|
73 | // do nothing |
|
74 | 0 | } |
75 | ||
76 | /** |
|
77 | * Returns something useful for logging |
|
78 | * @return something useful for logging |
|
79 | */ |
|
80 | public String toString() { |
|
81 | 0 | return "VariableExpression [variable name=" + variableName + "]"; |
82 | } |
|
83 | } |