Coverage Report - org.apache.myfaces.config.RuntimeConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
RuntimeConfig
0%
0/69
0%
0/14
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.config;
 20  
 
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collection;
 23  
 import java.util.Collections;
 24  
 import java.util.HashMap;
 25  
 import java.util.Map;
 26  
 
 27  
 import javax.el.CompositeELResolver;
 28  
 import javax.el.ELResolver;
 29  
 import javax.el.ExpressionFactory;
 30  
 import javax.faces.context.ExternalContext;
 31  
 import javax.faces.el.PropertyResolver;
 32  
 import javax.faces.el.VariableResolver;
 33  
 
 34  
 import org.apache.commons.logging.Log;
 35  
 import org.apache.commons.logging.LogFactory;
 36  
 import org.apache.myfaces.config.element.ManagedBean;
 37  
 import org.apache.myfaces.config.element.NavigationRule;
 38  
 import org.apache.myfaces.config.impl.digester.elements.ResourceBundle;
 39  
 
 40  
 /**
 41  
  * Holds all configuration information (from the faces-config xml files) that is needed later during runtime. The config
 42  
  * information in this class is only available to the MyFaces core implementation classes (i.e. the myfaces source
 43  
  * tree). See MyfacesConfig for config parameters that can be used for shared or component classes.
 44  
  * 
 45  
  * @author Manfred Geiler (latest modification by $Author: skitching $)
 46  
  * @version $Revision: 684459 $ $Date: 2008-08-10 06:13:56 -0500 (Sun, 10 Aug 2008) $
 47  
  */
 48  
 @SuppressWarnings("deprecation")
 49  0
 public class RuntimeConfig
 50  
 {
 51  0
     private static final Log log = LogFactory.getLog(RuntimeConfig.class);
 52  
 
 53  0
     private static final String APPLICATION_MAP_PARAM_NAME = RuntimeConfig.class.getName();
 54  
 
 55  0
     private final Collection<NavigationRule> _navigationRules = new ArrayList<NavigationRule>();
 56  0
     private final Map<String, ManagedBean> _managedBeans = new HashMap<String, ManagedBean>();
 57  0
     private boolean _navigationRulesChanged = false;
 58  0
     private final Map<String, ResourceBundle> _resourceBundles = new HashMap<String, ResourceBundle>();
 59  0
     private final Map<String, ManagedBean> _oldManagedBeans = new HashMap<String, ManagedBean>();
 60  
 
 61  
     private CompositeELResolver facesConfigElResolvers;
 62  
     private CompositeELResolver applicationElResolvers;
 63  
 
 64  
     private VariableResolver _variableResolver;
 65  
     private PropertyResolver _propertyResolver;
 66  
 
 67  
     private ExpressionFactory _expressionFactory;
 68  
 
 69  
     private PropertyResolver _propertyResolverChainHead;
 70  
 
 71  
     private VariableResolver _variableResolverChainHead;
 72  
 
 73  
     public static RuntimeConfig getCurrentInstance(ExternalContext externalContext)
 74  
     {
 75  0
         RuntimeConfig runtimeConfig = (RuntimeConfig) externalContext.getApplicationMap().get(
 76  
                 APPLICATION_MAP_PARAM_NAME);
 77  0
         if (runtimeConfig == null)
 78  
         {
 79  0
             runtimeConfig = new RuntimeConfig();
 80  0
             externalContext.getApplicationMap().put(APPLICATION_MAP_PARAM_NAME, runtimeConfig);
 81  
         }
 82  0
         return runtimeConfig;
 83  
     }
 84  
 
 85  
     public void purge()
 86  
     {
 87  0
         _navigationRules.clear();
 88  0
         _oldManagedBeans.clear();
 89  0
         _oldManagedBeans.putAll(_managedBeans);
 90  0
         _managedBeans.clear();
 91  0
         _navigationRulesChanged = false;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * Return the navigation rules that can be used by the NavigationHandler implementation.
 96  
      * 
 97  
      * @return a Collection of {@link org.apache.myfaces.config.element.NavigationRule NavigationRule}s
 98  
      */
 99  
     public Collection<NavigationRule> getNavigationRules()
 100  
     {
 101  0
         return Collections.unmodifiableCollection(_navigationRules);
 102  
     }
 103  
 
 104  
     public void addNavigationRule(NavigationRule navigationRule)
 105  
     {
 106  0
         _navigationRules.add(navigationRule);
 107  
 
 108  0
         _navigationRulesChanged = true;
 109  0
     }
 110  
 
 111  
     public boolean isNavigationRulesChanged()
 112  
     {
 113  0
         return _navigationRulesChanged;
 114  
     }
 115  
 
 116  
     public void setNavigationRulesChanged(boolean navigationRulesChanged)
 117  
     {
 118  0
         _navigationRulesChanged = navigationRulesChanged;
 119  0
     }
 120  
 
 121  
     /**
 122  
      * Return the managed bean info that can be used by the VariableResolver implementation.
 123  
      * 
 124  
      * @return a {@link org.apache.myfaces.config.element.ManagedBean ManagedBean}
 125  
      */
 126  
     public ManagedBean getManagedBean(String name)
 127  
     {
 128  0
         return _managedBeans.get(name);
 129  
     }
 130  
 
 131  
     public Map<String, ManagedBean> getManagedBeans()
 132  
     {
 133  0
         return Collections.unmodifiableMap(_managedBeans);
 134  
     }
 135  
 
 136  
     public void addManagedBean(String name, ManagedBean managedBean)
 137  
     {
 138  0
         _managedBeans.put(name, managedBean);
 139  0
         if(_oldManagedBeans!=null)
 140  0
             _oldManagedBeans.remove(name);
 141  0
     }
 142  
 
 143  
     /**
 144  
      * Return the resourcebundle which was configured in faces config by var name
 145  
      * 
 146  
      * @param name
 147  
      *            the name of the resource bundle (content of var)
 148  
      * @return the resource bundle or null if not found
 149  
      */
 150  
     public ResourceBundle getResourceBundle(String name)
 151  
     {
 152  0
         return _resourceBundles.get(name);
 153  
     }
 154  
 
 155  
     /**
 156  
      * @return the resourceBundles
 157  
      */
 158  
     public Map<String, ResourceBundle> getResourceBundles()
 159  
     {
 160  0
         return _resourceBundles;
 161  
     }
 162  
 
 163  
     public void addResourceBundle(ResourceBundle bundle)
 164  
     {
 165  0
         if (bundle == null)
 166  
         {
 167  0
             throw new IllegalArgumentException("bundle must not be null");
 168  
         }
 169  0
         String var = bundle.getVar();
 170  0
         if (_resourceBundles.containsKey(var) && log.isWarnEnabled())
 171  
         {
 172  0
             log.warn("Another resource bundle for var '" + var + "' with base name '"
 173  
                     + _resourceBundles.get(var).getBaseName() + "' is already registered. '"
 174  
                     + _resourceBundles.get(var).getBaseName() + "' will be replaced with '" + bundle.getBaseName()
 175  
                     + "'.");
 176  
         }
 177  0
         _resourceBundles.put(var, bundle);
 178  0
     }
 179  
 
 180  
     public void addFacesConfigElResolver(ELResolver resolver)
 181  
     {
 182  0
         if (facesConfigElResolvers == null)
 183  
         {
 184  0
             facesConfigElResolvers = new org.apache.myfaces.el.CompositeELResolver();
 185  
         }
 186  0
         facesConfigElResolvers.add(resolver);
 187  0
     }
 188  
 
 189  
     public ELResolver getFacesConfigElResolvers()
 190  
     {
 191  0
         return facesConfigElResolvers;
 192  
     }
 193  
 
 194  
     public void addApplicationElResolver(ELResolver resolver)
 195  
     {
 196  0
         if (applicationElResolvers == null)
 197  
         {
 198  0
             applicationElResolvers = new org.apache.myfaces.el.CompositeELResolver();
 199  
         }
 200  0
         applicationElResolvers.add(resolver);
 201  0
     }
 202  
 
 203  
     public ELResolver getApplicationElResolvers()
 204  
     {
 205  0
         return applicationElResolvers;
 206  
     }
 207  
 
 208  
     public void setVariableResolver(VariableResolver variableResolver)
 209  
     {
 210  0
         _variableResolver = variableResolver;
 211  0
     }
 212  
 
 213  
     public VariableResolver getVariableResolver()
 214  
     {
 215  0
         return _variableResolver;
 216  
     }
 217  
 
 218  
     public void setPropertyResolver(PropertyResolver propertyResolver)
 219  
     {
 220  0
         _propertyResolver = propertyResolver;
 221  0
     }
 222  
 
 223  
     public PropertyResolver getPropertyResolver()
 224  
     {
 225  0
         return _propertyResolver;
 226  
     }
 227  
 
 228  
     public ExpressionFactory getExpressionFactory()
 229  
     {
 230  0
         return _expressionFactory;
 231  
     }
 232  
 
 233  
     public void setExpressionFactory(ExpressionFactory expressionFactory)
 234  
     {
 235  0
         _expressionFactory = expressionFactory;
 236  0
     }
 237  
 
 238  
     public void setPropertyResolverChainHead(PropertyResolver resolver)
 239  
     {
 240  0
         _propertyResolverChainHead = resolver;
 241  0
     }
 242  
 
 243  
     public PropertyResolver getPropertyResolverChainHead()
 244  
     {
 245  0
         return _propertyResolverChainHead;
 246  
     }
 247  
 
 248  
     public void setVariableResolverChainHead(VariableResolver resolver)
 249  
     {
 250  0
         _variableResolverChainHead = resolver;
 251  0
     }
 252  
 
 253  
     public VariableResolver getVariableResolverChainHead()
 254  
     {
 255  0
         return _variableResolverChainHead;
 256  
     }
 257  
 
 258  
     public Map getManagedBeansNotReaddedAfterPurge()
 259  
     {
 260  0
         return _oldManagedBeans;
 261  
     }
 262  
 
 263  
     public void resetManagedBeansNotReaddedAfterPurge()
 264  
     {
 265  0
         _oldManagedBeans.clear();
 266  0
     }
 267  
 }