001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.betwixt.expression;
018
019
020 /** <p><code>ClassNameExpression</code> returns the current class name
021 * of the context bean
022 *
023 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
024 * @since 0.5
025 */
026 public class ClassNameExpression implements Expression {
027
028 /** Base constructor */
029 public ClassNameExpression() {
030 }
031
032 /**
033 * Evaluate on the current context and return the class name
034 *
035 * @param context the context against which this expression will be evaluated
036 * @return the name of the class of the current contex bean
037 */
038 public Object evaluate(Context context) {
039 Object bean = context.getBean();
040 if ( bean != null ) {
041 return bean.getClass().getName();
042 }
043 return null;
044 }
045
046 /**
047 * Do nothing.
048 * @see org.apache.commons.betwixt.expression.Expression
049 */
050 public void update(Context context, String newValue) {
051 // do nothing
052 }
053
054 /**
055 * Returns something useful for logging.
056 * @return something useful for logging
057 */
058 public String toString() {
059 return "ClassNameExpression";
060 }
061 }