4A Server -  2.0
 All Classes Namespaces Files Functions Variables Enumerator
SessionManager.java
Go to the documentation of this file.
1 /*
2  * Project: Server for annotations sharing
3  * Author: Ing. Jaroslav Dytrych idytrych@fit.vutbr.cz
4  * File: SessionManager.java
5  * Description: Class for manipulating with session
6  */
7 
8 /**
9  * @file SessionManager.java
10  *
11  * @brief Class for manipulating with session
12  */
13 
14 package cz.vutbr.fit.knot.annotations.web;
15 
16 import javax.el.ExpressionFactory;
17 import javax.el.ValueExpression;
18 import javax.faces.context.FacesContext;
19 import javax.servlet.http.HttpSession;
20 
21 /**
22  * Class for manipulating with session
23  *
24  * @brief Class for manipulating with session
25  * @author idytrych
26  */
27 public class SessionManager {
28 
29  /**
30  * Constructor
31  */
32  public SessionManager() {
33  }
34 
35  /**
36  * Gets instance of object for handling custom session variables
37  *
38  * @return Returns instance of object for handling custom session variables
39  */
40  public static WebSession getSession() {
41  FacesContext facesContext = FacesContext.getCurrentInstance();
42  HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
43  WebSession webSession = (WebSession) session.getAttribute("WebSession");
44  if (webSession == null) {
45  webSession = new WebSession();
46  session.setAttribute("WebSession", webSession);
47  }
48  return webSession;
49  }
50 
51  /**
52  * Gets instance of other session scoped bean
53  *
54  * @param name Name of bean
55  * @return Instance of session scoped bean
56  */
57  public static Object getBeanByName(String name) {
58  FacesContext context = FacesContext.getCurrentInstance();
59  ExpressionFactory ef = context.getApplication().getExpressionFactory();
60  ValueExpression ve = ef.createValueExpression(context.getELContext(), "#{" + name + "}", Object.class);
61  return ve.getValue(context.getELContext());
62  }
63 
64 } // public class SessionManager
Class for manipulating with session.
Class for handling session variables in the web.
Definition: WebSession.java:37