myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1136898 - in /myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces: config/FacesConfigurator.java config/RuntimeConfig.java el/unified/ResolverBuilderBase.java
Date Fri, 17 Jun 2011 14:49:49 GMT
Author: lu4242
Date: Fri Jun 17 14:49:48 2011
New Revision: 1136898

URL: http://svn.apache.org/viewvc?rev=1136898&view=rev
Log:
MYFACES-2873 Provide a way to change the order of ELResolvers

Modified:
    myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
    myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java

Modified: myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=1136898&r1=1136897&r2=1136898&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
(original)
+++ myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Fri Jun 17 14:49:48 2011
@@ -30,6 +30,7 @@ import org.apache.myfaces.config.impl.di
 import org.apache.myfaces.context.FacesContextFactoryImpl;
 import org.apache.myfaces.el.DefaultPropertyResolver;
 import org.apache.myfaces.el.VariableResolverImpl;
+import org.apache.myfaces.el.unified.ResolverBuilderBase;
 import org.apache.myfaces.lifecycle.LifecycleFactoryImpl;
 import org.apache.myfaces.renderkit.RenderKitFactoryImpl;
 import org.apache.myfaces.renderkit.html.HtmlRenderKitImpl;
@@ -71,6 +72,7 @@ import java.net.JarURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -944,6 +946,31 @@ public class FacesConfigurator
             runtimeConfig.addFacesConfigElResolver((ELResolver) ClassUtils.newInstance(iter.next(),
ELResolver.class));
         }
 
+        String comparatorClass = _externalContext.getInitParameter(ResolverBuilderBase.EL_RESOLVER_COMPARATOR);
+        
+        if (comparatorClass != null && !"".equals(comparatorClass))
+        {
+            // get the comparator class
+            Class<Comparator<ELResolver>> clazz;
+            try {
+                clazz = ClassUtils.classForName(comparatorClass);
+                // create the instance
+                Comparator<ELResolver> comparator = clazz.newInstance();
+                
+                runtimeConfig.setELResolverComparator(comparator);
+            } catch (Exception e)
+            {
+                if (log.isErrorEnabled())
+                {
+                    log.error("Cannot instantiate EL Resolver Comparator "+ comparatorClass+
+                            " . Check org.apache.myfaces.EL_RESOLVER_COMPARATOR web config
param. Initialization continues with no comparator used.", e);
+                }
+            } 
+        }
+        else
+        {
+            runtimeConfig.setELResolverComparator(null);
+        }
     }
 
     private void removePurgedBeansFromSessionAndApplication(RuntimeConfig runtimeConfig)

Modified: myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java?rev=1136898&r1=1136897&r2=1136898&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
(original)
+++ myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
Fri Jun 17 14:49:48 2011
@@ -21,6 +21,7 @@ package org.apache.myfaces.config;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -70,6 +71,8 @@ public class RuntimeConfig
     private PropertyResolver _propertyResolverChainHead;
 
     private VariableResolver _variableResolverChainHead;
+    
+    private Comparator<ELResolver> _elResolverComparator;
 
     private final Map<String, org.apache.myfaces.config.impl.digester.elements.Converter>
_converterClassNameToConfigurationMap =
         new ConcurrentHashMap<String, org.apache.myfaces.config.impl.digester.elements.Converter>();
@@ -301,4 +304,14 @@ public class RuntimeConfig
     {
         _oldManagedBeans.clear();
     }
+    
+    public Comparator<ELResolver> getELResolverComparator()
+    {
+        return _elResolverComparator;
+    }
+    
+    public void setELResolverComparator(Comparator<ELResolver> elResolverComparator)
+    {
+        _elResolverComparator = elResolverComparator;
+    }
 }

Modified: myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java?rev=1136898&r1=1136897&r2=1136898&view=diff
==============================================================================
--- myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
(original)
+++ myfaces/core/branches/1.2.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
Fri Jun 17 14:49:48 2011
@@ -19,16 +19,12 @@
 package org.apache.myfaces.el.unified;
 
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.el.CompositeELResolver;
 import javax.el.ELResolver;
 import javax.faces.application.Application;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
 import javax.faces.el.PropertyResolver;
 import javax.faces.el.VariableResolver;
 
@@ -36,7 +32,6 @@ import org.apache.myfaces.buildtools.mav
 import org.apache.myfaces.config.RuntimeConfig;
 import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
 import org.apache.myfaces.el.convert.VariableResolverToELResolver;
-import org.apache.myfaces.shared_impl.util.ClassUtils;
 
 /**
  * @author Mathias Broekelmann (latest modification by $Author$)
@@ -112,38 +107,12 @@ public class ResolverBuilderBase
     @SuppressWarnings("unchecked")
     protected void sortELResolvers(List<ELResolver> resolvers)
     {
-        ExternalContext externalContext 
-                = FacesContext.getCurrentInstance().getExternalContext();
-        
-        String comparatorClass = externalContext
-                .getInitParameter(EL_RESOLVER_COMPARATOR);
-        
-        if (comparatorClass != null && !"".equals(comparatorClass))
-        {
-            // the user provided the parameter.
-            
-            // if we already have a cached instance, use it
-            Comparator<ELResolver> comparator 
-                    = (Comparator<ELResolver>) externalContext.
-                        getApplicationMap().get(EL_RESOLVER_COMPARATOR);
+        if (_config.getELResolverComparator() != null)
+        {
             try
             {
-                if (comparator == null)
-                {
-                    // get the comparator class
-                    Class<Comparator<ELResolver>> clazz 
-                             = ClassUtils.classForName(comparatorClass);
-                    
-                    // create the instance
-                    comparator = clazz.newInstance();
-                    
-                    // cache the instance, because it will be used at least two times
-                    externalContext.getApplicationMap()
-                            .put(EL_RESOLVER_COMPARATOR, comparator);
-                }
-                
                 // sort the resolvers
-                Collections.sort(resolvers, comparator);
+                Collections.sort(resolvers, _config.getELResolverComparator());
             }
             catch (Exception e)
             {



Mime
View raw message