myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1136900 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: config/FacesConfigurator.java config/RuntimeConfig.java el/unified/ResolverBuilderBase.java
Date Fri, 17 Jun 2011 14:51:11 GMT
Author: lu4242
Date: Fri Jun 17 14:51:11 2011
New Revision: 1136900

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

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

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=1136900&r1=1136899&r2=1136900&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
Fri Jun 17 14:51:11 2011
@@ -18,6 +18,54 @@
  */
 package org.apache.myfaces.config;
 
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.el.ELResolver;
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.ConfigurableNavigationHandler;
+import javax.faces.application.NavigationHandler;
+import javax.faces.application.ProjectStage;
+import javax.faces.application.ResourceHandler;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.el.PropertyResolver;
+import javax.faces.el.VariableResolver;
+import javax.faces.event.ActionListener;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.PhaseListener;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PreDestroyCustomScopeEvent;
+import javax.faces.event.PreDestroyViewMapEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.validator.BeanValidator;
+import javax.faces.webapp.FacesServlet;
+
+import org.apache.commons.collections.Predicate;
 import org.apache.myfaces.application.ApplicationFactoryImpl;
 import org.apache.myfaces.application.BackwardsCompatibleNavigationHandlerWrapper;
 import org.apache.myfaces.component.visit.VisitContextFactoryImpl;
@@ -43,6 +91,7 @@ import org.apache.myfaces.context.FacesC
 import org.apache.myfaces.context.PartialViewContextFactoryImpl;
 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;
@@ -62,51 +111,6 @@ import org.apache.myfaces.view.facelets.
 import org.apache.myfaces.view.facelets.tag.ui.DebugPhaseListener;
 import org.apache.myfaces.webapp.ManagedBeanDestroyerListener;
 
