KickJava   Java API By Example, From Geeks To Geeks.

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


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.* ;
8
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ExternalContext;
12 import javax.faces.event.AbortProcessingException;
13 import javax.faces.event.ActionEvent;
14 import javax.faces.event.ActionListener;
15 import org.exoplatform.Constants;
16 import org.exoplatform.faces.context.PortletExternalContext;
17 import org.exoplatform.faces.core.Util;
18 import org.exoplatform.faces.core.component.InformationProvider;
19
20 /**
21  * Apr 17, 2004
22  * @author: Tuan Nguyen
23  * @email: tuan08@users.sourceforge.net
24  * @version: $Id: ExoActionListener.java,v 1.15 2004/10/21 15:24:26 tuan08 Exp $
25  **/

26 abstract public class ExoActionListener implements ActionListener {
27   private static List exceptionHandlers_ ;
28   static {
29     exceptionHandlers_ = new ArrayList(10);
30     exceptionHandlers_.add(new UniqueObjectExceptionHandler()) ;
31     exceptionHandlers_.add(new MessageExceptionHandler()) ;
32     exceptionHandlers_.add(new PermissionExceptionHandler()) ;
33     exceptionHandlers_.add(new FatalExceptionHandler()) ;
34   }
35   
36   private List interceptors_ ;
37   private String JavaDoc action_ ;
38   
39   public ExoActionListener() { }
40   
41   public void init() { }
42   
43   public ExoActionListener setActionToListen(String JavaDoc action) {
44     action_ = action ;
45     return this ;
46   }
47   
48   public String JavaDoc getActionName() { return action_ ; }
49   
50   final public void processAction(ActionEvent action) throws AbortProcessingException {
51     throw new AbortProcessingException("Use processAction(ExoActionEvent action)") ;
52   }
53   
54   public boolean canHandleAction(String JavaDoc action) {
55     return action_.equals(action) ;
56   }
57   
58   final public void processAction(ExoActionEvent action) throws AbortProcessingException {
59     try {
60       //execute interceptor , pre execute
61
if(interceptors_ != null) {
62         for(int i = 0; i < interceptors_.size(); i++) {
63           ActionInterceptor interceptor = (ActionInterceptor) interceptors_.get(i) ;
64           interceptor.preExecute(action) ;
65         }
66       }
67       execute(action) ;
68       //execute interceptor , post execute
69
if(interceptors_ != null) {
70         for(int i = 0; i < interceptors_.size(); i++) {
71           ActionInterceptor interceptor = (ActionInterceptor) interceptors_.get(i) ;
72           interceptor.preExecute(action) ;
73         }
74       }
75     } catch (Exception JavaDoc ex) {
76       ExceptionHandler handler = null;
77       for (int i = 0; i < exceptionHandlers_.size(); i++) {
78         ExceptionHandler eh = (ExceptionHandler) exceptionHandlers_.get(i) ;
79         if(eh.canHandleError(ex)) {
80           handler = eh ;
81           break ;
82         }
83       }
84       handler.handle(action, ex) ;
85     }
86     postExecute(action) ;
87   }
88   
89   protected void postExecute(ExoActionEvent action) {
90     FacesContext.getCurrentInstance().renderResponse() ;
91   }
92   
93   abstract public void execute(ExoActionEvent event) throws Exception JavaDoc ;
94   
95   public ExoActionListener addInterceptor(ActionInterceptor interceptor) {
96     if(interceptors_ == null) {
97       interceptors_ = new ArrayList(3) ;
98     }
99     interceptors_.add(interceptor) ;
100     return this ;
101   }
102   
103   protected String JavaDoc getResourceBaseName() {
104     String JavaDoc baseName = getClass().getName() ;
105     int idx = baseName.lastIndexOf('.') ;
106     baseName = baseName.substring(idx + 1, baseName.length()) ;
107     baseName = baseName.replace('$', '.') ;
108     return baseName ;
109   }
110   
111   public ResourceBundle getApplicationResourceBundle() {
112     ExternalContext eContext = FacesContext.getCurrentInstance().getExternalContext() ;
113     if(eContext instanceof PortletExternalContext) {
114       PortletExternalContext impl = (PortletExternalContext) eContext ;
115       return impl.getApplicationResourceBundle() ;
116     }
117     return (ResourceBundle)eContext.getRequestMap().get(Constants.APPLICATION_RESOURCE) ;
118   }
119   
120   protected InformationProvider findInformationProvider(UIComponent src) {
121     return Util.findInformationProvider(src) ;
122   }
123 }
124
Popular Tags