myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1296667 - in /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces: context/ context/servlet/ lifecycle/ view/ view/facelets/
Date Sat, 03 Mar 2012 16:54:08 GMT
Author: lu4242
Date: Sat Mar  3 16:54:07 2012
New Revision: 1296667

URL: http://svn.apache.org/viewvc?rev=1296667&view=rev
Log:
MYFACES-3486 [perf] cache Factories to prevent unnecessary FactoryFinder.getFactory() calls

Modified:
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java Sat Mar  3 16:54:07 2012
@@ -24,12 +24,15 @@ import java.util.logging.Logger;
 
 import javax.faces.FacesException;
 import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.context.ExceptionHandlerFactory;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.ExternalContextFactory;
 import javax.faces.context.FacesContext;
 import javax.faces.context.FacesContextFactory;
+import javax.faces.context.PartialViewContextFactory;
 import javax.faces.lifecycle.Lifecycle;
+import javax.faces.render.RenderKitFactory;
 import javax.servlet.ServletContext;
 
 import org.apache.myfaces.context.servlet.FacesContextImpl;
@@ -56,7 +59,13 @@ public class FacesContextFactoryImpl ext
      * Reference to factory to prevent unnecessary lookups
      */
     private final ExceptionHandlerFactory _exceptionHandlerFactory;
