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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.util.EventObject;
  18. import com.vaadin.Application;
  19. import com.vaadin.UIRequiresMoreInformationException;
  20. import com.vaadin.ui.UI;
  21. /**
  22. * Base class providing common functionality used in different bootstrap
  23. * modification events.
  24. *
  25. * @author Vaadin Ltd
  26. * @since 7.0.0
  27. */
  28. public abstract class BootstrapResponse extends EventObject {
  29. private final WrappedRequest request;
  30. private final Application application;
  31. private final Integer uiId;
  32. /**
  33. * Creates a new bootstrap event.
  34. *
  35. * @param handler
  36. * the bootstrap handler that is firing the event
  37. * @param request
  38. * the wrapped request for which the bootstrap page should be
  39. * generated
  40. * @param application
  41. * the application for which the bootstrap page should be
  42. * generated
  43. * @param uiId
  44. * the generated id of the UI that will be displayed on the page
  45. */
  46. public BootstrapResponse(BootstrapHandler handler, WrappedRequest request,
  47. Application application, Integer uiId) {
  48. super(handler);
  49. this.request = request;
  50. this.application = application;
  51. this.uiId = uiId;
  52. }
  53. /**
  54. * Gets the bootstrap handler that fired this event
  55. *
  56. * @return the bootstrap handler that fired this event
  57. */
  58. public BootstrapHandler getBootstrapHandler() {
  59. return (BootstrapHandler) getSource();
  60. }
  61. /**
  62. * Gets the request for which the generated bootstrap HTML will be the
  63. * response. This can be used to read request headers and other additional
  64. * information. Please note that {@link WrappedRequest#getBrowserDetails()}
  65. * will not be available because the bootstrap page is generated before the
  66. * bootstrap javascript has had a chance to send any information back to the
  67. * server.
  68. *
  69. * @return the wrapped request that is being handled
  70. */
  71. public WrappedRequest getRequest() {
  72. return request;
  73. }
  74. /**
  75. * Gets the application to which the rendered view belongs.
  76. *
  77. * @return the application
  78. */
  79. public Application getApplication() {
  80. return application;
  81. }
  82. /**
  83. * Gets the UI id that has been generated for this response. Please note
  84. * that if {@link Application#isUiPreserved()} is enabled, a previously
  85. * created UI with a different id might eventually end up being used.
  86. *
  87. * @return the UI id
  88. */
  89. public Integer getUIId() {
  90. return uiId;
  91. }
  92. /**
  93. * Gets the UI for which this page is being rendered, if available. Some
  94. * features of the framework will postpone the UI selection until after the
  95. * bootstrap page has been rendered and required information from the
  96. * browser has been sent back. This method will return <code>null</code> if
  97. * no UI instance is yet available.
  98. *
  99. * @see Application#isUiPreserved()
  100. * @see Application#getUI(WrappedRequest)
  101. * @see UIRequiresMoreInformationException
  102. *
  103. * @return The UI that will be displayed in the page being generated, or
  104. * <code>null</code> if all required information is not yet
  105. * available.
  106. */
  107. public UI getUI() {
  108. return UI.getCurrent();
  109. }
  110. }