1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.expression;
18
19 /*** <p><code>StringExpression</code> returns the current context object as a string.</p>
20 *
21 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
22 * @version $Revision: 438373 $
23 */
24 public class StringExpression implements Expression {
25
26 /*** We only need only <code>StringExpression</code> */
27 private static final StringExpression singleton = new StringExpression();
28
29 /***
30 * Gets the singleton
31 * @return the singleton <code>StringExpression</code> instance
32 */
33 public static StringExpression getInstance() {
34 return singleton;
35 }
36
37 /*** Base constructor. Should this be private? */
38 public StringExpression() {
39 }
40
41 /*** Return the context bean as a string
42 *
43 * @param context evaluate expression against this context
44 * @return the <code>toString()</code> representation of the context bean
45 */
46 public Object evaluate(Context context) {
47 Object value = context.getBean();
48 if ( value != null ) {
49 return value.toString();
50 }
51 return null;
52 }
53
54 /***
55 * Do nothing
56 * @see org.apache.commons.betwixt.expression.Expression
57 */
58 public void update(Context context, String newValue) {
59
60 }
61
62 /***
63 * Returns something useful for logging.
64 * @return the (short) class name
65 */
66 public String toString() {
67 return "StringExpression";
68 }
69
70 }