Home » tiles-2.2.1-src » org.apache.tiles.el » [javadoc | source]

    1   /*
    2    * $Id: ELContextImpl.java 816924 2009-09-19 13:45:40Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    * http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.tiles.el;
   23   
   24   import java.lang.reflect.Method;
   25   import java.util.HashMap;
   26   import java.util.Map;
   27   
   28   import javax.el.ELContext;
   29   import javax.el.ELResolver;
   30   import javax.el.FunctionMapper;
   31   import javax.el.ValueExpression;
   32   import javax.el.VariableMapper;
   33   
   34   /**
   35    * Implementation of ELContext.<br>
   36    * Copied from Apache Tomcat 6.0.16 source code.
   37    *
   38    * @since 2.2.1
   39    */
   40   public class ELContextImpl extends ELContext {
   41   
   42       /**
   43        * A null function mapper.
   44        */
   45       private static final FunctionMapper NULL_FUNCTION_MAPPER = new FunctionMapper() {
   46           public Method resolveFunction(String prefix, String localName) {
   47               return null;
   48           }
   49       };
   50   
   51       /**
   52        * Default implementation for the variable mapper.
   53        */
   54       private static final class VariableMapperImpl extends VariableMapper {
   55   
   56           /**
   57            * The mapped variables.
   58            */
   59           private Map<String, ValueExpression> vars;
   60   
   61           /** {@inheritDoc} */
   62           public ValueExpression resolveVariable(String variable) {
   63               if (vars == null) {
   64                   return null;
   65               }
   66               return vars.get(variable);
   67           }
   68   
   69           /** {@inheritDoc} */
   70           public ValueExpression setVariable(String variable,
   71                   ValueExpression expression) {
   72               if (vars == null) {
   73                   vars = new HashMap<String, ValueExpression>();
   74               }
   75               return vars.put(variable, expression);
   76           }
   77   
   78       }
   79   
   80       /**
   81        * The EL resolver to use.
   82        */
   83       private final ELResolver resolver;
   84   
   85       /**
   86        * The function mapper to use.
   87        */
   88       private FunctionMapper functionMapper = NULL_FUNCTION_MAPPER;
   89   
   90       /**
   91        * The variable mapper to use.
   92        */
   93       private VariableMapper variableMapper;
   94   
   95       /**
   96        * Constructor.
   97        *
   98        * @param resolver The resolver to use.
   99        */
  100       public ELContextImpl(ELResolver resolver) {
  101           this.resolver = resolver;
  102       }
  103   
  104       /** {@inheritDoc} */
  105       public ELResolver getELResolver() {
  106           return this.resolver;
  107       }
  108   
  109       /** {@inheritDoc} */
  110       public FunctionMapper getFunctionMapper() {
  111           return this.functionMapper;
  112       }
  113   
  114       /** {@inheritDoc} */
  115       public VariableMapper getVariableMapper() {
  116           if (this.variableMapper == null) {
  117               this.variableMapper = new VariableMapperImpl();
  118           }
  119           return this.variableMapper;
  120       }
  121   
  122       /**
  123        * Sets the function mapper to use.
  124        *
  125        * @param functionMapper The function mapper.
  126        * @since 2.2.1
  127        */
  128       public void setFunctionMapper(FunctionMapper functionMapper) {
  129           this.functionMapper = functionMapper;
  130       }
  131   
  132       /**
  133        * Sets the variable mapper to use.
  134        *
  135        * @param variableMapper The variable mapper.
  136        * @since 2.2.1
  137        */
  138       public void setVariableMapper(VariableMapper variableMapper) {
  139           this.variableMapper = variableMapper;
  140       }
  141   }

Home » tiles-2.2.1-src » org.apache.tiles.el » [javadoc | source]