KickJava   Java API By Example, From Geeks To Geeks.

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


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.UniqueObjectException;
11 import org.exoplatform.faces.core.Util;
12 import org.exoplatform.faces.core.component.InformationProvider;
13 /**
14  * Jun 3, 2004
15  * @author: Tuan Nguyen
16  * @email: tuan08@users.sourceforge.net
17  * @version: $ID$
18  **/

19 public class UniqueObjectExceptionHandler extends ExceptionHandler {
20   public boolean showStackTrace_ = false ;
21   
22     public UniqueObjectExceptionHandler() {
23   }
24   
25   public UniqueObjectExceptionHandler setShowStackTrace(boolean b) {
26     showStackTrace_ = b ;
27     return this ;
28   }
29   
30   public boolean canHandleError(Throwable JavaDoc error) {
31     return error instanceof UniqueObjectException ;
32   }
33   
34     public void handle(ExoActionEvent action, Throwable JavaDoc error) {
35     UniqueObjectException ex = (UniqueObjectException) error ;
36     UIComponent src = action.getComponent() ;
37     InformationProvider iprovider = Util.findInformationProvider(src) ;
38     if(iprovider != null) {
39       ResourceBundle JavaDoc res = Util.getApplicationResourceBundle() ;
40       String JavaDoc messageKey = ex.getMessageKey() ;
41       String JavaDoc message = this.getResource(res, messageKey) ;
42       if(message == null) {
43         message = "No explaination is found for the key: " + messageKey ;
44       }
45       iprovider.addMessage(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, ex.getExceptionDescription())) ;
46       iprovider.setDisplayMessageType(InformationProvider.FOOTER_MESSAGE_TYPE) ;
47     }
48     }
49 }
Popular Tags