View Javadoc

1   /*
2    * $Id: ClientStorageManager.java,v 1.1 2007/03/23 16:26:33 oeuillot Exp $
3    */
4   package org.rcfaces.core.util;
5   
6   import java.util.Map;
7   
8   import javax.faces.context.ExternalContext;
9   import javax.faces.context.FacesContext;
10  
11  import org.rcfaces.core.internal.Constants;
12  import org.rcfaces.core.internal.lang.ClientStorage;
13  import org.rcfaces.core.lang.IClientStorage;
14  
15  /**
16   * 
17   * @author Olivier Oeuillot (latest modification by $Author: oeuillot $)
18   * @version $Revision: 1.1 $ $Date: 2007/03/23 16:26:33 $
19   */
20  public class ClientStorageManager {
21      private static final String REVISION = "$Revision: 1.1 $";
22  
23      private static final String CLIENT_STORAGE_PROPERTY = Constants
24              .getPackagePrefix()
25              + ".CLIENT_STORAGE";
26  
27      public static IClientStorage get(FacesContext facesContext, boolean create) {
28  
29          ExternalContext externalContext = facesContext.getExternalContext();
30  
31          if (externalContext.getSession(create) == null) {
32              return null;
33          }
34  
35          Map sessionMap = externalContext.getSessionMap();
36  
37          IClientStorage clientStorage = (IClientStorage) sessionMap
38                  .get(CLIENT_STORAGE_PROPERTY);
39  
40          if (clientStorage != null) {
41              return clientStorage;
42          }
43  
44          clientStorage = new ClientStorage();
45          sessionMap.put(CLIENT_STORAGE_PROPERTY, clientStorage);
46  
47          return clientStorage;
48      }
49  }