Coverage Report - org.apache.myfaces.el.unified.resolver.ImportHandlerResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
ImportHandlerResolver
0%
0/37
0%
0/12
7
 
 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.el.unified.resolver;
 20  
 
 21  
 import java.lang.reflect.Constructor;
 22  
 import java.lang.reflect.InvocationTargetException;
 23  
 import java.lang.reflect.Method;
 24  
 
 25  
 import javax.el.ELContext;
 26  
 import javax.el.ELException;
 27  
 import javax.el.PropertyNotFoundException;
 28  
 
 29  
 import org.apache.myfaces.shared.util.ClassUtils;
 30  
 
 31  
 /**
 32  
  * See JSF 2.2 section 5.6.2.8
 33  
  */
 34  
 public class ImportHandlerResolver extends ScopedAttributeResolver
 35  
 {
 36  
     private static final Class EL_CLASS;
 37  
     private static final Constructor EL_CLASS_CONSTRUCTOR;
 38  
     private static final Method GET_IMPORT_HANDLER_METHOD;
 39  
     private static final Method IMPORT_HANDLER_RESOLVE_CLASS_METHOD;
 40  
     
 41  
     static
 42  
     {
 43  0
         Class elClass = null;
 44  0
         Class importHandlerClass = null;
 45  0
         Constructor elClassConstructor = null;
 46  0
         Method getImportHandlerMethod = null;
 47  0
         Method importHandlerResolveClassMethod = null;
 48  
         try
 49  
         {
 50  
             // These classes will only be available with EL 3+
 51  0
             elClass = ClassUtils.classForName("javax.el.ELClass");
 52  0
             importHandlerClass = ClassUtils.classForName("javax.el.ImportHandler");
 53  0
             getImportHandlerMethod = ELContext.class.getMethod("getImportHandler");
 54  0
             if (elClass != null && importHandlerClass != null) 
 55  
             {
 56  0
                 importHandlerResolveClassMethod = 
 57  
                     importHandlerClass.getDeclaredMethod("resolveClass", new Class[] {String.class});
 58  0
                 elClassConstructor = elClass.getConstructor(Class.class);
 59  
             }
 60  
         }
 61  0
         catch (SecurityException ex)
 62  
         {
 63  
             //No op
 64  
         }
 65  0
         catch (ClassNotFoundException ex)
 66  
         {
 67  
             //No op
 68  
         } 
 69  0
         catch (NoSuchMethodException e) 
 70  
         {
 71  
             // No op
 72  0
         }
 73  0
         EL_CLASS = elClass;
 74  0
         GET_IMPORT_HANDLER_METHOD = getImportHandlerMethod;
 75  0
         IMPORT_HANDLER_RESOLVE_CLASS_METHOD = importHandlerResolveClassMethod;
 76  0
         EL_CLASS_CONSTRUCTOR = elClassConstructor;
 77  0
     }
 78  
     
 79  
     /**
 80  
      * Creates a new instance of ImportHandlerResolver
 81  
      */
 82  
     public ImportHandlerResolver()
 83  0
     {
 84  0
     }
 85  
 
 86  
     /*
 87  
      * Handle the EL case for the name of an import class
 88  
      */
 89  
     @Override
 90  
     public Object getValue(final ELContext context, final Object base, final Object property)
 91  
         throws NullPointerException, PropertyNotFoundException, ELException
 92  
     {
 93  0
         if (EL_CLASS != null && EL_CLASS_CONSTRUCTOR != null 
 94  
                         && GET_IMPORT_HANDLER_METHOD != null && IMPORT_HANDLER_RESOLVE_CLASS_METHOD != null ) 
 95  
         {
 96  0
             Object importHandler = null;
 97  
             try 
 98  
             {
 99  
                 // In an EL 3+ environment, the ELContext will have a getImportHandler() method
 100  0
                 importHandler = GET_IMPORT_HANDLER_METHOD.invoke(context);
 101  0
                 if (importHandler != null) 
 102  
                 {
 103  
                     Class<?> clazz;
 104  0
                     clazz = (Class<?>) IMPORT_HANDLER_RESOLVE_CLASS_METHOD
 105  
                         .invoke(importHandler, property.toString());
 106  0
                     if (clazz != null) 
 107  
                     {
 108  0
                         context.setPropertyResolved(true);
 109  0
                         return EL_CLASS_CONSTRUCTOR.newInstance(clazz);
 110  
                     }
 111  
                 }
 112  
             } 
 113  0
             catch (IllegalAccessException ex) 
 114  
             {
 115  
                 //No op
 116  
             } 
 117  0
             catch (IllegalArgumentException ex) 
 118  
             {
 119  
                 //No op
 120  
             } 
 121  0
             catch (InvocationTargetException ex) 
 122  
             {
 123  
                 //No op
 124  
             } 
 125  0
             catch (SecurityException ex) 
 126  
             {
 127  
                 //No op
 128  
             } 
 129  0
             catch (InstantiationException e) 
 130  
             {
 131  
                 //No op
 132  0
             }
 133  
         }
 134  0
         return null;
 135  
     }
 136  
 }