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;
private final boolean productionMode;
- private final ClassLoader classLoader;
-
/**
* @param applicationUrl
* the URL the application should respond to.
* @param productionMode
* flag indicating whether the application is running in
* production mode.
- * @param classLoader
- * class loader to use for loading Root classes,
- * <code>null</code> 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;
}
/**
public boolean isProductionMode() {
return productionMode;
}
-
- /**
- * Gets the class loader to use for loading Root classes,
- * <code>null</code> indicates that the default class loader should be
- * used.
- *
- * @return the class loader, or <code>null</code> if not defined.
- *
- * @see Application#getClassLoader()
- */
- public ClassLoader getClassLoader() {
- return classLoader;
- }
}
private final static Logger logger = Logger.getLogger(Application.class
*/
private Set<Integer> initedRoots = new HashSet<Integer>();
- /**
- * The classloader that is used to load {@link Root} classes.
- */
- private ClassLoader classLoader;
-
/**
* Gets the user of the application.
*
productionMode = event.isProductionMode();
properties = event.getApplicationProperties();
context = event.getContext();
- classLoader = event.getClassLoader();
init();
applicationIsRunning = true;
}
* 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.
* </p>
*
* @param request
throws RootRequiresMoreInformationException {
String rootClassName = getRootClassName(request);
try {
- ClassLoader classLoader = getClassLoader();
+ ClassLoader classLoader = request.getDeploymentConfiguration()
+ .getClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
}
}
- /**
- * Get the class loader to use for loading Root classes. <code>null</code>
- * indicates that the default class loader should be used.
- *
- * @return the class loader to use, or <code>null</code>
- */
- protected ClassLoader getClassLoader() {
- return classLoader;
- }
-
/**
* Provides the name of the <code>Root</code> class that should be used for
* a request. The class must have an accessible no-args constructor.
*/
public String getApplicationOrSystemProperty(String propertyName,
String defaultValue);
+
+ /**
+ * Get the class loader to use for loading classes loaded by name, e.g.
+ * custom Root classes. <code>null</code> indicates that the default class
+ * loader should be used.
+ *
+ * @return the class loader to use, or <code>null</code>
+ */
+ public ClassLoader getClassLoader();
}
return "/html";
}
}
+
+ public ClassLoader getClassLoader() {
+ // Custom class loaders not currently supported in portlets (see
+ // #8574)
+ return null;
+ }
};
@Override
application.setLocale(locale);
// No application URL when running inside a portlet
application.start(new ApplicationStartEvent(null,
- applicationProperties, context, isProductionMode(), null));
+ applicationProperties, context, isProductionMode()));
}
}
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/";
application.setLocale(locale);
application.start(new ApplicationStartEvent(applicationUrl,
applicationProperties, webApplicationContext,
- isProductionMode(), getClassLoader()));
+ isProductionMode()));
}
}
app.start(new ApplicationStartEvent(new URL(
"http://localhost/"), new Properties(),
- context, true, null));
+ context, true));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
import com.vaadin.Application;
import com.vaadin.Application.ApplicationStartEvent;
import com.vaadin.RootRequiresMoreInformationException;
+import com.vaadin.terminal.DeploymentConfiguration;
import com.vaadin.terminal.WrappedRequest;
import com.vaadin.ui.Root;
public void testWithNullClassLoader() throws Exception {
Application application = createStubApplication();
application.start(new ApplicationStartEvent(null, new Properties(),
- null, false, null));
+ null, false));
- Root root = application.getRootForRequest(null);
+ Root root = application.getRootForRequest(createRequestMock(null));
assertTrue(root instanceof MyRoot);
}
+ private static WrappedRequest createRequestMock(ClassLoader classloader) {
+ // Mock a DeploymentConfiguration to give the passed classloader
+ DeploymentConfiguration configurationMock = EasyMock
+ .createMock(DeploymentConfiguration.class);
+ EasyMock.expect(configurationMock.getClassLoader()).andReturn(
+ classloader);
+
+ // Mock a WrappedRequest to give the mocked deployment configuration
+ WrappedRequest requestMock = EasyMock.createMock(WrappedRequest.class);
+ EasyMock.expect(requestMock.getDeploymentConfiguration()).andReturn(
+ configurationMock);
+
+ EasyMock.replay(configurationMock, requestMock);
+ return requestMock;
+ }
+
/**
* Tests that the ClassLoader passed in the ApplicationStartEvent is used to
* load Root classes.
Application application = createStubApplication();
application.start(new ApplicationStartEvent(null, new Properties(),
- null, false, loggingClassLoader));
+ null, false));
- Root root = application.getRootForRequest(null);
+ Root root = application
+ .getRootForRequest(createRequestMock(loggingClassLoader));
assertTrue(root instanceof MyRoot);
assertEquals(1, loggingClassLoader.requestedClasses.size());
assertEquals(MyRoot.class.getName(),
thisPackage = thisPackage.replaceAll(
CustomLayoutUsingTemplate.class.getSimpleName() + "$", "");
String template = thisPackage + "template.htm";
- InputStream is = getClassLoader().getResourceAsStream(template);
+ InputStream is = getClass().getClassLoader().getResourceAsStream(
+ template);
try {
layout = new CustomLayout(is);
layout.addComponent(new Button(