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. /** <p><code>ClassNameExpression</code> returns the current class name
  18. * of the context bean
  19. *
  20. * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  21. * @since 0.5
  22. */
  23. public class ClassNameExpression implements Expression {
  24. /** Base constructor */
  25. public ClassNameExpression() {
  26. }
  27. /**
  28. * Evaluate on the current context and return the class name
  29. *
  30. * @param context the context against which this expression will be evaluated
  31. * @return the name of the class of the current contex bean
  32. */
  33. public Object evaluate(Context context) {
  34. Object bean = context.getBean();
  35. if ( bean != null ) {
  36. return bean.getClass().getName();
  37. }
  38. return null;
  39. }
  40. /**
  41. * Do nothing.
  42. * @see org.apache.commons.betwixt.expression.Expression
  43. */
  44. public void update(Context context, String newValue) {
  45. // do nothing
  46. }
  47. /**
  48. * Returns something useful for logging.
  49. * @return something useful for logging
  50. */
  51. public String toString() {
  52. return "ClassNameExpression";
  53. }
  54. }