myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arobinso...@apache.org
Subject svn commit: r1239407 - in /myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component: UIXDocumentTemplate.java html/HtmlBodyTemplate.java html/HtmlHeadTemplate.java
Date Wed, 01 Feb 2012 23:42:30 GMT
Author: arobinson74
Date: Wed Feb  1 23:42:30 2012
New Revision: 1239407

URL: http://svn.apache.org/viewvc?rev=1239407&view=rev
Log:
TRINIDAD-2203 - Move the suspension and resume code into the setup/teardown of UIXDocument,
HtmlHead and HtmlBody so that the re-entrant call does not cause false errors in testing mode
since the context change stack is going to be suspended.

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXDocumentTemplate.java
    myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlBodyTemplate.java
    myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlHeadTemplate.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXDocumentTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXDocumentTemplate.java?rev=1239407&r1=1239406&r2=1239407&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXDocumentTemplate.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXDocumentTemplate.java
Wed Feb  1 23:42:30 2012
@@ -18,64 +18,77 @@
  */
 package org.apache.myfaces.trinidad.component;
 
-import javax.faces.FacesException;
-import javax.faces.component.ContextCallback;
-import javax.faces.component.visit.VisitCallback;
-import javax.faces.component.visit.VisitContext;
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Queue;
+
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.context.ComponentContextManager;
 import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidad.context.SuspendedContextChanges;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
 
 public abstract class UIXDocumentTemplate
   extends UIXComponentBase
 {
+  /**
+   * Suspends any context changes before allowing invokeOnComponent or visitTree calls to
continue,
+   * allowing components to undo any context changes during a re-entrant call.
+   * @param facesContext the faces context
+   * @see ComponentContextManager#suspend(FacesContext)
+   */
   @Override
-  public boolean visitTree(
-    VisitContext  visitContext,
-    VisitCallback callback)
+  protected void setupVisitingContext(FacesContext facesContext)
   {
     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
       .getComponentContextManager();
-    FacesContext facesContext = visitContext.getFacesContext();
 
     // Suspend any current component context during a visit tree for re-entrant
     // component tree processing
     SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
 
-    try
-    {
-      return super.visitTree(visitContext, callback);
-    }
-    finally
+    Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
+    @SuppressWarnings("unchecked")
+    Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
+      reqMap.get(_SUSPENDED_CHANGES_KEY);
+    if (suspendedChangesQueue == null)
     {
-      ctxMgr.resume(facesContext, suspendedChanges);
+      suspendedChangesQueue = Collections.asLifoQueue(new ArrayDeque<SuspendedContextChanges>());
+      reqMap.put(_SUSPENDED_CHANGES_KEY, suspendedChangesQueue);
     }
+
+    suspendedChangesQueue.offer(suspendedChanges);
+    _LOG.severe("UIXDocument suspended context changes in setupVisitingContext");
+
+    super.setupVisitingContext(facesContext);
   }
 
+  /**
+   * Re-applies the suspended context changes.
+   * @param facesContext the faces context
+   * @see #setupVisitingContext(FacesContext)
+   * @see ComponentContextManager#resume(FacesContext, SuspendedContextChanges)
+   */
   @Override
-  public boolean invokeOnComponent(
-    FacesContext    facesContext,
-    String          clientId,
-    ContextCallback callback
-    ) throws FacesException
+  protected void tearDownVisitingContext(FacesContext facesContext)
   {
+    super.tearDownVisitingContext(facesContext);
+
     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
       .getComponentContextManager();
-
-    // Suspend any current component context during an invoke on component call for re-entrant
-    // component tree processing
-    SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
-
-    try
-    {
-      return super.invokeOnComponent(facesContext, clientId, callback);
-    }
-    finally
-    {
-      ctxMgr.resume(facesContext, suspendedChanges);
-    }
+    Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
+    @SuppressWarnings("unchecked")
+    Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
+      reqMap.get(_SUSPENDED_CHANGES_KEY);
+    SuspendedContextChanges changes = suspendedChangesQueue.poll();
+    ctxMgr.resume(facesContext, changes);
+    _LOG.severe("UIXDocument resumed context changes in setupVisitingContext");
   }
+
+  private final static String _SUSPENDED_CHANGES_KEY = UIXDocument.class.getName() +
+                                                       ".SUSPENDED_CHANGES";
+  private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(UIXDocument.class);
 }

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlBodyTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlBodyTemplate.java?rev=1239407&r1=1239406&r2=1239407&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlBodyTemplate.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlBodyTemplate.java
Wed Feb  1 23:42:30 2012
@@ -18,10 +18,11 @@
  */
 package org.apache.myfaces.trinidad.component.html;
 
