KickJava   Java API By Example, From Geeks To Geeks.

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


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
19 /** <p><code>ClassNameExpression</code> returns the current class name
20   * of the context bean
21   *
22   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
23   * @since 0.5
24   */

25 public class ClassNameExpression implements Expression {
26
27     /** Base constructor */
28     public ClassNameExpression() {
29     }
30     
31     /**
32      * Evaluate on the current context and return the class name
33      *
34      * @param context the context against which this expression will be evaluated
35      * @return the name of the class of the current contex bean
36      */

37     public Object JavaDoc evaluate(Context context) {
38         Object JavaDoc bean = context.getBean();
39         if ( bean != null ) {
40             return bean.getClass().getName();
41         }
42         return null;
43     }
44
45     /**
46      * Do nothing.
47      * @see org.apache.commons.betwixt.expression.Expression
48      */

49     public void update(Context context, String JavaDoc newValue) {
50         // do nothing
51
}
52     
53     /**
54      * Returns something useful for logging.
55      * @return something useful for logging
56      */

57     public String JavaDoc toString() {
58         return "ClassNameExpression";
59     }
60 }
61
Popular Tags