From fb8cf5cb457f6fe95bd3b07d2fb1a1fb03a3be8f Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Fri, 21 Sep 2012 16:51:20 +0300 Subject: Allow specifying UIProvider using a servlet parameter (#9628) --- server/src/com/vaadin/server/Constants.java | 1 + .../com/vaadin/server/ServletPortletHelper.java | 46 ++++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) (limited to 'server/src') 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 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, -- cgit v1.2.3