Author: craigmcc
Date: Thu May 25 23:43:00 2006
New Revision: 409567
URL: http://svn.apache.org/viewvc?rev=409567&view=rev
Log:
Refactor the various places that exception caching (from application event
handlers) was occurring into a common strategy-based interface that can
ultimately be made customnizable. This is further progress towards the
coherent exception strategy that SHALE-125 envisions, but in the mean time
eliminates a bunch of redundant code.
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/CallbacksFactory.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/ViewPhaseListener.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
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=409567&r1=409566&r2=409567&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 23:43:00 2006
@@ -29,6 +29,7 @@
import org.apache.shale.util.Messages;
import org.apache.shale.view.Constants;
import org.apache.shale.view.ViewController;
+import org.apache.shale.view.faces.ExceptionHandlerFactory;
/**
* <p>Specialized implementation of <code>UINamingContainer</code> that
@@ -73,7 +74,7 @@
try {
vc.prerender();
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
super.processDecodes(context);
@@ -95,7 +96,7 @@
try {
vc.preprocess();
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
super.processDecodes(context);
@@ -171,69 +172,15 @@
/**
- * <p>Log the specified exception, and cache it on the list of exceptions
- * to be reported after all of the appropriate <code>destroy()</code> calls
- * have been completed.</p>
+ * <p>Handle the specified exception according to the strategy
+ * defined by our current [EMAIL PROTECTED] ExceptionHandler}.</p>
*
- * @param exception Exception to be cached
+ * @param exception Exception to be handled
*/
- private void cacheException(Exception exception) {
+ private void handleException(Exception exception) {
- // Log the exception unconditionally
- log(exception.getMessage(), exception);
-
- // Are we within the context of a JavaServer Faces request?
- // If so, accumulate this exception to the list that can be
- // reported at the completion of the request.
- FacesContext context = FacesContext.getCurrentInstance();
- if (context == null) {
- return;
- }
- List list = (List) context.getExternalContext().getRequestMap().
- get(Constants.EXCEPTIONS_LIST);
- if (list == null) {
- list = new ArrayList(4);
- context.getExternalContext().getRequestMap().
- put(Constants.EXCEPTIONS_LIST, list);
- }
- list.add(exception);
-
- }
-
-
- /**
- * <p>Log the specified message via <code>FacesContext</code> if it is
- * not null, or directly to the container otherwise.</p>
- *
- * @param message Message to be logged
- */
- private void log(String message) {
-
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- context.getExternalContext().log(message);
- } else {
- System.out.println(message);
- }
-
- }
-
-
- /**
- * <p>Log the specified message and exception via <code>FacesContext</code>
- * if it is not null, or directly to the container otherwise.</p>
- *
- * @param message Message to be logged
- * @param throwable Exception to be logged
- */
- private void log(String message, Throwable throwable) {
-
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- context.getExternalContext().log(message);
- } else {
- System.out.println(message);
- }
+ ExceptionHandlerFactory.getInstance().getExceptionHandler().
+ handleException(exception);
}
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/CallbacksFactory.java
URL:
http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/CallbacksFactory.java?rev=409567&r1=409566&r2=409567&view=diff
==============================================================================
---
struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/CallbacksFactory.java
(original)
+++
struts/shale/trunk/core-library/src/java/org/apache/shale/view/faces/CallbacksFactory.java
Thu May 25 23:43:00 2006
@@ -34,7 +34,7 @@
/**
* <p>Private constructor to prevent arbitrary object creation.</p>
*/
- public CallbacksFactory() {
+ private CallbacksFactory() {
}
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=409567&r1=409566&r2=409567&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 23:43:00 2006
@@ -559,37 +559,6 @@
/**
- * <p>Log the specified exception, and cache it on the list of exceptions
- * to be reported after all of the appropriate <code>destroy()</code> calls
- * have been completed.</p>
- *
- * @param exception Exception to be cached
- */
- protected void cacheException(Exception exception) {
-
- // Log the exception unconditionally
- log(exception.getMessage(), exception);
-
- // Are we within the context of a JavaServer Faces request?
- // If so, accumulate this exception to the list that can be
- // reported at the completion of the request.
- FacesContext context = FacesContext.getCurrentInstance();
- if (context == null) {
- return;
- }
- List list = (List) context.getExternalContext().getRequestMap().
- get(Constants.EXCEPTIONS_LIST);
- if (list == null) {
- list = new ArrayList(4);
- context.getExternalContext().getRequestMap().
- put(Constants.EXCEPTIONS_LIST, list);
- }
- list.add(exception);
-
- }
-
-
- /**
* <p>Fire a destroy event on an @{link AbstractApplicationBean}.</p>
*
* @param bean [EMAIL PROTECTED] AbstractApplicationBean} to fire event on
@@ -601,7 +570,7 @@
((AbstractApplicationBean) bean).destroy();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -619,7 +588,7 @@
((AbstractApplicationBean) bean).init();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -639,7 +608,7 @@
((ViewController) bean).destroy();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -659,7 +628,7 @@
((ViewController) bean).init();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -677,7 +646,7 @@
((AbstractSessionBean) bean).activate();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -695,7 +664,7 @@
((AbstractSessionBean) bean).destroy();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -713,7 +682,7 @@
((AbstractSessionBean) bean).init();
}
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -731,45 +700,22 @@
((AbstractSessionBean) bean).passivate();
}
} catch (Exception e) {
- cacheException(e);
- }
-
- }
-
-
- /**
- * <p>Log the specified message via <code>FacesContext</code> if it is
- * not null, or directly to the container otherwise.</p>
- *
- * @param message Message to be logged
- */
- protected void log(String message) {
-
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- context.getExternalContext().log(message);
- } else {
- System.out.println(message);
+ handleException(e);
}
}
/**
- * <p>Log the specified message and exception via <code>FacesContext</code>
- * if it is not null, or directly to the container otherwise.</p>
+ * <p>Handle the specified exception according to the strategy
+ * defined by our current [EMAIL PROTECTED] ExceptionHandler}.</p>
*
- * @param message Message to be logged
- * @param throwable Exception to be logged
+ * @param exception Exception to be handled
*/
- protected void log(String message, Throwable throwable) {
+ protected void handleException(Exception exception) {
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- context.getExternalContext().log(message);
- } else {
- System.out.println(message);
- }
+ ExceptionHandlerFactory.getInstance().getExceptionHandler().
+ handleException(exception);
}
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=409567&r1=409566&r2=409567&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 23:43:00 2006
@@ -165,7 +165,7 @@
try {
viewControllerCallbacks(event.getFacesContext()).preprocess(vc);
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -189,7 +189,7 @@
try {
viewControllerCallbacks(event.getFacesContext()).prerender(vc);
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
map.remove(Constants.VIEW_RENDERED);
@@ -197,74 +197,6 @@
/**
- * <p>Log the specified exception, and cache it on the list of exceptions
- * to be reported after all of the appropriate <code>destroy()</code> calls
- * have been completed.</p>
- *
- * @param exception Exception to be cached
- */
- private void cacheException(Exception exception) {
-
- // Log the exception unconditionally
- log(exception.getMessage(), exception);
-
- // Are we within the context of a JavaServer Faces request?
- // If so, accumulate this exception to the list that can be
- // reported at the completion of the request.
- FacesContext context = FacesContext.getCurrentInstance();
- if (context == null) {
- return;
- }
- List list = (List) context.getExternalContext().getRequestMap().
- get(Constants.EXCEPTIONS_LIST);
- if (list == null) {
- list = new ArrayList(4);
- context.getExternalContext().getRequestMap().
- put(Constants.EXCEPTIONS_LIST, list);
- }
- list.add(exception);
-
- }
-
-
- /**
- * <p>Log the specified message via <code>FacesContext</code> if it is
- * not null, or directly to the container otherwise.</p>
- *
- * @param message Message to be logged
- */
- private void log(String message) {
-
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- context.getExternalContext().log(message);
- } else {
- System.out.println(message);
- }
-
- }
-
-
- /**
- * <p>Log the specified message and exception via <code>FacesContext</code>
- * if it is not null, or directly to the container otherwise.</p>
- *
- * @param message Message to be logged
- * @param throwable Exception to be logged
- */
- private void log(String message, Throwable throwable) {
-
- FacesContext context = FacesContext.getCurrentInstance();
- if (context != null) {
- context.getExternalContext().log(message);
- } else {
- System.out.println(message);
- }
-
- }
-
-
- /**
* <p>The [EMAIL PROTECTED] ViewControllerCallbacks} instance we will use.
* This instance is lazily instantiated.</p>
*/
@@ -290,6 +222,20 @@
}
}
return viewControllerCallbacks;
+
+ }
+
+
+ /**
+ * <p>Handle the specified exception according to the strategy
+ * defined by our current [EMAIL PROTECTED] ExceptionHandler}.</p>
+ *
+ * @param exception Exception to be handled
+ */
+ private void handleException(Exception exception) {
+
+ ExceptionHandlerFactory.getInstance().getExceptionHandler().
+ handleException(exception);
}
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=409567&r1=409566&r2=409567&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 23:43:00 2006
@@ -320,9 +320,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -346,9 +346,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -373,9 +373,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -400,9 +400,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -426,9 +426,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -452,9 +452,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -478,9 +478,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
@@ -504,9 +504,9 @@
method.invoke(bean, PARAMETERS);
}
} catch (InvocationTargetException e) {
- cacheException((Exception) e.getCause());
+ handleException((Exception) e.getCause());
} catch (Exception e) {
- cacheException(e);
+ handleException(e);
}
}
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=409567&r1=409566&r2=409567&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 23:43:00 2006
@@ -28,6 +28,7 @@
import org.apache.shale.tiger.view.Prerender;
import org.apache.shale.tiger.view.View;
import org.apache.shale.view.ViewController;
+import org.apache.shale.view.faces.ExceptionHandlerFactory;
import org.apache.shale.view.faces.ViewControllerCallbacks;
/**
@@ -65,7 +66,11 @@
public void preprocess(Object instance) {
if (instance instanceof ViewController) {
- ((ViewController) instance).preprocess();
+ try {
+ ((ViewController) instance).preprocess();
+ } catch (Exception e) {
+ handleException(e);
+ }
return;
}
@@ -74,9 +79,9 @@
try {
method.invoke(instance, new Object[0]);
} catch (IllegalAccessException e) {
- throw new FacesException(e);
+ handleException(e);
} catch (InvocationTargetException e) {
- throw new FacesException(e.getCause());
+ handleException((Exception) e.getCause());
}
}
@@ -92,7 +97,11 @@
public void prerender(Object instance) {
if (instance instanceof ViewController) {
- ((ViewController) instance).prerender();
+ try {
+ ((ViewController) instance).prerender();
+ } catch (Exception e) {
+ handleException(e);
+ }
return;
}
@@ -101,9 +110,9 @@
try {
method.invoke(instance, new Object[0]);
} catch (IllegalAccessException e) {
- throw new FacesException(e);
+ handleException(e);
} catch (InvocationTargetException e) {
- throw new FacesException(e.getCause());
+ handleException((Exception) e.getCause());
}
}
@@ -111,6 +120,20 @@
// --------------------------------------------------------- Private
Methods
+
+
+ /**
+ * <p>Handle the specified exception according to the strategy
+ * defined by our current [EMAIL PROTECTED] ExceptionHandler}.</p>
+ *
+ * @param exception Exception to be handled
+ */
+ private void handleException(Exception exception) {
+
+ ExceptionHandlerFactory.getInstance().getExceptionHandler().
+ handleException(exception);
+
+ }
/**