KickJava   Java API By Example, From Geeks To Geeks.

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


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: 1.7 $
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 JavaDoc evaluate(Context context) {
46         Object JavaDoc 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 JavaDoc newValue) {
58         // do nothing
59
}
60     
61     /**
62      * Returns something useful for logging.
63      * @return the (short) class name
64      */

65     public String JavaDoc toString() {
66         return "StringExpression";
67     }
68
69 }
70
Popular Tags