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.

BootstrapResponse.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.server;
  5. import java.util.EventObject;
  6. import com.vaadin.Application;
  7. import com.vaadin.RootRequiresMoreInformationException;
  8. import com.vaadin.terminal.WrappedRequest;
  9. import com.vaadin.ui.Root;
  10. /**
  11. * Base class providing common functionality used in different bootstrap
  12. * modification events.
  13. *
  14. * @author Vaadin Ltd
  15. * @since 7.0.0
  16. */
  17. public abstract class BootstrapResponse extends EventObject {
  18. private final WrappedRequest request;
  19. private final Application application;
  20. private final Integer rootId;
  21. /**
  22. * Creates a new bootstrap event.
  23. *
  24. * @param handler
  25. * the bootstrap handler that is firing the event
  26. * @param request
  27. * the wrapped request for which the bootstrap page should be
  28. * generated
  29. * @param application
  30. * the application for which the bootstrap page should be
  31. * generated
  32. * @param rootId
  33. * the generated id of the Root that will be displayed on the
  34. * page
  35. */
  36. public BootstrapResponse(BootstrapHandler handler, WrappedRequest request,
  37. Application application, Integer rootId) {
  38. super(handler);
  39. this.request = request;
  40. this.application = application;
  41. this.rootId = rootId;
  42. }
  43. /**
  44. * Gets the bootstrap handler that fired this event
  45. *
  46. * @return the bootstrap handler that fired this event
  47. */
  48. public BootstrapHandler getBootstrapHandler() {
  49. return (BootstrapHandler) getSource();
  50. }
  51. /**
  52. * Gets the request for which the generated bootstrap HTML will be the
  53. * response. This can be used to read request headers and other additional
  54. * information. Please note that {@link WrappedRequest#getBrowserDetails()}
  55. * will not be available because the bootstrap page is generated before the
  56. * bootstrap javascript has had a chance to send any information back to the
  57. * server.
  58. *
  59. * @return the wrapped request that is being handled
  60. */
  61. public WrappedRequest getRequest() {
  62. return request;
  63. }
  64. /**
  65. * Gets the application to which the rendered view belongs.
  66. *
  67. * @return the application
  68. */
  69. public Application getApplication() {
  70. return application;
  71. }
  72. /**
  73. * Gets the root id that has been generated for this response. Please note
  74. * that if {@link Application#isRootPreserved()} is enabled, a previously
  75. * created Root with a different id might eventually end up being used.
  76. *
  77. * @return the root id
  78. */
  79. public Integer getRootId() {
  80. return rootId;
  81. }
  82. /**
  83. * Gets the Root for which this page is being rendered, if available. Some
  84. * features of the framework will postpone the Root selection until after
  85. * the bootstrap page has been rendered and required information from the
  86. * browser has been sent back. This method will return <code>null</code> if
  87. * no Root instance is yet available.
  88. *
  89. * @see Application#isRootPreserved()
  90. * @see Application#getRoot(WrappedRequest)
  91. * @see RootRequiresMoreInformationException
  92. *
  93. * @return The Root that will be displayed in the page being generated, or
  94. * <code>null</code> if all required information is not yet
  95. * available.
  96. */
  97. public Root getRoot() {
  98. return Root.getCurrent();
  99. }
  100. }