You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2023/01/17 16:50:57 UTC

[myfaces] branch main updated: MYFACES-4549

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/main by this push:
     new c4206c91e MYFACES-4549
c4206c91e is described below

commit c4206c91e2121ea4a58c0add5bde6084dea112d3
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Tue Jan 17 17:50:49 2023 +0100

    MYFACES-4549
---
 .../myfaces/el/resolver/ImportHandlerResolver.java | 81 +++-------------------
 1 file changed, 10 insertions(+), 71 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/el/resolver/ImportHandlerResolver.java b/impl/src/main/java/org/apache/myfaces/el/resolver/ImportHandlerResolver.java
index 8e22c5c0f..0a9207a91 100644
--- a/impl/src/main/java/org/apache/myfaces/el/resolver/ImportHandlerResolver.java
+++ b/impl/src/main/java/org/apache/myfaces/el/resolver/ImportHandlerResolver.java
@@ -18,60 +18,17 @@
  */
 package org.apache.myfaces.el.resolver;
 
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
+import jakarta.el.ELClass;
 import jakarta.el.ELContext;
 import jakarta.el.ELException;
+import jakarta.el.ImportHandler;
 import jakarta.el.PropertyNotFoundException;
 
-import org.apache.myfaces.util.lang.ClassUtils;
-
 /**
  * See Faces 2.2 section 5.6.2.8
  */
 public class ImportHandlerResolver extends ScopedAttributeResolver
 {
-    private static final Class EL_CLASS;
-    private static final Constructor EL_CLASS_CONSTRUCTOR;
-    private static final Method GET_IMPORT_HANDLER_METHOD;
-    private static final Method IMPORT_HANDLER_RESOLVE_CLASS_METHOD;
-    
-    static
-    {
-        Class elClass = null;
-        Class importHandlerClass = null;
-        Constructor elClassConstructor = null;
-        Method getImportHandlerMethod = null;
-        Method importHandlerResolveClassMethod = null;
-        try
-        {
-            // These classes will only be available with EL 3+
-            elClass = ClassUtils.classForName("jakarta.el.ELClass");
-            importHandlerClass = ClassUtils.classForName("jakarta.el.ImportHandler");
-            getImportHandlerMethod = ELContext.class.getMethod("getImportHandler");
-            if (elClass != null && importHandlerClass != null) 
-            {
-                importHandlerResolveClassMethod = 
-                    importHandlerClass.getDeclaredMethod("resolveClass", new Class[] {String.class});
-                elClassConstructor = elClass.getConstructor(Class.class);
-            }
-        }
-        catch (SecurityException | ClassNotFoundException | NoSuchMethodException ex)
-        {
-            //No op
-        }
-
-        EL_CLASS = elClass;
-        GET_IMPORT_HANDLER_METHOD = getImportHandlerMethod;
-        IMPORT_HANDLER_RESOLVE_CLASS_METHOD = importHandlerResolveClassMethod;
-        EL_CLASS_CONSTRUCTOR = elClassConstructor;
-    }
-    
-    /**
-     * Creates a new instance of ImportHandlerResolver
-     */
     public ImportHandlerResolver()
     {
     }
@@ -80,37 +37,19 @@ public class ImportHandlerResolver extends ScopedAttributeResolver
      * Handle the EL case for the name of an import class
      */
     @Override
-    public Object getValue(final ELContext context, final Object base, final Object property)
+    public Object getValue(ELContext context, Object base, Object property)
         throws NullPointerException, PropertyNotFoundException, ELException
     {
-        if (EL_CLASS == null
-                || EL_CLASS_CONSTRUCTOR == null 
-                || GET_IMPORT_HANDLER_METHOD == null
-                || IMPORT_HANDLER_RESOLVE_CLASS_METHOD == null)
-        {
-            return null;
-        }
-
-        try 
+        ImportHandler importHandler = context.getImportHandler();
+        if (importHandler != null) 
         {
-            // In an EL 3+ environment, the ELContext will have a getImportHandler() method
-            Object importHandler = GET_IMPORT_HANDLER_METHOD.invoke(context);
-            if (importHandler != null) 
+            Class<?> clazz = importHandler.resolveClass(property.toString());
+            if (clazz != null) 
             {
-                Class<?> clazz = (Class<?>) IMPORT_HANDLER_RESOLVE_CLASS_METHOD.invoke(
-                        importHandler, property.toString());
-                if (clazz != null) 
-                {
-                    context.setPropertyResolved(true);
-                    return EL_CLASS_CONSTRUCTOR.newInstance(clazz);
-                }
+                context.setPropertyResolved(true);
+                return new ELClass(clazz);
             }
-        } 
-        catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
-                | InstantiationException ex) 
-        {
-            //No op
-        }            
+        }
 
         return null;
     }