From 4155cb0d2c9e9ebe27d726ac38227ff7f0648bd7 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 16 Apr 2012 13:00:52 +0300 Subject: Remove classloader field to make Application serializable (#8644) The ClassLoader for loading Root instances is instead fetched using request.getDeploymentConfiguration().getClassLoader(); --- src/com/vaadin/Application.java | 48 ++++------------------ .../vaadin/terminal/DeploymentConfiguration.java | 9 ++++ .../gwt/server/AbstractApplicationPortlet.java | 8 +++- .../gwt/server/AbstractApplicationServlet.java | 10 ++++- 4 files changed, 32 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index 448daea4c0..4da1d52c00 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -40,6 +40,7 @@ import com.vaadin.service.ApplicationContext; import com.vaadin.terminal.AbstractErrorMessage; import com.vaadin.terminal.ApplicationResource; import com.vaadin.terminal.CombinedRequest; +import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.RequestHandler; import com.vaadin.terminal.Terminal; import com.vaadin.terminal.VariableOwner; @@ -343,8 +344,6 @@ public class Application implements Terminal.ErrorListener, Serializable { private final boolean productionMode; - private final ClassLoader classLoader; - /** * @param applicationUrl * the URL the application should respond to. @@ -356,19 +355,14 @@ public class Application implements Terminal.ErrorListener, Serializable { * @param productionMode * flag indicating whether the application is running in * production mode. - * @param classLoader - * class loader to use for loading Root classes, - * null indicates that the default class loader - * should be used. */ public ApplicationStartEvent(URL applicationUrl, Properties applicationProperties, ApplicationContext context, - boolean productionMode, ClassLoader classLoader) { + boolean productionMode) { this.applicationUrl = applicationUrl; this.applicationProperties = applicationProperties; this.context = context; this.productionMode = productionMode; - this.classLoader = classLoader; } /** @@ -417,19 +411,6 @@ public class Application implements Terminal.ErrorListener, Serializable { public boolean isProductionMode() { return productionMode; } - - /** - * Gets the class loader to use for loading Root classes, - * null indicates that the default class loader should be - * used. - * - * @return the class loader, or null if not defined. - * - * @see Application#getClassLoader() - */ - public ClassLoader getClassLoader() { - return classLoader; - } } private final static Logger logger = Logger.getLogger(Application.class @@ -521,11 +502,6 @@ public class Application implements Terminal.ErrorListener, Serializable { */ private Set initedRoots = new HashSet(); - /** - * The classloader that is used to load {@link Root} classes. - */ - private ClassLoader classLoader; - /** * Gets the user of the application. * @@ -640,7 +616,6 @@ public class Application implements Terminal.ErrorListener, Serializable { productionMode = event.isProductionMode(); properties = event.getApplicationProperties(); context = event.getContext(); - classLoader = event.getClassLoader(); init(); applicationIsRunning = true; } @@ -1867,9 +1842,9 @@ public class Application implements Terminal.ErrorListener, Serializable { * The default implementation in {@link Application} creates a new instance * of the Root class returned by {@link #getRootClassName(WrappedRequest)}, * which in turn uses the {@value #ROOT_PARAMETER} parameter from web.xml. - * If {@link #getClassLoader()} returns a {@link ClassLoader}, it is used - * for loading the Root class. Otherwise the {@link ClassLoader} used to - * load this class is used. + * If {@link DeploymentConfiguration#getClassLoader()} for the request + * returns a {@link ClassLoader}, it is used for loading the Root class. + * Otherwise the {@link ClassLoader} used to load this class is used. *

* * @param request @@ -1890,7 +1865,8 @@ public class Application implements Terminal.ErrorListener, Serializable { throws RootRequiresMoreInformationException { String rootClassName = getRootClassName(request); try { - ClassLoader classLoader = getClassLoader(); + ClassLoader classLoader = request.getDeploymentConfiguration() + .getClassLoader(); if (classLoader == null) { classLoader = getClass().getClassLoader(); } @@ -1909,16 +1885,6 @@ public class Application implements Terminal.ErrorListener, Serializable { } } - /** - * Get the class loader to use for loading Root classes. null - * indicates that the default class loader should be used. - * - * @return the class loader to use, or null - */ - protected ClassLoader getClassLoader() { - return classLoader; - } - /** * Provides the name of the Root class that should be used for * a request. The class must have an accessible no-args constructor. diff --git a/src/com/vaadin/terminal/DeploymentConfiguration.java b/src/com/vaadin/terminal/DeploymentConfiguration.java index 403a6d68b7..02a3f0200f 100644 --- a/src/com/vaadin/terminal/DeploymentConfiguration.java +++ b/src/com/vaadin/terminal/DeploymentConfiguration.java @@ -74,4 +74,13 @@ public interface DeploymentConfiguration extends Serializable { */ public String getApplicationOrSystemProperty(String propertyName, String defaultValue); + + /** + * Get the class loader to use for loading classes loaded by name, e.g. + * custom Root classes. null indicates that the default class + * loader should be used. + * + * @return the class loader to use, or null + */ + public ClassLoader getClassLoader(); } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 72a0432f4b..8235859758 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -287,6 +287,12 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet return "/html"; } } + + public ClassLoader getClassLoader() { + // Custom class loaders not currently supported in portlets (see + // #8574) + return null; + } }; @Override @@ -857,7 +863,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet application.setLocale(locale); // No application URL when running inside a portlet application.start(new ApplicationStartEvent(null, - applicationProperties, context, isProductionMode(), null)); + applicationProperties, context, isProductionMode())); } } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index c295e05ed7..18cc3f97f4 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -171,6 +171,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements public boolean isStandalone(WrappedRequest request) { return true; } + + public ClassLoader getClassLoader() { + try { + return AbstractApplicationServlet.this.getClassLoader(); + } catch (ServletException e) { + throw new RuntimeException(e); + } + } }; static final String UPLOAD_URL_PREFIX = "APP/UPLOAD/"; @@ -1037,7 +1045,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements application.setLocale(locale); application.start(new ApplicationStartEvent(applicationUrl, applicationProperties, webApplicationContext, - isProductionMode(), getClassLoader())); + isProductionMode())); } } -- cgit v1.2.3