Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
StringExpression |
|
| 1.4;1.4 |
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>StringExpression</code> returns the current context object as a string.</p> |
|
19 | * |
|
20 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
21 | * @version $Revision: 155402 $ |
|
22 | */ |
|
23 | 182 | public class StringExpression implements Expression { |
24 | ||
25 | /** We only need only <code>StringExpression</code> */ |
|
26 | 182 | private static final StringExpression singleton = new StringExpression(); |
27 | ||
28 | /** |
|
29 | * Gets the singleton |
|
30 | * @return the singleton <code>StringExpression</code> instance |
|
31 | */ |
|
32 | public static StringExpression getInstance() { |
|
33 | 429 | return singleton; |
34 | } |
|
35 | ||
36 | /** Base constructor. Should this be private? */ |
|
37 | 182 | public StringExpression() { |
38 | 182 | } |
39 | ||
40 | /** Return the context bean as a string |
|
41 | * |
|
42 | * @param context evaluate expression against this context |
|
43 | * @return the <code>toString()</code> representation of the context bean |
|
44 | */ |
|
45 | public Object evaluate(Context context) { |
|
46 | 1339 | Object value = context.getBean(); |
47 | 1339 | if ( value != null ) { |
48 | 1339 | return value.toString(); |
49 | } |
|
50 | 0 | return null; |
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 | 0 | } |
60 | ||
61 | /** |
|
62 | * Returns something useful for logging. |
|
63 | * @return the (short) class name |
|
64 | */ |
|
65 | public String toString() { |
|
66 | 0 | return "StringExpression"; |
67 | } |
|
68 | ||
69 | } |