- Rename OSGi to Osgi in class names.
- Rename VaadinOSGiPortlet to OSGiVaadinPortlet for consistency with
Spring, CDI etc. add-ons
- Add missing javadoc
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
@Component(immediate = true)
@Activate
void startup(ComponentContext context) throws Exception {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
service.publishWidgetset(WIDGETSET_NAME, httpService);
}
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
@Component(immediate = true)
@Activate
void startup(ComponentContext context) throws Exception {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
service.publishWidgetset(WIDGETSET_NAME, httpService);
}
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
@Component(immediate = true)
@Activate
void startup() throws Exception {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
for (String themeName : LEGACY_THEMES) {
service.publishTheme(themeName, httpService);
}
Vaadin Framework 8.1 and later versions provide two supported ways of publishing static resources for OSGi: by making OSGi services implementing an interface or by explicit calls to a service.
-The easiest way to publish a theme or a widgetset is to create a class implementing the interface [interfacename]#OSGiVaadinTheme# or [interfacename]#OSGiVaadinWidgetset# and annotating it with [interfacename]#@Component# to make it an OSGi service. This automatically publishes the theme or the widget set from the bundle at a path that contains the Vaadin Framework version used by the application.
+The easiest way to publish a theme or a widgetset is to create a class implementing the interface [interfacename]#OsgiVaadinTheme# or [interfacename]#OsgiVaadinWidgetset# and annotating it with [interfacename]#@Component# to make it an OSGi service. This automatically publishes the theme or the widget set from the bundle at a path that contains the Vaadin Framework version used by the application.
[source, java]
----
@Component
-public class MyTheme extends ValoTheme implements OSGiVaadinTheme {
+public class MyTheme extends ValoTheme implements OsgiVaadinTheme {
public static final String THEME_NAME = "mytheme";
@Override
}
----
-Alternatively, an OSGi bundle activator or an SCR Component [interfacename]#@Activate# method can obtain an instance of [classname]#VaadinResourceService# from [classname]#OSGiVaadinResources# and explicitly call its methods to publish a theme, a widget set or an individual file in the bundle as a static resource at the correct path.
+Alternatively, an OSGi bundle activator or an SCR Component [interfacename]#@Activate# method can obtain an instance of [classname]#VaadinResourceService# from [classname]#OsgiVaadinResources# and explicitly call its methods to publish a theme, a widget set or an individual file in the bundle as a static resource at the correct path.
[source, java]
----
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
service.publishTheme("mytheme", httpService);
----
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.osgi.liferay;
-
-import org.osgi.framework.ServiceObjects;
-
-import com.vaadin.server.UIClassSelectionEvent;
-import com.vaadin.server.UIProvider;
-import com.vaadin.ui.UI;
-
-/**
- * Vaadin {@link com.vaadin.server.UIProvider} that provides a single {@link UI}
- * class provided through the registration of a {@link UI} as an OSGi service.
- * <p>
- * This only applies to Liferay Portal 7+ with OSGi support.
- *
- * @author Sampsa Sohlman
- *
- * @since 8.1
- */
-@SuppressWarnings("serial")
-public class OSGiUIProvider extends UIProvider {
- private Class<UI> uiClass;
-
- @SuppressWarnings("unchecked")
- public OSGiUIProvider(ServiceObjects<UI> serviceObjects) {
- super();
- UI ui = serviceObjects.getService();
- uiClass = (Class<UI>) ui.getClass();
- serviceObjects.ungetService(ui);
- }
-
- @Override
- public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
- return uiClass;
- }
-
- public String getDefaultPortletName() {
- return uiClass.getName();
- }
-
- public String getDefaultDisplayName() {
- return uiClass.getSimpleName();
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.osgi.liferay;
-
-import com.vaadin.server.DeploymentConfiguration;
-import com.vaadin.server.ServiceException;
-import com.vaadin.server.VaadinPortlet;
-import com.vaadin.server.VaadinPortletService;
-import com.vaadin.server.VaadinPortletSession;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.server.VaadinSession;
-import com.vaadin.ui.UI;
-
-/**
- * {@link VaadinPortletService} class that uses the {@link OSGiUIProvider} to
- * configure the {@link UI} class for a {@link VaadinPortlet}.
- * <p>
- * This only applies to Liferay Portal 7+ with OSGi support.
- *
- * @author Sampsa Sohlman
- *
- * @since 8.1
- */
-@SuppressWarnings("serial")
-public class OSGiVaadinPortletService extends VaadinPortletService {
- private OSGiUIProvider osgiUIProvider;
-
- public OSGiVaadinPortletService(VaadinPortlet portlet,
- DeploymentConfiguration deploymentConfiguration,
- OSGiUIProvider osgiUIProvider) throws ServiceException {
-
- super(portlet, deploymentConfiguration);
- this.osgiUIProvider = osgiUIProvider;
- }
-
- @Override
- protected VaadinSession createVaadinSession(VaadinRequest request)
- throws ServiceException {
-
- VaadinSession vaadinSession = new VaadinPortletSession(this);
- vaadinSession.addUIProvider(osgiUIProvider);
-
- return vaadinSession;
- }
-
-}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.osgi.liferay;
+
+import org.osgi.framework.ServiceObjects;
+
+import com.vaadin.server.UIClassSelectionEvent;
+import com.vaadin.server.UIProvider;
+import com.vaadin.ui.UI;
+
+/**
+ * Vaadin {@link com.vaadin.server.UIProvider} that provides a single {@link UI}
+ * class provided through the registration of a {@link UI} as an OSGi service.
+ * <p>
+ * This only applies to Liferay Portal 7+ with OSGi support.
+ *
+ * @author Sampsa Sohlman
+ *
+ * @since 8.1
+ */
+@SuppressWarnings("serial")
+public class OsgiUIProvider extends UIProvider {
+ private Class<UI> uiClass;
+
+ @SuppressWarnings("unchecked")
+ public OsgiUIProvider(ServiceObjects<UI> serviceObjects) {
+ super();
+ UI ui = serviceObjects.getService();
+ uiClass = (Class<UI>) ui.getClass();
+ serviceObjects.ungetService(ui);
+ }
+
+ @Override
+ public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
+ return uiClass;
+ }
+
+ public String getDefaultPortletName() {
+ return uiClass.getName();
+ }
+
+ public String getDefaultDisplayName() {
+ return uiClass.getSimpleName();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.osgi.liferay;
+
+import com.vaadin.server.DeploymentConfiguration;
+import com.vaadin.server.ServiceException;
+import com.vaadin.server.VaadinPortlet;
+import com.vaadin.server.VaadinPortletService;
+import com.vaadin.ui.UI;
+
+/**
+ * {@link VaadinPortlet} that uses an {@link OsgiUIProvider} to configure its
+ * {@link UI}.
+ * <p>
+ * This only applies to Liferay Portal 7+ with OSGi support.
+ *
+ * @author Sampsa Sohlman
+ *
+ * @since 8.1
+ */
+@SuppressWarnings("serial")
+public class OsgiVaadinPortlet extends VaadinPortlet {
+ private OsgiUIProvider uiProvider;
+
+ public OsgiVaadinPortlet(OsgiUIProvider uiProvider) {
+ this.uiProvider = uiProvider;
+ }
+
+ @Override
+ protected VaadinPortletService createPortletService(
+ DeploymentConfiguration configuration) throws ServiceException {
+ OsgiVaadinPortletService osgiVaadinPortletService = new OsgiVaadinPortletService(
+ this, configuration, uiProvider);
+ osgiVaadinPortletService.init();
+ return osgiVaadinPortletService;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.osgi.liferay;
+
+import com.vaadin.server.DeploymentConfiguration;
+import com.vaadin.server.ServiceException;
+import com.vaadin.server.VaadinPortlet;
+import com.vaadin.server.VaadinPortletService;
+import com.vaadin.server.VaadinPortletSession;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.ui.UI;
+
+/**
+ * {@link VaadinPortletService} class that uses the {@link OsgiUIProvider} to
+ * configure the {@link UI} class for a {@link VaadinPortlet}.
+ * <p>
+ * This only applies to Liferay Portal 7+ with OSGi support.
+ *
+ * @author Sampsa Sohlman
+ *
+ * @since 8.1
+ */
+@SuppressWarnings("serial")
+public class OsgiVaadinPortletService extends VaadinPortletService {
+ private OsgiUIProvider osgiUIProvider;
+
+ public OsgiVaadinPortletService(VaadinPortlet portlet,
+ DeploymentConfiguration deploymentConfiguration,
+ OsgiUIProvider osgiUIProvider) throws ServiceException {
+
+ super(portlet, deploymentConfiguration);
+ this.osgiUIProvider = osgiUIProvider;
+ }
+
+ @Override
+ protected VaadinSession createVaadinSession(VaadinRequest request)
+ throws ServiceException {
+
+ VaadinSession vaadinSession = new VaadinPortletSession(this);
+ vaadinSession.addUIProvider(osgiUIProvider);
+
+ return vaadinSession;
+ }
+
+}
ServiceObjects<UI> serviceObjects = bundleContext
.getServiceObjects(reference);
- OSGiUIProvider uiProvider = new OSGiUIProvider(serviceObjects);
+ OsgiUIProvider uiProvider = new OsgiUIProvider(serviceObjects);
Dictionary<String, Object> properties = null;
if (configuration != null) {
properties = createPortletProperties(reference);
}
- VaadinOSGiPortlet portlet = new VaadinOSGiPortlet(uiProvider);
+ OsgiVaadinPortlet portlet = new OsgiVaadinPortlet(uiProvider);
ServiceRegistration<Portlet> serviceRegistration = bundleContext
.registerService(Portlet.class, portlet, properties);
}
private Dictionary<String, Object> createPortletProperties(
- OSGiUIProvider uiProvider, ServiceReference<UI> reference,
+ OsgiUIProvider uiProvider, ServiceReference<UI> reference,
VaadinLiferayPortletConfiguration configuration) {
Hashtable<String, Object> properties = new Hashtable<String, Object>();
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.osgi.liferay;
-
-import com.vaadin.server.DeploymentConfiguration;
-import com.vaadin.server.ServiceException;
-import com.vaadin.server.VaadinPortlet;
-import com.vaadin.server.VaadinPortletService;
-import com.vaadin.ui.UI;
-
-/**
- * {@link VaadinPortlet} that uses an {@link OSGiUIProvider} to configure its
- * {@link UI}.
- * <p>
- * This only applies to Liferay Portal 7+ with OSGi support.
- *
- * @author Sampsa Sohlman
- *
- * @since 8.1
- */
-@SuppressWarnings("serial")
-public class VaadinOSGiPortlet extends VaadinPortlet {
- private OSGiUIProvider uiProvider;
-
- public VaadinOSGiPortlet(OSGiUIProvider uiProvider) {
- this.uiProvider = uiProvider;
- }
-
- @Override
- protected VaadinPortletService createPortletService(
- DeploymentConfiguration configuration) throws ServiceException {
- OSGiVaadinPortletService osgiVaadinPortletService = new OSGiVaadinPortletService(
- this, configuration, uiProvider);
- osgiVaadinPortletService.init();
- return osgiVaadinPortletService;
- }
-}
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.util.tracker.ServiceTracker;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
import com.vaadin.ui.UI;
@Activate
void activate(ComponentContext componentContext) throws Exception {
BundleContext bundleContext = componentContext.getBundleContext();
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
portletUIServiceTrackerCustomizer = new PortletUIServiceTrackerCustomizer(
service);
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.osgi.service.log.LogService;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
-import com.vaadin.osgi.resources.OSGiVaadinResources.ResourceBundleInactiveException;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources.ResourceBundleInactiveException;
import com.vaadin.osgi.resources.VaadinResourceService;
import com.vaadin.server.Constants;
import com.vaadin.server.VaadinServlet;
}
private String getResourcePath() throws ResourceBundleInactiveException {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
return String.format("/%s", service.getResourcePathPrefix());
}
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
@Component(immediate = true)
@Activate
void startup(ComponentContext context) throws Exception {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
for (String resourceName : RESOURCES) {
service.publishResource(resourceName, httpService);
}
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
-import com.vaadin.osgi.resources.OSGiVaadinResources.ResourceBundleInactiveException;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources.ResourceBundleInactiveException;
import com.vaadin.osgi.resources.VaadinResourceService;
/**
@Activate
void startup() throws NamespaceException, ResourceBundleInactiveException {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
for (String resourceName : RESOURCES) {
service.publishResource(resourceName, httpService);
}
Bundle-SymbolicName: ${project.groupId}.shared
-Bundle-Activator: com.vaadin.osgi.resources.OSGiVaadinResources
+Bundle-Activator: com.vaadin.osgi.resources.OsgiVaadinResources
Bundle-Name: Vaadin Shared
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.osgi.resources;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-
-import com.vaadin.osgi.resources.impl.VaadinResourceServiceImpl;
-
-/**
- * {@link BundleActivator} used to provide access to the
- * {@link VaadinResourceService} singleton for publishing themes, widgetsets and
- * other necessary resources.
- *
- * @author Vaadin Ltd.
- *
- * @since 8.1
- */
-public class OSGiVaadinResources implements BundleActivator {
-
- /**
- * Thrown if a method is called when the Resource bundle is not active.
- *
- * @author Vaadin Ltd.
- *
- * @since 8.1
- */
- @SuppressWarnings("serial")
- public static class ResourceBundleInactiveException extends Exception {
- public ResourceBundleInactiveException(String message) {
- super(message);
- }
- }
-
- private static OSGiVaadinResources instance;
-
- private VaadinResourceServiceImpl service;
- private Version version;
-
- /**
- * Returns the {@link VaadinResourceService} instance. Always returns
- * non-null.
- *
- * @return the {@link VaadinResourceService resource service} to use for
- * publishing themes, widgetsets and other necessary resources
- * @throws ResourceBundleInactiveException
- * if the bundle is not active
- */
- public static VaadinResourceService getService()
- throws ResourceBundleInactiveException {
- if (instance == null) {
- throw new ResourceBundleInactiveException(
- "Vaadin Shared is not active!");
- }
- return instance.service;
- }
-
- @Override
- public void start(BundleContext context) throws Exception {
- version = context.getBundle().getVersion();
- service = new VaadinResourceServiceImpl();
- service.setBundleVersion(version.toString());
- instance = this;
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- instance = null;
- service = null;
- version = null;
- }
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.osgi.resources;
-
-/**
- * Used to declare a Vaadin Theme for use in OSGi. The theme is expected to be
- * in the same OSGi bundle as the class implementing this interface, under the
- * path "/VAADIN/themes/{themeName}" where {themeName} is what is returned by
- * {@link OSGiVaadinTheme#getName()}.
- * <p>
- * To publish a theme, an implementation of this interface needs to be
- * registered as an OSGi service, which makes
- * <code>VaadinResourceTrackerComponent</code> automatically publish the theme
- * with the given name.
- *
- * @author Vaadin Ltd.
- *
- * @since 8.1
- */
-public interface OSGiVaadinTheme {
- public String getName();
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.osgi.resources;
-
-/**
- * Used to declare a Vaadin Widgetset for use in OSGi. The widgetset is expected
- * to be in the same OSGi bundle as the class implementing this interface, under
- * the path "/VAADIN/widgetsets/{widgetsetName}" where {widgetsetName} is what
- * is returned by {@link OSGiVaadinWidgetset#getName()}.
- * <p>
- * To publish a widgetset, an implementation of this interface needs to be
- * registered as an OSGi service, which makes
- * <code>VaadinResourceTrackerComponent</code> automatically publish the
- * widgetset with the given name.
- *
- * @author Vaadin Ltd.
- *
- * @since 8.1
- */
-public interface OSGiVaadinWidgetset {
- public String getName();
-}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.osgi.resources;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+
+import com.vaadin.osgi.resources.impl.VaadinResourceServiceImpl;
+
+/**
+ * {@link BundleActivator} used to provide access to the
+ * {@link VaadinResourceService} singleton for publishing themes, widgetsets and
+ * other necessary resources.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @since 8.1
+ */
+public class OsgiVaadinResources implements BundleActivator {
+
+ /**
+ * Thrown if a method is called when the Resource bundle is not active.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @since 8.1
+ */
+ @SuppressWarnings("serial")
+ public static class ResourceBundleInactiveException extends Exception {
+ public ResourceBundleInactiveException(String message) {
+ super(message);
+ }
+ }
+
+ private static OsgiVaadinResources instance;
+
+ private VaadinResourceServiceImpl service;
+ private Version version;
+
+ /**
+ * Returns the {@link VaadinResourceService} instance. Always returns
+ * non-null.
+ *
+ * @return the {@link VaadinResourceService resource service} to use for
+ * publishing themes, widgetsets and other necessary resources
+ * @throws ResourceBundleInactiveException
+ * if the bundle is not active
+ */
+ public static VaadinResourceService getService()
+ throws ResourceBundleInactiveException {
+ if (instance == null) {
+ throw new ResourceBundleInactiveException(
+ "Vaadin Shared is not active!");
+ }
+ return instance.service;
+ }
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ version = context.getBundle().getVersion();
+ service = new VaadinResourceServiceImpl();
+ service.setBundleVersion(version.toString());
+ instance = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ instance = null;
+ service = null;
+ version = null;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.osgi.resources;
+
+/**
+ * Used to declare a Vaadin Theme for use in OSGi. The theme is expected to be
+ * in the same OSGi bundle as the class implementing this interface, under the
+ * path "/VAADIN/themes/{themeName}" where {themeName} is what is returned by
+ * {@link OsgiVaadinTheme#getName()}.
+ * <p>
+ * To publish a theme, an implementation of this interface needs to be
+ * registered as an OSGi service, which makes
+ * <code>VaadinResourceTrackerComponent</code> automatically publish the theme
+ * with the given name.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @since 8.1
+ */
+public interface OsgiVaadinTheme {
+ /**
+ * Return the theme name to publish for OSGi.
+ *
+ * @return theme name, not null
+ */
+ public String getName();
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.osgi.resources;
+
+/**
+ * Used to declare a Vaadin Widgetset for use in OSGi. The widgetset is expected
+ * to be in the same OSGi bundle as the class implementing this interface, under
+ * the path "/VAADIN/widgetsets/{widgetsetName}" where {widgetsetName} is what
+ * is returned by {@link OsgiVaadinWidgetset#getName()}.
+ * <p>
+ * To publish a widgetset, an implementation of this interface needs to be
+ * registered as an OSGi service, which makes
+ * <code>VaadinResourceTrackerComponent</code> automatically publish the
+ * widgetset with the given name.
+ *
+ * @author Vaadin Ltd.
+ *
+ * @since 8.1
+ */
+public interface OsgiVaadinWidgetset {
+ /**
+ * Return the widgetset name to publish for OSGi.
+ *
+ * @return widgetset name, not null
+ */
+ public String getName();
+}
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
-import com.vaadin.osgi.resources.OSGiVaadinResources.ResourceBundleInactiveException;
-import com.vaadin.osgi.resources.OSGiVaadinTheme;
-import com.vaadin.osgi.resources.OSGiVaadinWidgetset;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources.ResourceBundleInactiveException;
+import com.vaadin.osgi.resources.OsgiVaadinTheme;
+import com.vaadin.osgi.resources.OsgiVaadinWidgetset;
import com.vaadin.osgi.resources.VaadinResourceService;
/**
- * Tracks {@link OSGiVaadinWidgetset} and {@link OSGiVaadinTheme} registration
+ * Tracks {@link OsgiVaadinWidgetset} and {@link OsgiVaadinTheme} registration
* and uses {@link HttpService} to register them.
*
* @author Vaadin Ltd.
private Map<Long, String> widgetsetToAlias = Collections
.synchronizedMap(new LinkedHashMap<>());
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OSGiVaadinTheme.class, policy = ReferencePolicy.DYNAMIC)
- void bindTheme(ServiceReference<OSGiVaadinTheme> themeRef)
+ @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinTheme.class, policy = ReferencePolicy.DYNAMIC)
+ void bindTheme(ServiceReference<OsgiVaadinTheme> themeRef)
throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = themeRef.getBundle();
BundleContext context = bundle.getBundleContext();
- OSGiVaadinTheme theme = context.getService(themeRef);
+ OsgiVaadinTheme theme = context.getService(themeRef);
if (theme == null)
return;
- VaadinResourceService resourceService = OSGiVaadinResources
+ VaadinResourceService resourceService = OsgiVaadinResources
.getService();
try {
}
}
- void unbindTheme(ServiceReference<OSGiVaadinTheme> themeRef) {
+ void unbindTheme(ServiceReference<OsgiVaadinTheme> themeRef) {
Long serviceId = (Long) themeRef.getProperty(Constants.SERVICE_ID);
String themeAlias = themeToAlias.remove(serviceId);
if (themeAlias != null && httpService != null) {
}
}
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OSGiVaadinWidgetset.class, policy = ReferencePolicy.DYNAMIC)
- void bindWidgetset(ServiceReference<OSGiVaadinWidgetset> widgetsetRef)
+ @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinWidgetset.class, policy = ReferencePolicy.DYNAMIC)
+ void bindWidgetset(ServiceReference<OsgiVaadinWidgetset> widgetsetRef)
throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = widgetsetRef.getBundle();
BundleContext context = bundle.getBundleContext();
- OSGiVaadinWidgetset widgetset = context.getService(widgetsetRef);
+ OsgiVaadinWidgetset widgetset = context.getService(widgetsetRef);
if (widgetset == null)
return;
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
try {
String pathPrefix = service.getResourcePathPrefix();
}
- void unbindWidgetset(ServiceReference<OSGiVaadinWidgetset> widgetsetRef) {
+ void unbindWidgetset(ServiceReference<OsgiVaadinWidgetset> widgetsetRef) {
Long serviceId = (Long) widgetsetRef.getProperty(Constants.SERVICE_ID);
String widgetsetAlias = widgetsetToAlias.remove(serviceId);
if (widgetsetAlias != null && httpService != null) {
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
-import com.vaadin.osgi.resources.OSGiVaadinResources;
+import com.vaadin.osgi.resources.OsgiVaadinResources;
import com.vaadin.osgi.resources.VaadinResourceService;
@Component(immediate = true)
@Activate
void startup() throws Exception {
- VaadinResourceService service = OSGiVaadinResources.getService();
+ VaadinResourceService service = OsgiVaadinResources.getService();
service.publishTheme("valo", httpService);
}