You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/09/26 17:57:08 UTC

svn commit: r1526587 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: el/unified/ResolverBuilderBase.java el/unified/ResolverBuilderForFaces.java util/ExternalSpecifications.java

Author: lu4242
Date: Thu Sep 26 15:57:08 2013
New Revision: 1526587

URL: http://svn.apache.org/r1526587
Log:
MYFACES-3784 Add EL 3 ELResolvers when they are available 

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java?rev=1526587&r1=1526586&r2=1526587&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java Thu Sep 26 15:57:08 2013
@@ -216,4 +216,8 @@ public class ResolverBuilderBase
         return new PropertyResolverToELResolver(resolver);
     }
 
+    protected RuntimeConfig getRuntimeConfig()
+    {
+        return _config;
+    }
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java?rev=1526587&r1=1526586&r2=1526587&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java Thu Sep 26 15:57:08 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.el.unified;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,6 +27,7 @@ import javax.el.ArrayELResolver;
 import javax.el.BeanELResolver;
 import javax.el.CompositeELResolver;
 import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
 import javax.el.ListELResolver;
 import javax.el.MapELResolver;
 import javax.el.ResourceBundleELResolver;
@@ -38,6 +41,7 @@ import org.apache.myfaces.el.unified.res
 import org.apache.myfaces.el.unified.resolver.ResourceResolver;
 import org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver;
 import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
+import org.apache.myfaces.shared.util.ClassUtils;
 
 /**
  * Create the el resolver for faces. see 1.2 spec section 5.6.2
@@ -47,6 +51,34 @@ import org.apache.myfaces.el.unified.res
  */
 public class ResolverBuilderForFaces extends ResolverBuilderBase implements ELResolverBuilder
 {
+    private static final Class STATIC_FIELD_EL_RESOLVER_CLASS;
+    private static final Method GET_STREAM_EL_RESOLVER_METHOD;
+    
+    static
+    {
+        Class staticFieldELResolverClass = null;
+        Method getStreamELResolverMethod = null;
+        try
+        {
+            staticFieldELResolverClass = ClassUtils.classForName("javax.el.StaticFieldELResolver");
+            getStreamELResolverMethod = ExpressionFactory.class.getMethod("getStreamELResolver");
+        }
+        catch (NoSuchMethodException ex)
+        {
+            //No op
+        }
+        catch (SecurityException ex)
+        {
+            //No op
+        }
+        catch (ClassNotFoundException ex)
+        {
+            //No op
+        }
+        STATIC_FIELD_EL_RESOLVER_CLASS = staticFieldELResolverClass;
+        GET_STREAM_EL_RESOLVER_METHOD = getStreamELResolverMethod;
+    }
+    
     public ResolverBuilderForFaces(RuntimeConfig config)
     {
         super(config);
@@ -69,6 +101,36 @@ public class ResolverBuilderForFaces ext
         list.add(new ResourceResolver());
         list.add(new ResourceBundleELResolver());
         list.add(new ResourceBundleResolver());
+        
+        if (STATIC_FIELD_EL_RESOLVER_CLASS != null &&
+            GET_STREAM_EL_RESOLVER_METHOD != null)
+        {
+            try
+            {
+                ELResolver streamElResolver = (ELResolver) GET_STREAM_EL_RESOLVER_METHOD.invoke(
+                        getRuntimeConfig().getExpressionFactory());
+                if (streamElResolver != null)
+                {
+                    // By default return null, but in a EL 3 implementation it should be there,
+                    // this is just to avoid exceptions in junit testing
+                    list.add(streamElResolver);
+                }
+                list.add((ELResolver) STATIC_FIELD_EL_RESOLVER_CLASS.newInstance());
+            } 
+            catch (IllegalAccessException ex)
+            {
+            }
+            catch (IllegalArgumentException ex)
+            {
+            }
+            catch (InvocationTargetException ex)
+            {
+            }
+            catch (InstantiationException ex)
+            {
+            }
+        }
+        
         list.add(new MapELResolver());
         list.add(new ListELResolver());
         list.add(new ArrayELResolver());

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java?rev=1526587&r1=1526586&r2=1526587&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/util/ExternalSpecifications.java Thu Sep 26 15:57:08 2013
@@ -45,6 +45,7 @@ public final class ExternalSpecification
     private static volatile Boolean beanValidationAvailable;
     private static volatile Boolean unifiedELAvailable;
     private static volatile Boolean cdiAvailable;
+    private static volatile Boolean el3Available;
 
     /**
      * This method determines if Bean Validation is present.
@@ -162,6 +163,23 @@ public final class ExternalSpecification
             return cdiAvailable;
         }
     }
+    
+    public static boolean isEL3Available()
+    {
+        if (el3Available == null)
+        {
+            try
+            {
+                el3Available = Class.forName("javax.el.StaticFieldELResolver") != null ;
+            }
+            catch (Throwable t)
+            {
+                el3Available = false;
+            }
+            log.info("MyFaces EL 3.0 support " + (el3Available ? "enabled" : "disabled"));
+        }
+        return el3Available;
+    }
 
     /**
      * this class should not be instantiated.