-import javax.el.ELResolver;
-import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
-import javax.faces.application.ConfigurableNavigationHandler;
-import javax.faces.application.NavigationHandler;
-import javax.faces.application.ProjectStage;
-import javax.faces.application.ResourceHandler;
-import javax.faces.application.StateManager;
-import javax.faces.application.ViewHandler;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.el.PropertyResolver;
-import javax.faces.el.VariableResolver;
-import javax.faces.event.ActionListener;
-import javax.faces.event.ComponentSystemEvent;
-import javax.faces.event.PhaseListener;
-import javax.faces.event.PostConstructApplicationEvent;
-import javax.faces.event.PreDestroyCustomScopeEvent;
-import javax.faces.event.PreDestroyViewMapEvent;
-import javax.faces.event.SystemEvent;
-import javax.faces.lifecycle.Lifecycle;
-import javax.faces.lifecycle.LifecycleFactory;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-import javax.faces.validator.BeanValidator;
-import javax.faces.webapp.FacesServlet;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.JarURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
 /**
  * Configures everything for a given context. The FacesConfigurator is independent of the
concrete implementations that
  * lie behind FacesConfigUnmarshaller and FacesConfigDispenser.
@@ -739,7 +743,59 @@ public class FacesConfigurator
                 log.log(Level.SEVERE, "Named event could not be initialized, reason:",e);
             }
         }
+
+        String comparatorClass = _externalContext.getInitParameter(ResolverBuilderBase.EL_RESOLVER_COMPARATOR);
+        
+        if (comparatorClass != null && !"".equals(comparatorClass))
+        {
+            // get the comparator class
+            Class<Comparator<ELResolver>> clazz;
+            try {
+                clazz = (Class<Comparator<ELResolver>>) ClassUtils.classForName(comparatorClass);
+                // create the instance
+                Comparator<ELResolver> comparator = ClassUtils.newInstance(clazz);
+                
+                runtimeConfig.setELResolverComparator(comparator);
+            } catch (Exception e)
+            {
+                if (log.isLoggable(Level.SEVERE))
+                {
+                    log.log(Level.SEVERE, "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);
+        }
         
+        String elResolverPredicateClass = _externalContext.getInitParameter(ResolverBuilderBase.EL_RESOLVER_PREDICATE);
+        
+        if (elResolverPredicateClass != null && !"".equals(elResolverPredicateClass))
+        {
+            // get the comparator class
+            Class<Predicate> clazz;
+            try {
+                clazz = (Class<Predicate>) ClassUtils.classForName(elResolverPredicateClass);
+                // create the instance
+                Predicate elResolverPredicate = ClassUtils.newInstance(clazz);
+                
+                runtimeConfig.setELResolverPredicate(elResolverPredicate);
+            } catch (Exception e)
+            {
+                if (log.isLoggable(Level.SEVERE))
+                {
+                    log.log(Level.SEVERE, "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.setELResolverPredicate(null);
+        }
+
         for (FaceletsProcessing faceletsProcessing : dispenser.getFaceletsProcessing())
         {
             runtimeConfig.addFaceletProcessingConfiguration(faceletsProcessing.getFileExtension(),
faceletsProcessing);

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java?rev=1136900&r1=1136899&r2=1136900&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/RuntimeConfig.java Fri
Jun 17 14:51:11 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;
@@ -34,6 +35,7 @@ import javax.faces.context.ExternalConte
 import javax.faces.el.PropertyResolver;
 import javax.faces.el.VariableResolver;
 
+import org.apache.commons.collections.Predicate;
 import org.apache.myfaces.config.element.FaceletsProcessing;
 import org.apache.myfaces.config.element.ManagedBean;
 import org.apache.myfaces.config.element.NavigationRule;
@@ -74,6 +76,10 @@ public class RuntimeConfig
     private PropertyResolver _propertyResolverChainHead;
 
     private VariableResolver _variableResolverChainHead;
+    
+    private Comparator<ELResolver> _elResolverComparator;
+    
+    private Predicate _elResolverPredicate;
 
     private final Map<String, org.apache.myfaces.config.element.Converter> _converterClassNameToConfigurationMap
=
         new ConcurrentHashMap<String, org.apache.myfaces.config.element.Converter>();
@@ -330,6 +336,26 @@ public class RuntimeConfig
     {
         this._namedEventManager = namedEventManager;
     }
+
+    public Comparator<ELResolver> getELResolverComparator()
+    {
+        return _elResolverComparator;
+    }
+    
+    public void setELResolverComparator(Comparator<ELResolver> elResolverComparator)
+    {
+        _elResolverComparator = elResolverComparator;
+    }
+    
+    public Predicate getELResolverPredicate()
+    {
+        return _elResolverPredicate;
+    }
+    
+    public void setELResolverPredicate(Predicate elResolverPredicate)
+    {
+        _elResolverPredicate = elResolverPredicate;
+    }
     
     public void addFaceletProcessingConfiguration(String fileExtension, FaceletsProcessing
configuration)
     {

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=1136900&r1=1136899&r2=1136900&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
Fri Jun 17 14:51:11 2011
@@ -19,15 +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.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;
 
@@ -38,7 +35,6 @@ import org.apache.myfaces.config.Runtime
 import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
 import org.apache.myfaces.el.convert.VariableResolverToELResolver;
 import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope;
-import org.apache.myfaces.shared_impl.util.ClassUtils;
 
 /**
  * @author Mathias Broekelmann (latest modification by $Author$)
@@ -120,18 +116,16 @@ public class ResolverBuilderBase
     @SuppressWarnings("unchecked")
     protected void sortELResolvers(List<ELResolver> resolvers, Scope scope)
     {
-        Comparator<ELResolver> comparator = (Comparator<ELResolver>) getAplicationScopedObject(
-                FacesContext.getCurrentInstance(), EL_RESOLVER_COMPARATOR);
-        if (comparator != null)
+        if (_config.getELResolverComparator() != null)
         {
             try
             {
                 // sort the resolvers
-                Collections.sort(resolvers, comparator);
+                Collections.sort(resolvers, _config.getELResolverComparator());
                 
                 if (log.isLoggable(Level.INFO)) {
                     log.log(Level.INFO, "Chain of EL resolvers for {0} sorted with: {1} and
the result order is {2}", 
-                            new Object [] {scope, comparator, resolvers});
+                            new Object [] {scope, _config.getELResolverComparator(), resolvers});
                 }
             }
             catch (Exception e)
@@ -151,8 +145,7 @@ public class ResolverBuilderBase
     protected Iterable<ELResolver> filterELResolvers(List<ELResolver> resolvers,
Scope scope)
     {
         
-        Predicate predicate = (Predicate) getAplicationScopedObject(
-                FacesContext.getCurrentInstance(), EL_RESOLVER_PREDICATE);
+        Predicate predicate = _config.getELResolverPredicate();
         if (predicate != null) {
             try
             {
@@ -173,42 +166,6 @@ public class ResolverBuilderBase
         return resolvers;
     }
     
-    // TODO this is very common logic, move to Utils? 
-    protected Object getAplicationScopedObject(FacesContext facesContext, String initParameterName)
-    {
-        ExternalContext externalContext = facesContext.getExternalContext();
-        String className = externalContext.getInitParameter(initParameterName);
-
-        Object applicationScopedObject = null;
-        if (className != null && !"".equals(className))
-        {
-            // if we already have a cached instance, use it
-            applicationScopedObject = externalContext. getApplicationMap().get(initParameterName);
-            try
-            {
-                if (applicationScopedObject == null)
-                {
-                    // get the  class
-                    Class<?> clazz = ClassUtils.classForName(className);
-
-                    // create the instance
-                    applicationScopedObject = clazz.newInstance();
-
-                    // cache the instance, because it will be used at least two times
-                    externalContext.getApplicationMap()
-                    .put(initParameterName, applicationScopedObject);
-                }
-            }
-            catch (Exception e)
-            {
-                log.log(Level.WARNING, 
-                        "Could not create instance of " + className + " for context-param
" + initParameterName, e);
-            }
-        }    
-
-        return applicationScopedObject;
-    }
-
     protected ELResolver createELResolver(VariableResolver resolver)
     {
         return new VariableResolverToELResolver(resolver);



Mime
View raw message