View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */ 
17   package org.apache.commons.betwixt.expression;
18  
19  
20  /** <p><code>ClassNameExpression</code> returns the current class name 
21    * of the context bean
22    *
23    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
24    * @since 0.5
25    */
26  public class ClassNameExpression implements Expression {
27  
28      /** Base constructor */
29      public ClassNameExpression() {
30      }
31      
32      /** 
33       * Evaluate on the current context and return the class name  
34       *
35       * @param context the context against which this expression will be evaluated
36       * @return the name of the class of the current contex bean
37       */
38      public Object evaluate(Context context) {
39          Object bean = context.getBean();
40          if ( bean != null ) {
41              return bean.getClass().getName();
42          }
43          return null;
44      }
45  
46      /** 
47       * Do nothing.
48       * @see org.apache.commons.betwixt.expression.Expression
49       */
50      public void update(Context context, String newValue) {
51          // do nothing
52      }
53      
54      /** 
55       * Returns something useful for logging.
56       * @return something useful for logging
57       */
58      public String toString() {
59          return "ClassNameExpression";
60      }
61  }