You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebApplicationContext.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.server;
  5. import java.io.File;
  6. import javax.servlet.http.HttpSession;
  7. import javax.servlet.http.HttpSessionBindingListener;
  8. import com.vaadin.Application;
  9. /**
  10. * Web application context for Vaadin applications.
  11. *
  12. * This is automatically added as a {@link HttpSessionBindingListener} when
  13. * added to a {@link HttpSession}.
  14. *
  15. * @author IT Mill Ltd.
  16. * @version
  17. * @VERSION@
  18. * @since 3.1
  19. */
  20. @SuppressWarnings("serial")
  21. public class WebApplicationContext extends AbstractWebApplicationContext {
  22. protected transient HttpSession session;
  23. /**
  24. * Creates a new Web Application Context.
  25. *
  26. */
  27. WebApplicationContext() {
  28. }
  29. /**
  30. * Gets the application context base directory.
  31. *
  32. * @see com.vaadin.service.ApplicationContext#getBaseDirectory()
  33. */
  34. public File getBaseDirectory() {
  35. final String realPath = ApplicationServlet.getResourcePath(
  36. session.getServletContext(), "/");
  37. if (realPath == null) {
  38. return null;
  39. }
  40. return new File(realPath);
  41. }
  42. /**
  43. * Gets the http-session application is running in.
  44. *
  45. * @return HttpSession this application context resides in.
  46. */
  47. public HttpSession getHttpSession() {
  48. return session;
  49. }
  50. /**
  51. * Gets the application context for an HttpSession.
  52. *
  53. * @param session
  54. * the HTTP session.
  55. * @return the application context for HttpSession.
  56. */
  57. static public WebApplicationContext getApplicationContext(
  58. HttpSession session) {
  59. WebApplicationContext cx = (WebApplicationContext) session
  60. .getAttribute(WebApplicationContext.class.getName());
  61. if (cx == null) {
  62. cx = new WebApplicationContext();
  63. session.setAttribute(WebApplicationContext.class.getName(), cx);
  64. }
  65. if (cx.session == null) {
  66. cx.session = session;
  67. }
  68. return cx;
  69. }
  70. protected void addApplication(Application application) {
  71. applications.add(application);
  72. }
  73. /**
  74. * Gets communication manager for an application.
  75. *
  76. * If this application has not been running before, a new manager is
  77. * created.
  78. *
  79. * @param application
  80. * @return CommunicationManager
  81. */
  82. protected CommunicationManager getApplicationManager(
  83. Application application, AbstractApplicationServlet servlet) {
  84. CommunicationManager mgr = (CommunicationManager) applicationToAjaxAppMgrMap
  85. .get(application);
  86. if (mgr == null) {
  87. // Creates new manager
  88. mgr = new CommunicationManager(application, servlet);
  89. applicationToAjaxAppMgrMap.put(application, mgr);
  90. }
  91. return mgr;
  92. }
  93. }