Coverage Report - org.apache.myfaces.config.impl.digester.DigesterFacesConfigDispenserImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DigesterFacesConfigDispenserImpl
0%
0/114
0%
0/24
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.impl.digester;
 20  
 
 21  
 import org.apache.myfaces.config.FacesConfigDispenser;
 22  
 import org.apache.myfaces.config.element.ManagedBean;
 23  
 import org.apache.myfaces.config.element.NavigationRule;
 24  
 import org.apache.myfaces.config.element.Renderer;
 25  
 import org.apache.myfaces.config.impl.digester.elements.Application;
 26  
 import org.apache.myfaces.config.impl.digester.elements.Converter;
 27  
 import org.apache.myfaces.config.impl.digester.elements.FacesConfig;
 28  
 import org.apache.myfaces.config.impl.digester.elements.Factory;
 29  
 import org.apache.myfaces.config.impl.digester.elements.LocaleConfig;
 30  
 import org.apache.myfaces.config.impl.digester.elements.RenderKit;
 31  
 import org.apache.myfaces.config.impl.digester.elements.ResourceBundle;
 32  
 
 33  
 import javax.faces.render.RenderKitFactory;
 34  
 
 35  
 import java.util.ArrayList;
 36  
 import java.util.Collections;
 37  
 import java.util.HashMap;
 38  
 import java.util.Iterator;
 39  
 import java.util.LinkedHashMap;
 40  
 import java.util.List;
 41  
 import java.util.Map;
 42  
 
 43  
 /**
 44  
  * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
 45  
  */
 46  0
 public class DigesterFacesConfigDispenserImpl implements
 47  
         FacesConfigDispenser<FacesConfig>
 48  
 {
 49  
 
 50  0
     private List<String> applicationFactories = new ArrayList<String>();
 51  0
     private List<String> facesContextFactories = new ArrayList<String>();
 52  0
     private List<String> lifecycleFactories = new ArrayList<String>();
 53  0
     private List<String> renderKitFactories = new ArrayList<String>();
 54  0
     private Map<String, String> components = new HashMap<String, String>();
 55  0
     private Map<String, String> validators = new HashMap<String, String>();
 56  
     private String defaultRenderKitId;
 57  
     private LocaleConfig localeConfig;
 58  0
     private List<String> actionListeners = new ArrayList<String>();
 59  0
     private List<String> lifecyclePhaseListeners = new ArrayList<String>();
 60  
     private String messageBundle;
 61  0
     private List<String> navigationHandlers = new ArrayList<String>();
 62  0
     private List<String> viewHandlers = new ArrayList<String>();
 63  0
     private List<String> stateManagers = new ArrayList<String>();
 64  0
     private List<String> propertyResolver = new ArrayList<String>();
 65  0
     private List<String> variableResolver = new ArrayList<String>();
 66  0
     private Map<String, String> converterById = new HashMap<String, String>();
 67  0
     private Map<String, String> converterByClass = new HashMap<String, String>();
 68  0
     private Map<String, Converter> converterConfigurationByClassName = new HashMap<String, Converter>();
 69  0
     private Map<String, RenderKit> renderKits = new LinkedHashMap<String, RenderKit>();
 70  0
     private List<ManagedBean> managedBeans = new ArrayList<ManagedBean>();
 71  0
     private List<NavigationRule> navigationRules = new ArrayList<NavigationRule>();
 72  0
     private List<ResourceBundle> resourceBundles = new ArrayList<ResourceBundle>();
 73  0
     private List<String> elResolvers = new ArrayList<String>();
 74  
 
 75  
     /**
 76  
      * Add another unmarshalled faces config object.
 77  
      * 
 78  
      * @param config
 79  
      *            unmarshalled faces config object
 80  
      */
 81  
     public void feed(FacesConfig config)
 82  
     {
 83  0
         for (Factory factory : config.getFactories())
 84  
         {
 85  0
             applicationFactories.addAll(factory.getApplicationFactory());
 86  0
             facesContextFactories.addAll(factory.getFacesContextFactory());
 87  0
             lifecycleFactories.addAll(factory.getLifecycleFactory());
 88  0
             renderKitFactories.addAll(factory.getRenderkitFactory());
 89  
         }
 90  0
         components.putAll(config.getComponents());
 91  0
         validators.putAll(config.getValidators());
 92  
 
 93  0
         for (Application application : config.getApplications())
 94  
         {
 95  0
             if (!application.getDefaultRenderkitId().isEmpty())
 96  
             {
 97  0
                 defaultRenderKitId = application
 98  
                         .getDefaultRenderkitId().get(
 99  
                                 application.getDefaultRenderkitId().size() - 1);
 100  
             }
 101  0
             if (!application.getMessageBundle().isEmpty())
 102  
             {
 103  0
                 messageBundle = application.getMessageBundle().get(
 104  
                         application.getMessageBundle().size() - 1);
 105  
             }
 106  0
             if (!application.getLocaleConfig().isEmpty())
 107  
             {
 108  0
                 localeConfig = application.getLocaleConfig()
 109  
                         .get(application.getLocaleConfig().size() - 1);
 110  
             }
 111  0
             actionListeners.addAll(application.getActionListener());
 112  0
             navigationHandlers.addAll(application.getNavigationHandler());
 113  0
             viewHandlers.addAll(application.getViewHandler());
 114  0
             stateManagers.addAll(application.getStateManager());
 115  0
             propertyResolver.addAll(application.getPropertyResolver());
 116  0
             variableResolver.addAll(application.getVariableResolver());
 117  0
             resourceBundles.addAll(application.getResourceBundle());
 118  0
             elResolvers.addAll(application.getElResolver());
 119  
         }
 120  0
         for (Converter converter : config.getConverters()) {
 121  
 
 122  0
             if (converter.getConverterId() != null)
 123  
             {
 124  0
                 converterById.put(converter.getConverterId(),converter
 125  
                         .getConverterClass());
 126  
             }
 127  
             else
 128  
             {
 129  0
                 converterByClass.put(converter.getForClass(),converter
 130  
                         .getConverterClass());
 131  
             }
 132  
 
 133  0
             converterConfigurationByClassName.put(
 134  
                     converter.getConverterClass(), converter);
 135  
         }
 136  
 
 137  0
         for (RenderKit renderKit : config.getRenderKits())
 138  
         {
 139  0
             String renderKitId = renderKit.getId();
 140  
 
 141  0
             if (renderKitId == null)
 142  
             {
 143  0
                 renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
 144  
             }
 145  
 
 146  0
             RenderKit existing = renderKits.get(renderKitId);
 147  
 
 148  0
             if (existing == null)
 149  
             {
 150  0
                 renderKits.put(renderKitId, renderKit);
 151  
             }
 152  
             else
 153  
             {
 154  0
                 existing.merge(renderKit);
 155  
             }
 156  0
         }
 157  0
         lifecyclePhaseListeners.addAll(config.getLifecyclePhaseListener());
 158  0
         managedBeans.addAll(config.getManagedBeans());
 159  0
         navigationRules.addAll(config.getNavigationRules());
 160  0
     }
 161  
 
 162  
     /**
 163  
      * Add another ApplicationFactory class name
 164  
      * 
 165  
      * @param factoryClassName
 166  
      *            a class name
 167  
      */
 168  
     public void feedApplicationFactory(String factoryClassName)
 169  
     {
 170  0
         applicationFactories.add(factoryClassName);
 171  0
     }
 172  
 
 173  
     /**
 174  
      * Add another FacesContextFactory class name
 175  
      * 
 176  
      * @param factoryClassName
 177  
      *            a class name
 178  
      */
 179  
     public void feedFacesContextFactory(String factoryClassName)
 180  
     {
 181  0
         facesContextFactories.add(factoryClassName);
 182  0
     }
 183  
 
 184  
     /**
 185  
      * Add another LifecycleFactory class name
 186  
      * 
 187  
      * @param factoryClassName
 188  
      *            a class name
 189  
      */
 190  
     public void feedLifecycleFactory(String factoryClassName)
 191  
     {
 192  0
         lifecycleFactories.add(factoryClassName);
 193  0
     }
 194  
 
 195  
     /**
 196  
      * Add another RenderKitFactory class name
 197  
      * 
 198  
      * @param factoryClassName
 199  
      *            a class name
 200  
      */
 201  
     public void feedRenderKitFactory(String factoryClassName)
 202  
     {
 203  0
         renderKitFactories.add(factoryClassName);
 204  0
     }
 205  
 
 206  
     /**
 207  
      * @return Iterator over ApplicationFactory class names
 208  
      */
 209  
     public Iterator<String> getApplicationFactoryIterator()
 210  
     {
 211  0
         return applicationFactories.iterator();
 212  
     }
 213  
 
 214  
     /**
 215  
      * @return Iterator over FacesContextFactory class names
 216  
      */
 217  
     public Iterator<String> getFacesContextFactoryIterator()
 218  
     {
 219  0
         return facesContextFactories.iterator();
 220  
     }
 221  
 
 222  
     /**
 223  
      * @return Iterator over LifecycleFactory class names
 224  
      */
 225  
     public Iterator<String> getLifecycleFactoryIterator()
 226  
     {
 227  0
         return lifecycleFactories.iterator();
 228  
     }
 229  
 
 230  
     /**
 231  
      * @return Iterator over RenderKit factory class names
 232  
      */
 233  
     public Iterator<String> getRenderKitFactoryIterator()
 234  
     {
 235  0
         return renderKitFactories.iterator();
 236  
     }
 237  
 
 238  
     /**
 239  
      * @return Iterator over ActionListener class names
 240  
      */
 241  
     public Iterator<String> getActionListenerIterator()
 242  
     {
 243  0
         List<String> listeners = new ArrayList<String>(actionListeners);
 244  0
         return listeners.iterator();
 245  
     }
 246  
 
 247  
     /**
 248  
      * @return the default render kit id
 249  
      */
 250  
     public String getDefaultRenderKitId()
 251  
     {
 252  0
         return defaultRenderKitId;
 253  
     }
 254  
 
 255  
     /**
 256  
      * @return Iterator over message bundle names
 257  
      */
 258  
     public String getMessageBundle()
 259  
     {
 260  0
         return messageBundle;
 261  
     }
 262  
 
 263  
     /**
 264  
      * @return Iterator over NavigationHandler class names
 265  
      */
 266  
     public Iterator<String> getNavigationHandlerIterator()
 267  
     {
 268  0
         List<String> handlers = new ArrayList<String>(navigationHandlers);
 269  0
         return handlers.iterator();
 270  
     }
 271  
 
 272  
     /**
 273  
      * @return Iterator over ViewHandler class names
 274  
      */
 275  
     public Iterator<String> getViewHandlerIterator()
 276  
     {
 277  0
         List<String> handlers = new ArrayList<String>(viewHandlers);
 278  0
         return handlers.iterator();
 279  
     }
 280  
 
 281  
     /**
 282  
      * @return Iterator over StateManager class names
 283  
      */
 284  
     public Iterator<String> getStateManagerIterator()
 285  
     {
 286  0
         List<String> managers = new ArrayList<String>(stateManagers);
 287  0
         return managers.iterator();
 288  
     }
 289  
 
 290  
     /**
 291  
      * @return Iterator over PropertyResolver class names
 292  
      */
 293  
     public Iterator<String> getPropertyResolverIterator()
 294  
     {
 295  0
         List<String> resolver = new ArrayList<String>(propertyResolver);
 296  0
         return resolver.iterator();
 297  
     }
 298  
 
 299  
     /**
 300  
      * @return Iterator over VariableResolver class names
 301  
      */
 302  
     public Iterator<String> getVariableResolverIterator()
 303  
     {
 304  0
         List<String> resolver = new ArrayList<String>(variableResolver);
 305  
 
 306  0
         return resolver.iterator();
 307  
     }
 308  
 
 309  
     /**
 310  
      * @return the default locale name
 311  
      */
 312  
     public String getDefaultLocale()
 313  
     {
 314  0
         if (localeConfig != null)
 315  
         {
 316  0
             return localeConfig.getDefaultLocale();
 317  
         }
 318  0
         return null;
 319  
     }
 320  
 
 321  
     /**
 322  
      * @return Iterator over supported locale names
 323  
      */
 324  
     public Iterator getSupportedLocalesIterator()
 325  
     {
 326  0
         if (localeConfig != null)
 327  
         {
 328  0
             return localeConfig.getSupportedLocales().iterator();
 329  
         }
 330  0
         return Collections.EMPTY_LIST.iterator();
 331  
     }
 332  
 
 333  
     /**
 334  
      * @return Iterator over all defined component types
 335  
      */
 336  
     public Iterator getComponentTypes()
 337  
     {
 338  0
         return components.keySet().iterator();
 339  
     }
 340  
 
 341  
     /**
 342  
      * @return component class that belongs to the given component type
 343  
      */
 344  
     public String getComponentClass(String componentType)
 345  
     {
 346  0
         return components.get(componentType);
 347  
     }
 348  
 
 349  
     /**
 350  
      * @return Iterator over all defined converter ids
 351  
      */
 352  
     public Iterator<String> getConverterIds()
 353  
     {
 354  0
         return converterById.keySet().iterator();
 355  
     }
 356  
 
 357  
     /**
 358  
      * @return Iterator over all classes with an associated converter
 359  
      */
 360  
     public Iterator<String> getConverterClasses()
 361  
     {
 362  0
         return converterByClass.keySet().iterator();
 363  
     }
 364  
 
 365  
     public Iterator<String> getConverterConfigurationByClassName()
 366  
     {
 367  0
         return converterConfigurationByClassName.keySet().iterator();
 368  
     }
 369  
 
 370  
     public Converter getConverterConfiguration(String converterClassName)
 371  
     {
 372  0
         return converterConfigurationByClassName.get(converterClassName);
 373  
     }
 374  
 
 375  
     /**
 376  
      * @return converter class that belongs to the given converter id
 377  
      */
 378  
     public String getConverterClassById(String converterId)
 379  
     {
 380  0
         return converterById.get(converterId);
 381  
     }
 382  
 
 383  
     /**
 384  
      * @return converter class that is associated with the given class name
 385  
      */
 386  
     public String getConverterClassByClass(String className)
 387  
     {
 388  0
         return converterByClass.get(className);
 389  
     }
 390  
 
 391  
     /**
 392  
      * @return Iterator over all defined validator ids
 393  
      */
 394  
     public Iterator getValidatorIds()
 395  
     {
 396  0
         return validators.keySet().iterator();
 397  
     }
 398  
 
 399  
     /**
 400  
      * @return validator class name that belongs to the given validator id
 401  
      */
 402  
     public String getValidatorClass(String validatorId)
 403  
     {
 404  0
         return validators.get(validatorId);
 405  
     }
 406  
 
 407  
     /**
 408  
      * @return Iterator over
 409  
      *         {@link org.apache.myfaces.config.element.ManagedBean ManagedBean}s
 410  
      */
 411  
     public Iterator<ManagedBean> getManagedBeans()
 412  
     {
 413  0
         return managedBeans.iterator();
 414  
     }
 415  
 
 416  
     /**
 417  
      * @return Iterator over
 418  
      *         {@link org.apache.myfaces.config.element.NavigationRule NavigationRule}s
 419  
      */
 420  
     public Iterator<NavigationRule> getNavigationRules()
 421  
     {
 422  0
         return navigationRules.iterator();
 423  
     }
 424  
 
 425  
     /**
 426  
      * @return Iterator over all defined renderkit ids
 427  
      */
 428  
     public Iterator<String> getRenderKitIds()
 429  
     {
 430  0
         return renderKits.keySet().iterator();
 431  
     }
 432  
 
 433  
     /**
 434  
      * @return renderkit class name for given renderkit id
 435  
      */
 436  
     public String getRenderKitClass(String renderKitId)
 437  
     {
 438  0
         RenderKit renderKit = renderKits.get(renderKitId);
 439  0
         return renderKit.getRenderKitClass();
 440  
     }
 441  
 
 442  
     /**
 443  
      * @return Iterator over
 444  
      *         {@link org.apache.myfaces.config.element.Renderer Renderer}s for
 445  
      *         the given renderKitId
 446  
      */
 447  
     public Iterator<Renderer> getRenderers(String renderKitId)
 448  
     {
 449  0
         RenderKit renderKit = renderKits.get(renderKitId);
 450  0
         return renderKit.getRenderer().iterator();
 451  
     }
 452  
 
 453  
     /**
 454  
      * @return Iterator over {@link javax.faces.event.PhaseListener}
 455  
      *         implementation class names
 456  
      */
 457  
     public Iterator<String> getLifecyclePhaseListeners()
 458  
     {
 459  0
         return lifecyclePhaseListeners.iterator();
 460  
     }
 461  
 
 462  
     public Iterator<ResourceBundle> getResourceBundles()
 463  
     {
 464  0
         return resourceBundles.iterator();
 465  
     }
 466  
 
 467  
     public Iterator<String> getElResolvers()
 468  
     {
 469  0
         return elResolvers.iterator();
 470  
     }
 471  
 
 472  
 }