1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 public class StringExpression implements Expression {
24
25 /*** We only need only <code>StringExpression</code> */
26 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 return singleton;
34 }
35
36 /*** Base constructor. Should this be private? */
37 public StringExpression() {
38 }
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 Object value = context.getBean();
47 if ( value != null ) {
48 return value.toString();
49 }
50 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
59 }
60
61 /***
62 * Returns something useful for logging.
63 * @return the (short) class name
64 */
65 public String toString() {
66 return "StringExpression";
67 }
68
69 }