com.webmethods.caf.faces.data.error
Class BaseErrorHandler

java.lang.Object
  extended by com.webmethods.caf.faces.data.error.BaseErrorHandler
All Implemented Interfaces:
IErrorHandler
Direct Known Subclasses:
DbClientErrorHandler, WebserviceClientErrorHandler

public class BaseErrorHandler
extends Object
implements IErrorHandler

Base class for all error handlers. Implements support functions for different ways of handling an error


Field Summary
protected  String action
           
static String ACTION_NONE
          Do not handle error, but just parse it.
static String ACTION_REDIRECT
          Client browser is redirected to custom error handling page.
static String ACTION_REPORT_DETAILS
          Reports error details only
static String ACTION_REPORT_SUMMARY
          Default handler behavior is to report error summary only
static String ACTION_REPORT_SUMMARY_DETAILS
          Reports error summary and details details only
protected  IErrorHandler chainHandler
           
protected  String details
           
protected  String errorPage
           
protected  Exception exception
           
protected  String parsedDetails
           
protected  String parsedSummary
           
protected  String severity
           
static String SEVERITY_ERROR
           
static String SEVERITY_FATAL
           
static String SEVERITY_INFO
           
static String SEVERITY_WARN
           
protected  Object source
           
protected  String summary
           
protected  String viewID
           
 
Constructor Summary
BaseErrorHandler()
          Default constructor.
 
Method Summary
protected static String formatMessage(String message, String parsedMessage)
          Helper method to format the Exception's error messages with a custom message.
 String getAction()
          How error should be handled.
 IErrorHandler getChainHandler()
          Returns chained error handler.
 String getDetails()
          Returns error details message as parsed from service exception or configured.
 String getErrorPage()
          Error page name when error handling action is set to BaseErrorHandler.ACTION_REDIRECT
 Exception getException()
          Returns the last error.
protected  FacesMessage.Severity getFacesSeverity()
          Return the current severity on this handler as a FacesMessage.
 String getSeverity()
          Returns message severity if message is reported through Faces Messages control on the page.
 Object getSource()
          Returns source object (service bean) for the last error.
 String getSummary()
          Returns error message summary as parsed from Exception or configured directly.
protected  void gotoPage(String page, boolean redirect)
          Switches to the specified view page.
protected  void handleError()
          Handle the error based on the action set on this handler.
 boolean handleError(Object source, Exception error)
          Handles service error based on the action set on this handler.
 boolean isHasError()
          Returns true if there was error handled by this handler instance.
protected  boolean parseError()
          Set the Summary and Details from the exception's cause.
 void reset()
          Reset state of the error handler.
 void returnBack()
          Redirects the page back to the original page, after showing error reporting page when error handler action is set to BaseErrorHandler.ACTION_REDIRECT
 void setAction(String action)
          Sets error handling action
 void setChainHandler(IErrorHandler handler)
          Sets chained error handler to delegate error handling to, if this handler fails to handle it.
 void setDetails(String details)
          Overrides error details message with custom value Set a custom message with formating to include the raw error message from the exception.
 void setErrorPage(String errorPage)
          Sets error page to redirect to when error happens and error handling action is set to BaseErrorHandler.ACTION_REDIRECT.
 void setSeverity(String severity)
          Sets message severity is message is reported through Faces Messages control on the page.
 void setSummary(String summary)
          Overrides error message summary with custom value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEVERITY_INFO

public static final String SEVERITY_INFO
See Also:
Constant Field Values

SEVERITY_WARN

public static final String SEVERITY_WARN
See Also:
Constant Field Values

SEVERITY_ERROR

public static final String SEVERITY_ERROR
See Also:
Constant Field Values

SEVERITY_FATAL

public static final String SEVERITY_FATAL
See Also:
Constant Field Values

ACTION_NONE

public static final String ACTION_NONE
Do not handle error, but just parse it. Error information may be displayed using custom methods, for example in the popup modal dialog. After display of an error it is advisable to reset error information in the handler

See Also:
Constant Field Values

ACTION_REPORT_SUMMARY

public static final String ACTION_REPORT_SUMMARY
Default handler behavior is to report error summary only

See Also:
Constant Field Values

ACTION_REPORT_DETAILS

public static final String ACTION_REPORT_DETAILS
Reports error details only

See Also:
Constant Field Values

ACTION_REPORT_SUMMARY_DETAILS

public static final String ACTION_REPORT_SUMMARY_DETAILS
Reports error summary and details details only

See Also:
Constant Field Values

ACTION_REDIRECT

public static final String ACTION_REDIRECT
Client browser is redirected to custom error handling page. This page may obtain error information from error handler bean if it was defined as session scoped JSF managed bean

See Also:
Constant Field Values

source

protected Object source

exception

protected Exception exception

parsedSummary

protected String parsedSummary

parsedDetails

protected String parsedDetails

summary

protected String summary

details

protected String details

severity

protected String severity

action

protected String action

errorPage

protected String errorPage

chainHandler

protected IErrorHandler chainHandler

viewID

protected String viewID
Constructor Detail

BaseErrorHandler

public BaseErrorHandler()
Default constructor. Initialize error handler by calling BaseErrorHandler.reset().

Method Detail

getSource

public Object getSource()
Returns source object (service bean) for the last error.

