aboutsummaryrefslogtreecommitdiffstats
path: root/shared/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/main')
-rw-r--r--shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java41
1 files changed, 28 insertions, 13 deletions
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 932de4e787..031b1d1432 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
@@ -67,7 +67,7 @@ public class VaadinResourceTrackerComponent {
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinTheme.class, policy = ReferencePolicy.DYNAMIC)
void bindTheme(ServiceReference<OsgiVaadinTheme> themeRef)
- throws ResourceBundleInactiveException {
+ throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = themeRef.getBundle();
BundleContext context = bundle.getBundleContext();
@@ -94,7 +94,7 @@ public class VaadinResourceTrackerComponent {
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinWidgetset.class, policy = ReferencePolicy.DYNAMIC)
void bindWidgetset(ServiceReference<OsgiVaadinWidgetset> widgetsetRef)
- throws ResourceBundleInactiveException {
+ throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = widgetsetRef.getBundle();
BundleContext context = bundle.getBundleContext();
@@ -120,7 +120,7 @@ public class VaadinResourceTrackerComponent {
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinResource.class, policy = ReferencePolicy.DYNAMIC)
void bindResource(ServiceReference<OsgiVaadinResource> resourceRef)
- throws ResourceBundleInactiveException {
+ throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = resourceRef.getBundle();
BundleContext context = bundle.getBundleContext();
@@ -180,7 +180,7 @@ public class VaadinResourceTrackerComponent {
Long serviceId = (Long) contributorRef
.getProperty(Constants.SERVICE_ID);
List<ServiceRegistration<? extends OsgiVaadinResource>> registrations = contributorToRegistrations
- .get(serviceId);
+ .remove(serviceId);
if (registrations != null) {
for (ServiceRegistration<? extends OsgiVaadinResource> reg : registrations) {
reg.unregister();
@@ -205,9 +205,7 @@ public class VaadinResourceTrackerComponent {
@Activate
protected void activate() throws NamespaceException {
for (Delegate registration : resourceToRegistration.values()) {
- registration.init(httpService);
- httpService.registerResources(registration.alias, registration.path,
- registration);
+ registerResource(registration);
}
}
@@ -231,7 +229,8 @@ public class VaadinResourceTrackerComponent {
}
private void registerTheme(VaadinResourceService resourceService,
- Bundle bundle, Long serviceId, OsgiVaadinTheme theme) {
+ Bundle bundle, Long serviceId, OsgiVaadinTheme theme)
+ throws NamespaceException {
String pathPrefix = resourceService.getResourcePathPrefix();
String alias = PathFormatHelper.getThemeAlias(theme.getName(),
@@ -242,7 +241,8 @@ public class VaadinResourceTrackerComponent {
}
private void registerWidget(VaadinResourceService resourceService,
- Bundle bundle, Long serviceId, OsgiVaadinWidgetset widgetset) {
+ Bundle bundle, Long serviceId, OsgiVaadinWidgetset widgetset)
+ throws NamespaceException {
String pathPrefix = resourceService.getResourcePathPrefix();
String alias = PathFormatHelper.getWidgetsetAlias(widgetset.getName(),
@@ -253,7 +253,8 @@ public class VaadinResourceTrackerComponent {
}
private void registerResource(VaadinResourceService resourceService,
- Bundle bundle, Long serviceId, OsgiVaadinResource resource) {
+ Bundle bundle, Long serviceId, OsgiVaadinResource resource)
+ throws NamespaceException {
String pathPrefix = resourceService.getResourcePathPrefix();
String alias = PathFormatHelper.getRootResourceAlias(resource.getName(),
@@ -264,9 +265,19 @@ public class VaadinResourceTrackerComponent {
}
private void registerResource(String alias, String path, Bundle bundle,
- Long serviceId) {
- resourceToRegistration.put(serviceId,
- new Delegate(alias, path, bundle));
+ Long serviceId) throws NamespaceException {
+ Delegate registration = new Delegate(alias, path, bundle);
+ resourceToRegistration.put(serviceId, registration);
+ registerResource(registration);
+ }
+
+ private void registerResource(Delegate registration)
+ throws NamespaceException {
+ if (this.httpService != null && !registration.isInitialized()) {
+ registration.init(httpService);
+ httpService.registerResources(registration.alias, registration.path,
+ registration);
+ }
}
private void unregisterResource(Long serviceId) {
@@ -297,6 +308,10 @@ public class VaadinResourceTrackerComponent {
context = service.createDefaultHttpContext();
}
+ public boolean isInitialized() {
+ return context != null;
+ }
+
@Override
public boolean handleSecurity(HttpServletRequest request,
HttpServletResponse response) throws IOException {