From e788fa906b968a298414e60cbb15cc7d6389b8a1 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Mon, 15 May 2017 22:34:43 +0300 Subject: Rename OSGi classes for Java naming conventions (#9320) - Rename OSGi to Osgi in class names. - Rename VaadinOSGiPortlet to OSGiVaadinPortlet for consistency with Spring, CDI etc. add-ons - Add missing javadoc --- .../vaadin/osgi/resources/OSGiVaadinResources.java | 86 ---------------------- .../com/vaadin/osgi/resources/OSGiVaadinTheme.java | 35 --------- .../vaadin/osgi/resources/OSGiVaadinWidgetset.java | 35 --------- .../vaadin/osgi/resources/OsgiVaadinResources.java | 86 ++++++++++++++++++++++ .../com/vaadin/osgi/resources/OsgiVaadinTheme.java | 40 ++++++++++ .../vaadin/osgi/resources/OsgiVaadinWidgetset.java | 40 ++++++++++ .../impl/VaadinResourceTrackerComponent.java | 30 ++++---- 7 files changed, 181 insertions(+), 171 deletions(-) delete mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java delete mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinTheme.java delete mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinWidgetset.java create mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java create mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinTheme.java create mode 100644 shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinWidgetset.java (limited to 'shared/src/main/java/com/vaadin/osgi') diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java b/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java deleted file mode 100644 index 96f6f997ca..0000000000 --- a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinResources.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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; - } -} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinTheme.java b/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinTheme.java deleted file mode 100644 index 852dd93294..0000000000 --- a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinTheme.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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()}. - *

- * To publish a theme, an implementation of this interface needs to be - * registered as an OSGi service, which makes - * VaadinResourceTrackerComponent automatically publish the theme - * with the given name. - * - * @author Vaadin Ltd. - * - * @since 8.1 - */ -public interface OSGiVaadinTheme { - public String getName(); -} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinWidgetset.java b/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinWidgetset.java deleted file mode 100644 index c594443687..0000000000 --- a/shared/src/main/java/com/vaadin/osgi/resources/OSGiVaadinWidgetset.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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()}. - *

- * To publish a widgetset, an implementation of this interface needs to be - * registered as an OSGi service, which makes - * VaadinResourceTrackerComponent automatically publish the - * widgetset with the given name. - * - * @author Vaadin Ltd. - * - * @since 8.1 - */ -public interface OSGiVaadinWidgetset { - public String getName(); -} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java new file mode 100644 index 0000000000..a423791193 --- /dev/null +++ b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java @@ -0,0 +1,86 @@ +/* + * 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; + } +} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinTheme.java b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinTheme.java new file mode 100644 index 0000000000..0b4866b619 --- /dev/null +++ b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinTheme.java @@ -0,0 +1,40 @@ +/* + * 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()}. + *

+ * To publish a theme, an implementation of this interface needs to be + * registered as an OSGi service, which makes + * VaadinResourceTrackerComponent 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(); +} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinWidgetset.java b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinWidgetset.java new file mode 100644 index 0000000000..81e957ea5a --- /dev/null +++ b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinWidgetset.java @@ -0,0 +1,40 @@ +/* + * 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()}. + *

+ * To publish a widgetset, an implementation of this interface needs to be + * registered as an OSGi service, which makes + * VaadinResourceTrackerComponent 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(); +} diff --git a/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java b/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java index 0cf6aaeb18..adbde7d798 100644 --- a/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java +++ b/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java @@ -36,14 +36,14 @@ import org.osgi.service.http.HttpContext; 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. @@ -59,18 +59,18 @@ public class VaadinResourceTrackerComponent { private Map widgetsetToAlias = Collections .synchronizedMap(new LinkedHashMap<>()); - @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OSGiVaadinTheme.class, policy = ReferencePolicy.DYNAMIC) - void bindTheme(ServiceReference themeRef) + @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinTheme.class, policy = ReferencePolicy.DYNAMIC) + void bindTheme(ServiceReference 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 { @@ -90,7 +90,7 @@ public class VaadinResourceTrackerComponent { } } - void unbindTheme(ServiceReference themeRef) { + void unbindTheme(ServiceReference themeRef) { Long serviceId = (Long) themeRef.getProperty(Constants.SERVICE_ID); String themeAlias = themeToAlias.remove(serviceId); if (themeAlias != null && httpService != null) { @@ -98,17 +98,17 @@ public class VaadinResourceTrackerComponent { } } - @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OSGiVaadinWidgetset.class, policy = ReferencePolicy.DYNAMIC) - void bindWidgetset(ServiceReference widgetsetRef) + @Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinWidgetset.class, policy = ReferencePolicy.DYNAMIC) + void bindWidgetset(ServiceReference 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(); @@ -129,7 +129,7 @@ public class VaadinResourceTrackerComponent { } - void unbindWidgetset(ServiceReference widgetsetRef) { + void unbindWidgetset(ServiceReference widgetsetRef) { Long serviceId = (Long) widgetsetRef.getProperty(Constants.SERVICE_ID); String widgetsetAlias = widgetsetToAlias.remove(serviceId); if (widgetsetAlias != null && httpService != null) { -- cgit v1.2.3