Specified by:
getSource in interface IErrorHandler
Returns:
Source object (service bean).

getException

public Exception getException()
Returns the last error.

Specified by:
getException in interface IErrorHandler
Returns:
Exception being handled.

getDetails

public String getDetails()
Returns error details message as parsed from service exception or configured.

Returns:
The formated details, if provided, otherwise the raw error message from the exception.

setDetails

public void setDetails(String details)
Overrides error details message with custom value Set a custom message with formating to include the raw error message from the exception. See MessageFormat.format( String, Object[])

Parameters:
details - A custom error message.

getSeverity

public String getSeverity()
Returns message severity if message is reported through Faces Messages control on the page.

Returns:
The message severity, will be one of these:BaseErrorHandler.SEVERITY_INFO, BaseErrorHandler.SEVERITY_WARN, BaseErrorHandler.SEVERITY_ERROR, or BaseErrorHandler.SEVERITY_FATAL.

setSeverity

public void setSeverity(String severity)
Sets message severity is message is reported through Faces Messages control on the page.

Parameters:
severity - The message severity, use BaseErrorHandler.SEVERITY_INFO, BaseErrorHandler.SEVERITY_WARN, BaseErrorHandler.SEVERITY_ERROR, or BaseErrorHandler.SEVERITY_FATAL.

getSummary

public String getSummary()
Returns error message summary as parsed from Exception or configured directly.

Returns:
A preset summary for this error handler. If none set then default to the parsed summary.

setSummary

public void setSummary(String summary)
Overrides error message summary with custom value.

Parameters:
summary - A preset summary for this error handler.

getAction

public String getAction()
How error should be handled.

Returns:
One of the Available actions.

setAction

public void setAction(String action)
Sets error handling action

Parameters:
action - One of the Available actions: BaseErrorHandler.ACTION_NONE, BaseErrorHandler.ACTION_REPORT_SUMMARY, BaseErrorHandler.ACTION_REPORT_DETAILS, BaseErrorHandler.ACTION_REPORT_SUMMARY_DETAILS and BaseErrorHandler.ACTION_REDIRECT.

getErrorPage

public String getErrorPage()
Error page name when error handling action is set to BaseErrorHandler.ACTION_REDIRECT

Returns:
The URI of the page, for example: /portlet1/mypage.view

setErrorPage

public void setErrorPage(String errorPage)
Sets error page to redirect to when error happens and error handling action is set to BaseErrorHandler.ACTION_REDIRECT.

Parameters:
errorPage - The URI of the page, for example: /portlet1/mypage.view

getChainHandler

public IErrorHandler getChainHandler()
Returns chained error handler. Chained error handler is delegated handling of the error in the case when this handler failed to handle it.

Returns:
The delegated handling of the error. if this handler failed to handle it.

setChainHandler

public void setChainHandler(IErrorHandler handler)
Sets chained error handler to delegate error handling to, if this handler fails to handle it.

Parameters:
handler - The to delegate error handling to.

handleError

public boolean handleError(Object source,
                           Exception error)
                    throws Exception
Handles service error based on the action set on this handler. If this handler does handle the error, it is passed to the the chain handler.

Specified by:
handleError in interface IErrorHandler
Parameters:
source - The source object that threw the exception.
error - The Exception to handle.
Returns:
True if error was handled by this handler, false otherwise.
Throws:
Exception

isHasError

public boolean isHasError()
Returns true if there was error handled by this handler instance.

Returns:
True if the exception was set on this handler. Otherwise false.

reset

public void reset()
Reset state of the error handler. This method is usually called by service provider before invoking any service method which may produce a handler error.

Specified by:
reset in interface IErrorHandler

returnBack

public void returnBack()
Redirects the page back to the original page, after showing error reporting page when error handler action is set to BaseErrorHandler.ACTION_REDIRECT


parseError

protected boolean parseError()
Set the Summary and Details from the exception's cause.

Returns:
True if error was successfully parsed. Otherwise false.
See Also:
Throwable.getCause()

handleError

protected void handleError()
                    throws Exception
Handle the error based on the action set on this handler. Available actions are BaseErrorHandler.ACTION_NONE, BaseErrorHandler.ACTION_REPORT_SUMMARY, BaseErrorHandler.ACTION_REPORT_DETAILS, BaseErrorHandler.ACTION_REPORT_SUMMARY_DETAILS and BaseErrorHandler.ACTION_REDIRECT.

Throws:
Exception

getFacesSeverity

protected FacesMessage.Severity getFacesSeverity()
Return the current severity on this handler as a FacesMessage.

Returns:
Current severity. Defaults to FacesMessage#SEVERITY_ERROR.

gotoPage

protected void gotoPage(String page,
                        boolean redirect)
Switches to the specified view page. If redirect is false it will simply change the faces context view root to the contents of the specified viewId. If redirect is true, it will redirect to the URL of the specified view. This method should be called inside an action method to set the page URI for the next rendering request.

Parameters:
page - The URI of the page, for example: /portlet1/mypage.view
redirect - True to redirect to the page, false to just change the FacesContext view root.

formatMessage

protected static String formatMessage(String message,
                                      String parsedMessage)
Helper method to format the Exception's error messages with a custom message.

Parameters:
message - The custom message format. See MessageFormat.format(String, Object[])
parsedMessage - The Exception message.
Returns:
The formated string.