Coverage Report - org.apache.myfaces.spi.impl.TomcatAnnotationInjectionProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
TomcatAnnotationInjectionProvider
0%
0/33
0%
0/4
4.4
 
 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.util.logging.Level;
 23  
 import java.util.logging.Logger;
 24  
 
 25  
 import javax.faces.context.ExternalContext;
 26  
 import javax.naming.NamingException;
 27  
 import javax.servlet.ServletContext;
 28  
 
 29  
 import org.apache.myfaces.spi.InjectionProvider;
 30  
 import org.apache.myfaces.spi.InjectionProviderException;
 31  
 
 32  
 public class TomcatAnnotationInjectionProvider extends InjectionProvider
 33  
 {
 34  0
     private static Logger log = Logger.getLogger(TomcatAnnotationInjectionProvider.class.getName());
 35  
 
 36  
     private ExternalContext externalContext;
 37  
     private org.apache.AnnotationProcessor annotationProcessor;
 38  
 
 39  
     public TomcatAnnotationInjectionProvider(ExternalContext externalContext)
 40  0
     {
 41  0
         this.externalContext = externalContext;
 42  0
     }
 43  
 
 44  
     @Override
 45  
     public Object inject(Object instance) throws InjectionProviderException
 46  
     {
 47  
         try
 48  
         {
 49  0
             annotationProcessor.processAnnotations(instance);
 50  
         }
 51  0
         catch (IllegalAccessException ex)
 52  
         {
 53  0
             throw new InjectionProviderException(ex);
 54  
         }
 55  0
         catch (InvocationTargetException ex)
 56  
         {
 57  0
             throw new InjectionProviderException(ex);
 58  
         }
 59  0
         catch (NamingException ex)
 60  
         {
 61  0
             throw new InjectionProviderException(ex);
 62  0
         }
 63  0
         return null;
 64  
     }
 65  
 
 66  
     @Override
 67  
     public void preDestroy(Object instance, Object creationMetaData) throws InjectionProviderException
 68  
     {
 69  0
         if (log.isLoggable(Level.FINEST))
 70  
         {
 71  0
             log.info("Destroy instance of " + instance.getClass().getName());
 72  
         }
 73  
         try
 74  
         {
 75  0
             annotationProcessor.preDestroy(instance);
 76  
         }
 77  0
         catch (IllegalAccessException ex)
 78  
         {
 79  0
             throw new InjectionProviderException(ex);
 80  
         }
 81  0
         catch (InvocationTargetException ex)
 82  
         {
 83  0
             throw new InjectionProviderException(ex);
 84  0
         }
 85  0
     }
 86  
 
 87  
     @Override
 88  
     public boolean isAvailable()
 89  
     {
 90  
         try
 91  
         {
 92  0
             annotationProcessor =  (org.apache.AnnotationProcessor) ((ServletContext)
 93  
                      externalContext.getContext()).getAttribute(org.apache.AnnotationProcessor.class.getName());
 94  0
             return annotationProcessor != null;
 95  
         }
 96  0
         catch (Throwable e)
 97  
         {
 98  
             // ignore
 99  
         }
 100  0
         return false;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public void postConstruct(Object instance, Object creationMetaData) throws InjectionProviderException
 105  
     {
 106  
         try
 107  
         {
 108  0
             annotationProcessor.postConstruct(instance);
 109  
         }
 110  0
         catch (IllegalAccessException ex)
 111  
         {
 112  0
             throw new InjectionProviderException(ex);
 113  
         }
 114  0
         catch (InvocationTargetException ex)
 115  
         {
 116  0
             throw new InjectionProviderException(ex);
 117  0
         }
 118  0
     }
 119  
 }