01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: /** <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 evaluate(Context context) {
38: Object 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 newValue) {
50: // do nothing
51: }
52:
53: /**
54: * Returns something useful for logging.
55: * @return something useful for logging
56: */
57: public String toString() {
58: return "ClassNameExpression";
59: }
60: }
|