Source code: com/sun/facelets/el/VariableMapperWrapper.java
1 /**
2 * Licensed under the Common Development and Distribution License,
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.sun.com/cddl/
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15 package com.sun.facelets.el;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import javax.el.ValueExpression;
21 import javax.el.VariableMapper;
22
23 /**
24 * Utility class for wrapping another VariableMapper with a new context,
25 * represented by a {@link java.util.Map Map}. Modifications occur to the
26 * Map instance, but resolve against the wrapped
27 * VariableMapper if the Map doesn't contain the ValueExpression requested.
28 *
29 * @author Jacob Hookom
30 * @version $Id: VariableMapperWrapper.java,v 1.2 2005/08/24 04:38:57 jhook Exp $
31 */
32 public final class VariableMapperWrapper extends VariableMapper {
33
34 private final VariableMapper target;
35
36 private Map vars;
37
38 /**
39 *
40 */
41 public VariableMapperWrapper(VariableMapper orig) {
42 super();
43 this.target = orig;
44 }
45
46 /**
47 * First tries to resolve agains the inner Map, then the wrapped
48 * ValueExpression.
49 *
50 * @see javax.el.VariableMapper#resolveVariable(java.lang.String)
51 */
52 public ValueExpression resolveVariable(String variable) {
53 ValueExpression ve = null;
54 if (this.vars != null) {
55 ve = (ValueExpression) this.vars.get(variable);
56 }
57 if (ve == null) {
58 return this.target.resolveVariable(variable);
59 }
60 return ve;
61 }
62
63 /**
64 * Set the ValueExpression on the inner Map instance.
65 *
66 * @see javax.el.VariableMapper#setVariable(java.lang.String,
67 * javax.el.ValueExpression)
68 */
69 public ValueExpression setVariable(String variable,
70 ValueExpression expression) {
71 if (this.vars == null) {
72 this.vars = new HashMap();
73 }
74 return (ValueExpression) this.vars.put(variable, expression);
75 }
76 }