-import javax.faces.FacesException;
-import javax.faces.component.ContextCallback;
-import javax.faces.component.visit.VisitCallback;
-import javax.faces.component.visit.VisitContext;
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Queue;
+
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.component.UIXComponentBase;
@@ -33,50 +34,58 @@ import org.apache.myfaces.trinidad.conte
 public abstract class HtmlBodyTemplate
   extends UIXComponentBase
 {
+  /**
+   * Suspends any context changes before allowing invokeOnComponent or visitTree calls to
continue,
+   * allowing components to undo any context changes during a re-entrant call.
+   * @param facesContext the faces context
+   * @see ComponentContextManager#suspend(FacesContext)
+   */
   @Override
-  public boolean visitTree(
-    VisitContext  visitContext,
-    VisitCallback callback)
+  protected void setupVisitingContext(FacesContext facesContext)
   {
     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
       .getComponentContextManager();
-    FacesContext facesContext = visitContext.getFacesContext();
 
     // Suspend any current component context during a visit tree for re-entrant
     // component tree processing
     SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
 
-    try
-    {
-      return super.visitTree(visitContext, callback);
-    }
-    finally
+    Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
+    @SuppressWarnings("unchecked")
+    Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
+      reqMap.get(_SUSPENDED_CHANGES_KEY);
+    if (suspendedChanges == null)
     {
-      ctxMgr.resume(facesContext, suspendedChanges);
+      suspendedChangesQueue = Collections.asLifoQueue(new ArrayDeque<SuspendedContextChanges>());
+      reqMap.put(_SUSPENDED_CHANGES_KEY, suspendedChangesQueue);
     }
+
+    suspendedChangesQueue.offer(suspendedChanges);
+
+    super.setupVisitingContext(facesContext);
   }
 
+  /**
+   * Re-applies the suspended context changes.
+   * @param facesContext the faces context
+   * @see #setupVisitingContext(FacesContext)
+   * @see ComponentContextManager#resume(FacesContext, SuspendedContextChanges)
+   */
   @Override
-  public boolean invokeOnComponent(
-    FacesContext    facesContext,
-    String          clientId,
-    ContextCallback callback
-    ) throws FacesException
+  protected void tearDownVisitingContext(FacesContext facesContext)
   {
+    super.tearDownVisitingContext(facesContext);
+
     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
       .getComponentContextManager();
-
-    // Suspend any current component context during an invoke on component call for re-entrant
-    // component tree processing
-    SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
-
-    try
-    {
-      return super.invokeOnComponent(facesContext, clientId, callback);
-    }
-    finally
-    {
-      ctxMgr.resume(facesContext, suspendedChanges);
-    }
+    Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
+    @SuppressWarnings("unchecked")
+    Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
+      reqMap.get(_SUSPENDED_CHANGES_KEY);
+    SuspendedContextChanges changes = suspendedChangesQueue.poll();
+    ctxMgr.resume(facesContext, changes);
   }
+
+  private final static String _SUSPENDED_CHANGES_KEY = HtmlBody.class.getName() +
+                                                       ".SUSPENDED_CHANGES";
 }
