001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jasper.el;
018:
019: import java.lang.reflect.Method;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import javax.el.ELContext;
024: import javax.el.ELResolver;
025: import javax.el.FunctionMapper;
026: import javax.el.ValueExpression;
027: import javax.el.VariableMapper;
028:
029: /**
030: * Implementation of ELContext
031: *
032: * @author Jacob Hookom
033: */
034: public final class ELContextImpl extends ELContext {
035:
036: private final static FunctionMapper NullFunctionMapper = new FunctionMapper() {
037: public Method resolveFunction(String prefix, String localName) {
038: return null;
039: }
040: };
041:
042: private final static class VariableMapperImpl extends
043: VariableMapper {
044:
045: private Map<String, ValueExpression> vars;
046:
047: public ValueExpression resolveVariable(String variable) {
048: if (vars == null) {
049: return null;
050: }
051: return vars.get(variable);
052: }
053:
054: public ValueExpression setVariable(String variable,
055: ValueExpression expression) {
056: if (vars == null)
057: vars = new HashMap<String, ValueExpression>();
058: return vars.put(variable, expression);
059: }
060:
061: }
062:
063: private final ELResolver resolver;
064:
065: private FunctionMapper functionMapper = NullFunctionMapper; // immutable
066:
067: private VariableMapper variableMapper;
068:
069: public ELContextImpl() {
070: this (ELResolverImpl.DefaultResolver);
071: }
072:
073: public ELContextImpl(ELResolver resolver) {
074: this .resolver = resolver;
075: }
076:
077: public ELResolver getELResolver() {
078: return this .resolver;
079: }
080:
081: public FunctionMapper getFunctionMapper() {
082: return this .functionMapper;
083: }
084:
085: public VariableMapper getVariableMapper() {
086: if (this .variableMapper == null) {
087: this .variableMapper = new VariableMapperImpl();
088: }
089: return this .variableMapper;
090: }
091:
092: public void setFunctionMapper(FunctionMapper functionMapper) {
093: this .functionMapper = functionMapper;
094: }
095:
096: public void setVariableMapper(VariableMapper variableMapper) {
097: this.variableMapper = variableMapper;
098: }
099:
100: }
|