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.

ServiceInitEvent.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.ArrayList;
  18. import java.util.Collections;
  19. import java.util.EventObject;
  20. import java.util.List;
  21. import java.util.Objects;
  22. /**
  23. * Event fired to {@link VaadinServiceInitListener} when a {@link VaadinService}
  24. * is being initialized.
  25. * <p>
  26. * This event can also be used to add {@link RequestHandler}s that will be used
  27. * by the {@code VaadinService} for handling all requests.
  28. *
  29. * @since 8.0
  30. * @author Vaadin Ltd
  31. */
  32. public class ServiceInitEvent extends EventObject {
  33. private List<RequestHandler> addedRequestHandlers = new ArrayList<>();
  34. private List<DependencyFilter> addedDependencyFilters = new ArrayList<>();
  35. private List<ConnectorIdGenerator> addedConnectorIdGenerators = new ArrayList<>();
  36. /**
  37. * Creates a new service init event for a given {@link VaadinService} and
  38. * the {@link RequestHandler} that will be used by the service.
  39. *
  40. * @param service
  41. * the Vaadin service of this request
  42. */
  43. public ServiceInitEvent(VaadinService service) {
  44. super(service);
  45. }
  46. /**
  47. * Adds a new request handler that will be used by this service. The added
  48. * handler will be run before any of the framework's own request handlers,
  49. * but the ordering relative to other custom handlers is not guaranteed.
  50. *
  51. * @param requestHandler
  52. * the request handler to add, not <code>null</code>
  53. */
  54. public void addRequestHandler(RequestHandler requestHandler) {
  55. Objects.requireNonNull(requestHandler,
  56. "Request handler cannot be null");
  57. addedRequestHandlers.add(requestHandler);
  58. }
  59. /**
  60. * Gets an unmodifiable list of all custom request handlers that have been
  61. * added for the service.
  62. *
  63. * @return the current list of added request handlers
  64. */
  65. public List<RequestHandler> getAddedRequestHandlers() {
  66. return Collections.unmodifiableList(addedRequestHandlers);
  67. }
  68. /**
  69. * Adds a new dependency filter that will be used by this service.
  70. *
  71. * @param dependencyFilter
  72. * the dependency filter to add, not <code>null</code>
  73. *
  74. * @since 8.1
  75. */
  76. public void addDependencyFilter(DependencyFilter dependencyFilter) {
  77. Objects.requireNonNull(dependencyFilter,
  78. "Dependency filter cannot be null");
  79. addedDependencyFilters.add(dependencyFilter);
  80. }
  81. /**
  82. * Gets an unmodifiable list of all dependency filters that have been added
  83. * for the service.
  84. *
  85. * @return the current list of added dependency filters.
  86. *
  87. * @since 8.1
  88. */
  89. public List<DependencyFilter> getAddedDependencyFilters() {
  90. return Collections.unmodifiableList(addedDependencyFilters);
  91. }
  92. /**
  93. * Adds as connector id generator to be used by this service. By default,
  94. * the service will fail to deploy if more than one connector id generator
  95. * has been registered.
  96. *
  97. * @param connectorIdGenerator
  98. * the connector id generator to add, not <code>null</code>
  99. *
  100. * @since 8.1
  101. */
  102. public void addConnectorIdGenerator(
  103. ConnectorIdGenerator connectorIdGenerator) {
  104. Objects.requireNonNull(connectorIdGenerator,
  105. "Connector id generator cannot be null");
  106. /*
  107. * We're collecting all generators so that a custom service
  108. * implementation can pick which one to use even though the default
  109. * implementation throws if there are more than one.
  110. */
  111. addedConnectorIdGenerators.add(connectorIdGenerator);
  112. }
  113. /**
  114. * Gets an unmodifiable list of all connector id generators that have been
  115. * added for the service.
  116. *
  117. * @return the current list of added connector id generators
  118. *
  119. * @since 8.1
  120. */
  121. public List<ConnectorIdGenerator> getAddedConnectorIdGenerators() {
  122. return Collections.unmodifiableList(addedConnectorIdGenerators);
  123. }
  124. @Override
  125. public VaadinService getSource() {
  126. return (VaadinService) super.getSource();
  127. }
  128. }