\ No newline at end of file

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlHeadTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlHeadTemplate.java?rev=1239407&r1=1239406&r2=1239407&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlHeadTemplate.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/html/HtmlHeadTemplate.java
Wed Feb  1 23:42:30 2012
@@ -18,10 +18,11 @@
  */
 package org.apache.myfaces.trinidad.component.html;
 
-import javax.faces.FacesException;
-import javax.faces.component.ContextCallback;
-import javax.faces.component.visit.VisitCallback;
-import javax.faces.component.visit.VisitContext;
+import java.util.ArrayDeque;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Queue;
+
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.component.UIXComponentBase;
@@ -33,50 +34,58 @@ import org.apache.myfaces.trinidad.conte
 public abstract class HtmlHeadTemplate
   extends UIXComponentBase
 {
+  /**
+   * Suspends any context changes before allowing invokeOnComponent or visitTree calls to
continue,
+   * allowing components to undo any context changes during a re-entrant call.
+   * @param facesContext the faces context
+   * @see ComponentContextManager#suspend(FacesContext)
+   */
   @Override
-  public boolean visitTree(
-    VisitContext  visitContext,
-    VisitCallback callback)
+  protected void setupVisitingContext(FacesContext facesContext)
   {
     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
       .getComponentContextManager();
-    FacesContext facesContext = visitContext.getFacesContext();
 
     // Suspend any current component context during a visit tree for re-entrant
     // component tree processing
     SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
 
-    try
-    {
-      return super.visitTree(visitContext, callback);
-    }
-    finally
+    Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
+    @SuppressWarnings("unchecked")
+    Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
+      reqMap.get(_SUSPENDED_CHANGES_KEY);
+    if (suspendedChanges == null)
     {
-      ctxMgr.resume(facesContext, suspendedChanges);
+      suspendedChangesQueue = Collections.asLifoQueue(new ArrayDeque<SuspendedContextChanges>());
+      reqMap.put(_SUSPENDED_CHANGES_KEY, suspendedChangesQueue);
     }
+
+    suspendedChangesQueue.offer(suspendedChanges);
+
+    super.setupVisitingContext(facesContext);
   }
 
+  /**
+   * Re-applies the suspended context changes.
+   * @param facesContext the faces context
+   * @see #setupVisitingContext(FacesContext)
+   * @see ComponentContextManager#resume(FacesContext, SuspendedContextChanges)
+   */
   @Override
-  public boolean invokeOnComponent(
-    FacesContext    facesContext,
-    String          clientId,
-    ContextCallback callback
-    ) throws FacesException
+  protected void tearDownVisitingContext(FacesContext facesContext)
   {
+    super.tearDownVisitingContext(facesContext);
+
     ComponentContextManager ctxMgr = RequestContext.getCurrentInstance()
       .getComponentContextManager();
-
-    // Suspend any current component context during an invoke on component call for re-entrant
-    // component tree processing
-    SuspendedContextChanges suspendedChanges = ctxMgr.suspend(facesContext);
-
-    try
-    {
-      return super.invokeOnComponent(facesContext, clientId, callback);
-    }
-    finally
-    {
-      ctxMgr.resume(facesContext, suspendedChanges);
-    }
+    Map<String, Object> reqMap = facesContext.getExternalContext().getRequestMap();
+    @SuppressWarnings("unchecked")
+    Queue<SuspendedContextChanges> suspendedChangesQueue = (Queue<SuspendedContextChanges>)
+      reqMap.get(_SUSPENDED_CHANGES_KEY);
+    SuspendedContextChanges changes = suspendedChangesQueue.poll();
+    ctxMgr.resume(facesContext, changes);
   }
+
+  private final static String _SUSPENDED_CHANGES_KEY = HtmlHead.class.getName() +
+                                                       ".SUSPENDED_CHANGES";
 }
\ No newline at end of file



Mime
View raw message