Coverage Report - org.seasar.teeda.core.util.VariableResolverUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
VariableResolverUtil
75%
9/12
83%
5/6
2
 
 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.util;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import javax.faces.context.FacesContext;
 21  
 import javax.faces.el.VariableResolver;
 22  
 
 23  
 import org.seasar.teeda.core.JsfConstants;
 24  
 
 25  
 public class VariableResolverUtil {
 26  
 
 27  1
     private static final String[] DEFAULT_SCOPES = {
 28  
             JsfConstants.REQUEST_SCOPE, JsfConstants.SESSION_SCOPE,
 29  
             JsfConstants.APPLICATION_SCOPE };
 30  
 
 31  0
     private VariableResolverUtil() {
 32  0
     }
 33  
 
 34  
     public static Object resolveVariable(FacesContext context, String name) {
 35  102
         if (context == null) {
 36  0
             context = FacesContext.getCurrentInstance();
 37  
         }
 38  102
         return context.getApplication().getVariableResolver().resolveVariable(
 39  
                 context, name);
 40  
     }
 41  
 
 42  
     public static Map getDefaultScopeMap(FacesContext context,
 43  
             VariableResolver resolver, String key) {
 44  5
         return getScopeMap(context, resolver, key, DEFAULT_SCOPES);
 45  
     }
 46  
 
 47  
     private static Map getScopeMap(FacesContext context,
 48  
             VariableResolver resolver, String key, String[] scopes) {
 49  14
         for (int i = 0; i < scopes.length; i++) {
 50  12
             Map scopeMap = (Map) resolver.resolveVariable(context, scopes[i]);
 51  12
             if (scopeMap.get(key) != null) {
 52  3
                 return scopeMap;
 53  
             }
 54  
         }
 55  2
         return null;
 56  
 
 57  
     }
 58  
 }