summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-12-19 15:04:14 +0200
committerLeif Åstrand <leif@vaadin.com>2011-12-19 15:18:58 +0200
commitc8c54307c7d55ed79ed4cfe02e111c67829d19cd (patch)
tree6a8386a2815f9e845e51ec879d5565fc6ec93be6 /src
parente95377822a44324dc71b070752b7464e78d68e7e (diff)
downloadvaadin-framework-c8c54307c7d55ed79ed4cfe02e111c67829d19cd.tar.gz
vaadin-framework-c8c54307c7d55ed79ed4cfe02e111c67829d19cd.zip
#8052 Support for root instead of application in portlet.xml
Moved some code shared with servlet to a new static helper class
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java20
-rw-r--r--src/com/vaadin/terminal/gwt/server/ApplicationServlet.java54
-rw-r--r--src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java67
3 files changed, 81 insertions, 60 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java
index 3e15c1cf8f..7a46a07e6c 100644
--- a/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java
+++ b/src/com/vaadin/terminal/gwt/server/ApplicationPortlet2.java
@@ -8,6 +8,7 @@ import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import com.vaadin.Application;
+import com.vaadin.terminal.gwt.server.ServletPortletHelper.ApplicationClassException;
/**
* TODO Write documentation, fix JavaDoc tags.
@@ -18,23 +19,16 @@ public class ApplicationPortlet2 extends AbstractApplicationPortlet {
private Class<? extends Application> applicationClass;
- @SuppressWarnings("unchecked")
@Override
public void init(PortletConfig config) throws PortletException {
super.init(config);
- final String applicationClassName = config
- .getInitParameter("application");
- if (applicationClassName == null) {
- throw new PortletException(
- "Application not specified in portlet parameters");
- }
-
try {
- applicationClass = (Class<? extends Application>) getClassLoader()
- .loadClass(applicationClassName);
- } catch (final ClassNotFoundException e) {
- throw new PortletException("Failed to load application class: "
- + applicationClassName);
+ applicationClass = ServletPortletHelper.getApplicationClass(
+ config.getInitParameter("application"),
+ config.getInitParameter(Application.ROOT_PARAMETER),
+ getClassLoader());
+ } catch (ApplicationClassException e) {
+ throw new PortletException(e);
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java
index 724977b409..2c4d38ef24 100644
--- a/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java
@@ -8,7 +8,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import com.vaadin.Application;
-import com.vaadin.ui.Root;
+import com.vaadin.terminal.gwt.server.ServletPortletHelper.ApplicationClassException;
/**
* This servlet connects a Vaadin Application to Web.
@@ -44,53 +44,13 @@ public class ApplicationServlet extends AbstractApplicationServlet {
// Loads the application class using the same class loader
// as the servlet itself
- // Gets the application class name
- final String applicationClassName = servletConfig
- .getInitParameter("application");
- if (applicationClassName == null) {
- String rootParam = servletConfig
- .getInitParameter(Application.ROOT_PARAMETER);
-
- // Validate the parameter value
- verifyRootClass(rootParam);
-
- // Application can be used if a valid rootLayout is defined
- applicationClass = Application.class;
- return;
- }
-
try {
- applicationClass = (Class<? extends Application>) getClassLoader()
- .loadClass(applicationClassName);
- } catch (final ClassNotFoundException e) {
- throw new ServletException("Failed to load application class: "
- + applicationClassName);
- }
- }
-
- private void verifyRootClass(String className) throws ServletException {
- if (className == null) {
- throw new ServletException(Application.ROOT_PARAMETER
- + " servlet parameter not defined");
- }
-
- // Check that the root layout class can be found
- try {
- Class<?> rootClass = getClassLoader().loadClass(className);
- if (!Root.class.isAssignableFrom(rootClass)) {
- throw new ServletException(className
- + " does not implement Root");
- }
- // Try finding a default constructor, else throw exception
- rootClass.getConstructor();
- } catch (ClassNotFoundException e) {
- throw new ServletException(className + " could not be loaded", e);
- } catch (SecurityException e) {
- throw new ServletException("Could not access " + className
- + " class", e);
- } catch (NoSuchMethodException e) {
- throw new ServletException(className
- + " doesn't have a public no-args constructor");
+ applicationClass = ServletPortletHelper.getApplicationClass(
+ servletConfig.getInitParameter("application"),
+ servletConfig.getInitParameter(Application.ROOT_PARAMETER),
+ getClassLoader());
+ } catch (ApplicationClassException e) {
+ throw new ServletException(e);
}
}
diff --git a/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java b/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java
new file mode 100644
index 0000000000..e6282db7bd
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/server/ServletPortletHelper.java
@@ -0,0 +1,67 @@
+package com.vaadin.terminal.gwt.server;
+
+import com.vaadin.Application;
+import com.vaadin.ui.Root;
+
+class ServletPortletHelper {
+ public static class ApplicationClassException extends Exception {
+
+ public ApplicationClassException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ApplicationClassException(String message) {
+ super(message);
+ }
+ }
+
+ static Class<? extends Application> getApplicationClass(
+ String applicationParameter, String rootParameter,
+ ClassLoader classLoader) throws ApplicationClassException {
+ if (applicationParameter == null) {
+
+ // Validate the parameter value
+ verifyRootClass(rootParameter, classLoader);
+
+ // Application can be used if a valid rootLayout is defined
+ return Application.class;
+ }
+
+ try {
+ return (Class<? extends Application>) classLoader
+ .loadClass(applicationParameter);
+ } catch (final ClassNotFoundException e) {
+ throw new ApplicationClassException(
+ "Failed to load application class: " + applicationParameter,
+ e);
+ }
+ }
+
+ private static void verifyRootClass(String className,
+ ClassLoader classLoader) throws ApplicationClassException {
+ if (className == null) {
+ throw new ApplicationClassException(Application.ROOT_PARAMETER
+ + " init parameter not defined");
+ }
+
+ // Check that the root layout class can be found
+ try {
+ Class<?> rootClass = classLoader.loadClass(className);
+ if (!Root.class.isAssignableFrom(rootClass)) {
+ throw new ApplicationClassException(className
+ + " does not implement Root");
+ }
+ // Try finding a default constructor, else throw exception
+ rootClass.getConstructor();
+ } catch (ClassNotFoundException e) {
+ throw new ApplicationClassException(className
+ + " could not be loaded", e);
+ } catch (SecurityException e) {
+ throw new ApplicationClassException("Could not access " + className
+ + " class", e);
+ } catch (NoSuchMethodException e) {
+ throw new ApplicationClassException(className
+ + " doesn't have a public no-args constructor");
+ }
+ }
+}