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>ConstantExpression</code> represents a constant expression.</p>
  18. *
  19. * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
  20. *
  21. * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  22. * @version $Revision: 1.6 $
  23. */
  24. public class ConstantExpression implements Expression {
  25. /** The value of this expression */
  26. private Object value;
  27. /** Base constructor
  28. */
  29. public ConstantExpression() {
  30. }
  31. /**
  32. * Convenience constructor sets <code>value</code> property.
  33. * @param value the Object which is the constant value for this expression
  34. */
  35. public ConstantExpression(Object value) {
  36. this.value = value;
  37. }
  38. /**
  39. * Evaluate expression against given context.
  40. *
  41. * @param context evaluate expression against this context
  42. * @return current value of <code>value</code> property
  43. */
  44. public Object evaluate(Context context) {
  45. return value;
  46. }
  47. /**
  48. * Do nothing
  49. * @see org.apache.commons.betwixt.expression.Expression
  50. */
  51. public void update(Context context, String newValue) {
  52. // do nothing
  53. }
  54. /**
  55. * Gets the constant value of this expression
  56. * @return this expression's constant value
  57. */
  58. public Object getValue() {
  59. return value;
  60. }
  61. /**
  62. * Sets the constant value of this expression
  63. * @param value the constant value for this expression
  64. */
  65. public void setValue(Object value) {
  66. this.value = value;
  67. }
  68. /**
  69. * Returns something useful for logging
  70. * @return something useful for logging
  71. */
  72. public String toString() {
  73. return "ConstantExpression [value=" + value + "]";
  74. }
  75. }