| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 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 value; |
|
| 31 | ||
| 32 | /** Base constructor |
|
| 33 | */ |
|
| 34 | 0 | public ConstantExpression() { |
| 35 | 0 | } |
| 36 | ||
| 37 | /** Convenience constructor sets <code>value</code> property. |
|
| 38 | */ |
|
| 39 | 47203 | public ConstantExpression(Object value) { |
| 40 | 47203 | this.value = value; |
| 41 | 47203 | } |
| 42 | ||
| 43 | public String toString() { |
|
| 44 | 0 | return super.toString() + "[value=" + value +"]"; |
| 45 | } |
|
| 46 | ||
| 47 | public String getExpressionText() { |
|
| 48 | 169 | 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 evaluate(JellyContext context) { |
|
| 58 | 9230 | return value; |
| 59 | } |
|
| 60 | ||
| 61 | /** Gets the constant value of this expression */ |
|
| 62 | public Object getValue() { |
|
| 63 | 27768 | return value; |
| 64 | } |
|
| 65 | ||
| 66 | /** Sets the constant value of this expression */ |
|
| 67 | public void setValue(Object value) { |
|
| 68 | 0 | this.value = value; |
| 69 | 0 | } |
| 70 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |