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.

OsgiVaadinResources.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.resources;
  17. import org.osgi.framework.BundleActivator;
  18. import org.osgi.framework.BundleContext;
  19. import org.osgi.framework.Version;
  20. import com.vaadin.osgi.resources.impl.VaadinResourceServiceImpl;
  21. /**
  22. * {@link BundleActivator} used to provide access to the
  23. * {@link VaadinResourceService} singleton for publishing themes, widgetsets and
  24. * other necessary resources.
  25. *
  26. * @author Vaadin Ltd.
  27. *
  28. * @since 8.1
  29. */
  30. public class OsgiVaadinResources implements BundleActivator {
  31. /**
  32. * Thrown if a method is called when the Resource bundle is not active.
  33. *
  34. * @author Vaadin Ltd.
  35. *
  36. * @since 8.1
  37. */
  38. @SuppressWarnings("serial")
  39. public static class ResourceBundleInactiveException extends Exception {
  40. public ResourceBundleInactiveException(String message) {
  41. super(message);
  42. }
  43. }
  44. private static OsgiVaadinResources instance;
  45. private VaadinResourceServiceImpl service;
  46. private Version version;
  47. /**
  48. * Returns the {@link VaadinResourceService} instance. Always returns
  49. * non-null.
  50. *
  51. * @return the {@link VaadinResourceService resource service} to use for
  52. * publishing themes, widgetsets and other necessary resources
  53. * @throws ResourceBundleInactiveException
  54. * if the bundle is not active
  55. */
  56. public static VaadinResourceService getService()
  57. throws ResourceBundleInactiveException {
  58. if (instance == null) {
  59. throw new ResourceBundleInactiveException(
  60. "Vaadin Shared is not active!");
  61. }
  62. return instance.service;
  63. }
  64. @Override
  65. public void start(BundleContext context) throws Exception {
  66. version = context.getBundle().getVersion();
  67. service = new VaadinResourceServiceImpl();
  68. service.setBundleVersion(version.toString());
  69. instance = this;
  70. }
  71. @Override
  72. public void stop(BundleContext context) throws Exception {
  73. instance = null;
  74. service = null;
  75. version = null;
  76. }
  77. }