Coverage Report - org.seasar.teeda.core.mock.MockVariableResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
MockVariableResolver
92%
35/38
77%
17/22
7.667
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.mock;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 import javax.faces.context.ExternalContext;
 22  
 import javax.faces.context.FacesContext;
 23  
 import javax.faces.el.EvaluationException;
 24  
 import javax.faces.el.VariableResolver;
 25  
 
 26  
 import org.seasar.framework.container.S2Container;
 27  
 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
 28  
 import org.seasar.teeda.core.JsfConstants;
 29  
 
 30  
 /**
 31  
  * @author shot
 32  
  * @author manhole
 33  
  */
 34  
 public class MockVariableResolver extends VariableResolver {
 35  
 
 36  1707
     private Map values = new HashMap();
 37  
 
 38  1707
     public MockVariableResolver() {
 39  1707
     }
 40  
 
 41  
     public void putValue(String key, Object value) {
 42  47
         values.put(key, value);
 43  47
     }
 44  
 
 45  
     public Object resolveVariable(FacesContext context, String name)
 46  
             throws EvaluationException {
 47  116
         ExternalContext externalContext = context.getExternalContext();
 48  
         {
 49  116
             Object value = values.get(name);
 50  116
             if (value != null) {
 51  56
                 return value;
 52  
             }
 53  
         }
 54  60
         Map applicationMap = externalContext.getApplicationMap();
 55  60
         Map sessionMap = externalContext.getSessionMap();
 56  60
         Map requestMap = externalContext.getRequestMap();
 57  60
         if (JsfConstants.REQUEST_SCOPE.equals(name)) {
 58  2
             return requestMap;
 59  
         }
 60  58
         if (JsfConstants.SESSION_SCOPE.equals(name)) {
 61  2
             return sessionMap;
 62  
         }
 63  56
         if (JsfConstants.APPLICATION_SCOPE.equals(name)) {
 64  2
             return applicationMap;
 65  
         }
 66  
         {
 67  54
             Object value = requestMap.get(name);
 68  54
             if (value != null) {
 69  40
                 return value;
 70  
             }
 71  
         }
 72  
         {
 73  14
             Map requestParameterMap = externalContext.getRequestParameterMap();
 74  14
             Object value = requestParameterMap.get(name);
 75  14
             if (value != null) {
 76  0
                 return value;
 77  
             }
 78  
         }
 79  
         {
 80  14
             Object value = sessionMap.get(name);
 81  14
             if (value != null) {
 82  0
                 return value;
 83  
             }
 84  
         }
 85  
         {
 86  14
             Object value = applicationMap.get(name);
 87  14
             if (value != null) {
 88  0
                 return value;
 89  
             }
 90  
         }
 91  14
         if (SingletonS2ContainerFactory.hasContainer()) {
 92  14
             final S2Container container = SingletonS2ContainerFactory
 93  
                     .getContainer();
 94  14
             if (container.hasComponentDef(name)) {
 95  4
                 final Object value = container.getComponent(name);
 96  4
                 if (value != null) {
 97  4
                     return value;
 98  
                 }
 99  
             }
 100  
         }
 101  10
         return null;
 102  
     }
 103  
 
 104  
 }