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.

VaadinPortletProvider.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2000-2016 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.osgi.liferay;
  17. import org.osgi.framework.BundleContext;
  18. import org.osgi.framework.ServiceObjects;
  19. import org.osgi.service.component.ComponentContext;
  20. import org.osgi.service.component.annotations.Activate;
  21. import org.osgi.service.component.annotations.Component;
  22. import org.osgi.service.component.annotations.Deactivate;
  23. import org.osgi.util.tracker.ServiceTracker;
  24. import com.vaadin.osgi.resources.OsgiVaadinResources;
  25. import com.vaadin.osgi.resources.VaadinResourceService;
  26. import com.vaadin.ui.UI;
  27. /**
  28. * Initializes a service tracker with {@link PortletUIServiceTrackerCustomizer}
  29. * to track {@link UI} service registrations.
  30. * <p>
  31. * This only applies to Liferay Portal 7+ with OSGi support.
  32. *
  33. * @author Sampsa Sohlman
  34. *
  35. * @since 8.1
  36. */
  37. @Component(immediate = true)
  38. public class VaadinPortletProvider {
  39. private ServiceTracker<UI, ServiceObjects<UI>> serviceTracker;
  40. private PortletUIServiceTrackerCustomizer portletUIServiceTrackerCustomizer;
  41. @Activate
  42. void activate(ComponentContext componentContext) throws Exception {
  43. BundleContext bundleContext = componentContext.getBundleContext();
  44. VaadinResourceService service = OsgiVaadinResources.getService();
  45. portletUIServiceTrackerCustomizer = new PortletUIServiceTrackerCustomizer(
  46. service);
  47. serviceTracker = new ServiceTracker<UI, ServiceObjects<UI>>(
  48. bundleContext, UI.class, portletUIServiceTrackerCustomizer);
  49. serviceTracker.open();
  50. }
  51. @Deactivate
  52. void deactivate() {
  53. if (serviceTracker != null) {
  54. serviceTracker.close();
  55. portletUIServiceTrackerCustomizer.cleanPortletRegistrations();
  56. portletUIServiceTrackerCustomizer = null;
  57. }
  58. }
  59. }