diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-09-21 16:51:20 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-09-21 16:51:20 +0300 |
commit | fb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f (patch) | |
tree | 60fba1a290003fb9c1d381222d5e83c8d250c170 /server/src | |
parent | 167ff2bcea28bb5ad4a9ccba4f2b5b9819371390 (diff) | |
download | vaadin-framework-fb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f.tar.gz vaadin-framework-fb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f.zip |
Allow specifying UIProvider using a servlet parameter (#9628)
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/server/Constants.java | 1 | ||||
-rw-r--r-- | server/src/com/vaadin/server/ServletPortletHelper.java | 46 |
2 files changed, 39 insertions, 8 deletions
diff --git a/server/src/com/vaadin/server/Constants.java b/server/src/com/vaadin/server/Constants.java index f516b4b9a6..60f7aa03d0 100644 --- a/server/src/com/vaadin/server/Constants.java +++ b/server/src/com/vaadin/server/Constants.java @@ -63,6 +63,7 @@ public interface Constants { static final String SERVLET_PARAMETER_RESOURCE_CACHE_TIME = "resourceCacheTime"; static final String SERVLET_PARAMETER_HEARTBEAT_RATE = "heartbeatRate"; static final String SERVLET_PARAMETER_CLOSE_IDLE_UIS = "closeIdleUIs"; + static final String SERVLET_PARAMETER_UI_PROVIDER = "UIProvider"; // Configurable parameter names static final String PARAMETER_VAADIN_RESOURCES = "Resources"; diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java index e504aa53fb..f408fffdb1 100644 --- a/server/src/com/vaadin/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/server/ServletPortletHelper.java @@ -119,18 +119,48 @@ class ServletPortletHelper implements Serializable { public static void initDefaultUIProvider(VaadinSession session, VaadinService vaadinService) throws ServiceException { - Properties initParameters = vaadinService.getDeploymentConfiguration() - .getInitParameters(); - String uiProperty = initParameters - .getProperty(VaadinSession.UI_PARAMETER); - if (uiProperty == null) { - uiProperty = initParameters.getProperty(VaadinSession.UI_PARAMETER - .toLowerCase()); - } + String uiProperty = vaadinService.getDeploymentConfiguration() + .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER, + null); + + // Add provider for UI parameter first to give it lower priority + // (providers are FILO) if (uiProperty != null) { verifyUIClass(uiProperty, vaadinService.getClassLoader()); vaadinService.addUIProvider(session, new DefaultUIProvider()); } + + String uiProviderProperty = vaadinService.getDeploymentConfiguration() + .getApplicationOrSystemProperty( + Constants.SERVLET_PARAMETER_UI_PROVIDER, null); + // Then add custom UI provider if defined + if (uiProviderProperty != null) { + UIProvider uiProvider = getUIProvider(uiProviderProperty, + vaadinService.getClassLoader()); + vaadinService.addUIProvider(session, uiProvider); + } + } + + private static UIProvider getUIProvider(String uiProviderProperty, + ClassLoader classLoader) throws ServiceException { + try { + Class<?> providerClass = classLoader.loadClass(uiProviderProperty); + Class<? extends UIProvider> subclass = providerClass + .asSubclass(UIProvider.class); + return subclass.newInstance(); + } catch (ClassNotFoundException e) { + throw new ServiceException("Could not load UIProvider class " + + uiProviderProperty, e); + } catch (ClassCastException e) { + throw new ServiceException("UIProvider class " + uiProviderProperty + + " does not extend UIProvider", e); + } catch (InstantiationException e) { + throw new ServiceException("Could not instantiate UIProvider " + + uiProviderProperty, e); + } catch (IllegalAccessException e) { + throw new ServiceException("Could not instantiate UIProvider " + + uiProviderProperty, e); + } } public static void checkUiProviders(VaadinSession session, |