KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > ActionListenerManager


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;
6
7 import java.util.HashMap JavaDoc;
8 import org.exoplatform.container.configuration.ConfigurationManager;
9 import org.exoplatform.container.configuration.ServiceConfiguration;
10 import org.exoplatform.container.configuration.ValueParam;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 /**
13  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
14  * @since Aug 13, 2004
15  * @version $Id: ActionListenerManager.java,v 1.3 2004/09/09 03:22:19 tuan08 Exp $
16  */

17 public class ActionListenerManager extends HashMap JavaDoc {
18   private boolean cacheActionListener_ ;
19   
20   public ActionListenerManager(ConfigurationManager manager) throws Exception JavaDoc {
21     ServiceConfiguration sconf = manager.getServiceConfiguration(getClass()) ;
22     ValueParam param = sconf.getValueParam("cache.action.listener") ;
23     if(param != null) {
24       cacheActionListener_ = "true".equals(param.getValue()) ;
25     } else {
26       cacheActionListener_ = false ;
27     }
28   }
29   
30   public ExoActionListener getActionListener(Class JavaDoc clazz, String JavaDoc actionToListen) {
31     if(!cacheActionListener_) return createListener(clazz, actionToListen) ;
32     String JavaDoc key = actionToListen + "#" + clazz.getName() ;
33     ExoActionListener result = (ExoActionListener) get(key) ;
34     if(result != null) return result ;
35     synchronized (this) {
36       result = createListener(clazz, actionToListen) ;
37       put(key, result) ;
38     }
39     return result ;
40   }
41   
42   private ExoActionListener createListener(Class JavaDoc clazz, String JavaDoc actionToListen) {
43     try {
44       ExoActionListener result = (ExoActionListener) clazz.newInstance() ;
45       result.init() ;
46       result.setActionToListen(actionToListen) ;
47       return result ;
48     } catch (Exception JavaDoc ex) {
49       ex.printStackTrace() ;
50     }
51     return null ;
52   }
53 }
Popular Tags