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