You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/05/20 15:17:19 UTC

svn commit: r658235 - /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java

Author: skitching
Date: Tue May 20 06:17:19 2008
New Revision: 658235

URL: http://svn.apache.org/viewvc?rev=658235&view=rev
Log:
Ensure release is called on decorated instance at appropriate time. It is invoked before the FacesContext decorator runs its setup, so should be invoked after the FacesContext decorator runs its shutdown.

Modified:
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java?rev=658235&r1=658234&r2=658235&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/OrchestraFacesContextFactory.java Tue May 20 06:17:19 2008
@@ -99,7 +99,9 @@
         log.debug("getFacesContext: creating custom instance");
         return new _FacesContextWrapper(facesContext, false)
         {
-            // Constructor...
+            // Constructor. Note that the parent constructor runs first,
+            // which means that FacesContext.currentInstance is valid
+            // at the time that the RequestHandler objects run.
             {
                 log.debug("getFacesContext: running inner constructor");
                 ListIterator i = handlers.listIterator();
@@ -119,6 +121,8 @@
                 }
                 catch(RuntimeException e)
                 {
+                    // Oops, something went wrong. Undo any processing done by the
+                    // RequestHandlers that have successfully run so far.
                     _release(i);
                     throw e;
                 }
@@ -126,16 +130,29 @@
 
             public void release()
             {
+                // As the "setup" code for this inner class runs after the
+                // parent class constructor, the release code for this
+                // class should run before the parent release. This also
+                // ensures that FacesContext.currentInstance() is still
+                // valid when the RequestHandler objects run.
                 log.debug("Running release");
-                super.release();
+                
+                // Here, run the registered RequestHandlers in reverse order.
+                // Unfortunately, there is no ReverseListIterator class, so
+                // instead here we wind an iterator forward to the end of the
+                // list before passing it to _release, which then walks
+                // backwards through the list. Ecch.
                 ListIterator i = handlers.listIterator();
-                // ecch, wind forward to end of list.
                 while (i.hasNext())
                 {
                     i.next();
                 }
                 _release(i);
+
+                // And invoke the parent release (which will invoke release
+                // on the target instance that this object decorates).
                 log.debug("Release completed");
+                super.release();
             }
             
             private void _release(ListIterator i)