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