Coverage Report - org.apache.myfaces.spi.impl.DefaultFacesConfigurationProviderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultFacesConfigurationProviderFactory
0%
0/29
0%
0/6
3.5
DefaultFacesConfigurationProviderFactory$1
0%
0/2
N/A
3.5
 
 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.DefaultFacesConfigurationProvider;
 22  
 import org.apache.myfaces.shared.util.ClassUtils;
 23  
 import org.apache.myfaces.spi.FacesConfigurationProvider;
 24  
 import org.apache.myfaces.spi.FacesConfigurationProviderFactory;
 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  
  * @author Leonardo Uribe
 40  
  * @since 2.0.3
 41  
  */
 42  0
 public class DefaultFacesConfigurationProviderFactory extends FacesConfigurationProviderFactory
 43  
 {
 44  
 
 45  0
     public static final String FACES_CONFIGURATION_PROVIDER = FacesConfigurationProvider.class.getName();
 46  
     
 47  0
     public static final String FACES_CONFIGURATION_PROVIDER_LIST = FacesConfigurationProvider.class.getName()+".LIST";
 48  
     
 49  0
     public static final String FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY
 50  
             = FacesConfigurationProvider.class.getName() + ".INSTANCE";
 51  
 
 52  
     private Logger getLogger()
 53  
     {
 54  0
         return Logger.getLogger(DefaultFacesConfigurationProviderFactory.class.getName());
 55  
     }
 56  
 
 57  
     @Override
 58  
     public FacesConfigurationProvider getFacesConfigurationProvider(
 59  
             ExternalContext externalContext)
 60  
     {
 61  0
         FacesConfigurationProvider returnValue = (FacesConfigurationProvider)
 62  
                 externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY);
 63  0
         if (returnValue == null)
 64  
         {
 65  0
             final ExternalContext extContext = externalContext;
 66  
             try
 67  
             {
 68  0
                 if (System.getSecurityManager() != null)
 69  
                 {
 70  0
                     returnValue
 71  
                             = AccessController.doPrivileged(new PrivilegedExceptionAction<FacesConfigurationProvider>()
 72  0
                             {
 73  
                                 public FacesConfigurationProvider run() throws ClassNotFoundException,
 74  
                                         NoClassDefFoundError,
 75  
                                         InstantiationException,
 76  
                                         IllegalAccessException,
 77  
                                         InvocationTargetException,
 78  
                                         PrivilegedActionException
 79  
                                 {
 80  0
                                     return resolveFacesConfigurationProviderFromService(extContext);
 81  
                                 }
 82  
                             });
 83  
                 }
 84  
                 else
 85  
                 {
 86  0
                     returnValue = resolveFacesConfigurationProviderFromService(extContext);
 87  
                 }
 88  0
                 externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY, returnValue);
 89  
             }
 90  0
             catch (ClassNotFoundException e)
 91  
             {
 92  
                 // ignore
 93  
             }
 94  0
             catch (NoClassDefFoundError e)
 95  
             {
 96  
                 // ignore
 97  
             }
 98  0
             catch (InstantiationException e)
 99  
             {
 100  0
                 getLogger().log(Level.SEVERE, "", e);
 101  
             }
 102  0
             catch (IllegalAccessException e)
 103  
             {
 104  0
                 getLogger().log(Level.SEVERE, "", e);
 105  
             }
 106  0
             catch (InvocationTargetException e)
 107  
             {
 108  0
                 getLogger().log(Level.SEVERE, "", e);
 109  
             }
 110  0
             catch (PrivilegedActionException e)
 111  
             {
 112  0
                 throw new FacesException(e);
 113  0
             }
 114  
         }
 115  
 
 116  
 
 117  0
         return returnValue;
 118  
     }
 119  
 
 120  
     private FacesConfigurationProvider resolveFacesConfigurationProviderFromService(
 121  
             ExternalContext externalContext) throws ClassNotFoundException,
 122  
             NoClassDefFoundError,
 123  
             InstantiationException,
 124  
             IllegalAccessException,
 125  
             InvocationTargetException,
 126  
             PrivilegedActionException
 127  
     {
 128  0
         List<String> classList = (List<String>)
 129  
                 externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_LIST);
 130  0
         if (classList == null)
 131  
         {
 132  0
             classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).
 133  
                     getServiceProviderList(FACES_CONFIGURATION_PROVIDER);
 134  0
             externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_LIST, classList);
 135  
         }
 136  
 
 137  0
         return ClassUtils.buildApplicationObject(FacesConfigurationProvider.class, classList,
 138  
                                                  new DefaultFacesConfigurationProvider());
 139  
     }
 140  
 }