Author: craigmcc Date: Thu May 25 21:02:37 2006 New Revision: 409549 URL: http://svn.apache.org/viewvc?rev=409549&view=rev Log: Transfer responsibility for firing init() and destroy() callbacks on a ViewController (or, with the Tiger Extensions installed, on a class that has the @View annotation) from the custom ViewHandler to the LifecycleListener that does init/destroy callbacks on all the other lifecycle related classes. This is another step towards refactoring and simplifying the implementation of ViewViewHandler and ViewPhaseListener, and also progress towards the "coherent exception handling strategy" RFE (SHALE-125).
Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/component/Subview.java struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/LifecycleListener.java struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewControllerCallbacks.java struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewPhaseListener.java struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewViewHandler.java struts/shale/trunk/core-library/src/test/org/apache/shale/view/faces/ViewControllerCallbacksTestCase.java struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2.java struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2TestCase.java Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/component/Subview.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/component/Subview.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/component/Subview.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/component/Subview.java Thu May 25 21:02:37 2006 @@ -133,8 +133,8 @@ vc = (ViewController) context.getApplication(). createValueBinding(expr).getValue(context); if (vc == null) { - log.warn(messages.getMessage("subview.noBean", - new Object[] { getId() })); + log.debug(messages.getMessage("subview.noBean", + new Object[] { getId() })); return null; } } catch (ClassCastException e) { @@ -145,7 +145,7 @@ // Initialize the ViewController as needed vc.setPostBack(postback); - vc.init(); +// vc.init(); // Schedule this instance for later processing as needed Map map = econtext.getRequestMap(); Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/LifecycleListener.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/LifecycleListener.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/LifecycleListener.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/LifecycleListener.java Thu May 25 21:02:37 2006 @@ -39,6 +39,7 @@ import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; import org.apache.shale.view.Constants; +import org.apache.shale.view.ViewController; /** @@ -634,6 +635,8 @@ try { if (bean instanceof AbstractRequestBean) { ((AbstractRequestBean) bean).destroy(); + } else if (bean instanceof ViewController) { + ((ViewController) bean).destroy(); } } catch (Exception e) { cacheException(e); @@ -652,6 +655,8 @@ try { if (bean instanceof AbstractRequestBean) { ((AbstractRequestBean) bean).init(); + } else if (bean instanceof ViewController) { + ((ViewController) bean).init(); } } catch (Exception e) { cacheException(e); Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewControllerCallbacks.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewControllerCallbacks.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewControllerCallbacks.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewControllerCallbacks.java Thu May 25 21:02:37 2006 @@ -41,21 +41,6 @@ /** - * <p>Perform the <code>init</code> callback on the specified - * instance.</p> - * - * @param instance Bean instance on which to perform this callback - */ - public void init(Object instance) { - - if (instance instanceof ViewController) { - ((ViewController) instance).init(); - } - - } - - - /** * <p>Perform the <code>preprocess</code> callback on the specified * instance.</p> * @@ -80,21 +65,6 @@ if (instance instanceof ViewController) { ((ViewController) instance).prerender(); - } - - } - - - /** - * <p>Perform the <code>destroy</code> callback on the specified - * instance.</p> - * - * @param instance Bean instance on which to perform this callback - */ - public void destroy(Object instance) { - - if (instance instanceof ViewController) { - ((ViewController) instance).destroy(); } } Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewPhaseListener.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewPhaseListener.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewPhaseListener.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewPhaseListener.java Thu May 25 21:02:37 2006 @@ -135,7 +135,7 @@ Iterator vcs = list.iterator(); while (vcs.hasNext()) { Object vc = vcs.next(); - viewControllerCallbacks(event.getFacesContext()).destroy(vc); +// viewControllerCallbacks(event.getFacesContext()).destroy(vc); } map.remove(Constants.VIEWS_INITIALIZED); Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewViewHandler.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewViewHandler.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewViewHandler.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/ViewViewHandler.java Thu May 25 21:02:37 2006 @@ -304,7 +304,7 @@ if (vc instanceof ViewController) { ((ViewController) vc).setPostBack(postBack); } - viewControllerCallbacks(context).init(vc); + // viewControllerCallbacks(context).init(vc); // Schedule this instance for later processing as needed Map map = context.getExternalContext().getRequestMap(); Modified: struts/shale/trunk/core-library/src/test/org/apache/shale/view/faces/ViewControllerCallbacksTestCase.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/test/org/apache/shale/view/faces/ViewControllerCallbacksTestCase.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/test/org/apache/shale/view/faces/ViewControllerCallbacksTestCase.java (original) +++ struts/shale/trunk/core-library/src/test/org/apache/shale/view/faces/ViewControllerCallbacksTestCase.java Thu May 25 21:02:37 2006 @@ -84,11 +84,9 @@ public void testViewControllerCallbacks() { TestViewController tvc = new TestViewController(); - callbacks.init(tvc); callbacks.preprocess(tvc); callbacks.prerender(tvc); - callbacks.destroy(tvc); - assertEquals("init/preprocess/prerender/destroy/", + assertEquals("preprocess/prerender/", tvc.log()); } Modified: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java (original) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java Thu May 25 21:02:37 2006 @@ -38,6 +38,7 @@ import org.apache.shale.view.AbstractApplicationBean; import org.apache.shale.view.AbstractRequestBean; import org.apache.shale.view.AbstractSessionBean; +import org.apache.shale.view.ViewController; import org.apache.shale.view.faces.LifecycleListener; /** @@ -360,7 +361,8 @@ */ protected void fireRequestDestroy(Object bean) { - if (bean instanceof AbstractRequestBean) { + if ((bean instanceof AbstractRequestBean) || + (bean instanceof ViewController)) { super.fireRequestDestroy(bean); return; } @@ -386,7 +388,8 @@ */ protected void fireRequestInit(Object bean) { - if (bean instanceof AbstractRequestBean) { + if ((bean instanceof AbstractRequestBean) || + (bean instanceof ViewController)) { super.fireRequestInit(bean); return; } Modified: struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2.java (original) +++ struts/shale/trunk/tiger/src/java/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2.java Thu May 25 21:02:37 2006 @@ -57,33 +57,6 @@ /** - * <p>Perform the <code>init</code> callback on the specified - * instance.</p> - * - * @param instance Bean instance on which to perform this callback - */ - public void init(Object instance) { - - if (instance instanceof ViewController) { - ((ViewController) instance).init(); - return; - } - - Method method = method(instance, Init.class); - if (method != null) { - try { - method.invoke(instance, new Object[0]); - } catch (IllegalAccessException e) { - throw new FacesException(e); - } catch (InvocationTargetException e) { - throw new FacesException(e.getCause()); - } - } - - } - - - /** * <p>Perform the <code>preprocess</code> callback on the specified * instance.</p> * @@ -137,33 +110,6 @@ } - /** - * <p>Perform the <code>destroy</code> callback on the specified - * instance.</p> - * - * @param instance Bean instance on which to perform this callback - */ - public void destroy(Object instance) { - - if (instance instanceof ViewController) { - ((ViewController) instance).destroy(); - return; - } - - Method method = method(instance, Destroy.class); - if (method != null) { - try { - method.invoke(instance, new Object[0]); - } catch (IllegalAccessException e) { - throw new FacesException(e); - } catch (InvocationTargetException e) { - throw new FacesException(e.getCause()); - } - } - - } - - // --------------------------------------------------------- Private Methods @@ -171,7 +117,7 @@ * <p>The set of method annotations for callbacks of interest.</p> */ private static final Class annotations[] = - { Init.class, Preprocess.class, Prerender.class, Destroy.class }; + { Preprocess.class, Prerender.class }; Modified: struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2TestCase.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2TestCase.java?rev=409549&r1=409548&r2=409549&view=diff ============================================================================== --- struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2TestCase.java (original) +++ struts/shale/trunk/tiger/src/test/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2TestCase.java Thu May 25 21:02:37 2006 @@ -84,11 +84,9 @@ public void testViewControllerCallbacks() { TestViewController tvc = new TestViewController(); - callbacks.init(tvc); callbacks.preprocess(tvc); callbacks.prerender(tvc); - callbacks.destroy(tvc); - assertEquals("init/preprocess/prerender/destroy/", + assertEquals("preprocess/prerender/", tvc.log()); }