KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > expression > support > StaticExpression


1 /*
2  * Copyright 2002-2006 the original author or authors.
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.springframework.binding.expression.support;
17
18 import org.springframework.binding.expression.EvaluationContext;
19 import org.springframework.binding.expression.EvaluationException;
20 import org.springframework.binding.expression.Expression;
21 import org.springframework.util.ObjectUtils;
22
23 /**
24  * A simple expression evaluator that just returns the expression itself as the
25  * result of each evaluation.
26  * @author Keith Donald
27  */

28 public class StaticExpression implements Expression {
29
30     /**
31      * The value expression.
32      */

33     private Object JavaDoc value;
34
35     /**
36      * Create a static evaluator for the value expression.
37      * @param value the value expression
38      */

39     public StaticExpression(Object JavaDoc value) {
40         this.value = value;
41     }
42
43     public int hashCode() {
44         if (value == null) {
45             return 0;
46         }
47         else {
48             return value.hashCode();
49         }
50     }
51
52     public boolean equals(Object JavaDoc o) {
53         if (!(o instanceof StaticExpression)) {
54             return false;
55         }
56         StaticExpression other = (StaticExpression)o;
57         return ObjectUtils.nullSafeEquals(value, other.value);
58     }
59
60     public Object JavaDoc evaluate(Object JavaDoc target, EvaluationContext context) throws EvaluationException {
61         return value;
62     }
63
64     public String JavaDoc toString() {
65         return String.valueOf(value);
66     }
67 }
Popular Tags