1 17 package org.alfresco.web.app.context; 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.faces.context.FacesContext; 23 24 31 public final class UIContextService 32 { 33 36 private UIContextService() 37 { 38 } 39 40 45 public static UIContextService getInstance(FacesContext fc) 46 { 47 Map session = fc.getExternalContext().getSessionMap(); 48 UIContextService service = (UIContextService)session.get(CONTEXT_KEY); 49 if (service == null) 50 { 51 service = new UIContextService(); 52 session.put(CONTEXT_KEY, service); 53 } 54 55 return service; 56 } 57 58 63 public void registerBean(IContextListener bean) 64 { 65 if (bean == null) 66 { 67 throw new IllegalArgumentException ("Bean reference specified cannot be null!"); 68 } 69 70 this.registeredBeans.put(bean.getClass(), bean); 71 } 72 73 78 public void unregisterBean(IContextListener bean) 79 { 80 if (bean == null) 81 { 82 throw new IllegalArgumentException ("Bean reference specified cannot be null!"); 83 } 84 85 this.registeredBeans.remove(bean); 86 } 87 88 92 public void notifyBeans() 93 { 94 for (IContextListener listener: this.registeredBeans.values()) 95 { 96 listener.contextUpdated(); 97 } 98 } 99 100 101 102 private final static String CONTEXT_KEY = "__uiContextService"; 103 104 105 private Map <Class , IContextListener> registeredBeans = new HashMap <Class , IContextListener>(7, 1.0f); 106 } 107 | Popular Tags |