KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > el > ELContextImpl


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 package org.apache.jasper.el;
18
19 import java.lang.reflect.Method JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.el.ELContext;
24 import javax.el.ELResolver;
25 import javax.el.FunctionMapper;
26 import javax.el.ValueExpression;
27 import javax.el.VariableMapper;
28
29 /**
30  * Implementation of ELContext
31  *
32  * @author Jacob Hookom
33  */

34 public final class ELContextImpl extends ELContext {
35
36     private final static FunctionMapper NullFunctionMapper = new FunctionMapper() {
37         public Method JavaDoc resolveFunction(String JavaDoc prefix, String JavaDoc localName) {
38             return null;
39         }
40     };
41
42     private final static class VariableMapperImpl extends VariableMapper {
43
44         private Map JavaDoc<String JavaDoc, ValueExpression> vars;
45
46         public ValueExpression resolveVariable(String JavaDoc variable) {
47             if (vars == null) {
48                 return null;
49             }
50             return vars.get(variable);
51         }
52
53         public ValueExpression setVariable(String JavaDoc variable,
54                 ValueExpression expression) {
55             if (vars == null)
56                 vars = new HashMap JavaDoc<String JavaDoc, ValueExpression>();
57             return vars.put(variable, expression);
58         }
59
60     }
61
62     private final ELResolver resolver;
63
64     private FunctionMapper functionMapper = NullFunctionMapper; // immutable
65

66     private VariableMapper variableMapper;
67
68     public ELContextImpl() {
69         this(ELResolverImpl.DefaultResolver);
70     }
71
72     public ELContextImpl(ELResolver resolver) {
73         this.resolver = resolver;
74     }
75
76     public ELResolver getELResolver() {
77         return this.resolver;
78     }
79
80     public FunctionMapper getFunctionMapper() {
81         return this.functionMapper;
82     }
83
84     public VariableMapper getVariableMapper() {
85         if (this.variableMapper == null) {
86             this.variableMapper = new VariableMapperImpl();
87         }
88         return this.variableMapper;
89     }
90
91     public void setFunctionMapper(FunctionMapper functionMapper) {
92         this.functionMapper = functionMapper;
93     }
94
95     public void setVariableMapper(VariableMapper variableMapper) {
96         this.variableMapper = variableMapper;
97     }
98
99 }
100
Popular Tags