Coverage Report - org.apache.myfaces.spi.impl.DefaultFacesConfigResourceProviderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultFacesConfigResourceProviderFactory
0%
0/26
0%
0/4
3.25
DefaultFacesConfigResourceProviderFactory$1
0%
0/2
N/A
3.25
 
 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.spi.impl;
 20  
 
 21  
 import org.apache.myfaces.config.DefaultFacesConfigResourceProvider;
 22  
 import org.apache.myfaces.shared.util.ClassUtils;
 23  
 import org.apache.myfaces.spi.FacesConfigResourceProvider;
 24  
 import org.apache.myfaces.spi.FacesConfigResourceProviderFactory;
 25  
 import org.apache.myfaces.spi.ServiceProviderFinderFactory;
 26  
 
 27  
 import javax.faces.FacesException;
 28  
 import javax.faces.context.ExternalContext;
 29  
 import java.lang.reflect.InvocationTargetException;
 30  
 import java.security.AccessController;
 31  
 import java.security.PrivilegedActionException;
 32  
 import java.security.PrivilegedExceptionAction;
 33  
 import java.util.List;
 34  
 import java.util.logging.Level;
 35  
 import java.util.logging.Logger;
 36  
 
 37  
 /**
 38  
  * 
 39  
  * @since 2.0.2
 40  
  * @author Leonardo Uribe
 41  
  */
 42  0
 public class DefaultFacesConfigResourceProviderFactory extends FacesConfigResourceProviderFactory
 43  
 {
 44  0
     public static final String FACES_CONFIG_PROVIDER = FacesConfigResourceProvider.class.getName();
 45  
     
 46  0
     public static final String FACES_CONFIG_PROVIDER_LIST = FacesConfigResourceProvider.class.getName()+".LIST";
 47  
     
 48  
     private Logger getLogger()
 49  
     {
 50  0
         return Logger.getLogger(DefaultFacesConfigResourceProviderFactory.class.getName());
 51  
     }    
 52  
     
 53  
     @Override
 54  
     public FacesConfigResourceProvider createFacesConfigResourceProvider(
 55  
             ExternalContext externalContext)
 56  
     {
 57  0
         FacesConfigResourceProvider returnValue = null;
 58  0
         final ExternalContext extContext = externalContext;
 59  
         try
 60  
         {
 61  0
             if (System.getSecurityManager() != null)
 62  
             {
 63  0
                 returnValue = AccessController.doPrivileged(new PrivilegedExceptionAction<FacesConfigResourceProvider>()
 64  0
                         {
 65  
                             public FacesConfigResourceProvider run() throws ClassNotFoundException,
 66  
                                     NoClassDefFoundError,
 67  
                                     InstantiationException,
 68  
                                     IllegalAccessException,
 69  
                                     InvocationTargetException,
 70  
                                     PrivilegedActionException
 71  
                             {
 72  0
                                 return resolveFacesConfigResourceProviderFromService(extContext);
 73  
                             }
 74  
                         });
 75  
             }
 76  
             else
 77  
             {
 78  0
                 returnValue = resolveFacesConfigResourceProviderFromService(extContext);
 79  
             }
 80  
         }
 81  0
         catch (ClassNotFoundException e)
 82  
         {
 83  
             // ignore
 84  
         }
 85  0
         catch (NoClassDefFoundError e)
 86  
         {
 87  
             // ignore
 88  
         }
 89  0
         catch (InstantiationException e)
 90  
         {
 91  0
             getLogger().log(Level.SEVERE, "", e);
 92  
         }
 93  0
         catch (IllegalAccessException e)
 94  
         {
 95  0
             getLogger().log(Level.SEVERE, "", e);
 96  
         }
 97  0
         catch (InvocationTargetException e)
 98  
         {
 99  0
             getLogger().log(Level.SEVERE, "", e);
 100  
         }
 101  0
         catch (PrivilegedActionException e)
 102  
         {
 103  0
             throw new FacesException(e);
 104  0
         }
 105  0
         return returnValue;
 106  
     }
 107  
     
 108  
     private FacesConfigResourceProvider resolveFacesConfigResourceProviderFromService(
 109  
             ExternalContext externalContext) throws ClassNotFoundException,
 110  
             NoClassDefFoundError,
 111  
             InstantiationException,
 112  
             IllegalAccessException,
 113  
             InvocationTargetException,
 114  
             PrivilegedActionException
 115  
     {
 116  0
         List<String> classList = (List<String>) externalContext.getApplicationMap().get(FACES_CONFIG_PROVIDER_LIST);
 117  0
         if (classList == null)
 118  
         {
 119  0
             classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).
 120  
                     getServiceProviderList(FACES_CONFIG_PROVIDER);
 121  0
             externalContext.getApplicationMap().put(FACES_CONFIG_PROVIDER_LIST, classList);
 122  
         }
 123  
 
 124  0
         return ClassUtils.buildApplicationObject(FacesConfigResourceProvider.class, classList,
 125  
                                                  new DefaultFacesConfigResourceProvider());
 126  
     }
 127  
 
 128  
 }