myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1398929 - in /myfaces/core/trunk: impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/org/apache/myfaces/lifecycle/ impl/src/test/java/org/apache/myfaces/lifecycle/ shared/src/main/java/org/apache/myfaces/shared/application/
Date Tue, 16 Oct 2012 19:06:20 GMT
Author: lu4242
Date: Tue Oct 16 19:06:20 2012
New Revision: 1398929

URL: http://svn.apache.org/viewvc?rev=1398929&view=rev
Log:
MYFACES-3628 [perf] do not calculate facelets view mappings and context suffixes if not necessary


Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java
    myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java?rev=1398929&r1=1398928&r2=1398929&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
Tue Oct 16 19:06:20 2012
@@ -97,7 +97,7 @@ public class ViewHandlerImpl extends Vie
             try
             {
                 //TODO: JSF 2.0 - need to make sure calculateViewId follows the new algorithm
from 7.5.2 
-                return getViewHandlerSupport().calculateAndCheckViewId(context, input);
+                return getViewHandlerSupport(context).calculateAndCheckViewId(context, input);
             }
             catch (InvalidViewIdException e)
             {
@@ -115,7 +115,7 @@ public class ViewHandlerImpl extends Vie
             try
             {
                 //TODO: JSF 2.0 - need to make sure calculateViewId follows the new algorithm
from 7.5.2 
-                return getViewHandlerSupport().calculateViewId(context, rawViewId);
+                return getViewHandlerSupport(context).calculateViewId(context, rawViewId);
             }
             catch (InvalidViewIdException e)
             {
@@ -241,7 +241,7 @@ public class ViewHandlerImpl extends Vie
     public UIViewRoot createView(FacesContext context, String viewId)
     {
        checkNull(context, "facesContext");
-       String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
+       String calculatedViewId = getViewHandlerSupport(context).calculateViewId(context,
viewId);
        
        // we cannot use this.getVDL() directly (see getViewHandler())
        //return getViewHandler(context)
@@ -254,7 +254,7 @@ public class ViewHandlerImpl extends Vie
     @Override
     public String getActionURL(FacesContext context, String viewId)
     {
-        return getViewHandlerSupport().calculateActionURL(context, viewId);
+        return getViewHandlerSupport(context).calculateActionURL(context, viewId);
     }
 
     @Override
@@ -290,7 +290,7 @@ public class ViewHandlerImpl extends Vie
     {
         checkNull(context, "context");
     
-        String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
+        String calculatedViewId = getViewHandlerSupport(context).calculateViewId(context,
viewId);
         
         // we cannot use this.getVDL() directly (see getViewHandler())
         //return getViewHandler(context)
@@ -404,7 +404,7 @@ public class ViewHandlerImpl extends Vie
         }
         else
         {
-            String calculatedViewId = getViewHandlerSupport().calculateViewId(context, viewId);
 
+            String calculatedViewId = getViewHandlerSupport(context).calculateViewId(context,
viewId);  
             // we cannot use this.getVDL() directly (see getViewHandler())
             //ViewDeclarationLanguage vdl = getViewHandler(context).
             //        getViewDeclarationLanguage(context, calculatedViewId);
@@ -503,9 +503,14 @@ public class ViewHandlerImpl extends Vie
     
     protected ViewHandlerSupport getViewHandlerSupport()
     {
+        return getViewHandlerSupport(FacesContext.getCurrentInstance());
+    }
+
+    protected ViewHandlerSupport getViewHandlerSupport(FacesContext context)
+    {
         if (_viewHandlerSupport == null)
         {
-            _viewHandlerSupport = new DefaultViewHandlerSupport();
+            _viewHandlerSupport = new DefaultViewHandlerSupport(context);
         }
         return _viewHandlerSupport;
     }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java?rev=1398929&r1=1398928&r2=1398929&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
Tue Oct 16 19:06:20 2012
@@ -93,6 +93,27 @@ public class DefaultRestoreViewSupport i
     
     private RenderKitFactory _renderKitFactory = null;
     private VisitContextFactory _visitContextFactory = null;
+    
+    private final String[] _faceletsViewMappings;
+    private final String[] _contextSuffixes;
+    private final String _faceletsContextSufix;
+    private final boolean _initialized;
+    
+    public DefaultRestoreViewSupport()
+    {
+        _faceletsViewMappings = null;
+        _contextSuffixes = null;
+        _faceletsContextSufix = null;
+        _initialized = false;
+    }
+    
+    public DefaultRestoreViewSupport(FacesContext facesContext)
+    {
+        _faceletsViewMappings = getFaceletsViewMappings(facesContext);
+        _contextSuffixes = getContextSuffix(facesContext);
+        _faceletsContextSufix = getFaceletsContextSuffix(facesContext);
+        _initialized = true;
+    }
 
     public void processComponentBinding(FacesContext facesContext, UIComponent component)
     {
@@ -387,8 +408,8 @@ public class DefaultRestoreViewSupport i
      */
     protected String handleSuffixMapping(FacesContext context, String requestViewId)
     {
-        String[] faceletsViewMappings = getFaceletsViewMappings(context);
-        String[] jspDefaultSuffixes = getContextSuffix(context);
+        String[] faceletsViewMappings = _initialized ? _faceletsViewMappings : getFaceletsViewMappings(context);
+        String[] jspDefaultSuffixes = _initialized ? _contextSuffixes : getContextSuffix(context);
         
         int slashPos = requestViewId.lastIndexOf('/');
         int extensionPos = requestViewId.lastIndexOf('.');
@@ -443,7 +464,7 @@ public class DefaultRestoreViewSupport i
         }
         
         //jsp suffixes didn't match, try facelets suffix
-        String faceletsDefaultSuffix = this.getFaceletsContextSuffix(context);
+        String faceletsDefaultSuffix = _initialized ? _faceletsContextSufix : this.getFaceletsContextSuffix(context);
         if (faceletsDefaultSuffix != null)
         {
             for (String defaultSuffix : jspDefaultSuffixes)

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java?rev=1398929&r1=1398928&r2=1398929&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewExecutor.java
Tue Oct 16 19:06:20 2012
@@ -79,7 +79,7 @@ class RestoreViewExecutor extends PhaseE
         Application application = facesContext.getApplication();
         ViewHandler viewHandler = application.getViewHandler();
         UIViewRoot viewRoot = facesContext.getViewRoot();
-        RestoreViewSupport restoreViewSupport = getRestoreViewSupport();
+        RestoreViewSupport restoreViewSupport = getRestoreViewSupport(facesContext);
 
         // Examine the FacesContext instance for the current request. If it already contains
a UIViewRoot
         if (viewRoot != null)
@@ -284,9 +284,14 @@ class RestoreViewExecutor extends PhaseE
     
     protected RestoreViewSupport getRestoreViewSupport()
     {
+        return getRestoreViewSupport(FacesContext.getCurrentInstance());
+    }
+    
+    protected RestoreViewSupport getRestoreViewSupport(FacesContext context)
+    {
         if (_restoreViewSupport == null)
         {
-            _restoreViewSupport = new DefaultRestoreViewSupport();
+            _restoreViewSupport = new DefaultRestoreViewSupport(context);
         }
         return _restoreViewSupport;
     }

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java?rev=1398929&r1=1398928&r2=1398929&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java
(original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/lifecycle/RestoreViewExecutorTest.java
Tue Oct 16 19:06:20 2012
@@ -181,7 +181,14 @@ public class RestoreViewExecutorTest ext
      */
     public void testGetRestoreViewSupport() throws Exception
     {
-        assertTrue(DefaultRestoreViewSupport.class.equals(new RestoreViewExecutor().getRestoreViewSupport().getClass()));
+        expect(_facesContext.getExternalContext()).andReturn(_externalContext).anyTimes();
+        expect(_externalContext.getInitParameter("javax.faces.FACELETS_VIEW_MAPPINGS")).andReturn(null).anyTimes();
+        expect(_externalContext.getInitParameter("facelets.VIEW_MAPPINGS")).andReturn(null).anyTimes();
+        expect(_externalContext.getInitParameter("javax.faces.FACELETS_SUFFIX")).andReturn(null).anyTimes();
+        expect(_externalContext.getInitParameter("javax.faces.DEFAULT_SUFFIX")).andReturn(null).anyTimes();
+        _mocksControl.replay();
+        assertTrue(DefaultRestoreViewSupport.class.equals(new RestoreViewExecutor().getRestoreViewSupport(_facesContext).getClass()));
+        _mocksControl.verify();
     }
 
     /**

Modified: myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java?rev=1398929&r1=1398928&r2=1398929&view=diff
==============================================================================
--- myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
(original)
+++ myfaces/core/trunk/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
Tue Oct 16 19:06:20 2012
@@ -79,6 +79,27 @@ public class DefaultViewHandlerSupport i
 
     private volatile ConcurrentLRUCache<String, Boolean> _checkedViewIdMap = null;
     private Boolean _checkedViewIdCacheEnabled = null;
+    
+    private final String[] _faceletsViewMappings;
+    private final String[] _contextSuffixes;
+    private final String _faceletsContextSufix;
+    private final boolean _initialized;
+    
+    public DefaultViewHandlerSupport()
+    {
+        _faceletsViewMappings = null;
+        _contextSuffixes = null;
+        _faceletsContextSufix = null;
+        _initialized = false;
+    }
+    
+    public DefaultViewHandlerSupport(FacesContext facesContext)
+    {
+        _faceletsViewMappings = getFaceletsViewMappings(facesContext);
+        _contextSuffixes = getContextSuffix(facesContext);
+        _faceletsContextSufix = getFaceletsContextSuffix(facesContext);
+        _initialized = true;
+    }
 
     public String calculateViewId(FacesContext context, String viewId)
     {
@@ -183,7 +204,7 @@ public class DefaultViewHandlerSupport i
             if (mapping.isExtensionMapping())
             {
                 //See JSF 2.0 section 7.5.2 
-                String[] contextSuffixes = getContextSuffix(context); 
+                String[] contextSuffixes = _initialized ? _contextSuffixes : getContextSuffix(context);

                 boolean founded = false;
                 for (String contextSuffix : contextSuffixes)
                 {
@@ -408,8 +429,8 @@ public class DefaultViewHandlerSupport i
      */
     protected String handleSuffixMapping(FacesContext context, String requestViewId)
     {
-        String[] faceletsViewMappings = getFaceletsViewMappings(context);
-        String[] jspDefaultSuffixes = getContextSuffix(context);
+        String[] faceletsViewMappings = _initialized ? _faceletsViewMappings : getFaceletsViewMappings(context);
+        String[] jspDefaultSuffixes = _initialized ? _contextSuffixes : getContextSuffix(context);
         
         int slashPos = requestViewId.lastIndexOf('/');
         int extensionPos = requestViewId.lastIndexOf('.');
@@ -468,7 +489,7 @@ public class DefaultViewHandlerSupport i
         }
         
         //jsp suffixes didn't match, try facelets suffix
-        String faceletsDefaultSuffix = this.getFaceletsContextSuffix(context);
+        String faceletsDefaultSuffix = _initialized ? _faceletsContextSufix : this.getFaceletsContextSuffix(context);
         if (faceletsDefaultSuffix != null)
         {
             for (String defaultSuffix : jspDefaultSuffixes)



Mime
View raw message