2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shale.test.el;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  import javax.el.ValueExpression;
23  import javax.el.VariableMapper;
24  
25  /***
26   * <p>Mock implementation of <code>VariableMapper</code>.</p>
27   *
28   * @since 1.0.4
29   */
30  
31  public class MockVariableMapper extends VariableMapper {
32      
33  
34      // ------------------------------------------------------------ Constructors
35  
36  
37      /*** Creates a new instance of MockVariableMapper */
38      public MockVariableMapper() {
39      }
40      
41  
42      // ------------------------------------------------------ Instance Variables
43  
44  
45      /***
46       * <p>Map of <code>ValueExpression</code>s, keyed by variable name.</p>
47       */
48      private Map expressions = new HashMap();
49  
50  
51      // ----------------------------------------------------- Mock Object Methods
52  
53  
54      // -------------------------------------------------- FunctionMapper Methods
55  
56  
57      /*** {@inheritDoc} */
58      public ValueExpression resolveVariable(String variable) {
59  
60          return (ValueExpression) expressions.get(variable);
61  
62      }
63  
64  
65      /*** {@inheritDoc} */
66      public ValueExpression setVariable(String variable, ValueExpression expression) {
67  
68          ValueExpression original = (ValueExpression) expressions.get(variable);
69          if (expression == null) {
70              expressions.remove(variable);
71          } else {
72              expressions.put(variable, expression);
73          }
74          return original;
75  
76      }
77  
78  
79  }