-        
+    
+    private final ApplicationFactory _applicationFactory;
+    
+    private final RenderKitFactory _renderKitFactory;
+    
+    private final PartialViewContextFactory _partialViewContextFactory;
+    
     /**
      * This var is assigned as the same as javax.faces.context.ExternalContext._firstInstance,
      * and since it is a static reference and does not change, we can cache it here safely.
@@ -89,14 +98,18 @@ public class FacesContextFactoryImpl ext
         {
             // It could happen, but we can ignore it.
             if (log.isLoggable(Level.FINE))
+            {
                 log.log(Level.FINE, "Cannot access field _firstInstance"
                         + "from _MyFacesExternalContextHelper ", e);
+            }
         }
         catch (Exception e)
         {
             if (log.isLoggable(Level.SEVERE))
+            {
                 log.log(Level.SEVERE, "Cannot find field _firstInstance"
                         + "from _MyFacesExternalContextHelper ", e);
+            }
         }
         
         _firstExternalContextInstance = firstExternalContextInstance;
@@ -107,6 +120,14 @@ public class FacesContextFactoryImpl ext
         _exceptionHandlerFactory = (ExceptionHandlerFactory)
             FactoryFinder.getFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY);
         
+        _applicationFactory = (ApplicationFactory)
+            FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+        
+        _renderKitFactory = (RenderKitFactory)
+            FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+
+        _partialViewContextFactory = (PartialViewContextFactory) 
+            FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
     }
 
     @Override
@@ -154,15 +175,22 @@ public class FacesContextFactoryImpl ext
             FacesContext facesContext;
             if (externalContext instanceof ReleaseableExternalContext)
             {
-                facesContext = new FacesContextImpl(externalContext, (ReleaseableExternalContext) externalContext, this);
+                facesContext = new FacesContextImpl(externalContext, (ReleaseableExternalContext) externalContext,
+                                                    this, _applicationFactory, _renderKitFactory, 
+                                                    _partialViewContextFactory);
             }
             else if (defaultExternalContext != null && defaultExternalContext instanceof ReleaseableExternalContext)
             {
-                facesContext = new FacesContextImpl(externalContext, (ReleaseableExternalContext) defaultExternalContext, this);
+                facesContext = new FacesContextImpl(externalContext,
+                                                    (ReleaseableExternalContext) defaultExternalContext, this,
+                                                    _applicationFactory, _renderKitFactory, 
+                                                    _partialViewContextFactory);
             }
             else
             {
-                facesContext = new FacesContextImpl(externalContext, null, this);
+                facesContext = new FacesContextImpl(externalContext, null, this,
+                                                    _applicationFactory, _renderKitFactory, 
+                                                    _partialViewContextFactory);
             }
             
             facesContext.setExceptionHandler(_exceptionHandlerFactory.getExceptionHandler());

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/PartialViewContextFactoryImpl.java Sat Mar  3 16:54:07 2012
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.context;
 
+import javax.faces.FactoryFinder;
+import javax.faces.component.visit.VisitContextFactory;
 import javax.faces.context.FacesContext;
 import javax.faces.context.PartialViewContext;
 import javax.faces.context.PartialViewContextFactory;
@@ -26,10 +28,20 @@ import org.apache.myfaces.context.servle
 
 public class PartialViewContextFactoryImpl extends PartialViewContextFactory
 {
+    private final VisitContextFactory _visitContextFactory;
+    
+    public PartialViewContextFactoryImpl()
+    {
+        super();
+        
+        _visitContextFactory = (VisitContextFactory) 
+            FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+    }
 
+    
     @Override
     public PartialViewContext getPartialViewContext(FacesContext context)
     {
-        return new PartialViewContextImpl(context);
+        return new PartialViewContextImpl(context, _visitContextFactory);
     }
 }

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java Sat Mar  3 16:54:07 2012
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.faces.FactoryFinder;
+import javax.faces.application.ApplicationFactory;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
@@ -68,6 +69,9 @@ public class FacesContextImpl extends Fa
     private boolean _validationFailed = false;
     private PartialViewContext _partialViewContext = null;
     private ReleaseableFacesContextFactory _facesContextFactory = null;
+    
+    private PartialViewContextFactory _partialViewContextFactory = null;
+    private RenderKitFactory _renderKitFactory = null;
 
     // ~ Constructors -------------------------------------------------------------------------------
     
@@ -105,6 +109,22 @@ public class FacesContextImpl extends Fa
         
         _facesContextFactory = facesContextFactory;
     }
+    
+    public FacesContextImpl(final ExternalContext externalContext,
+            final ReleaseableExternalContext defaultExternalContext , 
+            final ReleaseableFacesContextFactory facesContextFactory,
+            final ApplicationFactory applicationFactory,
+            final RenderKitFactory renderKitFactory,
+            final PartialViewContextFactory partialViewContextFactory)
+    {
+        // setCurrentInstance is called in constructor of super class
+        super(externalContext, defaultExternalContext, applicationFactory, 
+                renderKitFactory);
+        
+        _facesContextFactory = facesContextFactory;
+        _renderKitFactory = renderKitFactory;
+        _partialViewContextFactory = partialViewContextFactory;
+    }
 
     // ~ Methods ------------------------------------------------------------------------------------
     
@@ -120,7 +140,10 @@ public class FacesContextImpl extends Fa
         _responseWriter = null;
         _maximumSeverity = null;
         _partialViewContext = null;
-        
+        _facesContextFactory = null;
+        _renderKitFactory = null;
+        _partialViewContextFactory = null;
+
         if (_facesContextFactory != null)
         {
             _facesContextFactory.release();
@@ -269,10 +292,13 @@ public class FacesContextImpl extends Fa
         if (_partialViewContext == null)
         {
             //Get through factory finder
-            PartialViewContextFactory factory = (PartialViewContextFactory)
-                FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
+            if (_partialViewContextFactory == null)
+            {
+                _partialViewContextFactory = (PartialViewContextFactory)
+                    FactoryFinder.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
+            }
             // Put actual facesContext as param, not this - this can be wrapped
-            _partialViewContext = factory.getPartialViewContext(FacesContext.getCurrentInstance());
+            _partialViewContext = _partialViewContextFactory.getPartialViewContext(FacesContext.getCurrentInstance());
         }
         return _partialViewContext;
     }
@@ -375,9 +401,12 @@ public class FacesContextImpl extends Fa
             // method to check if a request is a postback, is always detect the param
             // javax.faces.ViewState, so there is no problem after all.
             String renderKitId = facesContext.getApplication().getViewHandler().calculateRenderKitId(facesContext);
-            RenderKitFactory factory = (RenderKitFactory) 
-                FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
-            renderKit = factory.getRenderKit(facesContext, renderKitId);
+            if (_renderKitFactory == null)
+            {
+                _renderKitFactory = (RenderKitFactory) 
+                    FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+            }
+            renderKit = _renderKitFactory.getRenderKit(facesContext, renderKitId);
         }
         return renderKit.getResponseStateManager().isPostback(facesContext);
     }

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImplBase.java Sat Mar  3 16:54:07 2012
@@ -63,6 +63,8 @@ public abstract class FacesContextImplBa
     
     protected boolean _released = false;
     
+    private ApplicationFactory _applicationFactory = null;
+
     /**
      * Base constructor.
      * Calls FacesContext.setCurrentInstance(this);
@@ -78,6 +80,22 @@ public abstract class FacesContextImplBa
         FacesContext.setCurrentInstance(this);
     }
     
+    public FacesContextImplBase(final ExternalContext externalContext,
+            final ReleaseableExternalContext defaultExternalContext,
+            final ApplicationFactory applicationFactory,
+            final RenderKitFactory renderKitFactory)
+    {
+        _externalContext = externalContext;
+        _defaultExternalContext = defaultExternalContext;
+        
+        _applicationFactory = applicationFactory;
+        _renderKitFactory = renderKitFactory;
+        
+        // this FacesContext impl is now the current instance
+        // note that because this method is protected, it has to be called from here
+        FacesContext.setCurrentInstance(this);
+    }
+    
     /**
      * Releases the instance fields on FacesContextImplBase.
      * Must be called by sub-classes, when overriding it!
@@ -85,6 +103,8 @@ public abstract class FacesContextImplBa
     @Override
     public void release()
     {
+        _applicationFactory = null;
+
         if (_defaultExternalContext != null)
         {
             _defaultExternalContext.release();
@@ -128,8 +148,12 @@ public abstract class FacesContextImplBa
         
         if (_application == null)
         {
-            _application = ((ApplicationFactory) FactoryFinder.getFactory(
-                    FactoryFinder.APPLICATION_FACTORY)).getApplication();
+            if (_applicationFactory == null)
+            {
+                _applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(
+                    FactoryFinder.APPLICATION_FACTORY);
+            }
+            _application = _applicationFactory.getApplication();
         }
         
         return _application;
@@ -234,7 +258,8 @@ public abstract class FacesContextImplBa
         {
             throw new NullPointerException("viewRoot");
         }
-        // If the current UIViewRoot is non-null, and calling equals() on the argument root, passing the current UIViewRoot returns false
+        // If the current UIViewRoot is non-null, and calling equals() on the argument root,
+        // passing the current UIViewRoot returns false
         // the clear method must be called on the Map returned from UIViewRoot.getViewMap().
         if (_viewRoot != null && !_viewRoot.equals(viewRoot))
         {

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/context/servlet/PartialViewContextImpl.java Sat Mar  3 16:54:07 2012
@@ -35,6 +35,7 @@ import javax.faces.component.html.HtmlBo
 import javax.faces.component.html.HtmlHead;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitContextFactory;
 import javax.faces.component.visit.VisitHint;
 import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
@@ -53,7 +54,8 @@ import org.apache.myfaces.shared.config.
 import org.apache.myfaces.shared.util.ExternalContextUtils;
 import org.apache.myfaces.shared.util.StringUtils;
 
-public class PartialViewContextImpl extends PartialViewContext {
+public class PartialViewContextImpl extends PartialViewContext
+{
 
     private static final String FACES_REQUEST = "Faces-Request";
     private static final String PARTIAL_AJAX = "partial/ajax";
@@ -86,13 +88,23 @@ public class PartialViewContextImpl exte
     private Boolean _partialRequest = null;
     private Boolean _renderAll = null;
     private PartialResponseWriter _partialResponseWriter = null;
+    private VisitContextFactory _visitContextFactory = null;
 
-    public PartialViewContextImpl(FacesContext context) {
+    public PartialViewContextImpl(FacesContext context)
+    {
         _facesContext = context;
     }
+    
+    public PartialViewContextImpl(FacesContext context, 
+            VisitContextFactory visitContextFactory)
+    {
+        _facesContext = context;
+        _visitContextFactory = visitContextFactory;
+    }
 
     @Override
-    public boolean isAjaxRequest() {
+    public boolean isAjaxRequest()
+    {
         assertNotReleased();
         /*
          * Internal extension for
@@ -112,14 +124,17 @@ public class PartialViewContextImpl exte
     }
 
     @Override
-    public boolean isExecuteAll() {
+    public boolean isExecuteAll()
+    {
         assertNotReleased();
 
-        if (isAjaxRequest()) {
+        if (isAjaxRequest())
+        {
             String executeMode = _facesContext.getExternalContext().
                     getRequestParameterMap().get(
                     PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME);
-            if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode)) {
+            if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode))
+            {
                 return true;
             }
         }
@@ -127,31 +142,38 @@ public class PartialViewContextImpl exte
     }
 
     @Override
-    public boolean isPartialRequest() {
+    public boolean isPartialRequest()
+    {
         assertNotReleased();
 
-        if (_partialRequest == null) {
+        if (_partialRequest == null)
+        {
             String requestType = _facesContext.getExternalContext().
                     getRequestHeaderMap().get(FACES_REQUEST);
             _partialRequest = (requestType != null && PARTIAL_PROCESS.equals(requestType));
         }
-        return isAjaxRequest()  || _partialRequest;
+        return _partialRequest || isAjaxRequest();
     }
 
     @Override
-    public boolean isRenderAll() {
+    public boolean isRenderAll()
+    {
         assertNotReleased();
 
-        if (_renderAll == null) {
-            if (isAjaxRequest()) {
+        if (_renderAll == null)
+        {
+            if (isAjaxRequest())
+            {
                 String executeMode = _facesContext.getExternalContext().
                         getRequestParameterMap().get(
                         PartialViewContext.PARTIAL_RENDER_PARAM_NAME);
-                if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode)) {
+                if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode))
+                {
                     _renderAll = true;
                 }
             }
-            if (_renderAll == null) {
+            if (_renderAll == null)
+            {
                 _renderAll = false;
             }
         }
@@ -166,15 +188,18 @@ public class PartialViewContextImpl exte
      *
      * @return true if the current request is an iframe based ajax request
      */
-    public boolean isIFrameRequest() {
-        if(_iframeRequest == null) {
+    public boolean isIFrameRequest()
+    {
+        if (_iframeRequest == null)
+        {
             _iframeRequest = _facesContext.getExternalContext().getRequestParameterMap().containsKey(PARTIAL_IFRAME);
         }
         return _iframeRequest;
     }
 
     @Override
-    public void setPartialRequest(boolean isPartialRequest) {
+    public void setPartialRequest(boolean isPartialRequest)
+    {
         assertNotReleased();
 
         _partialRequest = isPartialRequest;
@@ -182,26 +207,31 @@ public class PartialViewContextImpl exte
     }
 
     @Override
-    public void setRenderAll(boolean renderAll) {
+    public void setRenderAll(boolean renderAll)
+    {
         assertNotReleased();
 
         _renderAll = renderAll;
     }
 
     @Override
-    public Collection<String> getExecuteIds() {
+    public Collection<String> getExecuteIds()
+    {
         assertNotReleased();
 
-        if (_executeClientIds == null) {
+        if (_executeClientIds == null)
+        {
             String executeMode = _facesContext.getExternalContext().
                     getRequestParameterMap().get(
                     PartialViewContext.PARTIAL_EXECUTE_PARAM_NAME);
 
             if (executeMode != null && !"".equals(executeMode) &&
                     //!PartialViewContext.NO_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode) &&
-                    !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode)) {
-                
-                String[] clientIds = StringUtils.splitShortString(_replaceTabOrEnterCharactersWithSpaces(executeMode), ' ');
+                    !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(executeMode))
+            {
+
+                String[] clientIds
+                        = StringUtils.splitShortString(_replaceTabOrEnterCharactersWithSpaces(executeMode), ' ');
 
                 //The collection must be mutable
                 List<String> tempList = new ArrayList<String>();
@@ -215,35 +245,37 @@ public class PartialViewContextImpl exte
                 // The "javax.faces.source" parameter needs to be added to the list of
                 // execute ids if missing (otherwise, we'd never execute an action associated
                 // with, e.g., a button).
-                
+
                 String source = _facesContext.getExternalContext().getRequestParameterMap().get
-                    (PartialViewContextImpl.SOURCE_PARAM_NAME);
-                
+                        (PartialViewContextImpl.SOURCE_PARAM_NAME);
+
                 if (source != null)
                 {
                     source = source.trim();
-                    
-                    if (!tempList.contains (source))
+
+                    if (!tempList.contains(source))
                     {
-                        tempList.add (source);
+                        tempList.add(source);
                     }
                 }
-                
+
                 _executeClientIds = tempList;
-            } else {
+            }
+            else
+            {
                 _executeClientIds = new ArrayList<String>();
             }
         }
         return _executeClientIds;
     }
-    
+
     private String _replaceTabOrEnterCharactersWithSpaces(String mode)
     {
         StringBuilder builder = new StringBuilder(mode.length());
         for (int i = 0; i < mode.length(); i++)
         {
-            if (mode.charAt(i) == '\t' || 
-                mode.charAt(i) == '\n')
+            if (mode.charAt(i) == '\t' ||
+                    mode.charAt(i) == '\n')
             {
                 builder.append(' ');
             }
@@ -256,10 +288,12 @@ public class PartialViewContextImpl exte
     }
 
     @Override
-    public Collection<String> getRenderIds() {
+    public Collection<String> getRenderIds()
+    {
         assertNotReleased();
 
-        if (_renderClientIds == null) {
+        if (_renderClientIds == null)
+        {
             String renderMode = _facesContext.getExternalContext().
                     getRequestParameterMap().get(
                     PartialViewContext.PARTIAL_RENDER_PARAM_NAME);
@@ -268,7 +302,8 @@ public class PartialViewContextImpl exte
                     //!PartialViewContext.NO_PARTIAL_PHASE_CLIENT_IDS.equals(renderMode) &&
                     !PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(renderMode))
             {
-                String[] clientIds = StringUtils.splitShortString(_replaceTabOrEnterCharactersWithSpaces(renderMode), ' ');
+                String[] clientIds
+                        = StringUtils.splitShortString(_replaceTabOrEnterCharactersWithSpaces(renderMode), ' ');
 
                 //The collection must be mutable
                 List<String> tempList = new ArrayList<String>();
@@ -280,12 +315,14 @@ public class PartialViewContextImpl exte
                     }
                 }
                 _renderClientIds = tempList;
-            } else {
+            }
+            else
+            {
                 _renderClientIds = new ArrayList<String>();
-                
-                if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals (renderMode))
+
+                if (PartialViewContext.ALL_PARTIAL_PHASE_CLIENT_IDS.equals(renderMode))
                 {
-                    _renderClientIds.add (PartialResponseWriter.RENDER_ALL_MARKER);
+                    _renderClientIds.add(PartialResponseWriter.RENDER_ALL_MARKER);
                 }
             }
         }
@@ -293,9 +330,10 @@ public class PartialViewContextImpl exte
     }
 
     @Override
-    public PartialResponseWriter getPartialResponseWriter() {
+    public PartialResponseWriter getPartialResponseWriter()
+    {
         assertNotReleased();
-        
+
         if (_partialResponseWriter == null)
         {
             ResponseWriter responseWriter = _facesContext.getResponseWriter();
@@ -313,8 +351,10 @@ public class PartialViewContextImpl exte
                         // renderKitId on that view, this could be still an ajax redirect,
                         // so we have to try to calculate the renderKitId and return a 
                         // RenderKit instance, to send the response.
-                        String renderKitId = _facesContext.getApplication().getViewHandler().calculateRenderKitId(_facesContext);
-                        RenderKitFactory rkf = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+                        String renderKitId
+                                = _facesContext.getApplication().getViewHandler().calculateRenderKitId(_facesContext);
+                        RenderKitFactory rkf
+                                = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
                         renderKit = rkf.getRenderKit(_facesContext, renderKitId);
                     }
                     responseWriter = renderKit.createResponseWriter(
@@ -323,7 +363,7 @@ public class PartialViewContextImpl exte
                 }
                 catch (IOException e)
                 {
-                    throw new IllegalStateException("Cannot create Partial Response Writer",e);
+                    throw new IllegalStateException("Cannot create Partial Response Writer", e);
                 }
             }
             // It is possible that the RenderKit return a PartialResponseWriter instance when 
@@ -347,44 +387,45 @@ public class PartialViewContextImpl exte
      *
      */
     @Override
-    public void processPartial(PhaseId phaseId) {
+    public void processPartial(PhaseId phaseId)
+    {
         assertNotReleased();
 
         UIViewRoot viewRoot = _facesContext.getViewRoot();
 
-        if (phaseId == PhaseId.APPLY_REQUEST_VALUES 
-                || phaseId == PhaseId.PROCESS_VALIDATIONS 
-                || phaseId == PhaseId.UPDATE_MODEL_VALUES) 
+        if (phaseId == PhaseId.APPLY_REQUEST_VALUES
+                || phaseId == PhaseId.PROCESS_VALIDATIONS
+                || phaseId == PhaseId.UPDATE_MODEL_VALUES)
         {
             processPartialExecute(viewRoot, phaseId);
-        } 
-        else if (phaseId == PhaseId.RENDER_RESPONSE) 
+        }
+        else if (phaseId == PhaseId.RENDER_RESPONSE)
         {
             processPartialRendering(viewRoot, phaseId);
         }
     }
 
-    private void processPartialExecute(UIViewRoot viewRoot, PhaseId phaseId) 
+    private void processPartialExecute(UIViewRoot viewRoot, PhaseId phaseId)
     {
         PartialViewContext pvc = _facesContext.getPartialViewContext();
         Collection<String> executeIds = pvc.getExecuteIds();
-        if (executeIds == null || executeIds.isEmpty()) 
+        if (executeIds == null || executeIds.isEmpty())
         {
             return;
         }
         Set<VisitHint> hints = new HashSet<VisitHint>();
         hints.add(VisitHint.EXECUTE_LIFECYCLE);
         hints.add(VisitHint.SKIP_UNRENDERED);
-        VisitContext visitCtx = VisitContext.createVisitContext(_facesContext, executeIds, hints);
+        VisitContext visitCtx = getVisitContextFactory().getVisitContext(_facesContext, executeIds, hints);
         viewRoot.visitTree(visitCtx, new PhaseAwareVisitCallback(_facesContext, phaseId));
     }
 
-    private void processPartialRendering(UIViewRoot viewRoot, PhaseId phaseId) 
+    private void processPartialRendering(UIViewRoot viewRoot, PhaseId phaseId)
     {
         //TODO process partial rendering
         //https://issues.apache.org/jira/browse/MYFACES-2118
         //Collection<String> renderIds = getRenderIds();
-        
+
         // We need to always update the view state marker when processing partial
         // rendering, because there is no way to check when the state has been changed
         // or not. Anyway, if we return empty response, according to the spec a javascript
@@ -397,7 +438,7 @@ public class PartialViewContextImpl exte
         // this could cause problems if PartialResponseWriter is wrapped
         PartialResponseWriter writer = _facesContext.getPartialViewContext().getPartialResponseWriter();
         PartialViewContext pvc = _facesContext.getPartialViewContext();
-        
+
         ResponseWriter oldWriter = _facesContext.getResponseWriter();
         boolean inDocument = false;
 
@@ -412,7 +453,7 @@ public class PartialViewContextImpl exte
         //http://support.microsoft.com/kb/234067
         externalContext.addResponseHeader("Expires", "-1");
 
-        try 
+        try
         {
             writer.startDocument();
             inDocument = true;
@@ -431,9 +472,9 @@ public class PartialViewContextImpl exte
                     Set<VisitHint> hints = new HashSet<VisitHint>();
                     // unrendered have to be skipped, transient definitely must be added to our list!
                     hints.add(VisitHint.SKIP_UNRENDERED);
-                    
+
                     // render=@all, so output the body.
-                    if (renderIds.contains (PartialResponseWriter.RENDER_ALL_MARKER))
+                    if (renderIds.contains(PartialResponseWriter.RENDER_ALL_MARKER))
                     {
                         processRenderAll(viewRoot, writer);
                     }
@@ -441,7 +482,7 @@ public class PartialViewContextImpl exte
                     {
                         List<UIComponent> updatedComponents = null;
                         if (!ExternalContextUtils.isPortlet(_facesContext.getExternalContext()) &&
-                             MyfacesConfig.getCurrentInstance(externalContext).isStrictJsf2RefreshTargetAjax())
+                                MyfacesConfig.getCurrentInstance(externalContext).isStrictJsf2RefreshTargetAjax())
                         {
                             RequestViewContext rvc = RequestViewContext.getCurrentInstance(_facesContext);
                             if (rvc.isRenderTarget("head"))
@@ -476,8 +517,10 @@ public class PartialViewContextImpl exte
                             }
                         }
 
-                        VisitContext visitCtx = VisitContext.createVisitContext(_facesContext, renderIds, hints);
-                        viewRoot.visitTree(visitCtx, new PhaseAwareVisitCallback(_facesContext, phaseId, updatedComponents));
+                        VisitContext visitCtx = getVisitContextFactory().getVisitContext(
+                                _facesContext, renderIds, hints);
+                        viewRoot.visitTree(visitCtx,
+                                           new PhaseAwareVisitCallback(_facesContext, phaseId, updatedComponents));
                     }
                 }
                 else if (!ExternalContextUtils.isPortlet(_facesContext.getExternalContext()) &&
@@ -506,12 +549,12 @@ public class PartialViewContextImpl exte
                     }
                 }
             }
-            
+
             // invoke encodeAll() on every UIViewParameter in the view to 
             // enable every UIViewParameter to save its value in the state
             // just like UIViewRoot.encodeEnd() does on a normal request
             // (see MYFACES-2645 for details)
-            Collection<UIViewParameter> viewParams = ViewMetadata.getViewParameters(viewRoot);    
+            Collection<UIViewParameter> viewParams = ViewMetadata.getViewParameters(viewRoot);
             if (!viewParams.isEmpty())
             {
                 for (UIViewParameter param : viewParams)
@@ -519,7 +562,7 @@ public class PartialViewContextImpl exte
                     param.encodeAll(_facesContext);
                 }
             }
-            
+
             //Retrieve the state and apply it if it is not null.
             String viewState = _facesContext.getApplication().getStateManager().getViewState(_facesContext);
             if (viewState != null)
@@ -528,22 +571,32 @@ public class PartialViewContextImpl exte
                 writer.write(viewState);
                 writer.endUpdate();
             }
-        } catch (IOException ex) {
+        }
+        catch (IOException ex)
+        {
             Logger log = Logger.getLogger(PartialViewContextImpl.class.getName());
-            if (log.isLoggable(Level.SEVERE)) {
-                log.log(Level.SEVERE, "" , ex);
+            if (log.isLoggable(Level.SEVERE))
+            {
+                log.log(Level.SEVERE, "", ex);
             }
 
-        } finally {
-            try {
-                if (inDocument) {
+        }
+        finally
+        {
+            try
+            {
+                if (inDocument)
+                {
                     writer.endDocument();
                 }
                 writer.flush();
-            } catch (IOException ex) {
+            }
+            catch (IOException ex)
+            {
                 Logger log = Logger.getLogger(PartialViewContextImpl.class.getName());
-                if (log.isLoggable(Level.SEVERE)) {
-                    log.log(Level.SEVERE, "" , ex);
+                if (log.isLoggable(Level.SEVERE))
+                {
+                    log.log(Level.SEVERE, "", ex);
                 }
             }
 
@@ -551,25 +604,26 @@ public class PartialViewContextImpl exte
         }
 
     }
-    
+
     private void processRenderAll(UIViewRoot viewRoot, PartialResponseWriter writer) throws IOException
     {
         //java.util.Iterator<UIComponent> iter = viewRoot.getFacetsAndChildren();
-        writer.startUpdate (PartialResponseWriter.RENDER_ALL_MARKER);
+        writer.startUpdate(PartialResponseWriter.RENDER_ALL_MARKER);
         //while (iter.hasNext()) 
         //{ 
-            //UIComponent comp = iter.next();
-            
-            //TODO: Do not check for a specific instance, 
-            //just render all children.
-            //if (comp instanceof javax.faces.component.html.HtmlBody)
-            //{
-                //comp.encodeAll (_facesContext);
-            //}
+        //UIComponent comp = iter.next();
+
+        //TODO: Do not check for a specific instance,
+        //just render all children.
+        //if (comp instanceof javax.faces.component.html.HtmlBody)
+        //{
+        //comp.encodeAll (_facesContext);
         //}
-        for (UIComponent comp : viewRoot.getChildren())
+        //}
+        for (int i = 0, childCount = viewRoot.getChildCount(); i < childCount; i++)
         {
-            comp.encodeAll (_facesContext);
+            UIComponent comp = viewRoot.getChildren().get(i);
+            comp.encodeAll(_facesContext);
         }
         writer.endUpdate();
     }
@@ -577,15 +631,19 @@ public class PartialViewContextImpl exte
     /**
      * has to be thrown in many of the methods if the method is called after the instance has been released!
      */
-    private void assertNotReleased() {
-        if (_released) {
+    private void assertNotReleased()
+    {
+        if (_released)
+        {
             throw new IllegalStateException("Error the FacesContext is already released!");
         }
     }
 
     @Override
-    public void release() {
+    public void release()
+    {
         assertNotReleased();
+        _visitContextFactory = null;
         _executeClientIds = null;
         _renderClientIds = null;
         _ajaxRequest = null;
@@ -594,7 +652,7 @@ public class PartialViewContextImpl exte
         _facesContext = null;
         _released = true;
     }
-    
+
     private UIComponent findHeadComponent(UIViewRoot root)
     {
         for (UIComponent child : root.getChildren())
@@ -616,7 +674,7 @@ public class PartialViewContextImpl exte
         }
         return null;
     }
-    
+
     private UIComponent findBodyComponent(UIViewRoot root)
     {
         for (UIComponent child : root.getChildren())
@@ -638,35 +696,58 @@ public class PartialViewContextImpl exte
         }
         return null;
     }
+    
+    private VisitContextFactory getVisitContextFactory()
+    {
+        if (_visitContextFactory == null)
+        {
+            _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+        }
+        return _visitContextFactory;
+    }
 
-    private class PhaseAwareVisitCallback implements VisitCallback {
+    private class PhaseAwareVisitCallback implements VisitCallback
+    {
 
         private PhaseId _phaseId;
         private FacesContext _facesContext;
         private List<UIComponent> _alreadyUpdatedComponents;
 
-        public PhaseAwareVisitCallback(FacesContext facesContext, PhaseId phaseId) {
+        public PhaseAwareVisitCallback(FacesContext facesContext, PhaseId phaseId)
+        {
             this._phaseId = phaseId;
             this._facesContext = facesContext;
             this._alreadyUpdatedComponents = null;
         }
-        
-        public PhaseAwareVisitCallback(FacesContext facesContext, PhaseId phaseId, List<UIComponent> alreadyUpdatedComponents) {
+
+        public PhaseAwareVisitCallback(FacesContext facesContext, PhaseId phaseId,
+                                       List<UIComponent> alreadyUpdatedComponents)
+        {
             this._phaseId = phaseId;
             this._facesContext = facesContext;
             this._alreadyUpdatedComponents = alreadyUpdatedComponents;
         }
 
-        public VisitResult visit(VisitContext context, UIComponent target) {
-            if (_phaseId == PhaseId.APPLY_REQUEST_VALUES) {
+        public VisitResult visit(VisitContext context, UIComponent target)
+        {
+            if (_phaseId == PhaseId.APPLY_REQUEST_VALUES)
+            {
                 target.processDecodes(_facesContext);
-            } else if (_phaseId == PhaseId.PROCESS_VALIDATIONS) {
+            }
+            else if (_phaseId == PhaseId.PROCESS_VALIDATIONS)
+            {
                 target.processValidators(_facesContext);
-            } else if (_phaseId == PhaseId.UPDATE_MODEL_VALUES) {
+            }
+            else if (_phaseId == PhaseId.UPDATE_MODEL_VALUES)
+            {
                 target.processUpdates(_facesContext);
-            } else if (_phaseId == PhaseId.RENDER_RESPONSE) {
+            }
+            else if (_phaseId == PhaseId.RENDER_RESPONSE)
+            {
                 processRenderComponent(target);
-            } else {
+            }
+            else
+            {
                 throw new IllegalStateException("PPR Response, illegale phase called");
             }
 
@@ -681,7 +762,8 @@ public class PartialViewContextImpl exte
          *
          * @param target the target component to be handled!
          */
-        private void processRenderComponent(UIComponent target) {
+        private void processRenderComponent(UIComponent target)
+        {
             boolean inUpdate = false;
             PartialResponseWriter writer = (PartialResponseWriter) _facesContext.getResponseWriter();
             if (this._alreadyUpdatedComponents != null)
@@ -697,22 +779,33 @@ public class PartialViewContextImpl exte
                     parent = parent.getParent();
                 }
             }
-            try {
+            try
+            {
                 writer.startUpdate(target.getClientId(_facesContext));
                 inUpdate = true;
                 target.encodeAll(_facesContext);
-            } catch (IOException ex) {
+            }
+            catch (IOException ex)
+            {
                 Logger log = Logger.getLogger(PartialViewContextImpl.class.getName());
-                if (log.isLoggable(Level.SEVERE)) {
+                if (log.isLoggable(Level.SEVERE))
+                {
                     log.log(Level.SEVERE, "IOException for rendering component", ex);
                 }
-            } finally {
-                if (inUpdate) {
-                    try {
+            }
+            finally
+            {
+                if (inUpdate)
+                {
+                    try
+                    {
                         writer.endUpdate();
-                    } catch (IOException ex) {
+                    }
+                    catch (IOException ex)
+                    {
                         Logger log = Logger.getLogger(PartialViewContextImpl.class.getName());
-                        if (log.isLoggable(Level.SEVERE)) {
+                        if (log.isLoggable(Level.SEVERE))
+                        {
                             log.log(Level.SEVERE, "IOException for rendering component, stopping update rendering", ex);
                         }
                     }

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java Sat Mar  3 16:54:07 2012
@@ -30,6 +30,8 @@ import javax.faces.application.ViewHandl
 import javax.faces.component.UIComponent;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitContextFactory;
+import javax.faces.component.visit.VisitHint;
 import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
@@ -84,6 +86,7 @@ public class DefaultRestoreViewSupport i
     private Boolean _checkedViewIdCacheEnabled = null;
     
     private RenderKitFactory _renderKitFactory = null;
+    private VisitContextFactory _visitContextFactory = null;
 
     public void processComponentBinding(FacesContext facesContext, UIComponent component)
     {
@@ -93,7 +96,9 @@ public class DefaultRestoreViewSupport i
         // TODO: Remove this hack and use VisitHints.SKIP_ITERATION in JSF 2.1
         facesContext.getAttributes().put(SKIP_ITERATION_HINT, Boolean.TRUE);
         
-        component.visitTree(VisitContext.createVisitContext(facesContext), new RestoreStateCallback());
+        VisitContext visitContext = (VisitContext) getVisitContextFactory().
+                    getVisitContext(facesContext, null, null);
+        component.visitTree(visitContext, new RestoreStateCallback());
         
         facesContext.getAttributes().remove(SKIP_ITERATION_HINT);
         
@@ -196,6 +201,15 @@ public class DefaultRestoreViewSupport i
         }
         return _renderKitFactory;
     }
+    
+    protected VisitContextFactory getVisitContextFactory()
+    {
+        if (_visitContextFactory == null)
+        {
+            _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+        }
+        return _visitContextFactory;
+    }
         
     private static class RestoreStateCallback implements VisitCallback
     {

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/ViewDeclarationLanguageFactoryImpl.java Sat Mar  3 16:54:07 2012
@@ -52,8 +52,8 @@ public class ViewDeclarationLanguageFact
 
     private static final Logger LOGGER = Logger.getLogger(ViewDeclarationLanguageFactoryImpl.class.getName());
     
-    private boolean _initialized;
-    private ViewDeclarationLanguageStrategy[] _supportedLanguages;
+    private volatile boolean _initialized;
+    private volatile ViewDeclarationLanguageStrategy[] _supportedLanguages;
     
     /**
      * 
@@ -77,7 +77,10 @@ public class ViewDeclarationLanguageFact
         // TODO: It would be nice to be able to preinitialize the factory. However, since it requires 
         //       access to the ExternalContext it may not be possible, depending on the loading order 
         //       in the FactoryFinder. Could use ideas here. -= SL =-
-        initialize();
+        if (!_initialized)
+        {
+            initialize();
+        }
         
         for (ViewDeclarationLanguageStrategy strategy : _supportedLanguages)
         {

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1296667&r1=1296666&r2=1296667&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Sat Mar  3 16:54:07 2012
@@ -39,6 +39,7 @@ import javax.faces.component.UIViewParam
 import javax.faces.component.UIViewRoot;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitContextFactory;
 import javax.faces.component.visit.VisitHint;
 import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
@@ -169,6 +170,8 @@ public class DefaultFaceletsStateManagem
     
     private RenderKitFactory _renderKitFactory = null;
     
+    private VisitContextFactory _visitContextFactory = null;
+    
     private Boolean _saveStateWithVisitTreeOnPSS;
     
     private String _checkIdsProductionMode;
@@ -712,7 +715,8 @@ public class DefaultFaceletsStateManagem
         facesContext.getAttributes().put(SKIP_ITERATION_HINT, Boolean.TRUE);
         try
         {
-            uiViewRoot.visitTree( VisitContext.createVisitContext (facesContext), new VisitCallback()
+            uiViewRoot.visitTree( getVisitContextFactory().getVisitContext(
+                    facesContext, null, null), new VisitCallback()
             {
                 public VisitResult visit(VisitContext context, UIComponent target)
                 {
@@ -1010,6 +1014,15 @@ public class DefaultFaceletsStateManagem
         }
         return _renderKitFactory;
     }
+    
+    protected VisitContextFactory getVisitContextFactory()
+    {
+        if (_visitContextFactory == null)
+        {
+            _visitContextFactory = (VisitContextFactory)FactoryFinder.getFactory(FactoryFinder.VISIT_CONTEXT_FACTORY);
+        }
+        return _visitContextFactory;
+    }
 
     protected String getCheckIdProductionMode(FacesContext facesContext)
     {



Mime
View raw message