Coverage Report - org.apache.myfaces.spi.InjectionProviderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
InjectionProviderFactory
0%
0/21
0%
0/6
2
InjectionProviderFactory$1
0%
0/2
N/A
2
 
 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;
 20  
 
 21  
 import java.security.AccessController;
 22  
 import java.security.PrivilegedActionException;
 23  
 import java.util.Map;
 24  
 
 25  
 import javax.faces.FacesException;
 26  
 import javax.faces.context.ExternalContext;
 27  
 import javax.faces.context.FacesContext;
 28  
 
 29  
 import org.apache.myfaces.spi.impl.SpiUtils;
 30  
 
 31  0
 public abstract class InjectionProviderFactory
 32  
 {
 33  
     protected static final String FACTORY_DEFAULT = 
 34  
         "org.apache.myfaces.spi.impl.DefaultInjectionProviderFactory";
 35  
 
 36  0
     private static final String FACTORY_KEY = InjectionProviderFactory.class.getName();
 37  
 
 38  
     public static InjectionProviderFactory getInjectionProviderFactory()
 39  
     {
 40  
         // Since we always provide a StartupFacesContext on initialization time, this is safe:
 41  0
         return getInjectionProviderFactory(FacesContext.getCurrentInstance().getExternalContext());
 42  
     }
 43  
     
 44  
     public static InjectionProviderFactory getInjectionProviderFactory(ExternalContext ctx)
 45  
     {
 46  0
         Map<String, Object> applicationMap = ctx.getApplicationMap();
 47  0
         InjectionProviderFactory instance = 
 48  
             (InjectionProviderFactory) applicationMap.get(FACTORY_KEY);
 49  0
         if (instance != null)
 50  
         {
 51  0
             return instance;
 52  
         }
 53  0
         InjectionProviderFactory lpf = null;
 54  
         try
 55  
         {
 56  
 
 57  0
             if (System.getSecurityManager() != null)
 58  
             {
 59  0
                 final ExternalContext ectx = ctx; 
 60  0
                 lpf = (InjectionProviderFactory)
 61  
                         AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Object>()
 62  0
                         {
 63  
                             public Object run() throws PrivilegedActionException
 64  
                             {
 65  0
                                 return SpiUtils.build(ectx,
 66  
                                         InjectionProviderFactory.class,
 67  
                                         FACTORY_DEFAULT);
 68  
                             }
 69  
                         });
 70  0
             }
 71  
             else
 72  
             {
 73  0
                 lpf = (InjectionProviderFactory) SpiUtils.build(ctx, 
 74  
                     InjectionProviderFactory.class, FACTORY_DEFAULT);
 75  
             }
 76  
         }
 77  0
         catch (PrivilegedActionException pae)
 78  
         {
 79  0
             throw new FacesException(pae);
 80  0
         }
 81  0
         if (lpf != null)
 82  
         {
 83  0
             applicationMap.put(FACTORY_KEY, lpf);
 84  
         }
 85  0
         return lpf;
 86  
     }
 87  
 
 88  
 
 89  
     public static void setInjectionProviderFactory(InjectionProviderFactory instance)
 90  
     {
 91  0
         FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().put(FACTORY_KEY, instance);
 92  0
     }
 93  
 
 94  
     public abstract InjectionProvider getInjectionProvider(ExternalContext externalContext);
 95  
 
 96  
     public abstract void release();
 97  
 
 98  
 }