KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jelly > expression > ConstantExpression


1 /*
2  * Copyright 2002,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.jelly.expression;
17
18 import org.apache.commons.jelly.JellyContext;
19
20 /** <p><code>ConstantExpression</code> represents a constant expression.</p>
21   *
22   * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
23   *
24   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
25   * @version $Revision: 155420 $
26   */

27 public class ConstantExpression extends ExpressionSupport {
28
29     /** The value of this expression */
30     private Object JavaDoc value;
31
32     /** Base constructor
33      */

34     public ConstantExpression() {
35     }
36
37     /** Convenience constructor sets <code>value</code> property.
38      */

39     public ConstantExpression(Object JavaDoc value) {
40         this.value = value;
41     }
42
43     public String JavaDoc toString() {
44         return super.toString() + "[value=" + value +"]";
45     }
46
47     public String JavaDoc getExpressionText() {
48         return value == null ? "null" : value.toString();
49     }
50
51     /**
52       * Evaluate expression against given context.
53       *
54       * @param context evaluate expression against this context
55       * @return current value of <code>value</code> property
56       */

57     public Object JavaDoc evaluate(JellyContext context) {
58         return value;
59     }
60
61     /** Gets the constant value of this expression */
62     public Object JavaDoc getValue() {
63         return value;
64     }
65
66     /** Sets the constant value of this expression */
67     public void setValue(Object JavaDoc value) {
68         this.value = value;
69     }
70 }
71
Popular Tags