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 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2000-2018 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.shared.VaadinUriResolver;
  19. import com.vaadin.ui.UI;
  20. /**
  21. * Base class providing common functionality used in different bootstrap
  22. * modification events.
  23. *
  24. * @author Vaadin Ltd
  25. * @since 7.0.0
  26. */
  27. public abstract class BootstrapResponse extends EventObject {
  28. private final VaadinRequest request;
  29. private final VaadinSession session;
  30. private final Class<? extends UI> uiClass;
  31. private final UIProvider uiProvider;
  32. private VaadinUriResolver uriResolver;
  33. /**
  34. * Creates a new bootstrap event.
  35. *
  36. * @param handler
  37. * the bootstrap handler that is firing the event
  38. * @param request
  39. * the Vaadin request for which the bootstrap page should be
  40. * generated
  41. * @param session
  42. * the session for which the bootstrap page should be generated
  43. * @param uiClass
  44. * the class of the UI that will be displayed on the page
  45. * @param uiProvider
  46. * the UI provider for the bootstrap
  47. */
  48. public BootstrapResponse(BootstrapHandler handler, VaadinRequest request,
  49. VaadinSession session, Class<? extends UI> uiClass,
  50. UIProvider uiProvider) {
  51. super(handler);
  52. this.request = request;
  53. this.session = session;
  54. this.uiClass = uiClass;
  55. this.uiProvider = uiProvider;
  56. }
  57. /**
  58. * Gets the bootstrap handler that fired this event.
  59. *
  60. * @return the bootstrap handler that fired this event
  61. */
  62. public BootstrapHandler getBootstrapHandler() {
  63. return (BootstrapHandler) getSource();
  64. }
  65. /**
  66. * Gets the request for which the generated bootstrap HTML will be the
  67. * response.
  68. *
  69. * This can be used to read request headers and other additional
  70. * information. Please note that {@link VaadinSession#getBrowser()} will not
  71. * be available because the bootstrap page is generated before the bootstrap
  72. * javascript has had a chance to send any information back to the server.
  73. *
  74. * @return the Vaadin request that is being handled
  75. */
  76. public VaadinRequest getRequest() {
  77. return request;
  78. }
  79. /**
  80. * Gets the service session to which the rendered view belongs.
  81. *
  82. * @return the Vaadin service session
  83. */
  84. public VaadinSession getSession() {
  85. return session;
  86. }
  87. /**
  88. * Gets the class of the UI that will be displayed on the generated
  89. * bootstrap page.
  90. *
  91. * @return the class of the UI
  92. */
  93. public Class<? extends UI> getUiClass() {
  94. return uiClass;
  95. }
  96. /**
  97. * Gets the UI provider that is used to provide information about the
  98. * bootstrapped UI.
  99. *
  100. * @return the UI provider
  101. */
  102. public UIProvider getUIProvider() {
  103. return uiProvider;
  104. }
  105. /**
  106. * Sets the URI resolver used in the bootstrap process.
  107. *
  108. * @param uriResolver
  109. * the uri resolver which is used
  110. * @since 8.1
  111. */
  112. public void setUriResolver(VaadinUriResolver uriResolver) {
  113. assert this.uriResolver == null : "URI resolver should never be changed";
  114. assert uriResolver != null : "URI resolver should never be null";
  115. this.uriResolver = uriResolver;
  116. }
  117. /**
  118. * Gets the URI resolver used in the bootstrap process.
  119. *
  120. * @return the URI resolver
  121. * @since 8.1
  122. */
  123. public VaadinUriResolver getUriResolver() {
  124. return uriResolver;
  125. }
  126. }