Coverage Report - org.apache.myfaces.spi.AnnotationProviderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
AnnotationProviderFactory
0%
0/21
0%
0/6
2.2
AnnotationProviderFactory$1
0%
0/2
N/A
2.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.security.PrivilegedExceptionAction;
 24  
 
 25  
 import javax.faces.FacesException;
 26  
 import javax.faces.context.ExternalContext;
 27  
 
 28  
 import org.apache.myfaces.spi.impl.DefaultAnnotationProviderFactory;
 29  
 import org.apache.myfaces.spi.impl.SpiUtils;
 30  
 
 31  
 /**
 32  
  * Factory that provide AnnotationProvider instances
 33  
  * 
 34  
  * @since 2.0.2
 35  
  * @author Leonardo Uribe
 36  
  */
 37  0
 public abstract class AnnotationProviderFactory
 38  
 {
 39  0
     protected static final String FACTORY_DEFAULT = DefaultAnnotationProviderFactory.class.getName();
 40  
 
 41  0
     private static final String FACTORY_KEY = AnnotationProviderFactory.class.getName();
 42  
 
 43  
     public static AnnotationProviderFactory getAnnotationProviderFactory(ExternalContext ctx)
 44  
     {
 45  0
         AnnotationProviderFactory instance = (AnnotationProviderFactory) ctx.getApplicationMap().get(FACTORY_KEY);
 46  0
         if (instance != null)
 47  
         {
 48  0
             return instance;
 49  
         }
 50  0
         AnnotationProviderFactory lpf = null;
 51  
         try
 52  
         {
 53  
 
 54  0
             if (System.getSecurityManager() != null)
 55  
             {
 56  0
                 final ExternalContext ectx = ctx;
 57  0
                 lpf = (AnnotationProviderFactory) AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
 58  0
                         {
 59  
                             public Object run() throws PrivilegedActionException
 60  
                             {
 61  0
                                 return SpiUtils.build(ectx, 
 62  
                                         AnnotationProviderFactory.class,
 63  
                                         FACTORY_DEFAULT);
 64  
                             }
 65  
                         });
 66  0
             }
 67  
             else
 68  
             {
 69  0
                 lpf = (AnnotationProviderFactory) SpiUtils.build(ctx, AnnotationProviderFactory.class, FACTORY_DEFAULT);
 70  
             }
 71  
         }
 72  0
         catch (PrivilegedActionException pae)
 73  
         {
 74  0
             throw new FacesException(pae);
 75  0
         }
 76  0
         if (lpf != null)
 77  
         {
 78  0
             setAnnotationProviderFactory(ctx, lpf);
 79  
         }
 80  0
         return lpf;
 81  
     }
 82  
 
 83  
     public static void setAnnotationProviderFactory(ExternalContext ctx, AnnotationProviderFactory instance)
 84  
     {
 85  0
         ctx.getApplicationMap().put(FACTORY_KEY, instance);
 86  0
     }
 87  
 
 88  
     public abstract AnnotationProvider createAnnotationProvider(ExternalContext externalContext);
 89  
     
 90  
     public AnnotationProvider getAnnotationProvider(ExternalContext externalContext)
 91  
     {
 92  0
         return createAnnotationProvider(externalContext);
 93  
     }
 94  
 }