Coverage Report - org.apache.tiles.el.ELContextImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ELContextImpl
100%
14/14
100%
2/2
1.444
ELContextImpl$1
100%
2/2
N/A
1.444
ELContextImpl$VariableMapperImpl
100%
7/7
75%
3/4
1.444
 
 1  
 /*
 2  
  * $Id: ELContextImpl.java 836180 2009-11-14 14:00:02Z 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  1
     private static final FunctionMapper NULL_FUNCTION_MAPPER = new FunctionMapper() {
 46  
         @Override
 47  
         public Method resolveFunction(String prefix, String localName) {
 48  1
             return null;
 49  
         }
 50  
     };
 51  
 
 52  
     /**
 53  
      * Default implementation for the variable mapper.
 54  
      */
 55  34
     private static final class VariableMapperImpl extends VariableMapper {
 56  
 
 57  
         /**
 58  
          * The mapped variables.
 59  
          */
 60  
         private Map<String, ValueExpression> vars;
 61  
 
 62  
         /** {@inheritDoc} */
 63  
         @Override
 64  
         public ValueExpression resolveVariable(String variable) {
 65  16
             if (vars == null) {
 66  15
                 return null;
 67  
             }
 68  1
             return vars.get(variable);
 69  
         }
 70  
 
 71  
         /** {@inheritDoc} */
 72  
         @Override
 73  
         public ValueExpression setVariable(String variable,
 74  
                 ValueExpression expression) {
 75  1
             if (vars == null) {
 76  1
                 vars = new HashMap<String, ValueExpression>();
 77  
             }
 78  1
             return vars.put(variable, expression);
 79  
         }
 80  
 
 81  
     }
 82  
 
 83  
     /**
 84  
      * The EL resolver to use.
 85  
      */
 86  
     private final ELResolver resolver;
 87  
 
 88  
     /**
 89  
      * The function mapper to use.
 90  
      */
 91  29
     private FunctionMapper functionMapper = NULL_FUNCTION_MAPPER;
 92  
 
 93  
     /**
 94  
      * The variable mapper to use.
 95  
      */
 96  
     private VariableMapper variableMapper;
 97  
 
 98  
     /**
 99  
      * Constructor.
 100  
      *
 101  
      * @param resolver The resolver to use.
 102  
      */
 103  29
     public ELContextImpl(ELResolver resolver) {
 104  29
         this.resolver = resolver;
 105  29
     }
 106  
 
 107  
     /** {@inheritDoc} */
 108  
     @Override
 109  
     public ELResolver getELResolver() {
 110  23
         return this.resolver;
 111  
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     @Override
 115  
     public FunctionMapper getFunctionMapper() {
 116  18
         return this.functionMapper;
 117  
     }
 118  
 
 119  
     /** {@inheritDoc} */
 120  
     @Override
 121  
     public VariableMapper getVariableMapper() {
 122  18
         if (this.variableMapper == null) {
 123  17
             this.variableMapper = new VariableMapperImpl();
 124  
         }
 125  18
         return this.variableMapper;
 126  
     }
 127  
 
 128  
     /**
 129  
      * Sets the function mapper to use.
 130  
      *
 131  
      * @param functionMapper The function mapper.
 132  
      * @since 2.2.1
 133  
      */
 134  
     public void setFunctionMapper(FunctionMapper functionMapper) {
 135  1
         this.functionMapper = functionMapper;
 136  1
     }
 137  
 
 138  
     /**
 139  
      * Sets the variable mapper to use.
 140  
      *
 141  
      * @param variableMapper The variable mapper.
 142  
      * @since 2.2.1
 143  
      */
 144  
     public void setVariableMapper(VariableMapper variableMapper) {
 145  1
         this.variableMapper = variableMapper;
 146  1
     }
 147  
 }