FileDocCategorySizeDatePackage
ErrorCodeExceptionHandler.javaAPI DocExample1927Sat Aug 14 11:46:12 BST 2004com.oreilly.strutsckbk.ch09

ErrorCodeExceptionHandler

public class ErrorCodeExceptionHandler extends org.apache.struts.action.ExceptionHandler

Fields Summary
Constructors Summary
Methods Summary
public org.apache.struts.action.ActionForwardexecute(java.lang.Exception ex, org.apache.struts.config.ExceptionConfig ae, org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm formInstance, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        
        if (!(ex instanceof ErrorCodeException)) {
            return super.execute(ex, ae, mapping, formInstance, request, response);
        }
        
        ErrorCodeException errCodeEx =(ErrorCodeException) ex;
        ActionForward forward = null;
        ActionMessage error = null;
        String property = null;

        // Build the forward from the exception mapping if it exists
        // or from the form input
        if (ae.getPath() != null) {
            forward = new ActionForward(ae.getPath());
        } else {
            forward = mapping.getInputForward();
        }

        ErrorCodeException ece =(ErrorCodeException) ex;
        String code = Integer.toString(ece.getCode());
        error = new ActionMessage(code, ece.getArgs());
        property = error.getKey();

        logException(ex);

        // Store the exception
        request.setAttribute(Globals.EXCEPTION_KEY, ex);
        storeException(request, property, error, forward, ae.getScope());

        return forward;