KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > event > MessageExceptionHandler


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.core.event;
6
7 import java.util.ResourceBundle JavaDoc;
8 import javax.faces.application.FacesMessage;
9 import javax.faces.component.UIComponent;
10 import org.exoplatform.commons.exception.ExoMessageException;
11 import org.exoplatform.commons.utils.ExceptionUtil;
12 import org.exoplatform.faces.application.ExoFacesMessage;
13 import org.exoplatform.faces.core.Util;
14 import org.exoplatform.faces.core.component.InformationProvider;
15 /**
16  * Jun 3, 2004
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $ID$
20  **/

21 public class MessageExceptionHandler extends ExceptionHandler {
22   
23     public MessageExceptionHandler() {
24   }
25   
26   public boolean canHandleError(Throwable JavaDoc error) {
27     return error instanceof ExoMessageException ;
28   }
29   
30     public void handle(ExoActionEvent action, Throwable JavaDoc error) {
31     ExoMessageException ex = (ExoMessageException) error ;
32     UIComponent src = action.getComponent() ;
33     InformationProvider iprovider = Util.findInformationProvider(src) ;
34     if(iprovider != null) {
35       ResourceBundle JavaDoc res = Util.getApplicationResourceBundle() ;
36       String JavaDoc message = ex.getMessage(res) ;
37       String JavaDoc stackTrace = null ;
38       if(ex.getSeverity() <= ExoMessageException.WARN) {
39         stackTrace = ExceptionUtil.getStackTrace(new Exception JavaDoc(), 3) ;
40       }
41       iprovider.addMessage(new ExoFacesMessage(FacesMessage.SEVERITY_ERROR, message, stackTrace, ex.getArguments())) ;
42       if(ex.getSeverity() <= ExoMessageException.WARN) {
43         iprovider.setDisplayMessageType(InformationProvider.BODY_MESSAGE_TYPE) ;
44       } else {
45         iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ;
46       }
47     } else {
48       //System.out.println(ExceptionUtil.getExoStackTrace(error)) ;
49
}
50     }
51 }
Popular Tags