1 5 package org.exoplatform.faces; 6 7 import java.util.HashMap ; 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 17 public class ActionListenerManager extends HashMap { 18 private boolean cacheActionListener_ ; 19 20 public ActionListenerManager(ConfigurationManager manager) throws Exception { 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 clazz, String actionToListen) { 31 if(!cacheActionListener_) return createListener(clazz, actionToListen) ; 32 String 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 clazz, String actionToListen) { 43 try { 44 ExoActionListener result = (ExoActionListener) clazz.newInstance() ; 45 result.init() ; 46 result.setActionToListen(actionToListen) ; 47 return result ; 48 } catch (Exception ex) { 49 ex.printStackTrace() ; 50 } 51 return null ; 52 } 53 } | Popular Tags |